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

Use status-based chips for teachers

parent 64b2f8bc
No related branches found
No related tags found
1 merge request!329Introduce substitution to do list
Pipeline #182660 failed
...@@ -31,16 +31,40 @@ import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js"; ...@@ -31,16 +31,40 @@ import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js";
item-text="fullName" item-text="fullName"
item-value="id" item-value="id"
:disabled="loading" :disabled="loading"
@input="save" @input="saveTeachers"
> >
<template #prepend-inner> <template #prepend-inner>
<v-chip <v-chip
v-for="teacher in teachersWithStatus(substitution).filter( v-for="teacher in teachersWithStatus.filter(
(t) => t.status === 'removed', (t) => t.status === 'removed',
)" )"
class="text-decoration-line-through text--secondary mb-2" outlined
>{{ teacher.fullName }}</v-chip color="error"
class="mb-2"
close
close-icon="mdi-reload"
@click:close="addTeacher(teacher)"
> >
<v-icon left>
$cancel
</v-icon>
<div class="text-decoration-line-through">{{ teacher.fullName }}</div>
</v-chip>
</template>
<template #selection="data">
<v-chip
v-bind="data.attrs"
:input-value="data.selected"
close
:outlined="getTeacherStatus(data.item) === 'new'"
:color="getTeacherStatus(data.item) === 'new' ? 'success' : ''"
@click:close="removeTeacher(data.item)"
>
<v-icon left v-if="getTeacherStatus(data.item) === 'new'">
mdi-plus
</v-icon>
{{ data.item.fullName }}
</v-chip>
</template> </template>
</v-autocomplete> </v-autocomplete>
...@@ -92,26 +116,21 @@ export default { ...@@ -92,26 +116,21 @@ export default {
}, },
}, },
methods: { methods: {
teachersWithStatus(lesson) { getTeacherStatus(teacher) {
let oldIds = lesson.amends.teachers.map((teacher) => teacher.id); return this.teachersWithStatus.find((t) => t.id === teacher.id)?.status;
let newIds = lesson.teachers.map((teacher) => teacher.id); },
let teachersWithStatus = lesson.amends.teachers addTeacher(teacher) {
.concat(lesson.teachers) this.teachers.push(teacher.id);
.map((teacher) => { this.saveTeachers();
let status = "regular";
if (newIds.includes(teacher.id) && !oldIds.includes(teacher.id)) {
status = "new";
} else if (
!newIds.includes(teacher.id) &&
oldIds.includes(teacher.id)
) {
status = "removed";
}
return { ...teacher, status: status };
});
return teachersWithStatus;
}, },
save() { removeTeacher(teacher) {
const index = this.teachers.indexOf(teacher.id);
if (index >= 0) {
this.teachers.splice(index, 1);
this.saveTeachers();
}
},
saveTeachers() {
this.createOrPatch([ this.createOrPatch([
{ {
id: this.substitution.id, id: this.substitution.id,
...@@ -128,6 +147,27 @@ export default { ...@@ -128,6 +147,27 @@ export default {
]); ]);
}, },
}, },
computed: {
teachersWithStatus() {
const oldIds = this.substitution.amends.teachers.map((teacher) => teacher.id);
const newIds = this.substitution.teachers.map((teacher) => teacher.id);
const allTeachers = new Set(this.substitution.amends.teachers.concat(this.substitution.teachers));
let teachersWithStatus = Array.from(allTeachers)
.map((teacher) => {
let status = "regular";
if (newIds.includes(teacher.id) && !oldIds.includes(teacher.id)) {
status = "new";
} else if (
!newIds.includes(teacher.id) &&
oldIds.includes(teacher.id)
) {
status = "removed";
}
return { ...teacher, status: status };
});
return teachersWithStatus;
},
},
apollo: { apollo: {
amendableTeachers: gqlPersons, amendableTeachers: gqlPersons,
}, },
......
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