From ce216204f12439ed594130594c3838dce8c94e7e Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Mon, 15 Apr 2019 10:53:52 +0200 Subject: [PATCH] Updates the cache on comment section updates. Implements missing client code. --- .../models/view-motion-comment-section.ts | 21 +++++++++++++------ openslides/motions/views.py | 8 +++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/client/src/app/site/motions/models/view-motion-comment-section.ts b/client/src/app/site/motions/models/view-motion-comment-section.ts index a17680e1b..31a723950 100644 --- a/client/src/app/site/motions/models/view-motion-comment-section.ts +++ b/client/src/app/site/motions/models/view-motion-comment-section.ts @@ -75,12 +75,21 @@ export class ViewMotionCommentSection extends BaseViewModel { */ public updateDependencies(update: BaseViewModel): void { if (update instanceof ViewGroup) { - this.updateGroup(update); + if (this.section.read_groups_id.includes(update.id)) { + const groupIndex = this.read_groups.findIndex(group => group.id === update.id); + if (groupIndex < 0) { + this.read_groups.push(update); + } else { + this.read_groups[groupIndex] = update; + } + } else if (this.section.write_groups_id.includes(update.id)) { + const groupIndex = this.write_groups.findIndex(group => group.id === update.id); + if (groupIndex < 0) { + this.write_groups.push(update); + } else { + this.write_groups[groupIndex] = update; + } + } } } - - // TODO: Implement updating of groups - public updateGroup(group: ViewGroup): void { - console.log('implement update group of motion comment section'); - } } diff --git a/openslides/motions/views.py b/openslides/motions/views.py index fe009b590..31d3acd91 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -1089,6 +1089,14 @@ class MotionCommentSectionViewSet(ModelViewSet): raise ValidationError({"detail": msg}) return result + def update(self, *args, **kwargs): + response = super().update(*args, **kwargs) + # Update all affected motioncomments to update their `read_groups_id` field, + # which is taken from the updated section. + section = self.get_object() + inform_changed_data(MotionComment.objects.filter(section=section)) + return response + class StatuteParagraphViewSet(ModelViewSet): """