From 8b118e5be3643cd033f4a0325dcc9d4d4305e329 Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Mon, 2 Oct 2023 14:18:36 +0200 Subject: [PATCH 1/2] Fix bulk change Submitters --- .../services/motion-multiselect.service.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts b/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts index 3b1f7a911b..3c2741e6f6 100644 --- a/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts +++ b/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts @@ -202,18 +202,22 @@ export class MotionMultiselectService { this.modelRequestService.closeSubscription(subscriptionName); if (selectedChoice) { let action: Action | null = null; - const users = (selectedChoice.ids as Ids).map(userId => ({ id: userId })); + const userIds = selectedChoice.ids as Ids; + const reloadedMotions = motions.map(motion => this.repo.getViewModel(motion.id)); + if (selectedChoice.action === ADD) { - action = Action.from(...motions.map(motion => this.submitterRepo.create(motion, ...users))); - } else if (selectedChoice.action === REMOVE) { action = Action.from( - this.submitterRepo.delete( - ...this.getSubmitterIds( - users.map(user => user.id), - motions + ...reloadedMotions + .filter(motion => this.newSubmittersInMotion(userIds, motion).length) + .map(motion => + this.submitterRepo.create(motion, ...this.newSubmittersInMotion(userIds, motion)) ) - ) ); + } else if (selectedChoice.action === REMOVE) { + const deleteSubmitterIds = this.getSubmitterIds(userIds, reloadedMotions); + if (deleteSubmitterIds.length) { + action = Action.from(this.submitterRepo.delete(...deleteSubmitterIds)); + } } if (action) { @@ -415,4 +419,11 @@ export class MotionMultiselectService { } return submitterIds.map(id => ({ id })); } + private submitterInMotion(userId: Id, motion: ViewMotion): boolean { + return motion.submitters.filter(submitter => userId == submitter.user_id).length > 0; + } + private newSubmittersInMotion(userIds: Ids, motion: ViewMotion): Identifiable[] { + const newSubmitters: Id[] = userIds.filter(userId => !this.submitterInMotion(userId, motion)); + return newSubmitters.map(id => ({ id })); + } } From ccac6c54d7a545cb46945e6d5d6c2035d5951edc Mon Sep 17 00:00:00 2001 From: Ludwig Reiter Date: Wed, 4 Oct 2023 08:54:03 +0200 Subject: [PATCH 2/2] Update helper function, use 'some' --- .../motion-multiselect/services/motion-multiselect.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts b/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts index 3c2741e6f6..2afc9cf6a8 100644 --- a/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts +++ b/client/src/app/site/pages/meetings/pages/motions/components/motion-multiselect/services/motion-multiselect.service.ts @@ -420,7 +420,7 @@ export class MotionMultiselectService { return submitterIds.map(id => ({ id })); } private submitterInMotion(userId: Id, motion: ViewMotion): boolean { - return motion.submitters.filter(submitter => userId == submitter.user_id).length > 0; + return motion.submitters.some(submitter => userId == submitter.user_id); } private newSubmittersInMotion(userIds: Ids, motion: ViewMotion): Identifiable[] { const newSubmitters: Id[] = userIds.filter(userId => !this.submitterInMotion(userId, motion));