Merge pull request #150 in TEA/mina-sidor-fa-web from bugfix/TV-676 to next
Squashed commit of the following:
commit e1e440d157044f59537f976273dfc810452c2108
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Tue Sep 28 13:14:36 2021 +0200
Changed variable-name
commit 1b23131743876338fd231382548ee6f51731e72a
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Tue Sep 28 12:05:02 2021 +0200
Removed comment
commit 66f5eaee5ba3c3f1fd5d2583c027dee99d744d8d
Merge: 41655741 de8931a8
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Tue Sep 28 11:57:15 2021 +0200
Merge branch 'next' into bugfix/TV-676
commit 4165574175e7ddcf8e3e3e78abc1ab24c65575d3
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Mon Sep 27 12:13:12 2021 +0200
WIP
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
<h2>Personallista</h2>
|
||||
|
||||
<form class="employees__search-wrapper" (ngSubmit)="setSearchFilter()">
|
||||
<form class="employees__search-wrapper" (ngSubmit)="setSearchString()">
|
||||
<digi-form-input-search
|
||||
af-label="Sök på personalens namn"
|
||||
(afOnInput)="setSearchValue($event)"
|
||||
|
||||
@@ -26,8 +26,8 @@ export class EmployeesComponent {
|
||||
return this._searchValue$.getValue();
|
||||
}
|
||||
|
||||
setSearchFilter(): void {
|
||||
this.employeeService.setSearchFilter(this.searchValue);
|
||||
setSearchString(): void {
|
||||
this.employeeService.setSearchString(this.searchValue);
|
||||
}
|
||||
|
||||
setSearchValue($event: CustomEvent<{ target: { value: string } }>): void {
|
||||
|
||||
@@ -23,19 +23,35 @@ import { ErrorService } from '@msfa-services/error.service';
|
||||
import { BehaviorSubject, combineLatest, Observable, of, throwError } from 'rxjs';
|
||||
import { catchError, distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
|
||||
interface EmployeeParams {
|
||||
page: number;
|
||||
limit: number;
|
||||
sort: keyof EmployeeCompactResponse;
|
||||
order: SortOrder;
|
||||
search: string;
|
||||
onlyEmployeesWithoutAuthorization: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class EmployeeService extends UnsubscribeDirective {
|
||||
private _apiBaseUrl = `${environment.api.url}/users`;
|
||||
private _currentEmployeeId$ = new BehaviorSubject<string>(null);
|
||||
private _limit$ = new BehaviorSubject<number>(10);
|
||||
private _page$ = new BehaviorSubject<number>(1);
|
||||
private _sort$ = new BehaviorSubject<Sort<keyof EmployeeCompactResponse>>({ key: 'name', order: SortOrder.ASC });
|
||||
public sort$: Observable<Sort<keyof EmployeeCompactResponse>> = this._sort$.asObservable();
|
||||
private _searchFilter$ = new BehaviorSubject<string>('');
|
||||
private _onlyEmployeesWithoutAuthorization$ = new BehaviorSubject<boolean>(false);
|
||||
public onlyEmployeesWithoutAuthorization$: Observable<boolean> = this._onlyEmployeesWithoutAuthorization$.asObservable();
|
||||
private _params$ = new BehaviorSubject<EmployeeParams>({
|
||||
page: 1,
|
||||
limit: 10,
|
||||
sort: 'name',
|
||||
order: SortOrder.ASC,
|
||||
search: '',
|
||||
onlyEmployeesWithoutAuthorization: false,
|
||||
});
|
||||
public sort$: Observable<Sort<keyof EmployeeCompactResponse>> = this._params$.pipe(
|
||||
map(({ sort, order }) => ({ key: sort, order }))
|
||||
);
|
||||
public onlyEmployeesWithoutAuthorization$: Observable<boolean> = this._params$.pipe(
|
||||
map(({ onlyEmployeesWithoutAuthorization }) => onlyEmployeesWithoutAuthorization)
|
||||
);
|
||||
private _employee$ = new BehaviorSubject<Employee>(null);
|
||||
public employee$: Observable<Employee> = this._employee$.asObservable();
|
||||
private _lastUpdatedEmployeeId$ = new BehaviorSubject<string>(null);
|
||||
@@ -67,17 +83,8 @@ export class EmployeeService extends UnsubscribeDirective {
|
||||
);
|
||||
}
|
||||
|
||||
public employeesData$: Observable<EmployeesData> = combineLatest([
|
||||
this._limit$,
|
||||
this._page$,
|
||||
this._sort$,
|
||||
this._searchFilter$,
|
||||
this._onlyEmployeesWithoutAuthorization$,
|
||||
this._lastDeletedEmployee$,
|
||||
]).pipe(
|
||||
switchMap(([limit, page, sort, searchFilter, onlyEmployeesWithoutAuthorization]) =>
|
||||
this._fetchEmployees$(limit, page, sort, searchFilter, onlyEmployeesWithoutAuthorization)
|
||||
)
|
||||
public employeesData$: Observable<EmployeesData> = combineLatest([this._params$, this._lastDeletedEmployee$]).pipe(
|
||||
switchMap(([params]) => this._fetchEmployees$(params))
|
||||
);
|
||||
|
||||
public setCurrentEmployeeId(currentEmployeeId: string): void {
|
||||
@@ -91,26 +98,21 @@ export class EmployeeService extends UnsubscribeDirective {
|
||||
this._lastUpdatedEmployeeId$.next(null);
|
||||
}
|
||||
|
||||
private _fetchEmployees$(
|
||||
limit: number,
|
||||
page: number,
|
||||
sort: Sort<keyof EmployeeCompactResponse>,
|
||||
searchFilter: string,
|
||||
onlyEmployeesWithoutAuthorization?: boolean
|
||||
): Observable<EmployeesData> {
|
||||
private _fetchEmployees$(employeeParams: EmployeeParams): Observable<EmployeesData> {
|
||||
const { sort, order, limit, page, search, onlyEmployeesWithoutAuthorization } = employeeParams;
|
||||
const params: Params = {
|
||||
sort: sort.key as string,
|
||||
order: sort.order as string,
|
||||
sort,
|
||||
order,
|
||||
limit: limit.toString(),
|
||||
page: page.toString(),
|
||||
};
|
||||
|
||||
if (searchFilter) {
|
||||
params.search = searchFilter;
|
||||
if (search) {
|
||||
params.search = search;
|
||||
}
|
||||
|
||||
if (onlyEmployeesWithoutAuthorization) {
|
||||
params.onlyEmployeesWithoutAuthorization = onlyEmployeesWithoutAuthorization?.toString();
|
||||
params.onlyEmployeesWithoutAuthorization = onlyEmployeesWithoutAuthorization.toString();
|
||||
}
|
||||
this._employeesLoading$.next(true);
|
||||
|
||||
@@ -134,12 +136,20 @@ export class EmployeeService extends UnsubscribeDirective {
|
||||
);
|
||||
}
|
||||
|
||||
public setSearchFilter(value: string): void {
|
||||
this._searchFilter$.next(value);
|
||||
public setSearchString(value: string): void {
|
||||
this._params$.next({
|
||||
...this._params$.getValue(),
|
||||
search: value,
|
||||
page: 1,
|
||||
});
|
||||
}
|
||||
|
||||
public setOnlyEmployeesWithoutAuthorization(value: boolean): void {
|
||||
this._onlyEmployeesWithoutAuthorization$.next(value);
|
||||
this._params$.next({
|
||||
...this._params$.getValue(),
|
||||
onlyEmployeesWithoutAuthorization: value,
|
||||
page: 1,
|
||||
});
|
||||
}
|
||||
|
||||
public setEmployeeToDelete(employee: Employee): void {
|
||||
@@ -156,16 +166,17 @@ export class EmployeeService extends UnsubscribeDirective {
|
||||
);
|
||||
}
|
||||
|
||||
public setSort(newSortKey: keyof EmployeeCompactResponse): void {
|
||||
const currentSort = this._sort$.getValue();
|
||||
const order =
|
||||
currentSort.key === newSortKey && currentSort.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||
public setSort(sort: keyof EmployeeCompactResponse): void {
|
||||
const currentParams = this._params$.getValue();
|
||||
const currentSort = currentParams.sort;
|
||||
const currentOrder = currentParams.order;
|
||||
const order = currentSort === sort && currentOrder === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||
|
||||
this._sort$.next({ key: newSortKey, order });
|
||||
this._params$.next({ ...this._params$.getValue(), sort, order });
|
||||
}
|
||||
|
||||
public setPage(page: number): void {
|
||||
this._page$.next(page);
|
||||
this._params$.next({ ...this._params$.getValue(), page });
|
||||
}
|
||||
|
||||
public postEmployeeInvitation(emails: string[]): Observable<EmployeeInviteResponse | null> {
|
||||
|
||||
Reference in New Issue
Block a user