diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql b/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql index 2ada207e9ef4333191c9df2f46a6d6e6f95083db..2ea83d8e6a8687a16d871979592a7d231d363444 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql +++ b/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql @@ -150,6 +150,13 @@ mutation createOrUpdateDocumentations($input: [DocumentationInputType]!) { tardiness isOptimistic } + subject { + id + name + shortName + colourFg + colourBg + } } } } diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue index 5bbc21c0de53b613986c30360e853ee6720526b5..15f4b371783f02a3efc95f7099e52e27430f0331 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue @@ -1,7 +1,11 @@ <template> <v-card :class="{ 'my-1 full-width': true, 'd-flex flex-column': !compact }"> <v-card-title v-if="!compact"> - <lesson-information v-bind="documentationPartProps" /> + <lesson-information + v-bind="{ ...$attrs, ...documentationPartProps }" + :is-create="false" + :gql-patch-mutation="documentationsMutation" + /> </v-card-title> <v-card-text @@ -11,7 +15,12 @@ 'pa-2': compact, }" > - <lesson-information v-if="compact" v-bind="documentationPartProps" /> + <lesson-information + v-if="compact" + v-bind="documentationPartProps" + :is-create="false" + :gql-patch-mutation="documentationsMutation" + /> <lesson-summary ref="summary" v-bind="{ ...$attrs, ...documentationPartProps }" diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue index bbad8dcdd8dee98b4bae619228c33d392ef3e63c..2f692025e83d2cf3ed951aec38f5e0c34cb59572 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue @@ -1,6 +1,8 @@ <script setup> import DocumentationStatus from "./DocumentationStatus.vue"; import PersonChip from "aleksis.core/components/person/PersonChip.vue"; +import SubjectChip from "aleksis.apps.cursus/components/SubjectChip.vue"; +import SubjectChipSelectField from "aleksis.apps.cursus/components/SubjectChipSelectField.vue"; </script> <template> @@ -58,16 +60,21 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; 'justify-start': !largeGrid, }" > - <subject-chip - v-if="documentation.subject" - :subject="documentation.subject" - v-bind="compact ? dialogActivator.attrs : {}" - v-on="compact ? dialogActivator.on : {}" - :class="{ - 'text-decoration-line-through': documentation.amends?.cancelled, - }" - :disabled="documentation.amends?.cancelled" - /> + <template v-if="documentation.subject"> + <subject-chip-select-field + v-if="documentation.canEdit" + :value="documentation.subject" + :enable-create="false" + :disabled="loading" + :loading="loading" + @input="editSubject" + /> + <subject-chip + v-else + :subject="documentation.subject" + :disabled="loading" + /> + </template> <subject-chip v-if=" documentation?.amends?.amends?.subject && @@ -109,20 +116,32 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; </template> <script> -import SubjectChip from "aleksis.apps.cursus/components/SubjectChip.vue"; import { DateTime } from "luxon"; + +import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js"; + import documentationPartMixin from "./documentationPartMixin"; +import documentationCacheUpdateMixin from "./documentationCacheUpdateMixin"; export default { name: "LessonInformation", - mixins: [documentationPartMixin], - components: { - SubjectChip, - }, + mixins: [ + createOrPatchMixin, + documentationCacheUpdateMixin, + documentationPartMixin, + ], methods: { toDateTime(dateString) { return DateTime.fromISO(dateString); }, + editSubject(subject) { + this.createOrPatch([ + { + id: this.documentation.id, + subject: subject.id, + }, + ]); + }, }, computed: { largeGrid() { diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue index f4ef410e2f12f17d7e284178e7a2b6acc8022e66..3710a45f83c7d267ba281f95d2cbbaaae95f46f3 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue @@ -146,10 +146,15 @@ import DocumentationFullDetails from "./DocumentationFullDetails.vue"; <script> import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js"; import documentationPartMixin from "./documentationPartMixin"; +import documentationCacheUpdateMixin from "./documentationCacheUpdateMixin"; export default { name: "LessonSummary", - mixins: [createOrPatchMixin, documentationPartMixin], + mixins: [ + createOrPatchMixin, + documentationCacheUpdateMixin, + documentationPartMixin, + ], emits: ["open"], data() { return { @@ -161,28 +166,6 @@ export default { }; }, methods: { - handleUpdateAfterCreateOrPatch(itemId) { - return (cached, incoming) => { - for (const object of incoming) { - console.log("summary: handleUpdateAfterCreateOrPatch", object); - // Replace the current documentation - const index = cached.findIndex( - (o) => o[itemId] === this.documentation.id, - ); - // merged with the incoming partial documentation - // if creation of proper documentation from dummy one, set ID of documentation currently being edited as oldID so that key in coursebook doesn't change - cached[index] = { - ...this.documentation, - ...object, - oldId: - this.documentation.id !== object.id - ? this.documentation.id - : this.documentation.oldId, - }; - } - return cached; - }; - }, handleAppendIconSuccess() { this.topicError = null; this.appendIcon = "$success"; diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationCacheUpdateMixin.js b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationCacheUpdateMixin.js new file mode 100644 index 0000000000000000000000000000000000000000..0e00a61a6cbcd5fbadbe5638a9138730acbf1369 --- /dev/null +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationCacheUpdateMixin.js @@ -0,0 +1,29 @@ +/** + * Mixin to provide the cache update functionality used after creating or patching documentations + */ +export default { + methods: { + handleUpdateAfterCreateOrPatch(itemId) { + return (cached, incoming) => { + for (const object of incoming) { + console.log("summary: handleUpdateAfterCreateOrPatch", object); + // Replace the current documentation + const index = cached.findIndex( + (o) => o[itemId] === this.documentation.id, + ); + // merged with the incoming partial documentation + // if creation of proper documentation from dummy one, set ID of documentation currently being edited as oldID so that key in coursebook doesn't change + cached[index] = { + ...this.documentation, + ...object, + oldId: + this.documentation.id !== object.id + ? this.documentation.id + : this.documentation.oldId, + }; + } + return cached; + }; + }, + }, +}; diff --git a/aleksis/apps/alsijil/frontend/messages/en.json b/aleksis/apps/alsijil/frontend/messages/en.json index 17769c47dbb20ca106eab4f05b046c51c158498a..dfaf794851353f2a2d490cf77b7d17bea76dfc5e 100644 --- a/aleksis/apps/alsijil/frontend/messages/en.json +++ b/aleksis/apps/alsijil/frontend/messages/en.json @@ -90,6 +90,11 @@ }, "absences_exist": "Only show lessons with absent participants" }, + "information": { + "subject": { + "field": "Edit subject" + } + }, "present_number": "{present}/{total} present", "no_data": "No lessons for the selected groups and courses in this period", "no_results": "No search results for {search}",