Skip to content

Commit

Permalink
Fix remove and add submitters (#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored Oct 9, 2023
1 parent ab0c23b commit aa36d6b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions client/src/app/gateways/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export class Action<T = void> {
private _actions: ActionRequest[];
private _sendActionFn: (requests: ActionRequest[]) => Promise<T[]>;

public setSendActionFn(sendActionFn: (requests: ActionRequest[]) => Promise<T[]>): void {
this._sendActionFn = sendActionFn;
}

public constructor(sendActionFn: (requests: ActionRequest[]) => Promise<T[]>, actions: ActionRequest[] = []) {
this._actions = actions.filter(action => !!action?.data?.length);
this._sendActionFn = sendActionFn;
Expand Down
8 changes: 6 additions & 2 deletions client/src/app/gateways/repositories/base-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,15 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode

protected tapViewModels(_viewModels: V[]): void {}

protected createAction<T = void>(name: string, payload: unknown | unknown[]): Action<T> {
protected createAction<T = void>(
name: string,
payload: unknown | unknown[],
handle_separately?: boolean
): Action<T> {
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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export class MotionSubmitterRepositoryService extends BaseMeetingRelatedReposito
return this.createAction(MotionSubmitterAction.DELETE, payload);
}

public async sort(submitters: Identifiable[], motion: Identifiable): Promise<void> {
public sort(submitters: Identifiable[], motion: Identifiable): Action<void> {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class MotionSubmitterControllerService extends BaseMeetingControllerServi
return this.repo.delete(...submitters);
}

public sort(submitters: Identifiable[], motion: Identifiable): Promise<void> {
public sort(submitters: Identifiable[], motion: Identifiable): Action<void> {
return this.repo.sort(submitters, motion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -111,21 +112,29 @@ 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)
)
)
)
);
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;
}

Expand Down

0 comments on commit aa36d6b

Please sign in to comment.