[ported] EditEvent set date of templates to today

Ported from flaschengeist-frontend @5e19a437bdfff83762ca899d506d4cd32da744ad
This commit is contained in:
Ferdinand Thiessen 2021-11-22 13:12:32 +01:00
parent 82a24a5a53
commit c31b804102
1 changed files with 29 additions and 8 deletions

View File

@ -75,10 +75,15 @@
</q-card-section> </q-card-section>
<q-separator /> <q-separator />
<q-card-section> <q-card-section>
<q-btn color="primary" label="Schicht hinzufügen" @click="addJob()" /> <div class="row justify-around q-mb-sm" align="around">
</q-card-section> <div class="text-h6 text-center col-6">Schichten</div>
<q-card-section v-for="(job, index) in event.jobs" :key="index"> <div class="col-6 text-center">
<edit-job-slot v-model="event.jobs[index]" @remove-job="removeJob(index)" /> <q-btn color="primary" label="Schicht hinzufügen" @click="addJob()" />
</div>
</div>
<template v-for="(job, index) in event.jobs" :key="index">
<edit-job-slot v-model="event.jobs[index]" @remove-job="removeJob(index)" />
</template>
</q-card-section> </q-card-section>
<q-card-actions align="around"> <q-card-actions align="around">
<q-card-actions align="left"> <q-card-actions align="left">
@ -139,7 +144,7 @@ export default defineComponent({
}); });
const templates = computed(() => store.templates); const templates = computed(() => store.templates);
const template = ref<FG.Event | undefined>(undefined); const template = ref<FG.Event>();
const event = ref<EditableEvent>(props.modelValue || emptyEvent(startDate.value)); const event = ref<EditableEvent>(props.modelValue || emptyEvent(startDate.value));
const eventtypes = computed(() => store.eventTypes); const eventtypes = computed(() => store.eventTypes);
const recurrent = ref(false); const recurrent = ref(false);
@ -160,13 +165,29 @@ export default defineComponent({
} }
function fromTemplate(tpl: FG.Event) { function fromTemplate(tpl: FG.Event) {
const today = new Date()
template.value = tpl; 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) { async function save(template = false) {
if (!event.value.is_template && template) event.value.id = NaN;
event.value.is_template = template; event.value.is_template = template;
try { try {
if (event.value?.id !== undefined) { if (event.value?.id !== undefined) {