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

Automatically deselect participations after action is finished

parent 0c7f7943
No related branches found
No related tags found
1 merge request!363Resolve "Add absence overview page"
Pipeline #191433 failed
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<v-card <v-card
outlined outlined
class="full-width" class="full-width"
v-show="pageType === 'absences' && selectedParticipations.length" v-show="pageType === 'absences' && combinedSelectedParticipations.length"
> >
<v-card-text> <v-card-text>
<v-row align="center"> <v-row align="center">
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
{{ {{
$tc( $tc(
"alsijil.coursebook.absences.action_for_selected", "alsijil.coursebook.absences.action_for_selected",
selectedParticipations.length, combinedSelectedParticipations.length,
) )
}} }}
</v-col> </v-col>
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
:is="itemComponent" :is="itemComponent"
:documentation="item" :documentation="item"
:affectedQuery="lastQuery" :affectedQuery="lastQuery"
@select="addSelectedParticipation" :value="selectedParticipations[item.id] ??= []"
@deselect="removeSelectedParticipation" @input="selectParticipation(item.id, $event)"
/> />
</template> </template>
...@@ -157,7 +157,7 @@ export default { ...@@ -157,7 +157,7 @@ export default {
initDate: false, initDate: false,
currentDate: "", currentDate: "",
hashUpdater: false, hashUpdater: false,
selectedParticipations: [], selectedParticipations: {},
}; };
}, },
computed: { computed: {
...@@ -228,23 +228,18 @@ export default { ...@@ -228,23 +228,18 @@ export default {
return "DocumentationAbsencesModal"; return "DocumentationAbsencesModal";
} }
}, },
combinedSelectedParticipations() {
return Object.values(this.selectedParticipations).flat();
},
}, },
methods: { methods: {
addSelectedParticipation(participation) { selectParticipation(id, value) {
this.selectedParticipations = [ this.selectedParticipations = Object.assign({}, this.selectedParticipations, { [id]: value });
...new Set([...this.selectedParticipations, participation]),
];
},
removeSelectedParticipation(participation) {
const index = this.selectedParticipations.indexOf(participation);
if (index >= 0) {
this.selectedParticipations.splice(index, 1);
}
}, },
handleMultipleAction(absenceReasonId) { handleMultipleAction(absenceReasonId) {
this.loadSelectedParticiptions = true; this.loadSelectedParticiptions = true;
this.sendToServer( this.sendToServer(
this.selectedParticipations, this.combinedSelectedParticipations,
"absenceReason", "absenceReason",
absenceReasonId, absenceReasonId,
); );
...@@ -252,7 +247,7 @@ export default { ...@@ -252,7 +247,7 @@ export default {
}, },
resetMultipleAction() { resetMultipleAction() {
this.loadSelectedParticiptions = false; this.loadSelectedParticiptions = false;
this.$set(this.selectedParticipations, []); this.selectedParticipations = {};
}, },
}, },
}; };
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
:include-present="false" :include-present="false"
class="participation-list" class="participation-list"
v-bind="documentationPartProps" v-bind="documentationPartProps"
v-on="selectListeners" :value="value"
@input="$emit('input', $event)"
/> />
</v-card-text> </v-card-text>
<v-spacer /> <v-spacer />
...@@ -54,7 +55,6 @@ import CancelButton from "aleksis.core/components/generic/buttons/CancelButton.v ...@@ -54,7 +55,6 @@ import CancelButton from "aleksis.core/components/generic/buttons/CancelButton.v
import { createOrUpdateDocumentations } from "../coursebook.graphql"; import { createOrUpdateDocumentations } from "../coursebook.graphql";
import selectParticipationMixin from "./selectParticipationMixin.js";
import documentationPartMixin from "../documentation/documentationPartMixin"; import documentationPartMixin from "../documentation/documentationPartMixin";
export default { export default {
...@@ -67,7 +67,7 @@ export default { ...@@ -67,7 +67,7 @@ export default {
CancelButton, CancelButton,
}, },
emits: ["open", "close"], emits: ["open", "close"],
mixins: [documentationPartMixin, selectParticipationMixin], mixins: [documentationPartMixin],
data() { data() {
return { return {
loading: false, loading: false,
...@@ -75,6 +75,12 @@ export default { ...@@ -75,6 +75,12 @@ export default {
selectedParticipations: [], selectedParticipations: [],
}; };
}, },
props: {
value: {
type: Array,
required: true,
},
},
methods: { methods: {
save() { save() {
this.$refs.summary.save(); this.$refs.summary.save();
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
compact compact
v-bind="$attrs" v-bind="$attrs"
:dialog-activator="activator" :dialog-activator="activator"
v-on="selectListeners" :value="value"
@input="$emit('input', $event)"
/> />
</template> </template>
<!-- dialog view -> deactivate dialog --> <!-- dialog view -> deactivate dialog -->
...@@ -16,7 +17,6 @@ ...@@ -16,7 +17,6 @@
<documentation-absences <documentation-absences
v-bind="$attrs" v-bind="$attrs"
@close="popup = false" @close="popup = false"
v-on="selectListeners"
/> />
</mobile-fullscreen-dialog> </mobile-fullscreen-dialog>
</template> </template>
...@@ -25,19 +25,22 @@ ...@@ -25,19 +25,22 @@
import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/MobileFullscreenDialog.vue"; import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/MobileFullscreenDialog.vue";
import DocumentationAbsences from "./DocumentationAbsences.vue"; import DocumentationAbsences from "./DocumentationAbsences.vue";
import selectParticipationMixin from "./selectParticipationMixin.js";
export default { export default {
name: "DocumentationAbsencesModal", name: "DocumentationAbsencesModal",
components: { components: {
MobileFullscreenDialog, MobileFullscreenDialog,
DocumentationAbsences, DocumentationAbsences,
}, },
mixins: [selectParticipationMixin],
data() { data() {
return { return {
popup: false, popup: false,
}; };
}, },
props: {
value: {
type: Array,
required: true,
},
},
}; };
</script> </script>
...@@ -3,45 +3,51 @@ import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/Mobi ...@@ -3,45 +3,51 @@ import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/Mobi
import AbsenceReasonGroupSelect from "aleksis.apps.kolego/components/AbsenceReasonGroupSelect.vue"; import AbsenceReasonGroupSelect from "aleksis.apps.kolego/components/AbsenceReasonGroupSelect.vue";
import selectParticipationMixin from "./selectParticipationMixin.js";
import updateParticipationMixin from "./updateParticipationMixin.js"; import updateParticipationMixin from "./updateParticipationMixin.js";
</script> </script>
<template> <template>
<v-list v-if="filteredParticipations.length"> <v-list v-if="filteredParticipations.length">
<v-divider /> <v-divider />
<v-list-item
v-for="(participation, index) in filteredParticipations" <v-list-item-group
:key="`documentation-${documentation.id}-participation-${participation.id}`" :value="value"
:value="participation" multiple
v-bind="$attrs" @change="changeSelect"
v-on="$listeners"
> >
<template #default="{ active }"> <template v-for="(participation, index) in filteredParticipations">
<v-list-item-action> <v-list-item
<v-checkbox :key="`documentation-${documentation.id}-participation-${participation.id}`"
:input-value="active" :value="participation.id"
@change="handleParticipationSelect($event, participation)" v-bind="$attrs"
/> >
</v-list-item-action> <template #default="{ active }">
<v-list-item-title> <v-list-item-action>
{{ participation.person.fullName }} <v-checkbox
</v-list-item-title> :input-value="active"
<v-list-item-action v-if="participation.absenceReason" class="full-width"> />
<absence-reason-group-select </v-list-item-action>
allow-empty <v-list-item-title>
empty-value="present" {{ participation.person.fullName }}
:loadSelectedChip="loading" </v-list-item-title>
:value="participation.absenceReason?.id || 'present'" <v-list-item-action v-if="participation.absenceReason" class="full-width">
@input="sendToServer([participation], 'absenceReason', $event)" <absence-reason-group-select
/> allow-empty
</v-list-item-action> empty-value="present"
:loadSelectedChip="loading"
:value="participation.absenceReason?.id || 'present'"
@input="sendToServer([participation], 'absenceReason', $event)"
/>
</v-list-item-action>
</template>
</v-list-item>
<v-divider
v-if="index < filteredParticipations.length - 1"
:key="index"
></v-divider>
</template> </template>
</v-list-item> </v-list-item-group>
<v-divider
v-if="index < filteredParticipations.length - 1"
:key="index"
></v-divider>
<mobile-fullscreen-dialog v-model="participationDialogs" max-width="500px"> <mobile-fullscreen-dialog v-model="participationDialogs" max-width="500px">
test test
</mobile-fullscreen-dialog> </mobile-fullscreen-dialog>
...@@ -74,7 +80,7 @@ import updateParticipationMixin from "./updateParticipationMixin.js"; ...@@ -74,7 +80,7 @@ import updateParticipationMixin from "./updateParticipationMixin.js";
<script> <script>
export default { export default {
name: "ParticipationList", name: "ParticipationList",
mixins: [selectParticipationMixin, updateParticipationMixin], mixins: [updateParticipationMixin],
data() { data() {
return { return {
loading: false, loading: false,
...@@ -88,6 +94,10 @@ export default { ...@@ -88,6 +94,10 @@ export default {
required: false, required: false,
default: true, default: true,
}, },
value: {
type: Array,
required: true,
},
}, },
computed: { computed: {
filteredParticipations() { filteredParticipations() {
...@@ -101,13 +111,10 @@ export default { ...@@ -101,13 +111,10 @@ export default {
}, },
}, },
methods: { methods: {
handleParticipationSelect(value, participation) { changeSelect(value) {
if (value) { console.log(value);
this.handleSelect(participation.id); this.$emit("input", value);
} else {
this.handleDeselect(participation.id);
}
}, },
}, }
}; };
</script> </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