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

Allow deletion of text-based personal notes

parent 8cec13a4
No related branches found
No related tags found
1 merge request!362Resolve "Add personal note management dialog in course book"
<script> <script>
import { import {
createPersonalNotes, createPersonalNotes,
deletePersonalNotes,
updatePersonalNotes, updatePersonalNotes,
} from "./personal_notes.graphql"; } from "./personal_notes.graphql";
import personalNoteRelatedMixin from "./personalNoteRelatedMixin"; import personalNoteRelatedMixin from "./personalNoteRelatedMixin";
import mutateMixin from "aleksis.core/mixins/mutateMixin.js"; import mutateMixin from "aleksis.core/mixins/mutateMixin.js";
import DeleteDialog from "aleksis.core/components/generic/dialogs/DeleteDialog.vue";
export default { export default {
name: "TextNote", name: "TextNote",
components: { DeleteDialog },
mixins: [mutateMixin, personalNoteRelatedMixin], mixins: [mutateMixin, personalNoteRelatedMixin],
props: { props: {
value: { value: {
...@@ -21,43 +24,17 @@ export default { ...@@ -21,43 +24,17 @@ export default {
return this.value.note; return this.value.note;
}, },
set(newValue) { set(newValue) {
const input = (extras) => ({ if (!newValue) {
input: [ // this is a DELETE action, show the dialog, ...
{ this.showDeleteConfirm = true;
note: newValue, return;
...extras, }
},
],
});
const updater =
(replace) => (storedDocumentations, incomingPersonalNotes) => {
const note = incomingPersonalNotes[0];
const documentation = storedDocumentations.find(
(doc) => doc.id === this.documentation.id,
);
const participationStatus = documentation.participations.find(
(part) => part.id === this.participation.id,
);
if (replace) {
const index = participationStatus.notesWithNote.findIndex(
(n) => n.id === this.participation.id,
);
participationStatus.notesWithNote.splice(index, 1, note);
} else {
participationStatus.notesWithNote.push(note);
this.$emit("create");
}
return storedDocumentations;
};
const create = !this.value.id; const create = !this.value.id;
this.mutate( this.mutate(
create ? createPersonalNotes : updatePersonalNotes, create ? createPersonalNotes : updatePersonalNotes,
input( this.getInput(
newValue,
create create
? { ? {
documentation: this.documentation.id, documentation: this.documentation.id,
...@@ -68,11 +45,66 @@ export default { ...@@ -68,11 +45,66 @@ export default {
id: this.value.id, id: this.value.id,
}, },
), ),
updater(!create), this.getUpdater(create ? "create" : "update"),
); );
}, },
}, },
}, },
methods: {
getInput(newValue, extras) {
return {
input: [
{
note: newValue,
...extras,
},
],
};
},
getUpdater(mode) {
return (storedDocumentations, incomingPersonalNotes) => {
const note = incomingPersonalNotes?.[0] || undefined;
const documentation = storedDocumentations.find(
(doc) => doc.id === this.documentation.id,
);
const participationStatus = documentation.participations.find(
(part) => part.id === this.participation.id,
);
switch (mode.toLowerCase()) {
case "update": case "delete": {
const updateIndex = participationStatus.notesWithNote.findIndex(
(n) => n.id === this.value.id,
);
if (mode === "update") {
participationStatus.notesWithNote.splice(updateIndex, 1, note);
} else {
participationStatus.notesWithNote.splice(updateIndex, 1);
}
break;
}
case "create":
participationStatus.notesWithNote.push(note);
this.$emit("create");
break;
default:
console.error("Invalid mode in getUpdater():", mode);
break;
}
return storedDocumentations;
};
},
},
data() {
return {
showDeleteConfirm: false,
deletePersonalNotes,
};
},
}; };
</script> </script>
...@@ -83,10 +115,38 @@ export default { ...@@ -83,10 +115,38 @@ export default {
outlined outlined
hide-details hide-details
class="mb-4" class="mb-4"
clearable
:label="$t('alsijil.personal_notes.note')" :label="$t('alsijil.personal_notes.note')"
:value="model" :value="model"
@change="model = $event" @change="model = $event"
:loading="loading" :loading="loading"
/> >
<template #append>
<v-slide-x-reverse-transition>
<v-btn v-if="!!model" icon @click="showDeleteConfirm = true">
<v-icon> $deleteContent </v-icon>
</v-btn>
</v-slide-x-reverse-transition>
<delete-dialog
v-model="showDeleteConfirm"
:gql-delete-mutation="deletePersonalNotes"
:affected-query="affectedQuery"
item-attribute="fullName"
:items="[value]"
:custom-update="getUpdater('delete')"
>
<template #title>
{{ $t("alsijil.personal_notes.confirm_delete") }}
</template>
<template #body>
{{
$t("alsijil.personal_notes.confirm_delete_explanation", {
note: value.note,
name: participation.person.fullName,
})
}}
</template>
</delete-dialog>
</template>
</v-textarea>
</template> </template>
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