Skip to content
Snippets Groups Projects
Commit c48942a4 authored by permcu's avatar permcu
Browse files

Adapt longterm-absences-frontend to optionally show periods

parent 2e1bc741
Loading
Pipeline #195066 failed
...@@ -24,32 +24,46 @@ ...@@ -24,32 +24,46 @@
</div> </div>
</v-row> </v-row>
<v-row> <v-row>
<v-col cols="12" :sm="6" class="pl-0"> <v-col cols="12" :sm="startPeriods ? 4 : 6" class="pl-0">
<div aria-required="true"> <div aria-required="true">
<date-time-field <date-time-field
:label="$t('forms.labels.start')" :label="$t('forms.labels.start')"
:max-date="maxStartDate"
:max-time="maxStartTime"
:limit-selectable-range="false"
:rules="$rules().required.build()" :rules="$rules().required.build()"
:value="startDate" :value="start.toISO()"
@input="handleStartDate" @input="handleStartDate"
/> />
</div> </div>
</v-col> </v-col>
<v-col cols="12" :sm="6" class="pr-0"> <v-col cols="12" :sm="2" v-if="startPeriods" align-self="end">
<v-select
:label="$t('lesrooster.slot.period')"
:items="startPeriods"
item-text="period"
:value="startSlot"
@input="handleStartSlot"
return-object
/>
</v-col>
<v-col cols="12" :sm="endPeriods ? 4 : 6" class="pr-0">
<div aria-required="true"> <div aria-required="true">
<date-time-field <date-time-field
:label="$t('forms.labels.end')" :label="$t('forms.labels.end')"
:min-date="minEndDate"
:min-time="minEndTime"
:limit-selectable-range="false"
:rules="$rules().required.build()" :rules="$rules().required.build()"
:value="endDate" :value="end.toISO()"
@input="handleEndDate" @input="handleEndDate"
/> />
</div> </div>
</v-col> </v-col>
<v-col cols="12" :sm="2" v-if="endPeriods" align-self="end">
<v-select
:label="$t('lesrooster.slot.period')"
:items="endPeriods"
item-text="period"
:value="endSlot"
@input="handleEndSlot"
return-object
/>
</v-col>
</v-row> </v-row>
<v-row> <v-row>
<v-text-field <v-text-field
...@@ -75,7 +89,10 @@ ...@@ -75,7 +89,10 @@
<script> <script>
import AbsenceReasonGroupSelect from "aleksis.apps.kolego/components/AbsenceReasonGroupSelect.vue"; import AbsenceReasonGroupSelect from "aleksis.apps.kolego/components/AbsenceReasonGroupSelect.vue";
import DateTimeField from "aleksis.core/components/generic/forms/DateTimeField.vue"; import DateTimeField from "aleksis.core/components/generic/forms/DateTimeField.vue";
import { persons } from "./absenceCreation.graphql"; import {
periodsByDay,
persons,
} from "./absenceCreation.graphql";
import formRulesMixin from "aleksis.core/mixins/formRulesMixin.js"; import formRulesMixin from "aleksis.core/mixins/formRulesMixin.js";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
...@@ -96,6 +113,13 @@ export default { ...@@ -96,6 +113,13 @@ export default {
], ],
apollo: { apollo: {
allPersons: persons, allPersons: persons,
periodsByDay: {
query: periodsByDay,
result({ data: { periodsByDay } }) {
this.handleStartDate(this.start);
this.handleEndDate(this.end);
},
},
}, },
props: { props: {
persons: { persons: {
...@@ -123,60 +147,91 @@ export default { ...@@ -123,60 +147,91 @@ export default {
required: true, required: true,
}, },
}, },
data() {
return {
startDT: DateTime.fromISO(this.startDate),
endDT: DateTime.fromISO(this.endDate),
startPeriods: false,
endPeriods: false,
startSlot: undefined,
endSlot: undefined,
};
},
computed: { computed: {
maxStartTime() { start: {
// Only if on the same day get() {
const start = DateTime.fromISO(this.startDate); return this.startDT;
const end = DateTime.fromISO(this.endDate); },
set(dt) {
if (start.day !== end.day) return; this.startDT = dt;
if (dt >= this.end) {
return end.minus({ minutes: 5 }).toFormat("HH:mm"); this.end = dt.plus({ minutes: 5 });
}
this.$emit("start-date", dt.toISO());
console.log("Set start", this.startDT.toISO());
},
}, },
minEndTime() { end: {
// Only if on the same day get() {
const start = DateTime.fromISO(this.startDate); return this.endDT;
const end = DateTime.fromISO(this.endDate); },
set(dt) {
if (start.day !== end.day) return; this.endDT = dt;
if (dt <= this.start) {
return start.plus({ minutes: 5 }).toFormat("HH:mm"); this.start = dt.minus({ minutes: 5 });
}, }
maxStartDate() { this.$emit("end-date", dt.toISO());
const end = DateTime.fromISO(this.endDate); },
return end.toISODate();
},
minEndDate() {
const start = DateTime.fromISO(this.startDate);
return start.toISODate();
}, },
}, },
methods: { methods: {
handleStartDate(startDate) { getPeriodsForWeekday(weekday) {
const parsedStart = DateTime.fromISO(startDate); // Adapt from python conventions
const parsedEnd = DateTime.fromISO(this.endDate); const pythonWeekday = weekday - 1;
if (parsedStart >= parsedEnd) { return this.periodsByDay.find((period) => period.weekday === pythonWeekday).periods;
this.$emit( },
"end-date", handleStartDate(date) {
parsedStart.plus({ minutes: 5 }).toISO({ suppressSeconds: true }), console.log("handleStartDate", date);
); this.start = DateTime.fromISO(date);
if (this.periodsByDay.length > 0) {
// Select periods for day
this.startPeriods = this.getPeriodsForWeekday(this.start.weekday);
// Sync PeriodSelect
const startTime = this.start.toFormat("HH:mm:ss")
console.log("syncing to ", startTime)
this.startSlot = this.startPeriods.find((period) => period.timeStart === startTime)
console.log("startSlot ", this.startSlot)
} }
this.$emit("start-date", startDate);
this.$refs.form.resetValidation();
this.$refs.form.validate();
}, },
handleEndDate(endDate) { handleEndDate(date) {
const parsedStart = DateTime.fromISO(this.startDate); this.end = DateTime.fromISO(date);
const parsedEnd = DateTime.fromISO(endDate);
if (parsedEnd <= parsedStart) { if (this.periodsByDay.length > 0) {
this.$emit( // Select periods for day
"start-date", this.endPeriods = this.getPeriodsForWeekday(this.end.weekday);
parsedEnd.minus({ minutes: 5 }).toISO({ suppressSeconds: true }), // Sync PeriodSelect
); const endTime = this.end.toFormat("HH:mm:ss")
this.endSlot = this.endPeriods.find((period) => period.endTime === endTime)
} }
this.$emit("end-date", endDate); },
this.$refs.form.resetValidation(); handleStartSlot(slot) {
this.$refs.form.validate(); // Sync TimeSelect
const startTime = DateTime.fromISO(slot.timeStart)
this.start = this.start.set({
hour: startTime.hour,
minute: startTime.minute,
second: startTime.second,
});
},
handleEndSlot(slot) {
// Sync TimeSelect
const endTime = DateTime.fromISO(slot.timeEnd)
this.end = this.end.set({
hour: endTime.hour,
minute: endTime.minute,
second: endTime.second,
});
}, },
}, },
}; };
......
...@@ -6,6 +6,17 @@ query persons { ...@@ -6,6 +6,17 @@ query persons {
} }
} }
query periodsByDay {
periodsByDay: periodsByDay {
weekday
periods {
period
timeStart
timeEnd
}
}
}
query lessonsForPersons($persons: [ID]!, $start: DateTime!, $end: DateTime!) { query lessonsForPersons($persons: [ID]!, $start: DateTime!, $end: DateTime!) {
items: lessonsForPersons(persons: $persons, start: $start, end: $end) { items: lessonsForPersons(persons: $persons, start: $start, end: $end) {
id id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment