From c31b804102e2af729a3e9dadd709392b005cccb5 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 22 Nov 2021 13:12:32 +0100 Subject: [PATCH] [ported] EditEvent set date of templates to today Ported from flaschengeist-frontend @5e19a437bdfff83762ca899d506d4cd32da744ad --- src/components/management/EditEvent.vue | 37 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/components/management/EditEvent.vue b/src/components/management/EditEvent.vue index 96a52d3..02504a2 100644 --- a/src/components/management/EditEvent.vue +++ b/src/components/management/EditEvent.vue @@ -75,10 +75,15 @@ - - - - +
+
Schichten
+
+ +
+
+
@@ -139,7 +144,7 @@ export default defineComponent({ }); const templates = computed(() => store.templates); - const template = ref(undefined); + const template = ref(); const event = ref(props.modelValue || emptyEvent(startDate.value)); const eventtypes = computed(() => store.eventTypes); const recurrent = ref(false); @@ -160,13 +165,29 @@ export default defineComponent({ } function fromTemplate(tpl: FG.Event) { + const today = new Date() template.value = tpl; - event.value = Object.assign({}, tpl); + + event.value = Object.assign({}, tpl, {id: undefined}); + // Adjust the start to match today + event.value.start = date.adjustDate(event.value.start,{ + date: today.getDate(), + month: today.getMonth() + 1, // js inconsitency between getDate (1-31) and getMonth (0-11) + year: today.getFullYear() + }) + // Use timestamp difference for faster adjustment + const diff = event.value.start.getTime() - tpl.start.getTime() + // Adjust end of event and all jobs + if (event.value.end) + event.value.end.setTime(event.value.end.getTime() + diff) + event.value.jobs.forEach(job => { + job.start.setTime(job.start.getTime() + diff) + if (job.end) + job.end.setTime(job.end.getTime() + diff) + }) } async function save(template = false) { - if (!event.value.is_template && template) event.value.id = NaN; - event.value.is_template = template; try { if (event.value?.id !== undefined) {