Skip to content
Snippets Groups Projects
SubstitutionOverview.vue 4.92 KiB
Newer Older
<script setup>
import SubstitutionCard from "./SubstitutionCard.vue";
import SubstitutionLoader from "./SubstitutionLoader.vue";
import InfiniteScrollingDateSortedCRUDIterator from "aleksis.core/components/generic/InfiniteScrollingDateSortedCRUDIterator.vue";
import {
  amendedLessonsFromAbsences,
  createOrUpdateSubstitutions,
  deleteAmendLessons,
  gqlGroups,
Hangzhi Yu's avatar
Hangzhi Yu committed
  gqlTeachers,
} from "../amendLesson.graphql";

import { DateTime } from "luxon";
  <infinite-scrolling-date-sorted-c-r-u-d-iterator
Hangzhi Yu's avatar
Hangzhi Yu committed
    :gql-query="gqlQuery"
    :gql-additional-query-args="gqlQueryArgs"
    :gql-patch-mutation="gqlPatchMutation"
    :get-patch-data="gqlGetPatchData"
    i18n-key="chronos.substitutions.overview"
    :enable-search="true"
    :enable-create="false"
    :show-create="false"
    :enable-delete="false"
    :enable-edit="true"
    :elevated="false"
    :force-model-item-update="true"
Jonathan Weth's avatar
Jonathan Weth committed
    :day-increment="3"
    empty-icon="mdi-account-multiple-check-outline"
Hangzhi Yu's avatar
Hangzhi Yu committed
    ref="iterator"
Hangzhi Yu's avatar
Hangzhi Yu committed
  >
    <template #additionalActions="{ attrs, on }">
      <v-autocomplete
        :items="groups"
        item-text="name"
Hangzhi Yu's avatar
Hangzhi Yu committed
        item-value="id"
Hangzhi Yu's avatar
Hangzhi Yu committed
        clearable
        filled
        dense
        hide-details
        :placeholder="$t('chronos.substitutions.overview.filter.groups')"
        :loading="$apollo.queries.groups.loading"
Hangzhi Yu's avatar
Hangzhi Yu committed
        :value="objId"
Hangzhi Yu's avatar
Hangzhi Yu committed
        @input="changeGroup"
        @click:clear="changeGroup"
      />
      <v-autocomplete
        :items="amendableTeachers"
        item-text="fullName"
        item-value="id"
        clearable
        filled
        dense
        hide-details
        :placeholder="$t('chronos.substitutions.overview.filter.teachers')"
        :loading="$apollo.queries.amendableTeachers.loading"
Hangzhi Yu's avatar
Hangzhi Yu committed
        :value="teacherId"
        @input="changeTeacher"
        @click:clear="changeTeacher"
Hangzhi Yu's avatar
Hangzhi Yu committed
      />
      <v-switch
        :loading="$apollo.queries.groups.loading"
        :label="$t('chronos.substitutions.overview.filter.missing')"
        v-model="incomplete"
        dense
        inset
        hide-details
        class="ml-6"
      />

Hangzhi Yu's avatar
Hangzhi Yu committed
      <v-alert type="info" outlined dense class="full-width">
        <v-row align="center" no-gutters>
          <v-col cols="12" md="9">
Hangzhi Yu's avatar
Hangzhi Yu committed
            {{ $t("chronos.substitutions.overview.info_alert.text") }}
          </v-col>
          <v-col cols="12" md="3" align="right">
Hangzhi Yu's avatar
Hangzhi Yu committed
            <v-btn
              color="info"
              outlined
              small
              :to="{ name: 'kolego.absences' }"
            >
              {{ $t("chronos.substitutions.overview.info_alert.button") }}
            </v-btn>
          </v-col>
        </v-row>
      </v-alert>
    </template>
Hangzhi Yu's avatar
Hangzhi Yu committed
    <template #item="{ item, lastQuery }">
      <substitution-card
        :substitution="item"
        :affected-query="lastQuery"
        :is-create="false"
        :gql-patch-mutation="gqlPatchMutation"
        :gql-delete-mutation="gqlDeleteMutation"
        :amendable-rooms="amendableRooms"
        :amendable-subjects="amendableSubjects"
        :amendable-teachers="amendableTeachers"
        @delete="handleDelete"
Hangzhi Yu's avatar
Hangzhi Yu committed
      />
    </template>
Hangzhi Yu's avatar
Hangzhi Yu committed

Hangzhi Yu's avatar
Hangzhi Yu committed
    <template #itemLoader>
      <substitution-loader />
Hangzhi Yu's avatar
Hangzhi Yu committed
    </template>
  </infinite-scrolling-date-sorted-c-r-u-d-iterator>
  name: "SubstitutionOverview",
  props: {
    objId: {
      type: [Number, String],
      required: false,
      default: null,
Hangzhi Yu's avatar
Hangzhi Yu committed
    teacherId: {
      type: [Number, String],
      required: false,
      default: null,
    },
  },
  data() {
    return {
      gqlQuery: amendedLessonsFromAbsences,
      gqlPatchMutation: createOrUpdateSubstitutions,
      gqlDeleteMutation: deleteAmendLessons,
Hangzhi Yu's avatar
Hangzhi Yu committed
      amendableTeachers: [],
      incomplete: false,
    };
  },
  methods: {
    gqlGetPatchData(item) {
      return { id: item.id, teachers: item.teachers };
    },
Hangzhi Yu's avatar
Hangzhi Yu committed
    changeGroup(group) {
      this.$router.push({
        name: "chronos.substitutionOverview",
        params: {
          objId: group ? group : "all",
          teacherId: this.teacherId,
        },
        hash: this.$route.hash,
      });
      this.$refs.iterator.resetDate();
    },
    changeTeacher(teacher) {
      this.$router.push({
Hangzhi Yu's avatar
Hangzhi Yu committed
          teacherId: teacher ? teacher : "all",
          objId: this.objId,
Hangzhi Yu's avatar
Hangzhi Yu committed
      this.$refs.iterator.resetDate();
    handleDelete(datetime) {
      this.$refs.iterator.refetchDay(DateTime.fromISO(datetime).toISODate());
    },
  },
  computed: {
    gqlQueryArgs() {
      return {
Hangzhi Yu's avatar
Hangzhi Yu committed
        objId: this.objId === "all" ? null : Number(this.objId),
Hangzhi Yu's avatar
Hangzhi Yu committed
        teacher: this.teacherId === "all" ? null : Number(this.teacherId),
        incomplete: !!this.incomplete,
    groups: gqlGroups,
    amendableRooms: gqlRooms,
    amendableSubjects: gqlSubjects,
Hangzhi Yu's avatar
Hangzhi Yu committed
    amendableTeachers: gqlTeachers,