Merge pull request #50 in TEA/dafa-web-monorepo from feature/TV-338 to develop

Squashed commit of the following:

commit e4a56f5e8afd00382810babfca258d31dbb30a15
Author: arbetsformedlingen_garcn <christian.gardebrink@arbetsformedlingen.se>
Date:   Mon Aug 16 02:48:58 2021 +0200

    TV-338 lade in lite justeringar av mockAPI:et för att det ska gå att se om en användare har behörigheter eller inte i gränssnittet när man filtrerar listan

commit 52aacae80777358b2ffab8d03dc0664c974803dc
Merge: eacbb04 466abd1
Author: arbetsformedlingen_garcn <christian.gardebrink@arbetsformedlingen.se>
Date:   Fri Aug 13 06:21:16 2021 +0200

    Merge branch 'develop-remote' into feature/TV-338

commit eacbb04bf17b87970efa2cfd1f27372928c1ca93
Author: arbetsformedlingen_garcn <christian.gardebrink@arbetsformedlingen.se>
Date:   Fri Aug 13 06:20:42 2021 +0200

    TV-338 har lagt till en query-param i anropet för att hämta en lista av personal/anställda, får kolla med backend vad den bör heta. I formuläret finns den representerad som en checkbox.
This commit is contained in:
Nicolas Fuentes Maturana
2021-08-16 09:26:52 +02:00
parent 466abd1dee
commit d020c81519
6 changed files with 40 additions and 3 deletions

View File

@@ -20,6 +20,11 @@
af-label-description="Sök på namn"
(afOnInput)="setSearchValue($event)"
></digi-form-input-search>
<digi-form-checkbox
class="employees__only-employees-without-authorization"
af-label="Visa endast personer utan behörigheter"
(afOnChange)="setOnlyEmployeesWithoutAuthorization($event)"
></digi-form-checkbox>
</form>
<dafa-employees-list

View File

@@ -7,8 +7,13 @@
&__search-wrapper {
display: flex;
flex-direction: column;
max-width: var(--digi--typography--text--max-width);
margin-top: $digi--layout--gutter--l;
margin-bottom: $digi--layout--gutter--xl;
}
&__only-employees-without-authorization {
margin-top: $digi--layout--gutter--l;
}
}

View File

@@ -13,6 +13,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
})
export class EmployeesComponent {
private _searchValue$ = new BehaviorSubject<string>('');
private _onlyEmployeesWithoutAuthorization$ = new BehaviorSubject<boolean>(false);
employeesData$: Observable<EmployeesData> = this.employeeService.employeesData$;
sort$: Observable<Sort<keyof Employee>> = 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);
}
}

View File

@@ -27,19 +27,26 @@ export class EmployeeService {
private _sort$ = new BehaviorSubject<Sort<keyof Employee>>({ key: 'fullName', order: SortOrder.ASC });
public sort$: Observable<Sort<keyof Employee>> = this._sort$.asObservable();
private _searchFilter$ = new BehaviorSubject<string>('');
private _onlyEmployeesWithoutAuthorization$ = new BehaviorSubject<boolean>(false);
public employeesData$: Observable<EmployeesData> = 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<keyof Employee>,
searchFilter: string
searchFilter: string,
onlyEmployeesWithoutAuthorization?: boolean
): Observable<EmployeesData> {
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<EmployeesApiResponse>(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 =

View File

@@ -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(),
};

View File

@@ -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)));
});