[schedule] Improved creating new events

This commit is contained in:
Ferdinand Thiessen 2021-03-20 00:59:44 +01:00
parent a4ce273bb1
commit 7e7f9c943d
4 changed files with 53 additions and 117 deletions

View File

@ -28,11 +28,11 @@ declare namespace FG {
id: number; id: number;
time: Date; time: Date;
amount: number; amount: number;
reversal_id: number; reversal_id?: number;
sender_id?: string;
receiver_id?: string;
author_id?: string; author_id?: string;
sender_id?: string;
original_id?: number; original_id?: number;
receiver_id?: string;
} }
interface Drink { interface Drink {
id: number; id: number;
@ -91,7 +91,7 @@ declare namespace FG {
start: Date; start: Date;
end?: Date; end?: Date;
description?: string; description?: string;
type: EventType; type: EventType | number;
jobs: Array<Job>; jobs: Array<Job>;
} }
interface EventType { interface EventType {
@ -102,8 +102,8 @@ declare namespace FG {
id: number; id: number;
start: Date; start: Date;
end?: Date; end?: Date;
comment: string; type: JobType | number;
type: JobType; comment?: string;
services: Array<Service>; services: Array<Service>;
required_services: number; required_services: number;
} }

View File

@ -43,13 +43,8 @@
<q-card-section v-for="(job, index) in event.jobs" :key="index"> <q-card-section v-for="(job, index) in event.jobs" :key="index">
<q-card class="q-my-auto"> <q-card class="q-my-auto">
<job <job
:job="job" v-model="event.jobs[index]"
:job-can-delete="jobDeleteDisabled" :job-can-delete="jobDeleteDisabled"
@set-start="setStart"
@set-required="setRequired"
@set-end="setEnd"
@set-comment="setComment"
@set-job-type="setJobType"
@remove-job="removeJob(index)" @remove-job="removeJob(index)"
/> />
</q-card> </q-card>
@ -78,59 +73,31 @@ export default defineComponent({
const eventtypes = computed(() => store.eventTypes); const eventtypes = computed(() => store.eventTypes);
const jobDeleteDisabled = computed(() => event.value.jobs.length < 2); const jobDeleteDisabled = computed(() => event.value.jobs.length < 2);
const newJob = ref<FG.Job>(({ const newJob = ref<FG.Job>({
id: NaN, id: NaN,
start: undefined, start: new Date(),
end: undefined, end: date.addToDate(new Date(), { hours: 1 }),
comment: '',
services: [], services: [],
required_services: 2, required_services: 2,
} as unknown) as FG.Job); type: store.jobTypes[0],
});
const event = ref<FG.Event>({ const event = ref<FG.Event>({
id: NaN, id: NaN,
start: new Date(), start: new Date(),
description: '',
jobs: [Object.assign({}, newJob.value)], jobs: [Object.assign({}, newJob.value)],
} as FG.Event); type: store.eventTypes[0],
});
onBeforeMount(() => { onBeforeMount(() => {
void store.getEventTypes(); void store.getEventTypes();
void store.getJobTypes(); void store.getJobTypes();
}); });
function setStart(data: { job: FG.Job; value: Date }) {
data.job.start = data.value;
}
function setEnd(data: { job: FG.Job; value: Date }) {
data.job.end = data.value;
}
function setComment(data: { job: FG.Job; value: string }) {
data.job.comment = data.value;
}
function setJobType(job: FG.Job, value: FG.JobType) {
job.type = value;
}
function setRequired(data: { job: FG.Job; value: number }) {
data.job.required_services = data.value;
}
function addJob() { function addJob() {
const addJob = Object.assign({}, newJob.value); event.value.jobs.push(Object.assign({}, newJob.value));
event.value.jobs.unshift(addJob);
} }
//function removeJob(id: number) {
// let jobtoremove = event.value.jobs.findIndex(job => job.id == id);
// if (jobtoremove != undefined) {
// event.value.jobs.splice(jobtoremove, 1);
// }
//}
function removeJob(index: number) { function removeJob(index: number) {
event.value.jobs.splice(index, 1); event.value.jobs.splice(index, 1);
} }
@ -174,11 +141,6 @@ export default defineComponent({
reset, reset,
event, event,
isAfterDate, isAfterDate,
setStart,
setEnd,
setComment,
setJobType,
setRequired,
}; };
}, },
}); });

View File

