feat(employee-list): Added possibility to sort and paginate inside the list of employees (TV-217) (TV-222)
Squashed commit of the following: commit f13b52a134693bb6237b2df6408020504c3fbe1c Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Wed Jun 9 07:47:56 2021 +0200 Updated after PR commit 4055d3a14eda9737ef76ed5e85ea35480e19e71c Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Jun 7 15:20:26 2021 +0200 updates after PR comments commit f515ed6d06087f62de7522745691429d7ca91153 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Jun 7 12:07:50 2021 +0200 Now using Sort interface again commit 5c793a5a7579a520c3792bb3d13c00bb68dbfcd4 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Jun 7 11:54:27 2021 +0200 Fixed bug showing wrong amount in pagination component commit 7c55751147e05c1279b75356dc143b069e63e6b2 Merge: 11eab63a701888Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Jun 7 11:42:59 2021 +0200 Updated after merge with develop commit 11eab6330191a140c2cfd7094838495793e02719 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Mon Jun 7 11:23:52 2021 +0200 Added functionality to sort on different columns commit f13422a2aa53a69a243f32f9cd0b7ed6bd3441fc Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Jun 4 11:40:22 2021 +0200 Fixed other mappings after changes in the mock-api commit ba2d3200167281422354f5e3cfdf7720444a9c4c Merge: 6232b32d91b3e6Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Jun 4 10:00:00 2021 +0200 Added paging functionality commit 6232b3274ff73f2da929342a244fbc87430b796f Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Fri Jun 4 09:25:01 2021 +0200 Added meta model and changed services to adapt new API data structure commit 3ea0046bb713a6ee13d2a2cb2983e92d10559aa3 Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se> Date: Thu Jun 3 13:02:44 2021 +0200 Adjusted mock-api functionality
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ParticipantStatus } from '@dafa-enums/participant-status.enum';
|
||||
import { SortOrder } from '@dafa-enums/sort-order.enum';
|
||||
import { environment } from '@dafa-environment';
|
||||
import { Participant } from '@dafa-models/participant.model';
|
||||
import { SortBy } from '@dafa-models/sort-by.model';
|
||||
import {
|
||||
mapParticipantApiResponseToParticipant,
|
||||
Participant,
|
||||
ParticipantsApiResponse,
|
||||
} from '@dafa-models/participant.model';
|
||||
import { Sort } from '@dafa-models/sort.model';
|
||||
import { sort } from '@dafa-utils/sort.util';
|
||||
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -21,13 +26,23 @@ function filterParticipants(participants: Participant[], searchFilter: string):
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ParticipantsService {
|
||||
private _allParticipants$: Observable<Participant[]> = this.httpClient.get<Participant[]>(
|
||||
`${environment.api.url}/participants`
|
||||
);
|
||||
private _activeParticipantsSortBy$ = new BehaviorSubject<SortBy | null>({ key: 'handleBefore', reverse: false });
|
||||
public activeParticipantsSortBy$: Observable<SortBy> = this._activeParticipantsSortBy$.asObservable();
|
||||
private _followUpParticipantsSortBy$ = new BehaviorSubject<SortBy | null>({ key: 'handleBefore', reverse: false });
|
||||
public followUpParticipantsSortBy$: Observable<SortBy> = this._followUpParticipantsSortBy$.asObservable();
|
||||
private _allParticipants$: Observable<Participant[]> = this.httpClient
|
||||
.get<ParticipantsApiResponse>(`${environment.api.url}/participants`)
|
||||
.pipe(map(response => response.data.map(participant => mapParticipantApiResponseToParticipant(participant))));
|
||||
private _activeParticipantsSortBy$ = new BehaviorSubject<Sort<keyof Participant> | null>({
|
||||
key: 'handleBefore',
|
||||
order: SortOrder.ASC,
|
||||
});
|
||||
public activeParticipantsSortBy$: Observable<
|
||||
Sort<keyof Participant>
|
||||
> = this._activeParticipantsSortBy$.asObservable();
|
||||
private _followUpParticipantsSortBy$ = new BehaviorSubject<Sort<keyof Participant> | null>({
|
||||
key: 'handleBefore',
|
||||
order: SortOrder.ASC,
|
||||
});
|
||||
public followUpParticipantsSortBy$: Observable<
|
||||
Sort<keyof Participant>
|
||||
> = this._followUpParticipantsSortBy$.asObservable();
|
||||
private _searchFilter$ = new BehaviorSubject<string>('');
|
||||
public searchFilter$: Observable<string> = this._searchFilter$.asObservable();
|
||||
|
||||
@@ -64,14 +79,20 @@ export class ParticipantsService {
|
||||
|
||||
public setActiveParticipantsSortKey(key: keyof Participant) {
|
||||
const currentSortBy = this._activeParticipantsSortBy$.getValue();
|
||||
const reverse = currentSortBy?.key === key ? !currentSortBy.reverse : false;
|
||||
this._activeParticipantsSortBy$.next({ key, reverse });
|
||||
let order = currentSortBy.order;
|
||||
if (currentSortBy?.key === key) {
|
||||
order = order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||
}
|
||||
this._activeParticipantsSortBy$.next({ key, order });
|
||||
}
|
||||
|
||||
public setFollowUpParticipantsSortKey(key: keyof Participant) {
|
||||
const currentSortBy = this._followUpParticipantsSortBy$.getValue();
|
||||
const reverse = currentSortBy?.key === key ? !currentSortBy.reverse : false;
|
||||
this._followUpParticipantsSortBy$.next({ key, reverse });
|
||||
let order = currentSortBy.order;
|
||||
if (currentSortBy?.key === key) {
|
||||
order = order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||
}
|
||||
this._followUpParticipantsSortBy$.next({ key, order });
|
||||
}
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
Reference in New Issue
Block a user