Skip to content

Commit

Permalink
Sort motion supporters in motion detail
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-beerboom committed Mar 4, 2024
1 parent 49b3ce0 commit f2ef564
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h4 *ngIf="perms.isAllowed('support', motion) || motion.hasSupporters()">{{ 'Sup
{{ motion.supporter_users.length }} {{ 'supporters' | translate }}
</button>
<p *ngIf="showSupporters" class="supporters">
<os-comma-separated-listing [list]="motion.supporter_users">
<os-comma-separated-listing [list]="supportersObservable | async">
<ng-template let-supporter>{{ supporter.full_name }}</ng-template>
</os-comma-separated-listing>
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { distinctUntilChanged, map, Subscription } from 'rxjs';
import { BehaviorSubject, distinctUntilChanged, map, Observable, Subscription } from 'rxjs';
import { Permission } from 'src/app/domain/definitions/permission';
import { Settings } from 'src/app/domain/models/meetings/meeting';
import { Motion } from 'src/app/domain/models/motions';
Expand All @@ -9,8 +9,10 @@ import { ChangeRecoMode } from 'src/app/domain/models/motions/motions.constants'
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';
import { ViewUser } from 'src/app/site/pages/meetings/view-models/view-user';
import { OperatorService } from 'src/app/site/services/operator.service';

import { ParticipantListSortService } from '../../../../../participants/pages/participant-list/services/participant-list-sort/participant-list-sort.service';
import { MotionForwardDialogService } from '../../../../components/motion-forward-dialog/services/motion-forward-dialog.service';
import { MotionEditorControllerService } from '../../../../modules/editors/services';
import { MotionSubmitterControllerService } from '../../../../modules/submitters/services';
Expand All @@ -24,7 +26,7 @@ import { SearchListDefinition } from '../motion-extension-field/motion-extension
templateUrl: `./motion-meta-data.component.html`,
styleUrls: [`./motion-meta-data.component.scss`]
})
export class MotionMetaDataComponent extends BaseMotionDetailChildComponent {
export class MotionMetaDataComponent extends BaseMotionDetailChildComponent implements OnInit, OnDestroy {
public motionBlocks: MotionBlock[] = [];

public categories: ViewMotionCategory[] = [];
Expand Down Expand Up @@ -114,6 +116,12 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent {

private _forwardingAvailable = false;

public get supportersObservable(): Observable<ViewUser[]> {
return this._supportersSubject;
}

private _supportersSubject = new BehaviorSubject<ViewUser[]>([]);

/**
* The subscription to the recommender config variable.
*/
Expand All @@ -127,7 +135,8 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent {
private meetingController: MeetingControllerService,
public motionSubmitterRepo: MotionSubmitterControllerService,
public motionEditorRepo: MotionEditorControllerService,
public motionWorkingGroupSpeakerRepo: MotionWorkingGroupSpeakerControllerService
public motionWorkingGroupSpeakerRepo: MotionWorkingGroupSpeakerControllerService,
private participantSort: ParticipantListSortService
) {
super();

Expand All @@ -140,6 +149,19 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent {
}
}

public ngOnInit(): void {
this.participantSort.initSorting();

this.subscriptions.push(
this.participantSort.getSortedViewModelListObservable().subscribe(() => this.updateSupportersSubject())
);
}

public override ngOnDestroy(): void {
this.participantSort.exitSortService();
super.ngOnDestroy();
}

/**
* Sets the state
*
Expand Down Expand Up @@ -300,6 +322,15 @@ export class MotionMetaDataComponent extends BaseMotionDetailChildComponent {
return origin?.canAccess();
}

protected override onAfterSetMotion(_previous: ViewMotion, _current: ViewMotion): void {
super.onAfterSetMotion(_previous, _current);
this.updateSupportersSubject();
}

private async updateSupportersSubject(): Promise<void> {
this._supportersSubject.next(await this.participantSort.sort(this.motion.supporter_users));
}

private isViewMotion(toTest: ViewMotion | ViewMeeting): boolean {
return toTest.COLLECTION === Motion.COLLECTION;
}
Expand Down

0 comments on commit f2ef564

Please sign in to comment.