@ -2,59 +2,52 @@
<q-card-section class="fit row justify-start content-center items-center"> <q-card-section class="fit row justify-start content-center items-center">
<q-card-section class="fit row justify-start content-center items-center"> <q-card-section class="fit row justify-start content-center items-center">
<IsoDateInput <IsoDateInput
v-model="job.start"
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
:value="job.start"
label="Beginn" label="Beginn"
type="datetime" type="datetime"
:rules="[noValidDate, notEmpty]" :rules="[notEmpty, noValidDate]"
@input="setStart"
/> />
<IsoDateInput <IsoDateInput
ref="bla" v-model="job.end"
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
:value="job.end"
label="Ende" label="Ende"
type="datetime" type="datetime"
:rules="[noValidDate, isAfterDate, notEmpty]" :rules="[notEmpty, noValidDate, isAfterDate]"
@input="setEnd"
/> />
</q-card-section> </q-card-section>
<q-card-section class="row fit justify-start content-center items-center"> <q-card-section class="row fit justify-start content-center items-center">
<q-select <q-select
:key="refreshKey" v-model="job.type"
filled filled
use-input use-input
label="Dienstart" label="Dienstart"
input-debounce="0" input-debounce="0"
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
:value="job.type"
:options="jobtypes" :options="jobtypes"
option-label="name" option-label="name"
option-value="name" option-value="id"
map-options map-options
clearable clearable
:rules="[notEmpty]" :rules="[notEmpty]"
@input="setJobType"
/> />
<q-input <q-input
v-model="job.required_services"
filled filled
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
label="Dienstanzahl" label="Dienstanzahl"
type="number" type="number"
:value="job.required_services"
:rules="[notEmpty]" :rules="[notEmpty]"
@input="setRequired"
/> />
</q-card-section> </q-card-section>
<q-card-section class="fit row justify-start content-center items-center"> <q-card-section class="fit row justify-start content-center items-center">
<q-input <q-input
v-model="job.comment"
class="col-xs-12 col-sm-6 q-pa-sm" class="col-xs-12 col-sm-6 q-pa-sm"
label="Beschreibung" label="Beschreibung"
type="textarea" type="textarea"
:value="job.comment"
filled filled
:rules="[notEmpty]" :rules="[notEmpty]"
@input="setComment"
/> />
</q-card-section> </q-card-section>
<q-btn label="Schicht löschen" color="negative" :disabled="jobCanDelete" @click="removeJob" /> <q-btn label="Schicht löschen" color="negative" :disabled="jobCanDelete" @click="removeJob" />
@ -63,7 +56,7 @@
<script lang="ts"> <script lang="ts">
import IsoDateInput from 'src/components/utils/IsoDateInput.vue'; import IsoDateInput from 'src/components/utils/IsoDateInput.vue';
import { defineComponent, computed, ref, onBeforeMount, PropType } from 'vue'; import { defineComponent, computed, onBeforeMount, PropType } from 'vue';
import { useScheduleStore } from '../../store'; import { useScheduleStore } from '../../store';
import { date } from 'quasar'; import { date } from 'quasar';
@ -71,19 +64,15 @@ export default defineComponent({
name: 'Job', name: 'Job',
components: { IsoDateInput }, components: { IsoDateInput },
props: { props: {
job: { modelValue: {
required: true, required: true,
type: Object as PropType<FG.Job>, type: Object as PropType<FG.Job>,
}, },
jobCanDelete: Boolean, jobCanDelete: Boolean,
}, },
emits: { emits: {
'set-start': (d: Date) => !!d,
'remove-job': () => true, 'remove-job': () => true,
'set-end': (d: Date) => !!d, 'update:modelValue': (job: FG.Job) => !!job,
'set-comment': (c: string) => !!c,
'set-job-type': (jt: FG.JobType) => !!jt,
'set-required': (r: number) => isFinite(r),
}, },
setup(props, { emit }) { setup(props, { emit }) {
const store = useScheduleStore(); const store = useScheduleStore();
@ -91,27 +80,22 @@ export default defineComponent({
onBeforeMount(() => store.getJobTypes()); onBeforeMount(() => store.getJobTypes());
const jobtypes = computed(() => store.jobTypes); const jobtypes = computed(() => store.jobTypes);
const refreshKey = ref<number>(0);
function setStart(value: Date) { const job = new Proxy(props.modelValue, {
emit('set-start', value); get(target, prop) {
if (typeof prop === 'string') {
return ((props.modelValue as unknown) as Record<string, unknown>)[prop];
} }
},
function setEnd(value: Date) { set(obj, prop, value) {
emit('set-end', value); console.log('...', obj, prop, value);
} if (typeof prop === 'string') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
function setComment(value: string) { emit('update:modelValue', Object.assign({}, props.modelValue, { [prop]: value }));
emit('set-comment', value);
}
function setJobType(value: FG.JobType) {
emit('set-job-type', value);
}
function setRequired(value: number) {
emit('set-required', value);
} }
return true;
},
});
function removeJob() { function removeJob() {
emit('remove-job'); emit('remove-job');
@ -121,31 +105,20 @@ export default defineComponent({
return !!val || 'Feld darf nicht leer sein!'; return !!val || 'Feld darf nicht leer sein!';
} }
function noValidDate(val: string) { function noValidDate(val: string) {
console.log(val);
return !!date.isValid(val) || 'Datum/Zeit muss gesetzt sein!'; return !!date.isValid(val) || 'Datum/Zeit muss gesetzt sein!';
} }
function isAfterDate(val: Date) { function isAfterDate(val: string) {
console.log('isAfterDate', props.job.start, val); return props.modelValue.start < new Date(val) || 'Ende muss hinter dem Start liegen';
return props.job.start < new Date(val) || 'Ende muss hinter dem Start liegen';
}
function refresh() {
refreshKey.value += 1;
} }
return { return {
job,
jobtypes, jobtypes,
setStart,
setEnd,
setComment,
setJobType,
setRequired,
removeJob, removeJob,
notEmpty, notEmpty,
noValidDate, noValidDate,
isAfterDate, isAfterDate,
refreshKey,
}; };
}, },
}); });

View File

@ -27,14 +27,15 @@ export const useScheduleStore = defineStore({
getters: {}, getters: {},
actions: { actions: {
async getJobTypes() { async getJobTypes(force = false) {
if (force || this.jobTypes.length == 0)
try { try {
const { data } = await api.get<FG.JobType[]>('/schedule/job-types'); const { data } = await api.get<FG.JobType[]>('/schedule/job-types');
this.jobTypes = data; this.jobTypes = data;
return this.jobTypes;
} catch (error) { } catch (error) {
throw error; throw error;
} }
return this.jobTypes;
}, },
async addJobType(name: string) { async addJobType(name: string) {