diff --git a/client/src/app/gateways/actions/action.ts b/client/src/app/gateways/actions/action.ts index 16604e9b15..fcc67c2c96 100644 --- a/client/src/app/gateways/actions/action.ts +++ b/client/src/app/gateways/actions/action.ts @@ -4,6 +4,10 @@ export class Action { private _actions: ActionRequest[]; private _sendActionFn: (requests: ActionRequest[]) => Promise; + public setSendActionFn(sendActionFn: (requests: ActionRequest[]) => Promise): void { + this._sendActionFn = sendActionFn; + } + public constructor(sendActionFn: (requests: ActionRequest[]) => Promise, actions: ActionRequest[] = []) { this._actions = actions.filter(action => !!action?.data?.length); this._sendActionFn = sendActionFn; diff --git a/client/src/app/gateways/repositories/base-repository.ts b/client/src/app/gateways/repositories/base-repository.ts index f5ac0e4983..797066f1d9 100644 --- a/client/src/app/gateways/repositories/base-repository.ts +++ b/client/src/app/gateways/repositories/base-repository.ts @@ -479,11 +479,15 @@ export abstract class BaseRepository(name: string, payload: unknown | unknown[]): Action { + protected createAction( + name: string, + payload: unknown | unknown[], + handle_separately?: boolean + ): Action { if (!Array.isArray(payload)) { payload = [payload]; } - return this.actions.create({ action: name, data: payload as unknown[] }); + return this.actions.createFromArray([{ action: name, data: payload as unknown[] }], handle_separately ?? false); } /** diff --git a/client/src/app/gateways/repositories/motions/motion-submitter-repository.service/motion-submitter-repository.service.ts b/client/src/app/gateways/repositories/motions/motion-submitter-repository.service/motion-submitter-repository.service.ts index 28358124ee..7e6cd28d96 100644 --- a/client/src/app/gateways/repositories/motions/motion-submitter-repository.service/motion-submitter-repository.service.ts +++ b/client/src/app/gateways/repositories/motions/motion-submitter-repository.service/motion-submitter-repository.service.ts @@ -39,11 +39,11 @@ export class MotionSubmitterRepositoryService extends BaseMeetingRelatedReposito return this.createAction(MotionSubmitterAction.DELETE, payload); } - public async sort(submitters: Identifiable[], motion: Identifiable): Promise { + public sort(submitters: Identifiable[], motion: Identifiable): Action { const payload = { motion_submitter_ids: submitters.map(submitter => submitter.id), motion_id: motion.id }; - await this.sendActionToBackend(MotionSubmitterAction.SORT, payload); + return this.createAction(MotionSubmitterAction.SORT, payload); } } diff --git a/client/src/app/site/pages/meetings/pages/motions/modules/submitters/services/motion-submitter-controller.service/motion-submitter-controller.service.ts b/client/src/app/site/pages/meetings/pages/motions/modules/submitters/services/motion-submitter-controller.service/motion-submitter-controller.service.ts index 13b8337dce..5f2938ba9a 100644 --- a/client/src/app/site/pages/meetings/pages/motions/modules/submitters/services/motion-submitter-controller.service/motion-submitter-controller.service.ts +++ b/client/src/app/site/pages/meetings/pages/motions/modules/submitters/services/motion-submitter-controller.service/motion-submitter-controller.service.ts @@ -34,7 +34,7 @@ export class MotionSubmitterControllerService extends BaseMeetingControllerServi return this.repo.delete(...submitters); } - public sort(submitters: Identifiable[], motion: Identifiable): Promise { + public sort(submitters: Identifiable[], motion: Identifiable): Action { return this.repo.sort(submitters, motion); } } diff --git a/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/components/motion-manage-submitters/motion-manage-submitters.component.ts b/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/components/motion-manage-submitters/motion-manage-submitters.component.ts index d5a58a4d79..05bd1f9b97 100644 --- a/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/components/motion-manage-submitters/motion-manage-submitters.component.ts +++ b/client/src/app/site/pages/meetings/pages/motions/pages/motion-detail/components/motion-manage-submitters/motion-manage-submitters.component.ts @@ -3,7 +3,7 @@ import { BehaviorSubject, filter, firstValueFrom, map, Observable } from 'rxjs'; import { Fqid, Id } from 'src/app/domain/definitions/key-types'; import { Identifiable } from 'src/app/domain/interfaces'; import { Selectable } from 'src/app/domain/interfaces/selectable'; -import { Action } from 'src/app/gateways/actions'; +import { Action, ActionService } from 'src/app/gateways/actions'; import { UserSelectionData } from 'src/app/site/pages/meetings/modules/participant-search-selector'; import { ViewMotion, ViewMotionSubmitter } from 'src/app/site/pages/meetings/pages/motions'; import { ParticipantControllerService } from 'src/app/site/pages/meetings/pages/participants/services/common/participant-controller.service/participant-controller.service'; @@ -77,7 +77,8 @@ export class MotionManageSubmittersComponent extends BaseUiComponent implements private userRepository: ParticipantControllerService, private motionSubmitterRepository: MotionSubmitterControllerService, public perms: MotionPermissionService, - private motionController: MotionControllerService + private motionController: MotionControllerService, + private actionService: ActionService ) { super(); @@ -111,13 +112,17 @@ export class MotionManageSubmittersComponent extends BaseUiComponent implements ...Array.from(this._addSubmittersSet).map(id => ({ id })) ) ); + + if (Object.values(this._removeSubmittersMap).length > 0) { + actions[0].setSendActionFn(r => this.actionService.sendRequests(r, true)); + } } - await Action.from(...actions).resolve(); - const submitters = await Promise.all( - this.editSubmitterSubject.value.map(async val => + + const submittersPromise = Promise.all( + this.editSubmitterSubject.value.map(val => val.user_id ? val - : await firstValueFrom( + : firstValueFrom( this.motionController.getViewModelObservable(this.motion.id).pipe( map(motion => motion.submitters.find(sub => sub.user_id === val.id)), filter(sub => !!sub) @@ -125,7 +130,11 @@ export class MotionManageSubmittersComponent extends BaseUiComponent implements ) ) ); - this.motionSubmitterRepository.sort(submitters, this.motion); + + await Action.from(...actions).resolve(); + + const submitters = await submittersPromise; + this.motionSubmitterRepository.sort(submitters, this.motion).resolve(); this.isEditMode = false; }