implement default destination for boats
This commit is contained in:
parent
ed0989e2a1
commit
715fae59fc
@ -105,6 +105,7 @@ interface ChoiceBoatEvent extends Event{
|
||||
customProperties: {
|
||||
amount_seats: number,
|
||||
owner: number,
|
||||
default_destination: string,
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -125,6 +126,9 @@ function selectBoatChange() {
|
||||
const amount_seats = event.detail.customProperties.amount_seats;
|
||||
setMaxAmountRowers("newrower", amount_seats);
|
||||
|
||||
const destination = <HTMLSelectElement>document.querySelector('#destination');
|
||||
destination.value = event.detail.customProperties.default_destination;
|
||||
|
||||
if (event.detail.customProperties.owner){
|
||||
choiceObjects["newrower"].setChoiceByValue(event.detail.customProperties.owner+"");
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ CREATE TABLE IF NOT EXISTS "boat" (
|
||||
"year_built" INTEGER,
|
||||
"boatbuilder" TEXT,
|
||||
"default_shipmaster_only_steering" boolean default false not null,
|
||||
"default_location" text,
|
||||
"skull" boolean default true NOT NULL, -- false => riemen
|
||||
"external" boolean default false NOT NULL -- false => owned by different club
|
||||
);
|
||||
|
@ -13,6 +13,7 @@ pub struct Boat {
|
||||
pub owner: Option<i64>,
|
||||
pub year_built: Option<i64>,
|
||||
pub boatbuilder: Option<String>,
|
||||
pub default_destination: Option<String>,
|
||||
#[serde(default = "bool::default")]
|
||||
default_shipmaster_only_steering: bool,
|
||||
#[serde(default = "bool::default")]
|
||||
@ -21,7 +22,7 @@ pub struct Boat {
|
||||
external: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum BoatDamage {
|
||||
None,
|
||||
@ -29,7 +30,7 @@ pub enum BoatDamage {
|
||||
Locked,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BoatWithDetails {
|
||||
#[serde(flatten)]
|
||||
boat: Boat,
|
||||
@ -44,6 +45,7 @@ pub struct BoatToAdd<'r> {
|
||||
pub year_built: Option<i64>,
|
||||
pub boatbuilder: Option<&'r str>,
|
||||
pub default_shipmaster_only_steering: bool,
|
||||
pub default_destination: Option<&'r str>,
|
||||
pub skull: bool,
|
||||
pub external: bool,
|
||||
pub location_id: Option<i64>,
|
||||
@ -57,6 +59,7 @@ pub struct BoatToUpdate<'r> {
|
||||
pub year_built: Option<i64>,
|
||||
pub boatbuilder: Option<&'r str>,
|
||||
pub default_shipmaster_only_steering: bool,
|
||||
pub default_destination: Option<&'r str>,
|
||||
pub skull: bool,
|
||||
pub external: bool,
|
||||
pub location_id: i64,
|
||||
@ -138,7 +141,7 @@ impl Boat {
|
||||
let boats = sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
|
||||
FROM boat
|
||||
ORDER BY amount_seats DESC
|
||||
"
|
||||
@ -158,7 +161,7 @@ ORDER BY amount_seats DESC
|
||||
sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
|
||||
FROM boat
|
||||
WHERE owner is null or owner = ?
|
||||
ORDER BY amount_seats DESC
|
||||
@ -172,7 +175,7 @@ ORDER BY amount_seats DESC
|
||||
sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
|
||||
SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
|
||||
FROM boat
|
||||
WHERE owner = ? OR (owner is null and amount_seats = 1)
|
||||
ORDER BY amount_seats DESC
|
||||
@ -191,7 +194,7 @@ ORDER BY amount_seats DESC
|
||||
let boats = sqlx::query_as!(
|
||||
Boat,
|
||||
"
|
||||
SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
|
||||
SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external
|
||||
FROM boat
|
||||
INNER JOIN location ON boat.location_id = location.id
|
||||
WHERE location.name=?
|
||||
@ -208,12 +211,13 @@ ORDER BY amount_seats DESC
|
||||
|
||||
pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> {
|
||||
sqlx::query!(
|
||||
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?)",
|
||||
"INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?,?)",
|
||||
boat.name,
|
||||
boat.amount_seats,
|
||||
boat.year_built,
|
||||
boat.boatbuilder,
|
||||
boat.default_shipmaster_only_steering,
|
||||
boat.default_destination,
|
||||
boat.skull,
|
||||
boat.external,
|
||||
boat.location_id,
|
||||
@ -226,12 +230,13 @@ ORDER BY amount_seats DESC
|
||||
|
||||
pub async fn update(&self, db: &SqlitePool, boat: BoatToUpdate<'_>) -> Result<(), String> {
|
||||
sqlx::query!(
|
||||
"UPDATE boat SET name=?, amount_seats=?, year_built=?, boatbuilder=?, default_shipmaster_only_steering=?, skull=?, external=?, location_id=?, owner=? WHERE id=?",
|
||||
"UPDATE boat SET name=?, amount_seats=?, year_built=?, boatbuilder=?, default_shipmaster_only_steering=?, default_destination=?, skull=?, external=?, location_id=?, owner=? WHERE id=?",
|
||||
boat.name,
|
||||
boat.amount_seats,
|
||||
boat.year_built,
|
||||
boat.boatbuilder,
|
||||
boat.default_shipmaster_only_steering,
|
||||
boat.default_destination,
|
||||
boat.skull,
|
||||
boat.external,
|
||||
boat.location_id,
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE boat ADD COLUMN "default_destination" TEXT;
|
@ -18,6 +18,7 @@
|
||||
{{ macros::input(label="Bootsbauer", name="boatbuilder", type="text") }}
|
||||
{{ macros::select(label="Standort", data=locations, name='location_id', selected_id=1) }}
|
||||
{{ macros::select(label="Besitzer", data=users, name='owner', default="Verein") }}
|
||||
{{ macros::input(label='Default destination', name='default_destination', type='text') }}
|
||||
<div>
|
||||
{{ macros::checkbox(label="handgesteuert", name="default_shipmaster_only_steering")}}
|
||||
{{ macros::checkbox(label="Skull", name="skull", checked=true)}}
|
||||
@ -50,7 +51,8 @@
|
||||
{{ macros::select(data=users, label='Besitzer', name='owner', selected_id=boat.owner, default="Vereinsboot") }}
|
||||
{{ macros::input(label='Baujahr', name='year_built', type='number', min=1950, value=boat.year_built) }}
|
||||
{{ macros::input(label='Bootsbauer', name='boatbuilder', type='text', value=boat.boatbuilder) }}
|
||||
{{ macros::checkbox(label='hangesteuert', name='default_shipmaster_only_steering', id=uuid , checked=boat.default_shipmaster_only_steering) }}
|
||||
{{ macros::checkbox(label='handgesteuert', name='default_shipmaster_only_steering', id=uuid , checked=boat.default_shipmaster_only_steering) }}
|
||||
{{ macros::input(label='Default destination', name='default_destination', type='text', value=boat.default_destination) }}
|
||||
{{ macros::checkbox(label='Skull', name='skull', id=uuid , checked=boat.skull) }}
|
||||
{{ macros::checkbox(label='Externes Boot', name='external', id=uuid , checked=boat.external) }}
|
||||
</div>
|
||||
|
@ -13,7 +13,7 @@
|
||||
<strong>{{ amount_seats }}x</strong>
|
||||
</div>
|
||||
{% for boat in grouped_boats %}
|
||||
<div id="boat-{{ boat.id }}" class="px-3 boats-js text-black dark:text-white {% if boat.damage != 'locked' and not boat.on_water %} cursor-pointer hover:text-primary-900 dark:hover:text-gray-100 {% endif %}" {% if boat.damage != 'locked' and not boat.on_water %} data-seats="{{boat.amount_seats}}" data-default_shipmaster_only_steering="{{boat.default_shipmaster_only_steering}}" data-onclick="true" {% endif %} data-id="{{ boat.id }}">
|
||||
<div id="boat-{{ boat.id }}" class="px-3 boats-js text-black dark:text-white {% if boat.damage != 'locked' and not boat.on_water %} cursor-pointer hover:text-primary-900 dark:hover:text-gray-100 {% endif %}" {% if boat.damage != 'locked' and not boat.on_water %} data-seats="{{boat.amount_seats}}" data-default_shipmaster_only_steering="{{boat.default_shipmaster_only_steering}}" data-default-destination="{{boat.default_destination}}" data-onclick="true" {% endif %} data-id="{{ boat.id }}">
|
||||
<span class="status-damage status-damage-{{ boat.damage }}"></span>
|
||||
<span {% if boat.damage == 'locked' or boat.on_water %} class="opacity-50" {% endif %}>{{ boat.name }}
|
||||
{% if boat.owner %}
|
||||
@ -66,10 +66,10 @@
|
||||
|
||||
{% macro boat_select(only_ones, id="boat_id") %}
|
||||
{% if not only_ones %}
|
||||
{{ macros::select(label="Boot", data=boats, name="boat_id", id=id, display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-4", show_seats=true) }}
|
||||
{{ macros::select(label="Boot", data=boats, name="boat_id", id=id, display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water", "default_destination"], wrapper_class="col-span-4", show_seats=true) }}
|
||||
{% else %}
|
||||
{% set ones = boats | filter(attribute="amount_seats", value=1) %}
|
||||
{{ macros::select(label="Boot", data=ones, name="boat_id", id=id, display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-4", show_seats=true) }}
|
||||
{{ macros::select(label="Boot", data=ones, name="boat_id", id=id, display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water", "default_destination"], wrapper_class="col-span-4", show_seats=true) }}
|
||||
{% endif %}
|
||||
{% endmacro boat_select %}
|
||||
|
||||
|
@ -175,7 +175,7 @@
|
||||
<option selected value>{{ default }}</option>
|
||||
{% endif %}
|
||||
{% for d in data %}
|
||||
<option value="{{ d.id }}" {% if d.id == selected_id %} selected {% endif %} {% if extras != '' %} {% for extra in extras %} {% if extra != 'on_water' %} data-{{extra}}={{d[extra]}} {% else %} {% if d[extra] %} disabled {% endif %} {% endif %} {% endfor %} {% endif %} {% if show_seats %} data-custom-properties='{"amount_seats": {{ d["amount_seats"] }}, "owner": "{{ d["owner"] }}"}'{% endif %}>
|
||||
<option value="{{ d.id }}" {% if d.id == selected_id %} selected {% endif %} {% if extras != '' %} {% for extra in extras %} {% if extra != 'on_water' and d[extra] %} data-{{extra}}={{d[extra]}} {% else %} {% if d[extra] %} disabled {% endif %} {% endif %} {% endfor %} {% endif %} {% if show_seats %} data-custom-properties='{"amount_seats": {{ d["amount_seats"] }}, "owner": "{{ d["owner"] }}", "default_destination": "{{ d["default_destination"] }}"}'{% endif %}>
|
||||
{% for displa in display -%}
|
||||
{%- if d[displa] -%}
|
||||
{{- d[displa] -}}
|
||||
|
Loading…
Reference in New Issue
Block a user