diff --git a/apps/dafa-web/src/app/pages/administration/pages/employees/employees.component.html b/apps/dafa-web/src/app/pages/administration/pages/employees/employees.component.html index 9e9e81a..754b764 100644 --- a/apps/dafa-web/src/app/pages/administration/pages/employees/employees.component.html +++ b/apps/dafa-web/src/app/pages/administration/pages/employees/employees.component.html @@ -20,6 +20,11 @@ af-label-description="Sök på namn" (afOnInput)="setSearchValue($event)" > + (''); + private _onlyEmployeesWithoutAuthorization$ = new BehaviorSubject(false); employeesData$: Observable = this.employeeService.employeesData$; sort$: Observable> = this.employeeService.sort$; iconType = IconType; @@ -38,4 +39,13 @@ export class EmployeesComponent { setNewPage(page: number): void { this.employeeService.setPage(page); } + + get onlyEmployeesWithoutAuthorization(): boolean { + return this._onlyEmployeesWithoutAuthorization$.getValue(); + } + + setOnlyEmployeesWithoutAuthorization(event: CustomEvent<{ target: { checked: boolean } }>): void { + this._onlyEmployeesWithoutAuthorization$.next(event.detail.target.checked); + this.employeeService.setOnlyEmployeesWithoutAuthorization(this.onlyEmployeesWithoutAuthorization); + } } diff --git a/apps/dafa-web/src/app/shared/services/api/employee.service.ts b/apps/dafa-web/src/app/shared/services/api/employee.service.ts index b169864..817915f 100644 --- a/apps/dafa-web/src/app/shared/services/api/employee.service.ts +++ b/apps/dafa-web/src/app/shared/services/api/employee.service.ts @@ -27,19 +27,26 @@ export class EmployeeService { private _sort$ = new BehaviorSubject>({ key: 'fullName', order: SortOrder.ASC }); public sort$: Observable> = this._sort$.asObservable(); private _searchFilter$ = new BehaviorSubject(''); + private _onlyEmployeesWithoutAuthorization$ = new BehaviorSubject(false); public employeesData$: Observable = combineLatest([ this._limit$, this._page$, this._sort$, this._searchFilter$, - ]).pipe(switchMap(([limit, page, sort, searchFilter]) => this._fetchEmployees$(limit, page, sort, searchFilter))); + this._onlyEmployeesWithoutAuthorization$, + ]).pipe( + switchMap(([limit, page, sort, searchFilter, onlyEmployeesWithoutAuthorization]) => + this._fetchEmployees$(limit, page, sort, searchFilter, onlyEmployeesWithoutAuthorization) + ) + ); private _fetchEmployees$( limit: number, page: number, sort: Sort, - searchFilter: string + searchFilter: string, + onlyEmployeesWithoutAuthorization?: boolean ): Observable { const params: { [param: string]: string | string[] } = { sort: sort.key as string, @@ -52,6 +59,10 @@ export class EmployeeService { params.search = searchFilter; } + if (onlyEmployeesWithoutAuthorization) { + params.onlyEmployeesWithoutAuthorization = onlyEmployeesWithoutAuthorization?.toString(); + } + return this.httpClient .get(this._apiUrl, { ...API_HEADERS, @@ -76,6 +87,10 @@ export class EmployeeService { this._searchFilter$.next(value); } + public setOnlyEmployeesWithoutAuthorization(value: boolean): void { + this._onlyEmployeesWithoutAuthorization$.next(value); + } + public setSort(newSortKey: keyof Employee): void { const currentSort = this._sort$.getValue(); const order = diff --git a/mock-api/dafa-web/scripts/employees.js b/mock-api/dafa-web/scripts/employees.js index 134a5a7..a90a580 100644 --- a/mock-api/dafa-web/scripts/employees.js +++ b/mock-api/dafa-web/scripts/employees.js @@ -24,7 +24,7 @@ function generateEmployees(amount = 10) { )}`, organizations: [ORGANIZATIONS[Math.floor(Math.random() * ORGANIZATIONS.length)]], services: [TJANSTER[Math.floor(Math.random() * TJANSTER.length)]], - authorizations: authorizations.generate(), + authorizations: i % 2 === 0 ? authorizations.generate() : [], createdAt: Date.now(), }; diff --git a/mock-api/dafa-web/server.js b/mock-api/dafa-web/server.js index f8dd81b..1acb13f 100644 --- a/mock-api/dafa-web/server.js +++ b/mock-api/dafa-web/server.js @@ -12,6 +12,7 @@ server.use( '*sort=services*': '$1sort=services[0].name$2', '*sort=organizations*': '$1sort=organizations[0].address.city$2', '/employee*search=*': '/employee$1fullName_like=$2', + '/employee*onlyEmployeesWithoutAuthorization=*': '/employee$1authorizations.length_gte=1', '/employee*': '/employees$1', '/participants': '/participants?_embed=employees', '/participant/:id': '/participants/:id?_embed=employees', @@ -72,6 +73,7 @@ router.render = (req, res) => { if (key === 'kommunCodes') { value = +value; } + newData.push(...data.filter(item => item[`related_${key}`].includes(value))); });