<script setup> import AmendedLessonCard from "./AmendedLessonCard.vue"; import CRUDIterator from "aleksis.core/components/generic/CRUDIterator.vue"; import DateField from "aleksis.core/components/generic/forms/DateField.vue"; import SubjectChip from "aleksis.apps.cursus/components/SubjectChip.vue"; import { DateTime } from "luxon"; import { amendedLessonsFromAbsences, batchPatchAmendLessons, groupsByOwner, } from "./amendLesson.graphql"; </script> <template> <c-r-u-d-iterator :gql-query="gqlQuery" :gql-additional-query-args="gqlQueryArgs" :gql-patch-mutation="gqlPatchMutation" :get-patch-data="gqlGetPatchData" i18n-key="chronos.amend_lesson.overview" :enable-search="true" :enable-create="false" :show-create="false" :enable-delete="false" :enable-edit="true" :force-model-item-update="true" @lastQuery="lastQuery = $event" > <template #additionalActions="{ attrs, on }"> <v-autocomplete :items="groups" item-text="name" clearable return-object filled dense hide-details :placeholder="$t('chronos.amend_lesson.overview.filter.groups')" :loading="$apollo.queries.groups.loading" :value="currentObj" @input="changeSelection" @click:clear="changeSelection" /> </template> <template #default="{ items }"> <v-list-item v-for="day in groupAmendedLessonsByDay(items)" two-line> <v-list-item-content> <v-list-item-title>{{ $d(day[0], "short") }}</v-list-item-title> <v-list> <v-list-item v-for="amendedLesson in day.slice(1)"> <amended-lesson-card :amended-lesson="amendedLesson" :affected-query="lastQuery" :is-create="false" :gql-patch-mutation="batchPatchAmendLessons" /> </v-list-item> </v-list> </v-list-item-content> </v-list-item> </template> </c-r-u-d-iterator> </template> <script> export default { props: { objId: { type: [Number, String], required: false, default: null, }, // Next two in ISODate dateStart: { type: String, required: false, default: "", }, dateEnd: { type: String, required: false, default: "", }, }, data() { return { gqlQuery: amendedLessonsFromAbsences, gqlPatchMutation: batchPatchAmendLessons, lastQuery: null, groups: [], }; }, methods: { groupAmendedLessonsByDay(amendedLessons) { const byDay = amendedLessons.reduce((byDay, amendedLesson) => { const day = DateTime.fromISO(amendedLesson.datetimeStart).startOf( "day", ); byDay[day] ??= [day]; byDay[day].push(amendedLesson); return byDay; }, {}); return Object.keys(byDay) .sort() .map((key) => byDay[key]); }, gqlGetPatchData(item) { return { id: item.id, teachers: item.teachers }; }, changeSelection(selection) { this.$router.push({ name: "chronos.amendLessonOvervievByTypeAndDate", params: { objId: selection.id, dateStart: this.dateStart, dateEnd: this.dateEnd, }, }); }, }, computed: { gqlQueryArgs() { return { objId: this.objId ? Number(this.objId) : null, dateStart: this.dateStart, dateEnd: this.dateEnd, }; }, currentObj() { return this.groups.find((o) => o.id === this.objId); }, }, apollo: { groups: groupsByOwner, }, }; </script>