Skip to content

Commit

Permalink
Add committee selector to motion meta data submitters (#3606)
Browse files Browse the repository at this point in the history
This selector allows to fill the submitters extension text field with
committee names.
  • Loading branch information
reiterl authored May 3, 2024
1 parent fc1dd4f commit 943cfe9
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import { Id } from 'src/app/domain/definitions/key-types';

import { Presenter } from './presenter';
import { PresenterService } from './presenter.service';

interface GetForwardCommitteesPresenterPayload {
meeting_id: Id;
}

type GetForwardingCommitteesPresenterResult = string[];

@Injectable({
providedIn: `root`
})
export class GetForwardingCommitteesPresenterService {
public constructor(private presenter: PresenterService) {}

public async call(payload: GetForwardCommitteesPresenterPayload): Promise<GetForwardingCommitteesPresenterResult> {
return await this.presenter.call<GetForwardingCommitteesPresenterResult>(
Presenter.GET_FORWARDING_COMMITTEES,
payload
);
}
}
1 change: 1 addition & 0 deletions client/src/app/gateways/presenter/presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum Presenter {
GET_ACTIVE_USER_AMOUNT = `get_active_users_amount`,
GET_USER_RELATED_MODELS = `get_user_related_models`,
GET_USER_SCOPE = `get_user_scope`,
GET_FORWARDING_COMMITTEES = `get_forwarding_committees`,
GET_FORWARDING_MEETINGS = `get_forwarding_meetings`,
SEARCH_USERS = `search_users`,
SEARCH_DELETED_MODELS = `search_deleted_models`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ <h4>
</mat-form-field>
</div>

<div *ngIf="useAdditionalInput" class="text-field-container">
<mat-form-field>
<mat-label>{{ secondSelectorLabel }}</mat-label>
<os-list-search-selector
[formControl]="secondSelectorFormControl"
[inputListValues]="secondSelectorValues"
[keepOpen]="true"
[disableOptionWhenFn]="getDisabledFn()"
(openedChange)="openedChange($event)"
></os-list-search-selector>
</mat-form-field>
</div>

<p>
<button type="button" mat-button (click)="onSave()">
<span>{{ 'Save' | translate }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse

public additionalInputControl: UntypedFormControl;

@Input()
public secondSelectorLabel: string;

@Input()
public secondSelectorValues: Selectable[];

public secondSelectorFormControl: UntypedFormControl;

private secondSelectorDisabledIds: number[] = [];

public get intermediateModels(): V[] {
return this.getIntermediateModels(this.motion);
}
Expand Down Expand Up @@ -117,9 +127,17 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse

public ngOnInit(): void {
this.additionalInputControl = this.fb.control(``);
this.secondSelectorFormControl = this.fb.control(``);
this.subscriptions.push(
this.editSubject.subscribe(ids => (this.editUserIds = ids.map(model => model.user_id ?? model.id)))
);
this.subscriptions.push(
this.secondSelectorFormControl.valueChanges.subscribe(value => {
if (value) {
this.changeSecondSelector();
}
})
);
}

public async onSave(): Promise<void> {
Expand Down Expand Up @@ -151,12 +169,9 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
)
);
if (this.useAdditionalInput) {
actions.push(
this.motionController.update(
{ [this.additionalInputField]: this.additionalInputControl.value },
this.motion
)
);
const value = this.additionalInputControl.value;
actions.push(this.motionController.update({ [this.additionalInputField]: value }, this.motion));
this.secondSelectorFormControl.setValue(null);
}

await Action.from(...actions).resolve();
Expand Down Expand Up @@ -220,6 +235,16 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
}
}

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

public openedChange(opened: boolean): void {
if (!opened) {
this.secondSelectorDisabledIds = [];
}
}

private updateData(models: V[]): void {
if (!this.isEditMode) {
this.editSubject.next(models);
Expand Down Expand Up @@ -270,4 +295,25 @@ export class MotionManageMotionMeetingUsersComponent<V extends BaseHasMeetingUse
const models = this.editSubject.value;
this.editSubject.next(models.concat(model));
}

/**
* helpers for second Selector
*/
private get secondSelectorSelectedValue(): string {
if (!this.secondSelectorFormControl.value) {
return ``;
}
const searchId = +this.secondSelectorFormControl.value;
const foundEntry = this.secondSelectorValues.find(entry => entry.id === searchId);
return !!foundEntry ? foundEntry.getTitle() : ``;
}

private changeSecondSelector(): void {
const value = this.additionalInputControl.value
? this.additionalInputControl.value + ` · ` + this.secondSelectorSelectedValue
: this.secondSelectorSelectedValue;
this.secondSelectorDisabledIds.push(+this.secondSelectorFormControl.value);
this.secondSelectorFormControl.setValue(null);
this.additionalInputControl.setValue(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
additionalInputField="additional_submitter"
additionalInputLabel="{{ 'Extension' | translate }}"
[additionalInputValue]="motion?.additional_submitter"
secondSelectorLabel="{{ 'Committees' | translate }}"
[secondSelectorValues]="forwardingCommittees"
></os-motion-manage-motion-meeting-users>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, distinctUntilChanged, map, Observable, Subscription } from 'rxjs';
import { Permission } from 'src/app/domain/definitions/permission';
import { Selectable } from 'src/app/domain/interfaces';
import { Settings } from 'src/app/domain/models/meetings/meeting';
import { Motion } from 'src/app/domain/models/motions';
import { MotionBlock } from 'src/app/domain/models/motions/motion-block';
import { ChangeRecoMode } from 'src/app/domain/models/motions/motions.constants';
import { GetForwardingCommitteesPresenterService } from 'src/app/gateways/presenter/get-forwarding-committees-presenter.service';
import { ViewMotion, ViewMotionCategory, ViewMotionState, ViewTag } from 'src/app/site/pages/meetings/pages/motions';
import { MeetingControllerService } from 'src/app/site/pages/meetings/services/meeting-controller.service';
import { ViewMeeting } from 'src/app/site/pages/meetings/view-models/view-meeting';
Expand Down Expand Up @@ -110,12 +112,18 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
return this._referencedMotions;
}

public get forwardingCommittees(): Selectable[] {
return this._forwardingCommittees;
}

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 All @@ -136,7 +144,8 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
public motionSubmitterRepo: MotionSubmitterControllerService,
public motionEditorRepo: MotionEditorControllerService,
public motionWorkingGroupSpeakerRepo: MotionWorkingGroupSpeakerControllerService,
private participantSort: ParticipantListSortService
private participantSort: ParticipantListSortService,
private presenter: GetForwardingCommitteesPresenterService
) {
super();

Expand All @@ -155,6 +164,7 @@ 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 @@ -377,4 +387,22 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent impl
});
}
}

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

0 comments on commit 943cfe9

Please sign in to comment.