Skip to content

Commit

Permalink
Prevent unneccessary presenter call (#3671)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored May 15, 2024
1 parent b025d67 commit 51703fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
public secondSelectorLabel: string;

@Input()
public loadSecondSelectorValues: () => Promise<Selectable[]>;

public secondSelectorValues: Selectable[];

public secondSelectorFormControl: UntypedFormControl;
Expand Down Expand Up @@ -98,6 +100,11 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
this._editMode = value;
this._addUsersSet.clear();
this._removeUsersMap = {};
if (value && this.loadSecondSelectorValues) {
this.loadSecondSelectorValues().then(items => {
this.secondSelectorValues = items;
});
}
}

public get isEditMode(): boolean {
Expand Down Expand Up @@ -235,7 +242,7 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
}
}

public getDisabledFn(): (Selectable) => boolean {
public getDisabledFn(): (v: Selectable) => boolean {
return (value: Selectable) => this.secondSelectorDisabledIds.includes(value.id);
}

Expand All @@ -246,7 +253,7 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
}

public get isSecondSelectorValuesFilled(): boolean {
return this.secondSelectorValues.length > 0;
return this.secondSelectorValues && this.secondSelectorValues.length > 0;
}

private updateData(models: V[]): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
additionalInputLabel="{{ 'Extension' | translate }}"
[additionalInputValue]="motion?.additional_submitter"
secondSelectorLabel="{{ 'Committees' | translate }}"
[secondSelectorValues]="forwardingCommittees"
[loadSecondSelectorValues]="loadForwardingCommittees"
></os-motion-manage-motion-meeting-users>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,14 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
return this._referencedMotions;
}

public get forwardingCommittees(): Selectable[] {
return this._forwardingCommittees;
}
public loadForwardingCommittees: () => Promise<Selectable[]>;

private _referencingMotions: ViewMotion[];

private _referencedMotions: ViewMotion[];

private _forwardingAvailable = false;

private _forwardingCommittees: (Selectable & { name: string; toString: any })[] = [];

public get supportersObservable(): Observable<ViewUser[]> {
return this._supportersSubject;
}
Expand Down Expand Up @@ -152,6 +148,9 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
if (operator.hasPerms(Permission.motionCanManage)) {
this.motionForwardingService.forwardingMeetingsAvailable().then(forwardingAvailable => {
this._forwardingAvailable = forwardingAvailable;
this.loadForwardingCommittees = async (): Promise<Selectable[]> => {
return (await this.checkPresenter()) as Selectable[];
};
});
} else {
this._forwardingAvailable = false;
Expand All @@ -164,7 +163,6 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
this.subscriptions.push(
this.participantSort.getSortedViewModelListObservable().subscribe(() => this.updateSupportersSubject())
);
this.checkPresenter();
}

public override ngOnDestroy(): void {
Expand Down Expand Up @@ -388,21 +386,23 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
}
}

private async checkPresenter(): Promise<void> {
private async checkPresenter(): Promise<(Selectable & { name: string; toString: any })[]> {
const meetingId = this.activeMeetingService.meetingId;
const committees =
this.operator.hasPerms(Permission.motionCanManage) && !!meetingId
? await this.presenter.call({ meeting_id: meetingId })
: [];
this._forwardingCommittees = [];
const forwardingCommittees: (Selectable & { name: string; toString: any })[] = [];
for (let n = 0; n < committees.length; n++) {
this._forwardingCommittees.push({
forwardingCommittees.push({
id: n + 1,
name: committees[n],
getTitle: () => committees[n],
getListTitle: () => ``,
toString: () => committees[n]
});
}

return forwardingCommittees;
}
}

0 comments on commit 51703fe

Please sign in to comment.