Skip to content
Snippets Groups Projects
Commit 03e2286c authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Make subject field editable

parent 140b0ce9
No related branches found
No related tags found
1 merge request!369Resolve "Make subject editable in new course book"
...@@ -146,6 +146,13 @@ mutation createOrUpdateDocumentations($input: [DocumentationInputType]!) { ...@@ -146,6 +146,13 @@ mutation createOrUpdateDocumentations($input: [DocumentationInputType]!) {
tardiness tardiness
isOptimistic isOptimistic
} }
subject {
id
name
shortName
colourFg
colourBg
}
} }
} }
} }
<template> <template>
<v-card :class="{ 'my-1 full-width': true, 'd-flex flex-column': !compact }"> <v-card :class="{ 'my-1 full-width': true, 'd-flex flex-column': !compact }">
<v-card-title v-if="!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-title>
<v-card-text <v-card-text
......
<script setup> <script setup>
import DocumentationStatus from "./DocumentationStatus.vue"; import DocumentationStatus from "./DocumentationStatus.vue";
import PersonChip from "aleksis.core/components/person/PersonChip.vue"; import PersonChip from "aleksis.core/components/person/PersonChip.vue";
import SubjectChip from "aleksis.apps.cursus/components/SubjectChip.vue";
import SubjectField from "aleksis.apps.cursus/components/SubjectField.vue";
</script> </script>
<template> <template>
...@@ -37,16 +39,29 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; ...@@ -37,16 +39,29 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue";
'justify-start': !largeGrid, 'justify-start': !largeGrid,
}" }"
> >
<subject-chip <v-slide-x-transition>
v-if="documentation.subject" <subject-chip
:subject="documentation.subject" v-if="documentation.subject && !subjectField"
v-bind="compact ? dialogActivator.attrs : {}" :subject="documentation.subject"
v-on="compact ? dialogActivator.on : {}" :append-icon="compact ? '' : '$edit'"
:class="{ :disabled="loading"
'text-decoration-line-through': documentation.amends?.cancelled, v-bind="compact ? dialogActivator.attrs : {}"
}" v-on="
:disabled="documentation.amends?.cancelled" compact
/> ? dialogActivator.on
: { click: () => (subjectField = true) }
"
/>
<subject-field
v-else-if="documentation.canEdit"
:value="documentation.subject"
:enable-create="false"
dense
filled
hide-details
@input="editSubject"
/>
</v-slide-x-transition>
<subject-chip <subject-chip
v-if=" v-if="
documentation?.amends?.amends?.subject && documentation?.amends?.amends?.subject &&
...@@ -88,20 +103,38 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; ...@@ -88,20 +103,38 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue";
</template> </template>
<script> <script>
import SubjectChip from "aleksis.apps.cursus/components/SubjectChip.vue";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js";
import documentationPartMixin from "./documentationPartMixin"; import documentationPartMixin from "./documentationPartMixin";
import documentationCacheUpdateMixin from "./documentationCacheUpdateMixin";
export default { export default {
name: "LessonInformation", name: "LessonInformation",
mixins: [documentationPartMixin], mixins: [
components: { createOrPatchMixin,
SubjectChip, documentationCacheUpdateMixin,
documentationPartMixin,
],
data() {
return {
subjectField: false,
};
}, },
methods: { methods: {
toDateTime(dateString) { toDateTime(dateString) {
return DateTime.fromISO(dateString); return DateTime.fromISO(dateString);
}, },
editSubject(subject) {
this.subjectField = false;
this.createOrPatch([
{
id: this.documentation.id,
subject: subject.id,
},
]);
},
}, },
computed: { computed: {
largeGrid() { largeGrid() {
......
...@@ -146,10 +146,15 @@ import DocumentationFullDetails from "./DocumentationFullDetails.vue"; ...@@ -146,10 +146,15 @@ import DocumentationFullDetails from "./DocumentationFullDetails.vue";
<script> <script>
import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js"; import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js";
import documentationPartMixin from "./documentationPartMixin"; import documentationPartMixin from "./documentationPartMixin";
import documentationCacheUpdateMixin from "./documentationCacheUpdateMixin";
export default { export default {
name: "LessonSummary", name: "LessonSummary",
mixins: [createOrPatchMixin, documentationPartMixin], mixins: [
createOrPatchMixin,
documentationCacheUpdateMixin,
documentationPartMixin,
],
emits: ["open"], emits: ["open"],
data() { data() {
return { return {
...@@ -161,28 +166,6 @@ export default { ...@@ -161,28 +166,6 @@ export default {
}; };
}, },
methods: { 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() { handleAppendIconSuccess() {
this.topicError = null; this.topicError = null;
this.appendIcon = "$success"; this.appendIcon = "$success";
......
/**
* 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;
};
},
},
};
...@@ -90,6 +90,11 @@ ...@@ -90,6 +90,11 @@
}, },
"absences_exist": "Only show lessons with absent participants" "absences_exist": "Only show lessons with absent participants"
}, },
"information": {
"subject": {
"field": "Edit subject"
}
},
"present_number": "{present}/{total} present", "present_number": "{present}/{total} present",
"no_data": "No lessons for the selected groups and courses in this period", "no_data": "No lessons for the selected groups and courses in this period",
"no_results": "No search results for {search}", "no_results": "No search results for {search}",
......
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