Skip to content
Snippets Groups Projects

Resolve "Frontend for Models"

Merged Julian requested to merge 1-frontend-for-models into master
Compare and Show latest version
21 files
+ 1868
204
Compare changes
  • Side-by-side
  • Inline
Files
21
<template>
<div id="slot-container">
<v-card style="grid-column: side; grid-row: 1">
<v-card-text>
<validity-range-field
solo
hide-details
v-model="internalValidityRange"
:loading="$apollo.queries.currentValidityRange.loading"
/>
</v-card-text>
<v-card class="sidebar">
<v-navigation-drawer
floating
permanent
>
<v-list dense rounded>
<validity-range-field
solo
rounded
hide-details
v-model="internalValidityRange"
:loading="$apollo.queries.currentValidityRange.loading"
/>
<slot-creator
:query="$apollo.queries.items"
:validity-range="internalValidityRange.id"
v-if="internalValidityRange"
:breaks="createBreaks"
>
<template #activator="{ on, attrs }">
<v-list-item link v-bind="attrs" v-on="on" @click="createBreaks = false">
<v-list-item-icon>
<v-icon>$plus</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ $t("lesrooster.slot.create_items") }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item link v-bind="attrs" v-on="on" @click="createBreaks = true">
<v-list-item-icon>
<v-icon>$plus</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ $t("lesrooster.break.create_items") }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</template>
</slot-creator>
</v-list>
</v-navigation-drawer>
</v-card>
<v-hover
@@ -20,12 +51,12 @@
>
<v-card :loading="$apollo.queries.items.loading">
<v-card-title class="d-flex flex-wrap justify-space-between align-center fill-height">
<span>{{ $t("weekdays." + weekday) }}</span>
<span class="min-height">{{ $t("weekdays." + weekday) }}</span>
<v-tooltip bottom>
<template #activator="{ on, attrs }">
<v-btn
disabled
@click="deleteSlotsOfDay(weekday)"
icon
v-bind="attrs"
v-on="on"
@@ -78,7 +109,7 @@
style="left: calc(-20px - 0.5rem)"
@click="add(left(weekday))"
>
<v-icon>mdi-plus</v-icon>
<v-icon>mdi-table-column-plus-before</v-icon>
</v-btn>
<v-btn
v-if="canAddDay(right(weekday))"
@@ -92,7 +123,7 @@
style="right: calc(-20px - 0.5rem)"
@click="add(right(weekday))"
>
<v-icon>mdi-plus</v-icon>
<v-icon>mdi-table-column-plus-after</v-icon>
</v-btn>
</v-card-title>
</v-card>
@@ -101,17 +132,67 @@
<template
v-for="slot in slots"
>
<slot-card
:item="slot"
:disabled="$apollo.queries.items.loading"
/>
<v-menu offset-y>
<template #activator="{ on, attrs }">
<slot-card
:item="slot"
:disabled="$apollo.queries.items.loading"
@click:delete="deleteSingularSlot"
@click:copy="on.click"
v-bind="attrs"
/>
</template>
<v-list>
<v-list-item
v-for="(item, index) in weekdays.filter(day => day !== slot.weekday)"
:key="index"
link
>
<v-list-item-title @click="copySingularSlotTodDay(slot, item)">{{
$t("weekdays." + item)
}}
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</template>
<delete-dialog
:gql-mutation="deleteMutation"
:gql-query="$apollo.queries.items"
v-model="deleteDialog"
:item="itemToDelete"
>
<template #body>
{{ $t("lesrooster." + itemToDelete.model.toLowerCase() + ".repr", itemToDelete) }}
</template>
</delete-dialog>
<delete-multiple-dialog
:gql-mutation="deleteMultipleMutation"
:gql-query="$apollo.queries.items"
:items="itemsToDelete"
v-model="deleteMultipleDialog"
>
<template #title>
{{ $t('lesrooster.slot.confirm_delete_multiple_slots', {day: $t("weekdays." + weekdays[0])}) }}
</template>
<template #body>
<ul class="text-body-1">
<li v-for="item in itemsToDelete">
{{ $t("lesrooster." + item.model.toLowerCase() + ".repr", item) }}
</li>
</ul>
</template>
</delete-multiple-dialog>
</div>
</template>
<script>
import {createBreakSlot, deleteBreakSlots} from "../break.graphql";
import {
carryOverSlots,
slots,
createSlot,
deleteSlot,
@@ -120,13 +201,15 @@ import {
} from "../slot.graphql";
import {currentValidityRange} from "../validityRange.graphql";
import ValidityRangeField from "../ValidityRangeField.vue";
import DeleteDialog from "aleksis.core/components/generic/dialogs/DeleteDialog.vue";
import DeleteMultipleDialog from "aleksis.core/components/generic/dialogs/DeleteMultipleDialog.vue";
import SecondaryActionButton from "aleksis.core/components/generic/buttons/SecondaryActionButton.vue";
import SlotCard from "./SlotCard.vue";
import SlotCreator from "./SlotCreator.vue";
export default {
name: "LessonRaster",
components: {SlotCard, SecondaryActionButton, ValidityRangeField},
components: {SlotCreator, DeleteDialog, DeleteMultipleDialog, SlotCard, SecondaryActionButton, ValidityRangeField},
apollo: {
items: {
query: slots,
@@ -155,7 +238,15 @@ export default {
return {
weekdays: [],
internalValidityRange: null,
loading: {}
loading: {},
gqlQuery: slots,
deleteMutation: deleteSlot,
deleteMultipleMutation: deleteSlots,
deleteDialog: false,
deleteMultipleDialog: false,
itemToDelete: null,
itemsToDelete: [],
createBreaks: false,
}
},
computed: {
@@ -163,12 +254,15 @@ export default {
return this.items;
},
columns() {
return "[side] 10vw " + this.weekdays.map(
return "[side] 256px " + this.weekdays.map(
day => `[${day}] 1fr`
).join(" ");
}
},
methods: {
intDay(weekday) {
return Number.isInteger(weekday) ? weekday : parseInt(weekday[2]);
},
canAddDay(weekday) {
if (!weekday) {
return false;
@@ -189,7 +283,7 @@ export default {
return weekday === "A_0" ? null : weekday.replace(/\d+$/, (match) => parseInt(match) - 1);
},
async copyTo(src, dest) {
this.loading[src] = true;
this.loading[dest] = true;
const slotsToDelete = this.items
.filter(slot => slot.weekday === dest && slot.model === "Slot")
.map(slot => slot.id);
@@ -199,42 +293,63 @@ export default {
// As there is an error when deleting breaks and normal slots in one action, we delete them separately
await Promise.all([
this.$apollo.mutate({
mutation: deleteSlots,
variables: {
ids: slotsToDelete
},
}),
this.$apollo.mutate({
mutation: deleteBreakSlots,
variables: {
ids: breaksToDelete
},
}),
let that = this;
await this.$apollo.mutate({
mutation: carryOverSlots,
variables: {
validityRange: this.internalValidityRange.id,
fromDay: this.intDay(src),
toDay: this.intDay(dest),
},
update(store, {data: {carryOverSlots: {result}}}) {
let query = {
...that.$apollo.queries.items.options,
variables: JSON.parse(that.$apollo.queries.items.previousVariablesJson)
}
// Read the data from cache for query
const storedData = store.readQuery(query);
if (!storedData) {
// There are no data in the cache yet
return;
}
storedData.items = [
...storedData.items.filter(item => item.weekday !== dest),
...result,
]
);
await Promise.all(
this.items
.filter(slot => slot.weekday === src)
.map(slot => {
this.$apollo.mutate({
mutation: slot.model === "Slot" ? createSlot : createBreakSlot,
variables: {
input: {
name: slot.name,
validityRange: slot.validityRange.id,
weekday: parseInt(dest[2]),
period: slot.period,
timeStart: slot.timeStart,
timeEnd: slot.timeEnd,
}
},
})
})
)
// Write data back to the cache
store.writeQuery({...query, data: storedData});
}
})
this.weekdays = this.weekdays.sort((a, b) => a[2] - b[2])
this.loading[dest] = false;
},
async copySingularSlotTodDay(slot, day) {
this.loading[day] = true;
this.$apollo.mutate({
mutation: carryOverSlots,
variables: {
validityRange: this.internalValidityRange.id || slot.validityRange.id,
fromDay: this.intDay(slot.weekday),
toDay: this.intDay(day),
only: [slot.id],
},
})
// FIXME: Optimistic response; add to store?
await this.$apollo.queries.items.refetch();
this.loading[src] = false;
this.loading[day] = false;
},
deleteSingularSlot(slot) {
this.itemToDelete = slot;
this.deleteDialog = true;
},
deleteSlotsOfDay(weekday) {
this.itemsToDelete = this.items.filter(slot => slot.weekday === weekday)
this.deleteMultipleDialog = true;
}
},
}
@@ -245,9 +360,18 @@ export default {
display: grid;
grid-template-columns: v-bind(columns);
grid-auto-rows: 1fr auto;
gap: 1rem;
gap: 0.7rem;
overflow-x: scroll;
margin: -1em;
padding: 1em;
}
.min-height {
min-height: 36px;
}
.sidebar {
position: fixed;
z-index: 1;
}
</style>
\ No newline at end of file
Loading