[events]: Added removal of events + minor optical improvement

This commit is contained in:
Ferdinand Thiessen 2021-03-22 03:25:59 +01:00
parent 851ce3aa8b
commit f2610b8e84
5 changed files with 91 additions and 20 deletions

@ -1 +1 @@
Subproject commit d0e503b1bfc65f64216042d0fe39daf5377b7901 Subproject commit ac6d0693a062f60d539d7f6d8fdee00fbcc528c7

View File

@ -53,11 +53,15 @@
locale="de-de" locale="de-de"
style="height: 100%; min-height: 400px" style="height: 100%; min-height: 400px"
> >
<template #day="{ scope: { timestamp } }" style="min-height: 200px"> <template #day="{ scope: { timestamp } }">
<template v-if="!events[timestamp.weekday]" style="min-height: 200px"> </template> <div itemref="" class="q-pb-sm" style="min-height: 200px">
<template v-for="(agenda, index) in events[timestamp.weekday]" :key="agenda.id"> <eventslot
<eventslot v-model="events[timestamp.weekday][index]" /> v-for="(agenda, index) in events[timestamp.weekday]"
</template> :key="index"
v-model="events[timestamp.weekday][index]"
@removeEvent="remove"
/>
</div>
</template> </template>
</q-calendar-agenda> </q-calendar-agenda>
</div> </div>
@ -86,7 +90,8 @@ export default defineComponent({
const calendarRealView = computed(() => (calendarDays.value != 7 ? 'day' : 'week')); const calendarRealView = computed(() => (calendarDays.value != 7 ? 'day' : 'week'));
const calendarDays = computed(() => const calendarDays = computed(() =>
calendarView.value == 'day' ? 1 : windowWidth.value < 1000 ? 3 : 7 // <= 1023 is the breakpoint for sm to md
calendarView.value == 'day' ? 1 : windowWidth.value <= 1023 ? 3 : 7
); );
const events = ref<Agendas>({}); const events = ref<Agendas>({});
@ -102,6 +107,22 @@ export default defineComponent({
await loadAgendas(); await loadAgendas();
}); });
async function remove(id: number) {
if (await store.removeEvent(id)) {
// Successfull removed
for (const idx in events.value) {
const i = events.value[idx].findIndex((event) => event.id === id);
if (i !== -1) {
events.value[idx].splice(i, 1);
break;
}
}
} else {
// Not found, this means our eventa are outdated
await loadAgendas();
}
}
async function loadAgendas() { async function loadAgendas() {
const selected = new Date(selectedDate.value); const selected = new Date(selectedDate.value);
console.log(selected); console.log(selected);
@ -180,6 +201,7 @@ export default defineComponent({
updateProxy, updateProxy,
saveNewSelectedDate, saveNewSelectedDate,
proxyDate, proxyDate,
remove,
calendarDays, calendarDays,
calendarView, calendarView,
calendarRealView, calendarRealView,

View File

@ -1,26 +1,52 @@
<template> <template>
<q-card <q-card
class="justify-start content-center items-center rounded-borders border-primary shadow-5 q-mb-xs" class="q-mx-xs q-mt-sm justify-start content-center items-center rounded-borders shadow-5"
bordered bordered
> >
<header class="text-primary q-px-xs"> <q-card-section class="text-primary q-pa-xs">
<div class="col text-weight-bolder"> <div class="text-weight-bolder text-center" style="font-size: 1.5vw">
{{ event.type.name }} {{ event.type.name }}
<template v-if="event.name"
>: <span style="font-size: 1.2vw">{{ event.name }}</span>
</template>
</div> </div>
<div v-if="event.description" class="col text-weight-medium" style="font-size: 10px"> <div v-if="event.description" class="text-weight-medium" style="font-size: 1vw">
Info
{{ event.description }} {{ event.description }}
</div> </div>
</header> </q-card-section>
<div v-for="(job, index) in event.jobs" :key="index"> <q-separator />
<q-separator style="justify-start content-center" /> <q-card-section class="q-pa-xs">
<JobSlot v-model="event.jobs[index]" :event-id="event.id" /> <!-- Jobs -->
</div> <JobSlot
v-for="(job, index) in event.jobs"
:key="index"
v-model="event.jobs[index]"
class="col q-my-xs"
:event-id="event.id"
/>
</q-card-section>
<q-card-actions v-if="canEdit || canDelete" vertical align="center">
<router-link v-if="canEdit" :to="{ name: 'events-edit', params: { id: event.id } }">
<template #default>
<q-btn color="secondary" flat label="Bearbeiten" style="min-width: 95%" />
</template>
</router-link>
<q-btn
v-if="canDelete"
color="negative"
flat
label="Löschen"
style="min-width: 95%"
@click="remove"
/>
</q-card-actions>
</q-card> </q-card>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, computed, PropType } from 'vue'; import { defineComponent, computed, PropType } from 'vue';
import { hasPermission } from 'src/utils/permission';
import { PERMISSIONS } from 'src/plugins/schedule/permissions';
import JobSlot from './JobSlot.vue'; import JobSlot from './JobSlot.vue';
export default defineComponent({ export default defineComponent({
@ -32,13 +58,26 @@ export default defineComponent({
type: Object as PropType<FG.Event>, type: Object as PropType<FG.Event>,
}, },
}, },
emits: { 'update:modelValue': (val: FG.Event) => !!val }, emits: {
'update:modelValue': (val: FG.Event) => !!val,
removeEvent: (val: number) => typeof val === 'number',
},
setup(props, { emit }) { setup(props, { emit }) {
const canDelete = computed(() => hasPermission(PERMISSIONS.DELETE));
const canEdit = computed(() => hasPermission(PERMISSIONS.EDIT));
const event = computed({ const event = computed({
get: () => props.modelValue, get: () => props.modelValue,
set: (v) => emit('update:modelValue', v), set: (v) => emit('update:modelValue', v),
}); });
function remove() {
emit('removeEvent', props.modelValue.id);
}
return { return {
canDelete,
canEdit,
remove,
event, event,
}; };
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<q-card-section> <q-card bordered>
<div class="text-weight-medium q-px-xs"> <div class="text-weight-medium q-px-xs">
{{ asHour(modelValue.start) }} {{ asHour(modelValue.start) }}
<template v-if="modelValue.end">- {{ asHour(modelValue.end) }}</template> <template v-if="modelValue.end">- {{ asHour(modelValue.end) }}</template>
@ -31,7 +31,7 @@
<q-btn v-if="isEnrolled" flat color="negative" label="Austragen" @click="signOutFromJob" /> <q-btn v-if="isEnrolled" flat color="negative" label="Austragen" @click="signOutFromJob" />
</div> </div>
</div> </div>
</q-card-section> </q-card>
</template> </template>
<script lang="ts"> <script lang="ts">

View File

@ -85,6 +85,16 @@ export const useScheduleStore = defineStore({
throw error; throw error;
} }
}, },
async removeEvent(id: number) {
try {
await api.delete(`/schedule/events/${id}`);
} catch (e) {
const error = <AxiosError>e;
if (error.response && error.response.status === 404) return false;
throw e;
}
return true;
},
async removeEventType(id: number) { async removeEventType(id: number) {
await api.delete(`/schedule/event-types/${id}`); await api.delete(`/schedule/event-types/${id}`);