Added simple pagination to participants-list
This commit is contained in:
committed by
Erik Tiekstra
parent
8a9b0049d4
commit
0a5448ff4f
@@ -0,0 +1,4 @@
|
|||||||
|
export enum ParticipantStatus {
|
||||||
|
ACTIVE = 'active',
|
||||||
|
FOLLOW_UP = 'follow-up',
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
|
import { ParticipantStatus } from '@dafa-enums/participant-status.enum';
|
||||||
import { Service } from '@dafa-enums/service.enum';
|
import { Service } from '@dafa-enums/service.enum';
|
||||||
|
|
||||||
export interface Participant {
|
export interface Participant {
|
||||||
id: number;
|
id: number;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
|
status: ParticipantStatus;
|
||||||
|
nextStep: string;
|
||||||
service: Service;
|
service: Service;
|
||||||
errandNumber: number;
|
errandNumber: number;
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let participant of participants">
|
<tr *ngFor="let participant of pagedParticipants">
|
||||||
<th scope="row">{{ participant.firstName }} {{ participant.lastName }}</th>
|
<th scope="row">{{ participant.firstName }} {{ participant.lastName }}</th>
|
||||||
<td>{{ participant.errandNumber }}</td>
|
<td>{{ participant.errandNumber }}</td>
|
||||||
<td>{{ participant.service }}</td>
|
<td>{{ participant.service }}</td>
|
||||||
@@ -70,3 +70,14 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</digi-ng-table>
|
</digi-ng-table>
|
||||||
|
|
||||||
|
<digi-navigation-pagination
|
||||||
|
*ngIf="participants.length > pagedParticipants.length"
|
||||||
|
class="participants-list__pagination"
|
||||||
|
[afTotalPages]="totalPages"
|
||||||
|
[afCurrentResultStart]="currentResultStart"
|
||||||
|
[afCurrentResultEnd]="currentResultEnd"
|
||||||
|
[afTotalResults]="participants.length"
|
||||||
|
(afOnPageChange)="handlePagination($event.detail)"
|
||||||
|
af-result-name="deltagare"
|
||||||
|
></digi-navigation-pagination>
|
||||||
|
|||||||
@@ -27,4 +27,9 @@
|
|||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
right: 0.5rem;
|
right: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__pagination {
|
||||||
|
display: block;
|
||||||
|
margin-top: var(--digi--layout--gutter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
import { Participant } from '@dafa-models/participant.model';
|
import { Participant } from '@dafa-models/participant.model';
|
||||||
import { SortBy } from '@dafa-models/sort-by.model';
|
import { SortBy } from '@dafa-models/sort-by.model';
|
||||||
import { ParticipantsService } from '@dafa-services/api/participants.service';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'dafa-participants-list',
|
selector: 'dafa-participants-list',
|
||||||
@@ -14,9 +14,34 @@ export class ParticipantsListComponent {
|
|||||||
@Input() sortBy: SortBy | null;
|
@Input() sortBy: SortBy | null;
|
||||||
@Output() sorted = new EventEmitter<keyof Participant>();
|
@Output() sorted = new EventEmitter<keyof Participant>();
|
||||||
|
|
||||||
constructor(private participantsService: ParticipantsService) {}
|
private _currentPage$ = new BehaviorSubject<number>(1);
|
||||||
|
private _participantsPerPage = 10;
|
||||||
|
|
||||||
|
get currentPage(): number {
|
||||||
|
return this._currentPage$.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
get totalPages(): number {
|
||||||
|
return Math.ceil(this.participants.length / this._participantsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
get pagedParticipants(): Participant[] {
|
||||||
|
return [...this.participants].slice(this.currentResultStart - 1, this.currentResultEnd - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
get currentResultStart(): number {
|
||||||
|
return (this.currentPage - 1) * this._participantsPerPage + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
get currentResultEnd(): number {
|
||||||
|
return this.currentResultStart + this._participantsPerPage;
|
||||||
|
}
|
||||||
|
|
||||||
handleSort(key: keyof Participant): void {
|
handleSort(key: keyof Participant): void {
|
||||||
this.sorted.emit(key);
|
this.sorted.emit(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePagination(page: number): void {
|
||||||
|
this._currentPage$.next(page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { DigiNgTableModule } from '@af/digi-ng/_table/table';
|
import { DigiNgTableModule } from '@af/digi-ng/_table/table';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { NgModule } from '@angular/core';
|
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
|
||||||
import { ParticipantsListComponent } from './participants-list.component';
|
import { ParticipantsListComponent } from './participants-list.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
declarations: [ParticipantsListComponent],
|
declarations: [ParticipantsListComponent],
|
||||||
imports: [CommonModule, DigiNgTableModule],
|
imports: [CommonModule, DigiNgTableModule],
|
||||||
exports: [ParticipantsListComponent],
|
exports: [ParticipantsListComponent],
|
||||||
|
|||||||
@@ -16,19 +16,25 @@
|
|||||||
></digi-form-input-search>
|
></digi-form-input-search>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<dafa-participants-list
|
<section class="participants__list">
|
||||||
*ngIf="activeParticipants$ | async as participants; else loadingRef"
|
<h2>Pågående tjänst</h2>
|
||||||
[participants]="participants"
|
<dafa-participants-list
|
||||||
[sortBy]="activeParticipantsSortBy$ | async"
|
*ngIf="activeParticipants$ | async as participants; else loadingRef"
|
||||||
(sorted)="handleActiveParticipantsSort($event)"
|
[participants]="participants"
|
||||||
></dafa-participants-list>
|
[sortBy]="activeParticipantsSortBy$ | async"
|
||||||
|
(sorted)="handleActiveParticipantsSort($event)"
|
||||||
|
></dafa-participants-list>
|
||||||
|
</section>
|
||||||
|
|
||||||
<dafa-participants-list
|
<section class="participants__list">
|
||||||
*ngIf="followUpParticipants$ | async as participants; else loadingRef"
|
<h2>För uppföljning</h2>
|
||||||
[participants]="participants"
|
<dafa-participants-list
|
||||||
[sortBy]="followUpParticipantsSortBy$ | async"
|
*ngIf="followUpParticipants$ | async as participants; else loadingRef"
|
||||||
(sorted)="handleFollowUpParticipantsSort($event)"
|
[participants]="participants"
|
||||||
></dafa-participants-list>
|
[sortBy]="followUpParticipantsSortBy$ | async"
|
||||||
|
(sorted)="handleFollowUpParticipantsSort($event)"
|
||||||
|
></dafa-participants-list>
|
||||||
|
</section>
|
||||||
|
|
||||||
<ng-template #loadingRef>
|
<ng-template #loadingRef>
|
||||||
<digi-ng-skeleton-base [afCount]="3" afText="Laddar deltagare"></digi-ng-skeleton-base>
|
<digi-ng-skeleton-base [afCount]="3" afText="Laddar deltagare"></digi-ng-skeleton-base>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { ParticipantStatus } from '@dafa-enums/participant-status.enum';
|
||||||
import { environment } from '@dafa-environment';
|
import { environment } from '@dafa-environment';
|
||||||
import { Participant } from '@dafa-models/participant.model';
|
import { Participant } from '@dafa-models/participant.model';
|
||||||
import { SortBy } from '@dafa-models/sort-by.model';
|
import { SortBy } from '@dafa-models/sort-by.model';
|
||||||
@@ -47,7 +48,8 @@ export class ParticipantsService {
|
|||||||
this._activeParticipantsSortBy$,
|
this._activeParticipantsSortBy$,
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([participants, sortBy]) => {
|
map(([participants, sortBy]) => {
|
||||||
return sortBy ? sort(participants, sortBy) : participants;
|
const activeParticipants = participants.filter(participant => participant.status === ParticipantStatus.ACTIVE);
|
||||||
|
return sortBy ? sort(activeParticipants, sortBy) : activeParticipants;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -56,7 +58,10 @@ export class ParticipantsService {
|
|||||||
this._followUpParticipantsSortBy$,
|
this._followUpParticipantsSortBy$,
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([participants, sortBy]) => {
|
map(([participants, sortBy]) => {
|
||||||
return sortBy ? sort(participants, sortBy) : participants;
|
const followUpParticipants = participants.filter(
|
||||||
|
participant => participant.status === ParticipantStatus.FOLLOW_UP
|
||||||
|
);
|
||||||
|
return sortBy ? sort(followUpParticipants, sortBy) : followUpParticipants;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user