Skip to content
Snippets Groups Projects
Commit 344a0374 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch '303-extra-marks-also-in-person-multiple-select-in-lesson-dialog' into 'master'

Resolve "Extra marks also in person multiple select in lesson dialog"

Closes #303 and #291

See merge request !400
parents 33eba090 d83310f0
No related branches found
No related tags found
1 merge request!400Resolve "Extra marks also in person multiple select in lesson dialog"
Pipeline #192400 failed
......@@ -12,11 +12,13 @@ import PersonalNotes from "../personal_notes/PersonalNotes.vue";
import ExtraMarkChip from "../../extra_marks/ExtraMarkChip.vue";
import TardinessChip from "./TardinessChip.vue";
import TardinessField from "./TardinessField.vue";
import ExtraMarkButtons from "../../extra_marks/ExtraMarkButtons.vue";
export default {
name: "ManageStudentsDialog",
extends: MobileFullscreenDialog,
components: {
ExtraMarkButtons,
TardinessChip,
ExtraMarkChip,
AbsenceReasonChip,
......@@ -57,9 +59,9 @@ export default {
},
},
methods: {
handleMultipleAction(absenceReasonId) {
handleMultipleAction(field, id) {
this.loadSelected = true;
this.sendToServer(this.selected, "absenceReason", absenceReasonId);
this.sendToServer(this.selected, field, id);
this.$once("save", this.resetMultipleAction);
},
resetMultipleAction() {
......@@ -209,11 +211,17 @@ export default {
<template #actions>
<v-scroll-y-reverse-transition>
<div v-show="selected.length > 0" class="full-width">
<h4>{{ $t("alsijil.coursebook.participation_status") }}</h4>
<absence-reason-buttons
class="mb-1"
allow-empty
empty-value="present"
:custom-absence-reasons="absenceReasons"
@input="handleMultipleAction"
@input="handleMultipleAction('absenceReason', $event)"
/>
<h4>{{ $t("alsijil.extra_marks.title_plural") }}</h4>
<extra-mark-buttons
@input="handleMultipleAction('extraMark', $event)"
/>
</div>
</v-scroll-y-reverse-transition>
......
/**
* Mixin to provide shared functionality needed to send updated participation data to the server
*/
import { createPersonalNotes } from "../personal_notes/personal_notes.graphql";
import { updateParticipationStatuses } from "./participationStatus.graphql";
import mutateMixin from "aleksis.core/mixins/mutateMixin.js";
......@@ -18,6 +19,10 @@ export default {
fieldValue = {
tardiness: value,
};
} else if (field === "extraMark") {
// Too much different logic → own method
this.addExtraMarks(participations, value);
return;
} else {
console.error(`Wrong field '${field}' for sendToServer`);
return;
......@@ -46,6 +51,42 @@ export default {
participationStatus.isOptimistic = newStatus.isOptimistic;
});
return storedDocumentations;
},
);
},
addExtraMarks(participations, extraMarkId) {
// Get all participation statuses without this extra mark and get the respective person ids
const participants = participations
.filter(
(participation) =>
!participation.notesWithExtraMark.some(
(note) => note.extraMark.id === extraMarkId,
),
)
.map((participation) => participation.person.id);
// CREATE new personal note
this.mutate(
createPersonalNotes,
{
input: participants.map((person) => ({
documentation: this.documentation.id,
person: person,
extraMark: extraMarkId,
})),
},
(storedDocumentations, incomingPersonalNotes) => {
const documentation = storedDocumentations.find(
(doc) => doc.id === this.documentation.id,
);
incomingPersonalNotes.forEach((note, index) => {
const participationStatus = documentation.participations.find(
(part) => part.person.id === participants[index],
);
participationStatus.notesWithExtraMark.push(note);
});
return storedDocumentations;
},
);
......
<script>
import { extraMarks } from "./extra_marks.graphql";
export default {
name: "ExtraMarkButtons",
data() {
return {
extraMarks: [],
};
},
apollo: {
extraMarks: {
query: extraMarks,
update: (data) => data.items,
skip() {
return this.customExtraMarks > 0;
},
},
},
props: {
customExtraMarks: {
type: Array,
required: false,
default: () => [],
},
},
computed: {
innerExtraMarks() {
if (this.customExtraMarks.length > 0) {
return this.customExtraMarks;
} else {
return this.extraMarks;
}
},
},
methods: {
emit(value) {
this.$emit("input", value);
this.$emit("click", value);
},
},
};
</script>
<template>
<div class="d-flex flex-wrap" style="gap: 0.5em">
<v-skeleton-loader
class="full-width d-flex flex-wrap child-flex-grow-1"
style="gap: 0.5em"
v-if="$apollo.queries.extraMarks.loading"
type="button@4"
/>
<template v-else>
<v-btn
v-for="extraMark in innerExtraMarks"
:key="'extra-mark-' + extraMark.id"
:color="extraMark.colourBg"
:style="{ color: extraMark.colourFg }"
class="flex-grow-1"
depressed
@click="emit(extraMark.id)"
>
{{ extraMark.name }}
</v-btn>
</template>
</div>
</template>
<style>
.child-flex-grow-1 > * {
flex-grow: 1;
}
</style>
......@@ -55,6 +55,7 @@
"cancelled": "Lesson cancelled",
"pending": "Lesson pending"
},
"participation_status": "Participation Status",
"summary": {
"topic": {
"label": "Topic",
......
......@@ -47,7 +47,7 @@ class ParticipationStatusType(
person=root.person,
documentation=root.related_documentation,
note__isnull=False,
)
).exclude(note="")
class ParticipationStatusBatchPatchMutation(BaseBatchPatchMutation):
......
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