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

Create absences for the rest of the day

parent 10406c72
No related branches found
No related tags found
1 merge request!373Resolve "Suggest creating Kolego absence for the rest of the day when entering absences"
...@@ -8,6 +8,10 @@ import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/Mobi ...@@ -8,6 +8,10 @@ import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/Mobi
import updateParticipationMixin from "./updateParticipationMixin.js"; import updateParticipationMixin from "./updateParticipationMixin.js";
import deepSearchMixin from "aleksis.core/mixins/deepSearchMixin.js"; import deepSearchMixin from "aleksis.core/mixins/deepSearchMixin.js";
import LessonInformation from "../documentation/LessonInformation.vue"; import LessonInformation from "../documentation/LessonInformation.vue";
import {
extendParticipationStatuses,
updateParticipationStatuses,
} from "./participationStatus.graphql";
import SlideIterator from "aleksis.core/components/generic/SlideIterator.vue"; import SlideIterator from "aleksis.core/components/generic/SlideIterator.vue";
import PersonalNotes from "../personal_notes/PersonalNotes.vue"; import PersonalNotes from "../personal_notes/PersonalNotes.vue";
import ExtraMarkChip from "../../extra_marks/ExtraMarkChip.vue"; import ExtraMarkChip from "../../extra_marks/ExtraMarkChip.vue";
...@@ -48,7 +52,8 @@ export default { ...@@ -48,7 +52,8 @@ export default {
num: 0, num: 0,
reason: "no reason", reason: "no reason",
name: "nobody", name: "nobody",
personIds: [], participationIDs: [],
loading: false,
}, },
}; };
}, },
...@@ -70,6 +75,58 @@ export default { ...@@ -70,6 +75,58 @@ export default {
}, },
}, },
methods: { methods: {
sendToServer(participations, field, value) {
let fieldValue;
if (field === "absenceReason") {
fieldValue = {
absenceReason: value === "present" ? null : value,
};
} else if (field === "tardiness") {
fieldValue = {
tardiness: value,
};
} else {
console.error(`Wrong field '${field}' for sendToServer`);
return;
}
this.markAsAbsentDay.showAlert = false;
this.markAsAbsentDay.participationIDs = [];
this.mutate(
updateParticipationStatuses,
{
input: participations.map((participation) => ({
id: participation.id,
...fieldValue,
})),
},
(storedDocumentations, incomingStatuses) => {
const documentation = storedDocumentations.find(
(doc) => doc.id === this.documentation.id,
);
incomingStatuses.forEach((newStatus) => {
const participationStatus = documentation.participations.find(
(part) => part.id === newStatus.id,
);
participationStatus.absenceReason = newStatus.absenceReason;
participationStatus.tardiness = newStatus.tardiness;
participationStatus.isOptimistic = newStatus.isOptimistic;
});
this.markAsAbsentDay.reason = incomingStatuses[0].absenceReason.name;
this.markAsAbsentDay.num = incomingStatuses.length;
return storedDocumentations;
},
);
if (field === "absenceReason" && value !== "present") {
this.$once("save", this.activateFullDayDialog);
}
},
handleMultipleAction(field, id) { handleMultipleAction(field, id) {
this.loadSelected = true; this.loadSelected = true;
this.sendToServer(this.selected, field, id); this.sendToServer(this.selected, field, id);
...@@ -80,18 +137,57 @@ export default { ...@@ -80,18 +137,57 @@ export default {
this.$set(this.selected, []); this.$set(this.selected, []);
this.$refs.iterator.selected = []; this.$refs.iterator.selected = [];
}, },
activateFullDayDialog({ data: { updateParticipationStatuses: { items }}}) { activateFullDayDialog({
const itemIds = items.map(item => item.id); data: {
const participations = this.documentation.participations.filter(part => itemIds.includes(part.id)); updateParticipationStatuses: { items },
},
}) {
const itemIds = items.map((item) => item.id);
const participations = this.documentation.participations.filter((part) =>
itemIds.includes(part.id),
);
if (this.markAsAbsentDay.num === 1) { if (this.markAsAbsentDay.num === 1) {
this.markAsAbsentDay.name = participations[0].person.firstName; this.markAsAbsentDay.name = participations[0].person.firstName;
} }
this.$set(this.markAsAbsentDay.personIds, itemIds); this.$set(this.markAsAbsentDay, "participationIDs", itemIds);
this.markAsAbsentDay.loading = false;
this.markAsAbsentDay.showAlert = true; this.markAsAbsentDay.showAlert = true;
} },
markAsAbsentDayClick() {
this.markAsAbsentDay.loading = true;
this.mutate(
extendParticipationStatuses,
{
input: this.markAsAbsentDay.participationIDs,
},
(storedDocumentations, incomingStatuses) => {
const documentation = storedDocumentations.find(
(doc) => doc.id === this.documentation.id,
);
incomingStatuses.forEach((newStatus) => {
const participationStatus = documentation.participations.find(
(part) => part.id === newStatus.id,
);
participationStatus.baseAbsence = newStatus.baseAbsence;
participationStatus.isOptimistic = newStatus.isOptimistic;
});
this.markAsAbsentDay.reason = "no reason";
this.markAsAbsentDay.num = 0;
this.markAsAbsentDay.participationIDs = [];
this.markAsAbsentDay.loading = false;
this.markAsAbsentDay.showAlert = false;
return storedDocumentations;
},
);
},
}, },
}; };
</script> </script>
...@@ -138,17 +234,29 @@ export default { ...@@ -138,17 +234,29 @@ export default {
class="mt-4 mb-0 full-width" class="mt-4 mb-0 full-width"
> >
<div class="text-subtitle-2"> <div class="text-subtitle-2">
{{ $tc("alsijil.coursebook.mark_as_absent_day.title", markAsAbsentDay.num, markAsAbsentDay) }} {{
$tc(
"alsijil.coursebook.mark_as_absent_day.title",
markAsAbsentDay.num,
markAsAbsentDay,
)
}}
</div> </div>
<p class="text-body-2 pa-0 ma-0" style="word-break: break-word"> <p class="text-body-2 pa-0 ma-0" style="word-break: break-word">
{{ $t("alsijil.coursebook.mark_as_absent_day.description", markAsAbsentDay) }} {{
$t(
"alsijil.coursebook.mark_as_absent_day.description",
markAsAbsentDay,
)
}}
</p> </p>
<secondary-action-button <secondary-action-button
color="success" color="success"
i18n-key="alsijil.coursebook.mark_as_absent_day.action_button" i18n-key="alsijil.coursebook.mark_as_absent_day.action_button"
class="mt-2" class="mt-2"
@click="markAsAbsentDay.showAlert = false" :loading="markAsAbsentDay.loading"
@click="markAsAbsentDayClick"
/> />
</message-box> </message-box>
</template> </template>
......
...@@ -64,3 +64,14 @@ mutation touchDocumentation($documentationId: ID!) { ...@@ -64,3 +64,14 @@ mutation touchDocumentation($documentationId: ID!) {
} }
} }
} }
mutation extendParticipationStatuses($input: [ID]!) {
extendParticipationStatuses(input: $input) {
items: participations {
id
}
absences {
id
}
}
}
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