Merge branch 'new-db' into 'staging'
New db See merge request PhilippHofer/rot!55
This commit is contained in:
commit
143da65609
248
frontend/main.ts
248
frontend/main.ts
@ -22,14 +22,23 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
function setCurrentdate(input: HTMLInputElement) {
|
||||
if(input) {
|
||||
const inputElement = document.getElementById("departure") as HTMLInputElement;
|
||||
const now = new Date();
|
||||
const formattedDateTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
||||
|
||||
inputElement.value = formattedDateTime;
|
||||
input.value = formattedDateTime;
|
||||
}
|
||||
}
|
||||
|
||||
interface ChoiceBoatEvent extends Event{
|
||||
detail: {
|
||||
value: string;
|
||||
label: string,
|
||||
customProperties: {
|
||||
amount_seats: number,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function selectBoatChange() {
|
||||
const boatSelect = <HTMLSelectElement>document.querySelector('#boat_id');
|
||||
|
||||
@ -39,43 +48,22 @@ function selectBoatChange() {
|
||||
noResultsText: 'Keine Ergebnisse gefunden',
|
||||
noChoicesText: 'Keine Ergebnisse gefunden',
|
||||
itemSelectText: 'Zum Auswählen klicken',
|
||||
callbackOnCreateTemplates: function () {
|
||||
return {
|
||||
option: ({ label, value, customProperties, active, disabled, }: any) => {
|
||||
const opt: HTMLOptionElement = Choices.defaults.templates.option.call(
|
||||
this,
|
||||
{ label, value, customProperties, active, disabled }
|
||||
);
|
||||
|
||||
// We get the original <option> from choicejs
|
||||
const originalOption: HTMLOptionElement = this._presetOptions.filter(
|
||||
(option: HTMLOptionElement) => option.value === value
|
||||
)[0];
|
||||
|
||||
const rowers = Number(originalOption.dataset.amount_seats) - 1;
|
||||
const isShipmasterSteering = originalOption.dataset.default_shipmaster_only_steering;
|
||||
|
||||
setMaxAmountRowers(rowers,isShipmasterSteering);
|
||||
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
|
||||
boatSelect.addEventListener('addItem', function(e) {
|
||||
const event = e as ChoiceBoatEvent;
|
||||
const amount_seats = event.detail.customProperties.amount_seats;
|
||||
setMaxAmountRowers("newrower", amount_seats);
|
||||
|
||||
const inputElement = document.getElementById("departure") as HTMLInputElement;
|
||||
const now = new Date();
|
||||
const formattedDateTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
||||
|
||||
inputElement.value = formattedDateTime;
|
||||
},false);
|
||||
|
||||
choiceObjects[boatSelect.id] = boatChoice;
|
||||
}
|
||||
|
||||
const shipmasterSelect = <HTMLSelectElement>document.querySelector('#shipmaster');
|
||||
if(shipmasterSelect) {
|
||||
const shipmasterChoice = new Choices(shipmasterSelect, {
|
||||
loadingText: 'Wird geladen...',
|
||||
noResultsText: 'Keine Ergebnisse gefunden',
|
||||
noChoicesText: 'Keine Ergebnisse gefunden',
|
||||
itemSelectText: 'Zum Auswählen klicken',
|
||||
});
|
||||
|
||||
choiceObjects[shipmasterSelect.id] = shipmasterChoice;
|
||||
choiceObjects["boat_id"] = boatChoice;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,52 +83,55 @@ function reloadPage() {
|
||||
});
|
||||
}
|
||||
|
||||
function setMaxAmountRowers(rowers: number, isShipmasterSteering='false') {
|
||||
if(choiceObjects['newrower']) {
|
||||
let curSelection = choiceObjects['newrower'].getValue(true);
|
||||
let amount_to_delete = (<any>curSelection).length - rowers;
|
||||
function setMaxAmountRowers(name: string, rowers: number) {
|
||||
console.log("called fct: name="+name+"; rowers="+rowers);
|
||||
if(choiceObjects[name]) {
|
||||
choiceObjects[name].removeActiveItems(-1);
|
||||
//let curSelection = choiceObjects[name].getValue(true);
|
||||
//let amount_to_delete = (<any>curSelection).length - rowers;
|
||||
|
||||
if (amount_to_delete > 0){
|
||||
let to_delete = (<any>curSelection).slice(-amount_to_delete);
|
||||
for (let del of to_delete) {
|
||||
choiceObjects['newrower'].removeActiveItemsByValue(del);
|
||||
}
|
||||
}
|
||||
//if (amount_to_delete > 0){
|
||||
// let to_delete = (<any>curSelection).slice(-amount_to_delete);
|
||||
// for (let del of to_delete) {
|
||||
// choiceObjects[name].removeActiveItemsByValue(del);
|
||||
// }
|
||||
//}
|
||||
|
||||
let input = <HTMLElement>document.querySelector('#newrower');
|
||||
let input = <HTMLElement>document.querySelector('#'+name);
|
||||
|
||||
if(input) {
|
||||
choiceObjects['newrower'].config.maxItemCount = rowers;
|
||||
choiceObjects[name].config.maxItemCount = rowers;
|
||||
if (rowers === 0) {
|
||||
choiceObjects['newrower'].disable()
|
||||
choiceObjects[name].disable()
|
||||
input.parentElement?.parentElement?.parentElement?.classList.add('hidden');
|
||||
input.parentElement?.parentElement?.parentElement?.classList.add('md:block');
|
||||
input.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
||||
} else{
|
||||
choiceObjects['newrower'].enable();
|
||||
choiceObjects[name].enable();
|
||||
input.parentElement?.parentElement?.parentElement?.classList.remove('hidden');
|
||||
input.parentElement?.parentElement?.parentElement?.classList.remove('md:block');
|
||||
input.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50');
|
||||
}
|
||||
}
|
||||
|
||||
let only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering');
|
||||
if(only_steering) {
|
||||
if(isShipmasterSteering == 'true') {
|
||||
only_steering.removeAttribute('disabled');
|
||||
only_steering.setAttribute('checked', 'true');
|
||||
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('hidden');
|
||||
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('md:block');
|
||||
only_steering.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50');
|
||||
} else {
|
||||
only_steering.setAttribute('disabled', 'disabled');
|
||||
only_steering.removeAttribute('checked');
|
||||
only_steering.parentElement?.parentElement?.parentElement?.classList.add('hidden');
|
||||
only_steering.parentElement?.parentElement?.parentElement?.classList.add('md:block');
|
||||
only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
||||
}
|
||||
}
|
||||
//let only_steering = <HTMLSelectElement>document.querySelector('#shipmaster_only_steering');
|
||||
//if(only_steering) {
|
||||
// if(isShipmasterSteering == 'true') {
|
||||
// only_steering.removeAttribute('disabled');
|
||||
// only_steering.setAttribute('checked', 'true');
|
||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.remove('hidden');
|
||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.remove('md:block');
|
||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.remove('opacity-50');
|
||||
// } else {
|
||||
// only_steering.setAttribute('disabled', 'disabled');
|
||||
// only_steering.removeAttribute('checked');
|
||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('hidden');
|
||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('md:block');
|
||||
// only_steering.parentElement?.parentElement?.parentElement?.classList.add('opacity-50');
|
||||
// }
|
||||
//}
|
||||
}
|
||||
console.log(choiceObjects["newrower"].config.maxItemCount);
|
||||
}
|
||||
|
||||
function initBoatActions() {
|
||||
@ -149,22 +140,11 @@ function initBoatActions() {
|
||||
Array.prototype.forEach.call(boatSelects, (select: HTMLInputElement) => {
|
||||
select.addEventListener('click', function() {
|
||||
if(select.dataset.seats) {
|
||||
const rowers = Number(select.dataset.seats) - 1;
|
||||
const isShipmasterSteering = select.dataset.default_shipmaster_only_steering;
|
||||
|
||||
setMaxAmountRowers(rowers, isShipmasterSteering);
|
||||
|
||||
if (select.dataset.id) {
|
||||
choiceObjects['boat_id'].setChoiceByValue(select.dataset.id);
|
||||
}
|
||||
|
||||
window.scrollTo(0, 0);
|
||||
|
||||
const inputElement = document.getElementById("departure") as HTMLInputElement;
|
||||
const now = new Date();
|
||||
const formattedDateTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
||||
|
||||
inputElement.value = formattedDateTime;
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -180,6 +160,18 @@ function initChoices() {
|
||||
}
|
||||
}
|
||||
|
||||
interface ChoiceEvent extends Event{
|
||||
detail: {
|
||||
value: string;
|
||||
label: string,
|
||||
customProperties: {
|
||||
is_cox: boolean,
|
||||
steers: boolean,
|
||||
cox_on_boat: boolean,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function initNewChoice(select: HTMLInputElement) {
|
||||
const choice = new Choices(select, {
|
||||
removeItemButton: true,
|
||||
@ -192,11 +184,95 @@ function initNewChoice(select: HTMLInputElement) {
|
||||
maxItemText: (maxItemCount) => {
|
||||
return `Nur ${maxItemCount} Ruderer können hinzugefügt werden`;
|
||||
},
|
||||
callbackOnCreateTemplates: function () {
|
||||
return {
|
||||
option: ({ label, value, customProperties, active, disabled, }: any) => {
|
||||
const opt: HTMLOptionElement = Choices.defaults.templates.option.call(
|
||||
this,
|
||||
{ label, value, customProperties, active, disabled }
|
||||
);
|
||||
|
||||
// We get the original <option> from choicejs
|
||||
//const originalOption: HTMLOptionElement = this._presetOptions.filter(
|
||||
// (option: HTMLOptionElement) => option.value === value
|
||||
//)[0];
|
||||
//
|
||||
//const rowers = Number(originalOption.dataset.amount_seats);
|
||||
//const isShipmasterSteering = originalOption.dataset.default_shipmaster_only_steering;
|
||||
|
||||
//setMaxAmountRowersoselect.id, curr_boat_rowers, isShipmasterSteering);
|
||||
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
},
|
||||
callbackOnInit: function() {
|
||||
this._currentState.items.forEach(function(obj){
|
||||
if (obj.customProperties && obj.customProperties.is_cox){
|
||||
const coxSelect = <HTMLSelectElement>document.querySelector('#shipmaster-' + select.id + 'js');
|
||||
var new_option = new Option(obj.label, obj.value);
|
||||
if (obj.customProperties.cox_on_boat){
|
||||
new_option.selected = true;
|
||||
}
|
||||
coxSelect.add(new_option);
|
||||
}
|
||||
const steeringSelect = <HTMLSelectElement>document.querySelector('#steering_person-' + select.id + 'js');
|
||||
if (steeringSelect) {
|
||||
var new_option = new Option(obj.label, obj.value);
|
||||
if (obj.customProperties && obj.customProperties.steers){
|
||||
new_option.selected = true;
|
||||
}
|
||||
steeringSelect.add(new_option);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
choiceObjects[select.id] = choice;
|
||||
|
||||
select.addEventListener('addItem', function(e) {
|
||||
const event = e as ChoiceEvent;
|
||||
const user_id = event.detail.value;
|
||||
const name = event.detail.label;
|
||||
|
||||
if (event.detail.customProperties.is_cox) {
|
||||
const coxSelect = <HTMLSelectElement>document.querySelector('#shipmaster-' + select.id + 'js');
|
||||
if (coxSelect){
|
||||
coxSelect.add(new Option(name, user_id));
|
||||
}
|
||||
}
|
||||
|
||||
const steeringSelect = <HTMLSelectElement>document.querySelector('#steering_person-' + select.id + 'js');
|
||||
if (steeringSelect) {
|
||||
steeringSelect.add(new Option(name, user_id));
|
||||
}
|
||||
},false);
|
||||
|
||||
select.addEventListener('removeItem', function(e) {
|
||||
const event = e as ChoiceEvent;
|
||||
|
||||
const user_id = event.detail.value;
|
||||
|
||||
const coxSelect = <HTMLSelectElement>document.querySelector('#shipmaster-' + select.id + 'js');
|
||||
if (coxSelect) {
|
||||
for (var i=0; i<coxSelect.length; i++) {
|
||||
if (coxSelect.options[i].value == user_id)
|
||||
coxSelect.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
const steeringSelect = <HTMLSelectElement>document.querySelector('#steering_person-' + select.id + 'js');
|
||||
if (steeringSelect) {
|
||||
for (var i=0; i<steeringSelect.length; i++) {
|
||||
if (steeringSelect.options[i].value == user_id)
|
||||
steeringSelect.remove(i);
|
||||
}
|
||||
}
|
||||
},false);
|
||||
|
||||
choiceObjects[select.id] = choice;
|
||||
}
|
||||
|
||||
|
||||
function initToggle() {
|
||||
// get filter btns & set object sessionStorage
|
||||
const btns = <NodeListOf<HTMLButtonElement>>document.querySelectorAll('.filter-trips-js');
|
||||
@ -380,12 +456,6 @@ function initTripSidebar(triggerElement: HTMLElement) {
|
||||
let bodyElement = <HTMLElement>body.cloneNode(true);
|
||||
let bodyContainerElement = <HTMLElement>sidebarElement.querySelector('.body-js');
|
||||
|
||||
const selects = bodyElement.querySelectorAll('select[multiple]');
|
||||
if(selects) {
|
||||
Array.prototype.forEach.call(selects, (select: HTMLInputElement) => {
|
||||
initNewChoice(select);
|
||||
});
|
||||
}
|
||||
|
||||
/* Quickfix duplicate ids checkboxes */
|
||||
const checkboxes = <NodeListOf<HTMLElement>>bodyElement.querySelectorAll('input[type="checkbox"]');
|
||||
@ -408,6 +478,7 @@ function initTripSidebar(triggerElement: HTMLElement) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(bodyContainerElement) {
|
||||
bodyContainerElement.innerHTML = '';
|
||||
bodyContainerElement.append(bodyElement);
|
||||
@ -425,7 +496,18 @@ function initTripSidebar(triggerElement: HTMLElement) {
|
||||
if(headerElement) {
|
||||
headerElement.innerHTML = triggerElement.dataset.header;
|
||||
}
|
||||
const selects = bodyElement.querySelectorAll('select[multiple]');
|
||||
if(selects) {
|
||||
Array.prototype.forEach.call(selects, (select: HTMLInputElement) => {
|
||||
initNewChoice(select);
|
||||
});
|
||||
}
|
||||
}
|
||||
const defaultDateTimes = <NodeListOf<HTMLInputElement>>document.querySelectorAll('.current-date-time');
|
||||
defaultDateTimes.forEach((defaultDateTime) => {
|
||||
setCurrentdate(defaultDateTime);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function addRelationMagic(bodyElement: HTMLElement) {
|
||||
|
@ -87,6 +87,7 @@ CREATE TABLE IF NOT EXISTS "logbook" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"boat_id" INTEGER NOT NULL REFERENCES boat(id),
|
||||
"shipmaster" INTEGER NOT NULL REFERENCES user(id),
|
||||
"steering_person" INTEGER NOT NULL REFERENCES user(id),
|
||||
"shipmaster_only_steering" boolean not null,
|
||||
"departure" datetime not null,
|
||||
"arrival" datetime, -- None -> ship is on water
|
||||
|
@ -26,9 +26,9 @@ INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Ottensheim Boot',
|
||||
INSERT INTO "boat" (name, amount_seats, location_id, owner) VALUES ('second_private_boat_from_rower', 1, 1, 2);
|
||||
INSERT INTO "logbook_type" (name) VALUES ('Wanderfahrt');
|
||||
INSERT INTO "logbook_type" (name) VALUES ('Regatta');
|
||||
INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure) VALUES (2, 2, false, '1142-12-24 10:00');
|
||||
INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (1, 4, false, '1141-12-24 10:00', '2141-12-24 15:00', 'Ottensheim', 25);
|
||||
INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (3, 4, false, '1142-12-24 10:00', '2142-12-24 11:30', 'Ottensheim + Regattastrecke', 29);
|
||||
INSERT INTO "logbook" (boat_id, shipmaster,steering_person, shipmaster_only_steering, departure) VALUES (2, 2, 2, false, '1142-12-24 10:00');
|
||||
INSERT INTO "logbook" (boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (1, 4, 4, false, '1141-12-24 10:00', '2141-12-24 15:00', 'Ottensheim', 25);
|
||||
INSERT INTO "logbook" (boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (3, 4, 4, false, '1142-12-24 10:00', '2142-12-24 11:30', 'Ottensheim + Regattastrecke', 29);
|
||||
INSERT INTO "rower" (logbook_id, rower_id) VALUES(3,3);
|
||||
INSERT INTO "boat_damage" (boat_id, desc, user_id_created, created_at) VALUES(4,'Dolle bei Position 2 fehlt', 5, '2142-12-24 15:02');
|
||||
INSERT INTO "boat_damage" (boat_id, desc, user_id_created, created_at, lock_boat) VALUES(5, 'TOHT', 5, '2142-12-24 15:02', 1);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use rocket::serde::{Deserialize, Serialize};
|
||||
use rocket::FromForm;
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||
|
||||
use super::user::User;
|
||||
|
||||
@ -70,6 +70,12 @@ impl Boat {
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
pub async fn find_by_id_tx(db: &mut Transaction<'_, Sqlite>, id: i32) -> Option<Self> {
|
||||
sqlx::query_as!(Self, "SELECT * FROM boat WHERE id like ?", id)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub async fn find_by_name(db: &SqlitePool, name: String) -> Option<Self> {
|
||||
sqlx::query_as!(Self, "SELECT * FROM boat WHERE name like ?", name)
|
||||
|
@ -1,6 +1,6 @@
|
||||
use chrono::{DateTime, Local, NaiveDateTime, TimeZone, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||
|
||||
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
||||
pub struct Log {
|
||||
@ -15,6 +15,12 @@ impl Log {
|
||||
.await
|
||||
.is_ok()
|
||||
}
|
||||
pub async fn create_with_tx(db: &mut Transaction<'_, Sqlite>, msg: String) -> bool {
|
||||
sqlx::query!("INSERT INTO log(msg) VALUES (?)", msg,)
|
||||
.execute(db)
|
||||
.await
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
async fn last(db: &SqlitePool) -> Vec<Log> {
|
||||
sqlx::query_as!(
|
||||
|
@ -1,5 +1,4 @@
|
||||
use chrono::{NaiveDateTime, TimeZone};
|
||||
use chrono_tz::Europe::Vienna;
|
||||
use chrono::NaiveDateTime;
|
||||
use rocket::FromForm;
|
||||
use serde::Serialize;
|
||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||
@ -11,6 +10,7 @@ pub struct Logbook {
|
||||
pub id: i64,
|
||||
pub boat_id: i64,
|
||||
pub shipmaster: i64,
|
||||
pub steering_person: i64,
|
||||
#[serde(default = "bool::default")]
|
||||
pub shipmaster_only_steering: bool,
|
||||
pub departure: NaiveDateTime,
|
||||
@ -27,10 +27,11 @@ impl PartialEq for Logbook {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm, Debug)]
|
||||
#[derive(FromForm, Debug, Clone)]
|
||||
pub struct LogToAdd {
|
||||
pub boat_id: i32,
|
||||
pub shipmaster: i64,
|
||||
pub steering_person: i64,
|
||||
pub shipmaster_only_steering: bool,
|
||||
pub departure: String,
|
||||
pub arrival: Option<String>,
|
||||
@ -43,6 +44,11 @@ pub struct LogToAdd {
|
||||
|
||||
#[derive(FromForm, Debug)]
|
||||
pub struct LogToFinalize {
|
||||
pub shipmaster: i64,
|
||||
pub steering_person: i64,
|
||||
pub shipmaster_only_steering: bool,
|
||||
pub departure: String,
|
||||
pub arrival: String,
|
||||
pub destination: String,
|
||||
pub distance_in_km: i64,
|
||||
pub comments: Option<String>,
|
||||
@ -50,12 +56,37 @@ pub struct LogToFinalize {
|
||||
pub rowers: Vec<i64>,
|
||||
}
|
||||
|
||||
impl TryFrom<LogToAdd> for LogToFinalize {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(value: LogToAdd) -> Result<Self, Self::Error> {
|
||||
if let (Some(arrival), Some(destination), Some(distance_in_km)) =
|
||||
(value.arrival, value.destination, value.distance_in_km)
|
||||
{
|
||||
return Ok(LogToFinalize {
|
||||
arrival,
|
||||
destination,
|
||||
distance_in_km,
|
||||
shipmaster: value.shipmaster,
|
||||
steering_person: value.steering_person,
|
||||
shipmaster_only_steering: value.shipmaster_only_steering,
|
||||
departure: value.departure,
|
||||
comments: value.comments,
|
||||
logtype: value.logtype,
|
||||
rowers: value.rowers,
|
||||
});
|
||||
}
|
||||
Err("Arrival, destination or distance_in_km not set".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct LogbookWithBoatAndRowers {
|
||||
#[serde(flatten)]
|
||||
pub logbook: Logbook,
|
||||
pub boat: Boat,
|
||||
pub shipmaster_user: User,
|
||||
pub steering_user: User,
|
||||
pub rowers: Vec<User>,
|
||||
}
|
||||
|
||||
@ -65,6 +96,9 @@ pub enum LogbookUpdateError {
|
||||
TooManyRowers(usize, usize),
|
||||
RowerCreateError(i64, String),
|
||||
ArrivalNotAfterDeparture,
|
||||
ShipmasterNotInRowers,
|
||||
SteeringPersonNotInRowers,
|
||||
UserNotAllowedToUseBoat,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -74,18 +108,40 @@ pub enum LogbookDeleteError {
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum LogbookCreateError {
|
||||
ArrivalSetButNoDestination,
|
||||
UserNotAllowedToUseBoat,
|
||||
ArrivalSetButNoDistance,
|
||||
BoatAlreadyOnWater,
|
||||
BoatLocked,
|
||||
BoatNotFound,
|
||||
TooManyRowers(usize, usize),
|
||||
ShipmasterAlreadyOnWater,
|
||||
RowerAlreadyOnWater(User),
|
||||
RowerCreateError(i64, String),
|
||||
SamePersonShipmasterAndRower,
|
||||
ArrivalNotAfterDeparture,
|
||||
SteeringPersonNotInRowers,
|
||||
ShipmasterNotInRowers,
|
||||
NotYourEntry,
|
||||
ArrivalSetButNotRemainingTwo,
|
||||
}
|
||||
|
||||
impl From<LogbookUpdateError> for LogbookCreateError {
|
||||
fn from(value: LogbookUpdateError) -> Self {
|
||||
return match value {
|
||||
LogbookUpdateError::NotYourEntry => LogbookCreateError::NotYourEntry,
|
||||
LogbookUpdateError::TooManyRowers(a, b) => LogbookCreateError::TooManyRowers(a, b),
|
||||
LogbookUpdateError::RowerCreateError(a, b) => {
|
||||
LogbookCreateError::RowerCreateError(a, b)
|
||||
}
|
||||
LogbookUpdateError::ArrivalNotAfterDeparture => {
|
||||
LogbookCreateError::ArrivalNotAfterDeparture
|
||||
}
|
||||
LogbookUpdateError::ShipmasterNotInRowers => LogbookCreateError::ShipmasterNotInRowers,
|
||||
LogbookUpdateError::SteeringPersonNotInRowers => {
|
||||
LogbookCreateError::SteeringPersonNotInRowers
|
||||
}
|
||||
LogbookUpdateError::UserNotAllowedToUseBoat => {
|
||||
LogbookCreateError::UserNotAllowedToUseBoat
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl Logbook {
|
||||
@ -93,7 +149,7 @@ impl Logbook {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id,boat_id,shipmaster,shipmaster_only_steering,departure,arrival,destination,distance_in_km,comments,logtype
|
||||
SELECT id,boat_id,shipmaster,steering_person,shipmaster_only_steering,departure,arrival,destination,distance_in_km,comments,logtype
|
||||
FROM logbook
|
||||
WHERE id like ?
|
||||
",
|
||||
@ -107,7 +163,7 @@ impl Logbook {
|
||||
pub async fn on_water(db: &SqlitePool) -> Vec<LogbookWithBoatAndRowers> {
|
||||
let rows = sqlx::query!(
|
||||
"
|
||||
SELECT id, boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype
|
||||
SELECT id, boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype
|
||||
FROM logbook
|
||||
WHERE arrival is null
|
||||
ORDER BY departure DESC
|
||||
@ -123,6 +179,7 @@ ORDER BY departure DESC
|
||||
id: row.id,
|
||||
boat_id: row.boat_id,
|
||||
shipmaster: row.shipmaster,
|
||||
steering_person: row.steering_person,
|
||||
shipmaster_only_steering: row.shipmaster_only_steering,
|
||||
departure: row.departure,
|
||||
arrival: row.arrival,
|
||||
@ -139,6 +196,9 @@ ORDER BY departure DESC
|
||||
rowers: Rower::for_log(db, &log).await,
|
||||
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
|
||||
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
|
||||
steering_user: User::find_by_id(db, log.steering_person as i32)
|
||||
.await
|
||||
.unwrap(),
|
||||
logbook: log,
|
||||
});
|
||||
}
|
||||
@ -149,7 +209,7 @@ ORDER BY departure DESC
|
||||
let logs = sqlx::query_as!(
|
||||
Logbook,
|
||||
"
|
||||
SELECT id, boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype
|
||||
SELECT id, boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype
|
||||
FROM logbook
|
||||
WHERE arrival is not null
|
||||
ORDER BY departure DESC
|
||||
@ -165,6 +225,9 @@ ORDER BY departure DESC
|
||||
rowers: Rower::for_log(db, &log).await,
|
||||
boat: Boat::find_by_id(db, log.boat_id as i32).await.unwrap(),
|
||||
shipmaster_user: User::find_by_id(db, log.shipmaster as i32).await.unwrap(),
|
||||
steering_user: User::find_by_id(db, log.steering_person as i32)
|
||||
.await
|
||||
.unwrap(),
|
||||
logbook: log,
|
||||
});
|
||||
}
|
||||
@ -180,6 +243,48 @@ ORDER BY departure DESC
|
||||
return Err(LogbookCreateError::BoatNotFound);
|
||||
};
|
||||
|
||||
if let Ok(log_to_finalize) = TryInto::<LogToFinalize>::try_into(log.clone()) {
|
||||
//TODO: fix clone()
|
||||
|
||||
if !boat.shipmaster_allowed(created_by_user).await {
|
||||
return Err(LogbookCreateError::UserNotAllowedToUseBoat);
|
||||
}
|
||||
|
||||
let mut tx = db.begin().await.unwrap();
|
||||
|
||||
let inserted_row = sqlx::query!(
|
||||
"INSERT INTO logbook(boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype) VALUES (?,?,?,?,?,?,?,?,?,?) RETURNING id",
|
||||
log.boat_id,
|
||||
log.shipmaster,
|
||||
log.steering_person,
|
||||
log.shipmaster_only_steering,
|
||||
log.departure,
|
||||
log.arrival,
|
||||
log.destination,
|
||||
log.distance_in_km,
|
||||
log.comments,
|
||||
log.logtype
|
||||
)
|
||||
.fetch_one(&mut tx)
|
||||
.await.unwrap().id;
|
||||
|
||||
let logbook = Logbook::find_by_id(db, inserted_row as i32).await.unwrap(); //ok
|
||||
|
||||
return match logbook
|
||||
.home_with_transaction(&mut tx, created_by_user, log_to_finalize)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
tx.commit().await.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
Err(a) => Err(a.into()),
|
||||
};
|
||||
}
|
||||
if log.arrival.is_some() {
|
||||
return Err(LogbookCreateError::ArrivalSetButNotRemainingTwo);
|
||||
}
|
||||
|
||||
if boat.is_locked(db).await {
|
||||
return Err(LogbookCreateError::BoatLocked);
|
||||
}
|
||||
@ -188,39 +293,22 @@ ORDER BY departure DESC
|
||||
return Err(LogbookCreateError::BoatAlreadyOnWater);
|
||||
}
|
||||
|
||||
let shipmaster = User::find_by_id(db, log.shipmaster as i32).await.unwrap();
|
||||
|
||||
if shipmaster.on_water(db).await {
|
||||
return Err(LogbookCreateError::ShipmasterAlreadyOnWater);
|
||||
if !log.rowers.contains(&log.shipmaster) {
|
||||
return Err(LogbookCreateError::ShipmasterNotInRowers);
|
||||
}
|
||||
if !log.rowers.contains(&log.steering_person) {
|
||||
return Err(LogbookCreateError::SteeringPersonNotInRowers);
|
||||
}
|
||||
|
||||
if let Some(arrival) = &log.arrival {
|
||||
let dep = NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%dT%H:%M").unwrap();
|
||||
let arr = NaiveDateTime::parse_from_str(arrival, "%Y-%m-%dT%H:%M").unwrap();
|
||||
if arr <= dep {
|
||||
return Err(LogbookCreateError::ArrivalNotAfterDeparture);
|
||||
}
|
||||
|
||||
if log.destination.is_none() {
|
||||
return Err(LogbookCreateError::ArrivalSetButNoDestination);
|
||||
}
|
||||
if log.distance_in_km.is_none() {
|
||||
return Err(LogbookCreateError::ArrivalSetButNoDistance);
|
||||
}
|
||||
}
|
||||
|
||||
if log.rowers.len() > boat.amount_seats as usize - 1 {
|
||||
if log.rowers.len() > boat.amount_seats as usize {
|
||||
return Err(LogbookCreateError::TooManyRowers(
|
||||
boat.amount_seats as usize,
|
||||
log.rowers.len() + 1,
|
||||
log.rowers.len(),
|
||||
));
|
||||
}
|
||||
|
||||
for rower in &log.rowers {
|
||||
let user = User::find_by_id(db, *rower as i32).await.unwrap();
|
||||
if *rower == log.shipmaster {
|
||||
return Err(LogbookCreateError::SamePersonShipmasterAndRower);
|
||||
}
|
||||
|
||||
if user.on_water(db).await {
|
||||
return Err(LogbookCreateError::RowerAlreadyOnWater(user));
|
||||
@ -236,25 +324,11 @@ ORDER BY departure DESC
|
||||
|
||||
let mut tx = db.begin().await.unwrap();
|
||||
|
||||
//let departure = NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%dT%H:%M").unwrap();
|
||||
//let departure_vienna = chrono::Utc
|
||||
// .from_local_datetime(&departure)
|
||||
// .single()
|
||||
// .unwrap();
|
||||
//let departure_utc = departure_vienna.with_timezone(&Vienna);
|
||||
|
||||
//let arrival = log.arrival.map(|a| {
|
||||
// let arr = NaiveDateTime::parse_from_str(&a, "%Y-%m-%dT%H:%M").unwrap();
|
||||
// let arr_vienna = Vienna.from_local_datetime(&arr).single().unwrap();
|
||||
// arr_vienna
|
||||
// .with_timezone(&chrono::Utc)
|
||||
// .format("%Y-%m-%d %H:%M")
|
||||
//});
|
||||
//let arrival = log.arrival.map(|a| format!("{}+02:00", a));
|
||||
let inserted_row = sqlx::query!(
|
||||
"INSERT INTO logbook(boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype) VALUES (?,?,?,?,?,?,?,?,?) RETURNING id",
|
||||
"INSERT INTO logbook(boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype) VALUES (?,?,?,?,?,?,?,?,?,?) RETURNING id",
|
||||
log.boat_id,
|
||||
log.shipmaster,
|
||||
log.steering_person,
|
||||
log.shipmaster_only_steering,
|
||||
log.departure,
|
||||
log.arrival,
|
||||
@ -319,51 +393,80 @@ ORDER BY departure DESC
|
||||
user: &User,
|
||||
log: LogToFinalize,
|
||||
) -> Result<(), LogbookUpdateError> {
|
||||
let mut tx = db.begin().await.unwrap();
|
||||
self.home_with_transaction(&mut tx, user, log).await?;
|
||||
tx.commit().await.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn home_with_transaction(
|
||||
&self,
|
||||
db: &mut Transaction<'_, Sqlite>,
|
||||
user: &User,
|
||||
log: LogToFinalize,
|
||||
) -> Result<(), LogbookUpdateError> {
|
||||
//TODO: extract common tests with `create()`
|
||||
if user.id != self.shipmaster {
|
||||
return Err(LogbookUpdateError::NotYourEntry);
|
||||
}
|
||||
|
||||
let boat = Boat::find_by_id(db, self.boat_id as i32).await.unwrap(); //ok
|
||||
if !log.rowers.contains(&log.shipmaster) {
|
||||
return Err(LogbookUpdateError::ShipmasterNotInRowers);
|
||||
}
|
||||
if !log.rowers.contains(&log.steering_person) {
|
||||
return Err(LogbookUpdateError::SteeringPersonNotInRowers);
|
||||
}
|
||||
|
||||
if log.rowers.len() > boat.amount_seats as usize - 1 {
|
||||
let boat = Boat::find_by_id_tx(db, self.boat_id as i32).await.unwrap(); //ok
|
||||
|
||||
if !boat.shipmaster_allowed(&user).await && self.shipmaster != user.id {
|
||||
//second part:
|
||||
//shipmaster has
|
||||
//entered a
|
||||
//different user,
|
||||
//then the user
|
||||
//should be able
|
||||
//to `home` it
|
||||
return Err(LogbookUpdateError::UserNotAllowedToUseBoat);
|
||||
}
|
||||
|
||||
if log.rowers.len() > boat.amount_seats as usize {
|
||||
return Err(LogbookUpdateError::TooManyRowers(
|
||||
boat.amount_seats as usize,
|
||||
log.rowers.len() + 1,
|
||||
log.rowers.len(),
|
||||
));
|
||||
}
|
||||
|
||||
let arrival = chrono::offset::Utc::now().naive_utc();
|
||||
let arrival = Vienna.from_utc_datetime(&arrival);
|
||||
|
||||
if arrival.timestamp() + 60 * 60 * 2 <= self.departure.timestamp() {
|
||||
//TODO: fixme
|
||||
let dep = NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%dT%H:%M").unwrap();
|
||||
let arr = NaiveDateTime::parse_from_str(&log.arrival, "%Y-%m-%dT%H:%M").unwrap();
|
||||
if arr.timestamp() <= dep.timestamp() {
|
||||
return Err(LogbookUpdateError::ArrivalNotAfterDeparture);
|
||||
}
|
||||
|
||||
Log::create(db, format!("New trip: {log:?}")).await;
|
||||
let mut tx = db.begin().await.unwrap();
|
||||
|
||||
sqlx::query!(
|
||||
"UPDATE logbook SET destination=?, distance_in_km=?, comments=?, logtype=?, arrival=? WHERE id=?",
|
||||
log.destination,
|
||||
log.distance_in_km,
|
||||
log.comments,
|
||||
log.logtype,
|
||||
arrival,
|
||||
self.id
|
||||
)
|
||||
.execute(&mut tx)
|
||||
.await.unwrap(); //TODO: fixme
|
||||
|
||||
self.remove_rowers(&mut tx).await;
|
||||
Log::create_with_tx(db, format!("New trip: {log:?}")).await;
|
||||
|
||||
self.remove_rowers(db).await;
|
||||
for rower in &log.rowers {
|
||||
Rower::create(&mut tx, self.id, *rower)
|
||||
Rower::create(db, self.id, *rower)
|
||||
.await
|
||||
.map_err(|e| LogbookUpdateError::RowerCreateError(*rower, e.to_string()))?;
|
||||
}
|
||||
|
||||
tx.commit().await.unwrap();
|
||||
sqlx::query!(
|
||||
"UPDATE logbook SET shipmaster=?, steering_person=?, shipmaster_only_steering=?, departure=?, destination=?, distance_in_km=?, comments=?, logtype=?, arrival=? WHERE id=?",
|
||||
log.shipmaster,
|
||||
log.steering_person,
|
||||
log.shipmaster_only_steering,
|
||||
log.departure,
|
||||
log.destination,
|
||||
log.distance_in_km,
|
||||
log.comments,
|
||||
log.logtype,
|
||||
log.arrival,
|
||||
self.id
|
||||
)
|
||||
.execute(db)
|
||||
.await.unwrap(); //TODO: fixme
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -444,6 +547,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 3,
|
||||
shipmaster: 4,
|
||||
steering_person: 4,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -451,7 +555,7 @@ mod test {
|
||||
distance_in_km: None,
|
||||
comments: None,
|
||||
logtype: None,
|
||||
rowers: Vec::new(),
|
||||
rowers: vec![4],
|
||||
},
|
||||
&User::find_by_id(&pool, 4).await.unwrap(),
|
||||
)
|
||||
@ -468,6 +572,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 999,
|
||||
shipmaster: 5,
|
||||
steering_person: 5,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -475,7 +580,7 @@ mod test {
|
||||
distance_in_km: None,
|
||||
comments: None,
|
||||
logtype: None,
|
||||
rowers: Vec::new(),
|
||||
rowers: vec![5],
|
||||
},
|
||||
&User::find_by_id(&pool, 4).await.unwrap(),
|
||||
)
|
||||
@ -493,6 +598,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 5,
|
||||
shipmaster: 5,
|
||||
steering_person: 5,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -500,7 +606,7 @@ mod test {
|
||||
distance_in_km: None,
|
||||
comments: None,
|
||||
logtype: None,
|
||||
rowers: Vec::new(),
|
||||
rowers: vec![5],
|
||||
},
|
||||
&User::find_by_id(&pool, 4).await.unwrap(),
|
||||
)
|
||||
@ -518,6 +624,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 2,
|
||||
shipmaster: 5,
|
||||
steering_person: 5,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -525,7 +632,7 @@ mod test {
|
||||
distance_in_km: None,
|
||||
comments: None,
|
||||
logtype: None,
|
||||
rowers: Vec::new(),
|
||||
rowers: vec![5],
|
||||
},
|
||||
&User::find_by_id(&pool, 5).await.unwrap(),
|
||||
)
|
||||
@ -543,6 +650,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 3,
|
||||
shipmaster: 5,
|
||||
steering_person: 5,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: Some("2128-05-20T11:00".into()),
|
||||
@ -550,17 +658,17 @@ mod test {
|
||||
distance_in_km: None,
|
||||
comments: None,
|
||||
logtype: None,
|
||||
rowers: Vec::new(),
|
||||
rowers: vec![5],
|
||||
},
|
||||
&User::find_by_id(&pool, 5).await.unwrap(),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(res, Err(LogbookCreateError::ArrivalNotAfterDeparture));
|
||||
assert_eq!(res, Err(LogbookCreateError::ArrivalSetButNotRemainingTwo));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_create_shipmaster_on_water() {
|
||||
fn test_create_shipmaster_not_in_rowers() {
|
||||
let pool = testdb!();
|
||||
|
||||
let res = Logbook::create(
|
||||
@ -568,6 +676,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 3,
|
||||
shipmaster: 2,
|
||||
steering_person: 2,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -581,11 +690,11 @@ mod test {
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(res, Err(LogbookCreateError::ShipmasterAlreadyOnWater));
|
||||
assert_eq!(res, Err(LogbookCreateError::ShipmasterNotInRowers));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_create_same_person_cox_and_rower() {
|
||||
fn test_create_steering_person_not_in_rowers() {
|
||||
let pool = testdb!();
|
||||
|
||||
let res = Logbook::create(
|
||||
@ -593,6 +702,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 3,
|
||||
shipmaster: 5,
|
||||
steering_person: 1,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -606,7 +716,7 @@ mod test {
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(res, Err(LogbookCreateError::SamePersonShipmasterAndRower));
|
||||
assert_eq!(res, Err(LogbookCreateError::SteeringPersonNotInRowers));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
@ -618,6 +728,7 @@ mod test {
|
||||
LogToAdd {
|
||||
boat_id: 1,
|
||||
shipmaster: 5,
|
||||
steering_person: 5,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "2128-05-20T12:00".into(),
|
||||
arrival: None,
|
||||
@ -625,7 +736,7 @@ mod test {
|
||||
distance_in_km: None,
|
||||
comments: None,
|
||||
logtype: None,
|
||||
rowers: vec![1],
|
||||
rowers: vec![1, 5],
|
||||
},
|
||||
&User::find_by_id(&pool, 5).await.unwrap(),
|
||||
)
|
||||
@ -665,7 +776,12 @@ mod test {
|
||||
distance_in_km: 42,
|
||||
comments: Some("Perfect water".into()),
|
||||
logtype: None,
|
||||
rowers: vec![],
|
||||
rowers: vec![2],
|
||||
shipmaster: 2,
|
||||
steering_person: 2,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "1990-01-01T10:00".into(),
|
||||
arrival: "1990-01-01T12:00".into(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
@ -688,7 +804,12 @@ mod test {
|
||||
distance_in_km: 42,
|
||||
comments: Some("Perfect water".into()),
|
||||
logtype: None,
|
||||
rowers: vec![],
|
||||
rowers: vec![1],
|
||||
shipmaster: 1,
|
||||
steering_person: 1,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "1990-01-01T10:00".into(),
|
||||
arrival: "1990-01-01T12:00".into(),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
@ -712,7 +833,12 @@ mod test {
|
||||
distance_in_km: 42,
|
||||
comments: Some("Perfect water".into()),
|
||||
logtype: None,
|
||||
rowers: vec![1],
|
||||
rowers: vec![1, 2],
|
||||
shipmaster: 2,
|
||||
steering_person: 2,
|
||||
shipmaster_only_steering: false,
|
||||
departure: "1990-01-01T10:00".into(),
|
||||
arrival: "1990-01-01T12:00".into(),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
@ -13,21 +13,11 @@ impl Stat {
|
||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||
sqlx::query(
|
||||
"
|
||||
SELECT u.name, CAST(SUM(sub.distance_in_km) AS INTEGER) AS rowed_km
|
||||
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
|
||||
FROM user u
|
||||
INNER JOIN (
|
||||
SELECT r.rower_id AS user_id, l.distance_in_km
|
||||
FROM logbook l
|
||||
INNER JOIN rower r ON l.id = r.logbook_id
|
||||
WHERE l.distance_in_km IS NOT NULL
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT l.shipmaster AS user_id, l.distance_in_km
|
||||
FROM logbook l
|
||||
WHERE l.distance_in_km IS NOT NULL
|
||||
) sub ON u.id = sub.user_id
|
||||
WHERE u.is_guest = false
|
||||
INNER JOIN rower r ON u.id = r.rower_id
|
||||
INNER JOIN logbook l ON r.logbook_id = l.id
|
||||
WHERE u.is_guest = 0 AND l.distance_in_km IS NOT NULL
|
||||
GROUP BY u.name
|
||||
ORDER BY rowed_km DESC;
|
||||
",
|
||||
|
@ -11,7 +11,7 @@ use rocket::{
|
||||
Request,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
||||
|
||||
use super::{log::Log, tripdetails::TripDetails, Day};
|
||||
|
||||
@ -103,6 +103,21 @@ WHERE id like ?
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub async fn find_by_id_tx(db: &mut Transaction<'_, Sqlite>, id: i32) -> Option<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, name, pw, is_cox, is_admin, is_guest, deleted, last_access, is_tech
|
||||
FROM user
|
||||
WHERE id like ?
|
||||
",
|
||||
id
|
||||
)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub async fn find_by_name(db: &SqlitePool, name: &str) -> Option<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
|
@ -162,15 +162,6 @@ async fn create_logbook(
|
||||
data: Form<LogToAdd>,
|
||||
user: &NonGuestUser,
|
||||
) -> Flash<Redirect> {
|
||||
Log::create(
|
||||
db,
|
||||
format!(
|
||||
"User {} tries to create log entry={:?}",
|
||||
user.user.name, data
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
match Logbook::create(
|
||||
db,
|
||||
data.into_inner(),
|
||||
@ -180,17 +171,17 @@ async fn create_logbook(
|
||||
{
|
||||
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt erfolgreich hinzugefügt"),
|
||||
Err(LogbookCreateError::BoatAlreadyOnWater) => Flash::error(Redirect::to("/log"), "Boot schon am Wasser"),
|
||||
Err(LogbookCreateError::ShipmasterAlreadyOnWater) => Flash::error(Redirect::to("/log"), "Schiffsführer schon am Wasser"),
|
||||
Err(LogbookCreateError::RowerAlreadyOnWater(rower)) => Flash::error(Redirect::to("/log"), format!("Ruderer {} schon am Wasser", rower.name)),
|
||||
Err(LogbookCreateError::BoatLocked) => Flash::error(Redirect::to("/log"),"Boot gesperrt"),
|
||||
Err(LogbookCreateError::BoatNotFound) => Flash::error(Redirect::to("/log"), "Boot gibt's ned"),
|
||||
Err(LogbookCreateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
|
||||
Err(LogbookCreateError::RowerCreateError(rower, e)) => Flash::error(Redirect::to("/log"), format!("Fehler bei Ruderer {rower}: {e}")),
|
||||
Err(LogbookCreateError::SamePersonShipmasterAndRower) => Flash::error(Redirect::to("/log"), "Selbe Person als Schiffsführer und Ruderer ausgewählt"),
|
||||
Err(LogbookCreateError::ArrivalSetButNoDistance) => Flash::error(Redirect::to("/log"), "Distanz notwendig, wenn Ankunftszeit angegeben wurde"),
|
||||
Err(LogbookCreateError::ArrivalSetButNoDestination) => Flash::error(Redirect::to("/log"), "Ziel notwendig, wenn Ankunftszeit angegeben wurde"),
|
||||
Err(LogbookCreateError::ArrivalNotAfterDeparture) => Flash::error(Redirect::to("/log"), "Ankunftszeit kann nicht vor der Abfahrtszeit sein"),
|
||||
Err(LogbookCreateError::UserNotAllowedToUseBoat) => Flash::error(Redirect::to("/log"), "Schiffsführer darf dieses Boot nicht verwenden"),
|
||||
Err(LogbookCreateError::SteeringPersonNotInRowers) => Flash::error(Redirect::to("/log"), "Steuerperson nicht in Liste der Ruderer!"),
|
||||
Err(LogbookCreateError::ShipmasterNotInRowers) => Flash::error(Redirect::to("/log"), "Schiffsführer nicht in Liste der Ruderer!"),
|
||||
Err(LogbookCreateError::NotYourEntry) => Flash::error(Redirect::to("/log"), "Nicht deine Ausfahrt!"),
|
||||
Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"),
|
||||
|
||||
}
|
||||
}
|
||||
@ -201,6 +192,15 @@ async fn create(
|
||||
data: Form<LogToAdd>,
|
||||
user: NonGuestUser,
|
||||
) -> Flash<Redirect> {
|
||||
Log::create(
|
||||
db,
|
||||
format!(
|
||||
"User {} tries to create log entry={:?}",
|
||||
user.user.name, data
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
create_logbook(db, data, &user).await
|
||||
}
|
||||
|
||||
@ -240,9 +240,9 @@ async fn home_logbook(
|
||||
match logbook.home(db, &user.user, data.into_inner()).await {
|
||||
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"),
|
||||
Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
|
||||
Err(_) => Flash::error(
|
||||
Err(e) => Flash::error(
|
||||
Redirect::to("/log"),
|
||||
format!("Eintrag {} konnte nicht abgesendet werden!", logbook_id),
|
||||
format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"),
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -515,7 +515,7 @@ mod test {
|
||||
let req = client
|
||||
.post("/log")
|
||||
.header(ContentType::Form)
|
||||
.body("boat_id=1&shipmaster=4&departure=2199-12-31T10:00");
|
||||
.body("boat_id=1&shipmaster=4&departure=2199-12-31T10:00&steering_person=4&rowers[]=4");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
@ -546,7 +546,7 @@ mod test {
|
||||
let req = client
|
||||
.post("/log/1")
|
||||
.header(ContentType::Form)
|
||||
.body("destination=Ottensheim&distance_in_km=25");
|
||||
.body("destination=Ottensheim&distance_in_km=25&shipmaster=2&steering_person=2&departure=1990-01-01T10:00&arrival=1990-01-01T12:00&rowers[]=2");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
@ -655,7 +655,7 @@ mod test {
|
||||
let shipmaster_id = User::find_by_name(&db, "rower2".into()).await.unwrap().id;
|
||||
|
||||
let req = client.post("/log").header(ContentType::Form).body(format!(
|
||||
"boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00"
|
||||
"boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00&steering_person={shipmaster_id}&rowers[]={shipmaster_id}"
|
||||
));
|
||||
let response = req.dispatch().await;
|
||||
|
||||
@ -684,7 +684,7 @@ mod test {
|
||||
let req = client
|
||||
.post(format!("/log/{log_id}"))
|
||||
.header(ContentType::Form)
|
||||
.body("destination=Ottensheim&distance_in_km=25");
|
||||
.body(format!("destination=Ottensheim&distance_in_km=25&shipmaster={shipmaster_id}&steering_person={shipmaster_id}&departure=1990-01-01T10:00&arrival=1990-01-01T12:00&rowers[]={shipmaster_id}"));
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
@ -875,7 +875,7 @@ mod test {
|
||||
let req = client
|
||||
.post("/log/1")
|
||||
.header(ContentType::Form)
|
||||
.body("destination=Ottensheim&distance_in_km=25");
|
||||
.body("destination=Ottensheim&distance_in_km=25&shipmaster=1&steering_person=1&departure=1199-12-12T10:00&arrival=1199-12-12T12:00&rowers[]=1");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
@ -888,7 +888,7 @@ mod test {
|
||||
|
||||
assert_eq!(
|
||||
flash_cookie.value(),
|
||||
"5:errorEintrag 1 konnte nicht abgesendet werden!"
|
||||
"5:errorEintrag 1 konnte nicht abgesendet werden (Fehler: NotYourEntry)!"
|
||||
);
|
||||
}
|
||||
|
||||
@ -902,7 +902,7 @@ mod test {
|
||||
let shipmaster_id = User::find_by_name(db, &shipmaster_name).await.unwrap().id;
|
||||
|
||||
let req = client.post("/log").header(ContentType::Form).body(format!(
|
||||
"boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00"
|
||||
"boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00&steering_person={shipmaster_id}&rowers[]={shipmaster_id}"
|
||||
));
|
||||
let response = req.dispatch().await;
|
||||
|
||||
@ -924,7 +924,7 @@ mod test {
|
||||
let req = client
|
||||
.post(format!("/log/{log_id}"))
|
||||
.header(ContentType::Form)
|
||||
.body("destination=Ottensheim&distance_in_km=25");
|
||||
.body(format!("destination=Ottensheim&distance_in_km=25&shipmaster={shipmaster_id}&steering_person={shipmaster_id}&departure=1199-12-31T10:00&arrival=1199-12-31T12:00&rowers[]={shipmaster_id}"));
|
||||
let response = req.dispatch().await;
|
||||
|
||||
assert_eq!(response.status(), Status::SeeOther);
|
||||
@ -952,7 +952,7 @@ mod test {
|
||||
let shipmaster_id = User::find_by_name(db, &shipmaster_name).await.unwrap().id;
|
||||
|
||||
let req = client.post("/log").header(ContentType::Form).body(format!(
|
||||
"boat_id={boat_id}&shipmaster={shipmaster_id}&departure=2199-12-31T10:00"
|
||||
"boat_id={boat_id}&shipmaster={shipmaster_id}&departure=2199-12-31T10:00&steering_person={shipmaster_id}&rowers[]={shipmaster_id}"
|
||||
));
|
||||
let response = req.dispatch().await;
|
||||
|
||||
|
@ -30,31 +30,6 @@
|
||||
{% macro new(only_ones, shipmaster) %}
|
||||
<form action="/log" method="post" id="form" class="grid grid-cols-4 gap-3" onsubmit="Array.from(this.elements).forEach(e=>!e.value.trim()&&(e.disabled=true));">
|
||||
{{ log::boat_select(only_ones=only_ones) }}
|
||||
|
||||
<div class="col-span-4 md:col-span-3">
|
||||
<label for="shipmaster" class=" text-sm text-gray-600 ">Schiffsführer</label>
|
||||
|
||||
<select name="shipmaster" id="shipmaster" class="input rounded-md h-10">
|
||||
<optgroup label="Steuerleute">
|
||||
{% for cox in coxes %}
|
||||
<option value="{{ cox.id }}" {% if cox.on_water %} disabled="disabled" {% else %} {% if cox.id == shipmaster %} selected {% endif %} {% endif %}>{{ cox.name }}
|
||||
{% if cox.on_water %}
|
||||
(am Wasser)
|
||||
{% endif %}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
<optgroup label="Mitglieder">
|
||||
{% for user in users | filter(attribute="is_cox", value=false) %}
|
||||
<option value="{{ user.id }}" {% if user.id == shipmaster %} selected {% endif %} {% if user.on_water %} disabled="disabled" {% endif %}>{{ user.name }}
|
||||
{% if user.on_water %}
|
||||
(am Wasser)
|
||||
{% endif %}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
{% if not only_ones %}
|
||||
<div class="col-span-4 md:col-span-1">
|
||||
<div class="text-sm text-gray-600">Bootssteuerung</div>
|
||||
@ -63,34 +38,27 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not only_ones %}
|
||||
{{ log::rower_select(id="newrower", selected=[], class="col-span-4", init=true) }}
|
||||
{% endif %}
|
||||
|
||||
{{ macros::select(label="Schiffsführer", data=[], name='shipmaster', id="shipmaster-newrowerjs", wrapper_class="col-span-2") }}
|
||||
{{ macros::select(label="Steuerperson", data=[], name='steering_person', id="steering_person-newrowerjs", wrapper_class="col-span-2") }}
|
||||
{{ macros::input(label='Abfahrtszeit', name='departure', type='datetime-local', required=true, wrapper_class='col-span-2') }}
|
||||
{{ macros::input(label='Ankunftszeit', name='arrival', type='datetime-local', wrapper_class='col-span-2') }}
|
||||
|
||||
<div class="relative col-span-2">
|
||||
<label for="destination" class="text-sm text-gray-600">Ziel</label>
|
||||
|
||||
<input class="input rounded-md set-distance-js" type="search" list="destinations" placeholder="Destination" id="destination" name="destination" value="" data-relation="distance_in_km"/>
|
||||
<datalist id="destinations">
|
||||
{% for distance in distances %}
|
||||
<option value="{{ distance.0 }}" distance={{ distance.1 }} />
|
||||
{% for distance in distances %}<option value="{{ distance.0 }}" distance={{ distance.1 }}/>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</div>
|
||||
|
||||
<div class="relative col-span-2">
|
||||
{{ macros::input(label="Distanz", name="distance_in_km", id="distance_in_km" , type="number", min=0, value='', class="rounded-md") }}
|
||||
<span class="absolute right-0 bottom-0 py-1.5 px-2 bg-white border-0 text-gray-600 ring-1 ring-inset ring-gray-300 rounded-br-md rounded-tr-md">km</span>
|
||||
</div>
|
||||
|
||||
{{ macros::input(label="Kommentar", name="comments", type="text", wrapper_class="col-span-4") }}
|
||||
|
||||
{{ macros::select(label="Typ", data=logtypes, name='logtype', default="Normal", wrapper_class="col-span-4") }}
|
||||
|
||||
<input type="submit" value="Ausfahrt eintragen" class="btn btn-primary w-full col-span-4 m-auto"/>
|
||||
</form>
|
||||
{% endmacro new %}
|
||||
@ -98,15 +66,15 @@
|
||||
|
||||
{% 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") }}
|
||||
{{ 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) }}
|
||||
{% 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") }}
|
||||
{{ 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) }}
|
||||
{% endif %}
|
||||
{% endmacro boat_select %}
|
||||
|
||||
{% macro rower_select(id, selected, amount_seats='', class='', init='false') %}
|
||||
{% if not amount_seats or amount_seats > 1 %}
|
||||
{% macro rower_select(id, selected, amount_seats='', class='', init='false', cox_on_boat='', steering_person_id='') %}
|
||||
{#{% if not amount_seats or amount_seats > 1 %}#}
|
||||
<div class="{{ class }}">
|
||||
<label for="{{id}}" class="text-sm text-gray-600 ">Ruderer</label>
|
||||
<select style="width: 100%;" multiple name="rowers[]" id="{{id}}" class="w-full" data-seats="{{amount_seats}}" data-init={{init}}>
|
||||
@ -117,7 +85,7 @@
|
||||
{% set_global sel = true %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<option value="{{ user.id }}" {% if sel %} selected {% endif %} {% if user.on_water %} disabled="disabled" {% endif %}>
|
||||
<option value="{{ user.id }}" {% if sel %} selected {% endif %} {% if user.on_water %} disabled="disabled" {% endif %} data-custom-properties='{"is_cox": {{ user.is_cox }}, "steers": {{ user.id == steering_person_id }}, "cox_on_boat": {{ user.id == cox_on_boat}}}'>
|
||||
{{user.name}}
|
||||
{% if user.on_water %}
|
||||
(am Wasser)
|
||||
@ -126,7 +94,7 @@
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
{#{% endif %}#}
|
||||
{% endmacro rower_select %}
|
||||
|
||||
{% macro show(log, state, allowed_to_close=false, only_ones) %}
|
||||
@ -166,22 +134,16 @@
|
||||
{{ log.destination }}
|
||||
{% endif %}
|
||||
|
||||
{% for user in users %}
|
||||
{% if user.id == log.shipmaster %}
|
||||
<p>
|
||||
<strong>{{ user.name }}</strong>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% for rower in log.rowers %}
|
||||
<p>{{ rower.name }}</p>
|
||||
<p>{{ rower.name }} {% if rower.id == log.shipmaster %}Schiffsführer {% endif %}{% if rower.id == log.steering_person%}Steuerperson{% endif %}</p>
|
||||
{# @MB: shipmaster + steering_person could be prettier :') #}
|
||||
{% endfor %}
|
||||
|
||||
{% set amount_rowers = log.rowers | length %}
|
||||
{% set amount_guests = log.boat.amount_seats - amount_rowers -1 %}
|
||||
{% if amount_guests > 0 %}
|
||||
Gäste (ohne Account): {{ amount_guests }}
|
||||
Gäste (ohne Account):
|
||||
{{ amount_guests }}
|
||||
{% endif %}
|
||||
|
||||
{% if allowed_to_close and state == "on_water" %}
|
||||
@ -251,18 +213,25 @@
|
||||
{% endmacro show_old %}
|
||||
|
||||
{% macro home(log, only_ones) %}
|
||||
{# @MB: Maaaarieeee, please fix col-span-2 madness #}
|
||||
<form class="grid grid-cols-1 gap-3" action="/log/{{log.id}}" method="post">
|
||||
{% for user in users %}
|
||||
{% if user.id == log.shipmaster %}
|
||||
<p>
|
||||
<strong>{{ user.name }}</strong>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if not only_ones %}
|
||||
{{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats) }}
|
||||
{% endif %}
|
||||
<div class="relative">
|
||||
{{ log::rower_select(id="rowers"~log.id, selected=log.rowers, amount_seats=log.boat.amount_seats, class="col-span-2", steering_person_id=log.steering_user.id, cox_on_boat=log.shipmaster_user.id) }}
|
||||
{{ macros::select(label="Schiffsführer", data=[], name='shipmaster', id="shipmaster-rowers"~log.id, wrapper_class="col-span-2", class="change-id-js", selected_id=log.shipmaster_user.id, required=true) }}
|
||||
{{ macros::select(label="Steuerperson", data=[], name='steering_person', id="steering_person-rowers"~log.id, wrapper_class="col-span-2", class="change-id-js", selected_id=log.steering_user.id, required=true) }}
|
||||
|
||||
<div class="col-span-2">
|
||||
{{ macros::checkbox(label="Handgesteuert", name="shipmaster_only_steering", id="shipmaster_only_steering" ~ log.id , checked=log.shipmaster_only_steering,class="rounded-md change-id-js") }}
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
{{ macros::input(label='Abfahrtszeit', name='departure', type='datetime-local', required=true, class="change-id-js rounded-md", value=log.departure) }}
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
{{ macros::input(label='Ankunftszeit', name='arrival', type='datetime-local', required=true, class="change-id-js rounded-md current-date-time") }}
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
<label for="destination" class="text-sm text-gray-600">Ziel</label>
|
||||
|
||||
<input class="input rounded-md set-distance-js change-id-js" type="search" list="destinations" placeholder="Destination" required="required" id="destination{{ log.id }}" name="destination" value="{{log.destination}}" data-relation="distance_in_km{{log.id}}"/>
|
||||
@ -273,9 +242,9 @@
|
||||
<span class="absolute right-0 bottom-0 py-1.5 px-2 bg-white border-0 text-gray-600 ring-1 ring-inset ring-gray-300 rounded-br-md rounded-tr-md">km</span>
|
||||
</div>
|
||||
|
||||
{{ macros::input(label="Kommentar", name="comments", id="comments" ~ log.id, type="text", value=log.comments, class="rounded-md change-id-js") }}
|
||||
{{ macros::select(label="Typ", data=logtypes, name="logtype", id="logtype" ~ log.id, default="Normal", selected_id=log.logtype, class="rounded-md change-id-js") }}
|
||||
{{ macros::input(label="Kommentar", name="comments", id="comments" ~ log.id, type="text", value=log.comments, class="rounded-md change-id-js", wrapper_class="col-span-2") }}
|
||||
{{ macros::select(label="Typ", data=logtypes, name="logtype", id="logtype" ~ log.id, default="Normal", selected_id=log.logtype, class="rounded-md change-id-js col-span-2") }}
|
||||
|
||||
<input class="btn btn-primary" type="submit" value="Ausfahrt beenden"/>
|
||||
<input class="btn btn-primary col-span-2" type="submit" value="Ausfahrt beenden"/>
|
||||
</form>
|
||||
{% endmacro home %}
|
||||
|
@ -78,18 +78,18 @@
|
||||
</label>
|
||||
{% endmacro checkbox %}
|
||||
|
||||
{% macro select(label, data, name='trip_type', default='', id='', selected_id='', display='', extras='', class='', wrapper_class='') %}
|
||||
{% macro select(label, data, name='trip_type', default='', id='', selected_id='', display='', extras='', class='', wrapper_class='', required=false, show_seats=false) %}
|
||||
<div class="{{wrapper_class}}">
|
||||
<label for="{{ name }}" class="text-sm text-gray-600">{{ label }}</label>
|
||||
{% if display == '' %}
|
||||
{% set display = ["name"] %}
|
||||
{% endif %}
|
||||
<select name="{{ name }}" {% if id %} id="{{ id }}" {% else %} id="{{ name }}" {% endif %} class="input rounded-md {{ class }}">
|
||||
<select name="{{ name }}" {% if id %} id="{{ id }}" {% else %} id="{{ name }}" {% endif %} class="input rounded-md {{ class }}" {% if required %}required="required"{% endif %}>
|
||||
{% if default %}
|
||||
<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 %}>
|
||||
<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"] }}}'{% endif %}>
|
||||
{% for displa in display -%}
|
||||
{%- if d[displa] -%}
|
||||
{{- d[displa] -}}
|
||||
|
@ -4,7 +4,6 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="w-full">
|
||||
<h1 class="h1">Logbuch</h1>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user