Skip to content
Snippets Groups Projects
Commit 2d2bf75a authored by Julian's avatar Julian
Browse files

Use the CopyFromTimeGridMenu in the LessonRaster

parent 3ebc9788
No related branches found
No related tags found
1 merge request!2Resolve "Frontend for Models"
......@@ -154,3 +154,32 @@ mutation carryOverSlots(
}
}
}
mutation copySlotsFromGrid($toTimeGrid: ID!, $fromTimeGrid: ID!) {
copySlotsFromGrid(timeGrid: $toTimeGrid, fromTimeGrid: $fromTimeGrid) {
result {
id
model
name
timeGrid {
id
group {
id
name
}
validityRange {
id
name
}
}
weekday
period
periodAfter
timeStart
timeEnd
canEdit
canDelete
}
deleted
}
}
......@@ -49,7 +49,11 @@
</template>
</slot-creator>
<copy-from-range-menu v-if="internalTimeGrid">
<copy-from-time-grid-menu
v-if="internalTimeGrid"
:deny-ids="[internalTimeGrid.id]"
@confirm="copyFromGrid"
>
<template #activator="{ on, attrs }">
<v-list-item link v-bind="attrs" v-on="on">
<v-list-item-icon>
......@@ -57,12 +61,12 @@
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{
$t("lesrooster.slot.copy_from_range")
$t("actions.copy_last_configuration")
}}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</template>
</copy-from-range-menu>
</copy-from-time-grid-menu>
</v-list>
</v-navigation-drawer>
</v-card>
......@@ -215,13 +219,14 @@
<script>
import {
carryOverSlots,
copySlotsFromGrid,
slots,
deleteSlot,
deleteSlots,
} from "../breaks_and_slots/slot.graphql";
import DeleteDialog from "aleksis.core/components/generic/dialogs/DeleteDialog.vue";
import DeleteMultipleDialog from "aleksis.core/components/generic/dialogs/DeleteMultipleDialog.vue";
import CopyFromRangeMenu from "../validity_range/CopyFromRangeMenu.vue";
import CopyFromTimeGridMenu from "../validity_range/CopyFromTimeGridMenu.vue";
import SlotCard from "./SlotCard.vue";
import SlotCreator from "./SlotCreator.vue";
import TimeGridField from "../validity_range/TimeGridField.vue";
......@@ -230,7 +235,7 @@ export default {
name: "LessonRaster",
components: {
TimeGridField,
CopyFromRangeMenu,
CopyFromTimeGridMenu,
SlotCreator,
DeleteDialog,
DeleteMultipleDialog,
......@@ -425,6 +430,69 @@ export default {
);
this.deleteMultipleDialog = true;
},
copyFromGrid(existingTimeGrid) {
if (!this.internalTimeGrid || !this.internalTimeGrid.id) return;
let that = this;
this.loading.main = true;
this.$apollo.mutate(
{
mutation: copySlotsFromGrid,
variables: {
fromTimeGrid: existingTimeGrid.id,
toTimeGrid: this.internalTimeGrid.id,
},
update(
store,
{
data: {
copySlotsFromGrid: {result, deleted},
},
}
) {
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;
}
for (const id of deleted) {
// Remove item from stored data
const index = storedData.items.findIndex(
(m) => m.id === id
);
storedData.items.splice(index, 1);
}
storedData.items.push(...result);
// Write data back to the cache
store.writeQuery({...query, data: storedData});
},
},
).then(
(data) => {
this.$toastSuccess();
}
).catch(
(error) => {
this.$toastError();
}
).finally(
() => {
this.loading.main = false;
}
);
},
},
};
</script>
......
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