Skip to content
Snippets Groups Projects
SubstitutionOverview.vue 4.23 KiB
Newer Older
<script setup>
import SubstitutionCard from "./substitutions/SubstitutionCard.vue";
import InfiniteScrollingDateSortedCRUDIterator from "aleksis.core/components/generic/InfiniteScrollingDateSortedCRUDIterator.vue";
import SubjectChip from "aleksis.apps.cursus/components/SubjectChip.vue";

import {
  amendedLessonsFromAbsences,
  createOrUpdateSubstitutions,
  gqlGroups,
} from "./amendLesson.graphql";
  <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"
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"
        clearable
        return-object
        filled
        dense
        hide-details
        :placeholder="$t('chronos.substitutions.overview.filter.groups')"
        :loading="$apollo.queries.groups.loading"
Hangzhi Yu's avatar
Hangzhi Yu committed
        :value="currentGroup"
Hangzhi Yu's avatar
Hangzhi Yu committed
        @input="changeSelection"
        @click:clear="changeSelection"
      />
      <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 class="grow">
            {{ $t("chronos.substitutions.overview.info_alert.text") }}
          </v-col>
          <v-spacer></v-spacer>
          <v-col class="shrink">
            <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"
      />
    </template>
Hangzhi Yu's avatar
Hangzhi Yu committed

Hangzhi Yu's avatar
Hangzhi Yu committed
    <template #itemLoader>
      <v-card class="my-2 full-width">
        <div class="full-width d-flex flex-column align-stretch flex-md-row">
          <v-card-text>
            <v-skeleton-loader
              type="avatar, heading, chip"
              class="d-flex full-width align-center gap"
              height="100%"
            />
          </v-card-text>
          <v-card-text>
            <v-skeleton-loader
              type="heading"
              class="d-flex full-width align-center gap"
              height="100%"
            />
          </v-card-text>
          <v-card-text>
            <v-skeleton-loader
              type="button"
              class="d-flex full-width align-center justify-end gap"
              height="100%"
            />
          </v-card-text>
        </div>
      </v-card>
    </template>
  </infinite-scrolling-date-sorted-c-r-u-d-iterator>
  name: "SubstitutionOverview",
  props: {
    objId: {
      type: [Number, String],
      required: false,
      default: null,
  },
  data() {
    return {
      gqlQuery: amendedLessonsFromAbsences,
      gqlPatchMutation: createOrUpdateSubstitutions,
      incomplete: false,
    };
  },
  methods: {
    gqlGetPatchData(item) {
      return { id: item.id, teachers: item.teachers };
    },
    changeSelection(selection) {
      this.$router.push({
        params: {
          objId: selection.id,
        },
Hangzhi Yu's avatar
Hangzhi Yu committed
      this.$refs.iterator.resetDate();
    },
  },
  computed: {
    gqlQueryArgs() {
      return {
        objId: this.objId ? Number(this.objId) : null,
        incomplete: !!this.incomplete,
Hangzhi Yu's avatar
Hangzhi Yu committed
    currentGroup() {
      return this.groups.find((o) => o.id === this.objId);
    },
  },
  apollo: {
    groups: gqlGroups,