Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,40 @@ <h3>{{ 'Candidates' | translate }}</h3>
<div>
@if (assignment?.candidates?.length) {
<div class="candidates-list">
@if (assignmentCandidates.length > 1) {
<div class="candidate-sorting-button margin-bottom-5">
<button mat-button [matMenuTriggerFor]="sortMenu">
<mat-icon>sort</mat-icon>
{{ 'Sort' | translate }}
</button>
<mat-menu #sortMenu="matMenu">
<button mat-menu-item (click)="sortCandidates('first_name')">
<mat-icon>
{{
currentSort === 'first_name'
? sortAscending
? 'arrow_upward'
: 'arrow_downward'
: ''
}}
</mat-icon>
<span>{{ 'Given name' | translate }}</span>
</button>
<button mat-menu-item (click)="sortCandidates('last_name')">
<mat-icon>
{{
currentSort === 'last_name'
? sortAscending
? 'arrow_upward'
: 'arrow_downward'
: ''
}}
</mat-icon>
<span>{{ 'Surname' | translate }}</span>
</button>
</mat-menu>
</div>
}
<os-sorting-list
[count]="assignment.number_poll_candidates"
[enable]="hasPerms('manage')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { UserControllerService } from 'src/app/site/services/user-controller.ser
import { PromptService } from 'src/app/ui/modules/prompt-dialog';

import { AgendaItemControllerService } from '../../../../../agenda/services/agenda-item-controller.service';
import { getAssignmentDetailSubscriptionConfig } from '../../../../assignments.subscription';
import { AssignmentPhases } from '../../../../definitions';
import { AssignmentPollService } from '../../../../modules/assignment-poll/services/assignment-poll.service';
import { AssignmentPollDialogService } from '../../../../modules/assignment-poll/services/assignment-poll-dialog.service';
Expand Down Expand Up @@ -72,6 +73,9 @@ export class AssignmentDetailComponent extends BaseMeetingComponent implements O
*/
public candidateUserIds: number[] = [];

public currentSort: 'first_name' | 'last_name' = 'first_name';
public sortAscending = true;

/**
* Used for the search value selector
*/
Expand Down Expand Up @@ -119,6 +123,29 @@ export class AssignmentDetailComponent extends BaseMeetingComponent implements O
: false;
}

/**
* Sorts the assignment candidates by the given property. If the same property
* is already active, toggles the sort direction. Otherwise, sorts ascending.
*
* @param property The user name field to sort by
*/
public async sortCandidates(property: 'first_name' | 'last_name'): Promise<void> {
if (this.currentSort === property) {
this.sortAscending = !this.sortAscending;
} else {
this.currentSort = property;
this.sortAscending = true;
}
const sorted = [...this.assignmentCandidates].sort((a, b) => {
const nameA = property === 'first_name' ? (a.user?.first_name ?? '') : (a.user?.last_name ?? '');
const nameB = property === 'first_name' ? (b.user?.first_name ?? '') : (b.user?.last_name ?? '');
const comparison = nameA.localeCompare(nameB);
return this.sortAscending ? comparison : -comparison;
});
this._assignmentCandidates = sorted;
await this.onSortingChange(sorted);
}

/**
* Checks if there are any tags available
*/
Expand Down Expand Up @@ -215,6 +242,7 @@ export class AssignmentDetailComponent extends BaseMeetingComponent implements O
}
})
);
this.modelRequestService.subscribeTo(getAssignmentDetailSubscriptionConfig(assignmentId));
}

/**
Expand Down