From 2d520298e7ca7500c14e3b86d6266d25a7fb4e08 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 30 Oct 2023 13:39:58 +0100 Subject: [PATCH] frontend for new db --- frontend/main.ts | 128 +++++++++++++++++-------- src/model/logbook.rs | 14 ++- templates/includes/forms/log.html.tera | 105 ++++++++++---------- templates/includes/macros.html.tera | 44 ++++----- 4 files changed, 173 insertions(+), 118 deletions(-) diff --git a/frontend/main.ts b/frontend/main.ts index c47ab54..e17a717 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -22,11 +22,10 @@ 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; } } @@ -53,9 +52,8 @@ function selectBoatChange() { )[0]; const rowers = Number(originalOption.dataset.amount_seats); - const isShipmasterSteering = originalOption.dataset.default_shipmaster_only_steering; - setMaxAmountRowers(rowers,isShipmasterSteering); + setMaxAmountRowers("newrower", rowers); return opt; } @@ -83,51 +81,51 @@ function reloadPage() { }); } -function setMaxAmountRowers(rowers: number, isShipmasterSteering='false') { - if(choiceObjects['newrower']) { - let curSelection = choiceObjects['newrower'].getValue(true); +function setMaxAmountRowers(name: string, rowers: number) { + if(choiceObjects[name]) { + let curSelection = choiceObjects[name].getValue(true); let amount_to_delete = (curSelection).length - rowers; if (amount_to_delete > 0){ let to_delete = (curSelection).slice(-amount_to_delete); for (let del of to_delete) { - choiceObjects['newrower'].removeActiveItemsByValue(del); + choiceObjects[name].removeActiveItemsByValue(del); } } - let input = document.querySelector('#newrower'); + let input = 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 = 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 = 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'); + // } + //} } } @@ -138,9 +136,8 @@ function initBoatActions() { select.addEventListener('click', function() { if(select.dataset.seats) { const rowers = Number(select.dataset.seats); - const isShipmasterSteering = select.dataset.default_shipmaster_only_steering; - setMaxAmountRowers(rowers, isShipmasterSteering); + setMaxAmountRowers("newrower", rowers); if (select.dataset.id) { choiceObjects['boat_id'].setChoiceByValue(select.dataset.id); @@ -174,6 +171,8 @@ interface ChoiceEvent extends Event{ label: string, customProperties: { is_cox: boolean, + steers: boolean, + cox_on_boat: boolean, } }; } @@ -190,7 +189,50 @@ 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