From 81c50f5b2f4439b064353333bdeca7dde33398b0 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Fri, 12 Apr 2019 13:23:22 +0200 Subject: [PATCH] bulk set/unset favorite status --- .../core/ui-services/personal-note.service.ts | 36 ++++++++++++++++ .../personal-note.component.html | 2 +- .../motion-list/motion-list.component.html | 4 ++ .../services/motion-multiselect.service.ts | 42 ++++++++++++++----- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/client/src/app/core/ui-services/personal-note.service.ts b/client/src/app/core/ui-services/personal-note.service.ts index b181259ea..4c915c20b 100644 --- a/client/src/app/core/ui-services/personal-note.service.ts +++ b/client/src/app/core/ui-services/personal-note.service.ts @@ -60,6 +60,42 @@ export class PersonalNoteService { } pnObject.notes[model.collectionString][model.id] = content; + this.savePersonalNoteObject(pnObject); + } + + /** + * Sets the 'favorite' status for several models of a type in bulk + * + * @param models The model the content belongs to + * @param star The new 'favorite' status + */ + public async bulkSetStar(models: (BaseModel | BaseViewModel)[], star: boolean): Promise { + if (!models.length) { + return; + } + const pnObject: Partial = this.personalNoteObject || {}; + if (!pnObject.notes) { + pnObject.notes = {}; + } + for (const model of models) { + if (!pnObject.notes[model.collectionString]) { + pnObject.notes[model.collectionString] = {}; + } + if (pnObject.notes[model.collectionString][model.id]) { + pnObject.notes[model.collectionString][model.id].star = star; + } else { + pnObject.notes[model.collectionString][model.id] = { star: star, note: '' }; + } + } + await this.savePersonalNoteObject(pnObject); + } + + /** + * Sends an updated personal note to the server + * + * @param pnObject a partial (if new) or complete personal note object + */ + private async savePersonalNoteObject(pnObject: Partial): Promise { if (!pnObject.id) { await this.http.post('rest/users/personal-note/', pnObject); } else { diff --git a/client/src/app/site/motions/modules/motion-detail/components/personal-note/personal-note.component.html b/client/src/app/site/motions/modules/motion-detail/components/personal-note/personal-note.component.html index 9892ffd9c..3778b4906 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/personal-note/personal-note.component.html +++ b/client/src/app/site/motions/modules/motion-detail/components/personal-note/personal-note.component.html @@ -6,7 +6,7 @@
-
+
No personal note
diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html index cb3416f37..c0ec1d13d 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html @@ -221,6 +221,10 @@
+