Skip to content

Commit 76fc9eb

Browse files
xkostka2HejdaJakub
authored andcommitted
fix(admin): replace mat-selects for our custom search selects
* fixed AddMemberToResource dialog where we were still using plain mat-selects instead of our custom search selects
1 parent 154f665 commit 76fc9eb

File tree

10 files changed

+47
-74
lines changed

10 files changed

+47
-74
lines changed

apps/admin-gui/src/app/shared/components/dialogs/add-member-to-resource-dialog/add-member-to-resource-dialog.component.html

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,27 @@ <h1 mat-dialog-title>{{'DIALOGS.ADD_MEMBER_TO_RESOURCE.TITLE' | translate}}</h1>
99
>
1010
<mat-spinner *ngIf="loading" class="mr-auto ml-auto"></mat-spinner>
1111
<div *ngIf="!loading">
12-
<div>
13-
<mat-form-field class="input-style">
14-
<input
15-
[formControl]="facilityCtrl"
16-
[matAutocomplete]="autoFacility"
17-
aria-label="Number"
18-
matInput
19-
placeholder="{{ 'DIALOGS.ADD_MEMBER_TO_RESOURCE.FILTER' | translate}}"
20-
type="text" />
21-
<mat-autocomplete #autoFacility="matAutocomplete" autoActiveFirstOption>
22-
<mat-option *ngFor="let facility of filteredFacilities | async" [value]="facility">
23-
{{facility}}
24-
</mat-option>
25-
</mat-autocomplete>
26-
</mat-form-field>
12+
<div class="input-style">
13+
<perun-web-apps-facility-search-select
14+
(facilitySelected)="filterResources($event.name); stepper.selected.completed = true"
15+
[disableAutoSelect]="true"
16+
[facilities]="facilities"
17+
[selectPlaceholder]="'DIALOGS.ADD_MEMBER_TO_RESOURCE.FILTER'">
18+
</perun-web-apps-facility-search-select>
2719
</div>
28-
<div>
29-
<mat-form-field class="input-style">
30-
<mat-select
31-
disableOptionCentering="true"
32-
placeholder="{{ 'DIALOGS.ADD_MEMBER_TO_RESOURCE.SELECTED' | translate}}"
33-
required>
34-
<mat-option
35-
(click)="setResource(resource);
36-
stepper.selected.completed = true"
37-
*ngFor="let resource of filteredResources | async"
38-
[value]="resource">
39-
{{resource.name}}
40-
</mat-option>
41-
</mat-select>
42-
</mat-form-field>
20+
<div class="input-style">
21+
<perun-web-apps-resource-search-select
22+
(resourceSelected)="setResource($event);
23+
stepper.selected.completed = true"
24+
*ngIf="!processing"
25+
[disableAutoSelect]="true"
26+
[required]="true"
27+
[resource]="selectedResource"
28+
[resources]="filteredResources">
29+
</perun-web-apps-resource-search-select>
30+
<perun-web-apps-resource-search-select
31+
*ngIf="processing"
32+
[resources]="[]"></perun-web-apps-resource-search-select>
4333
</div>
4434
<div>
4535
<span

apps/admin-gui/src/app/shared/components/dialogs/add-member-to-resource-dialog/add-member-to-resource-dialog.component.ts

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
1010
import { GuiAuthResolver, NotificatorService } from '@perun-web-apps/perun/services';
1111
import { TranslateService } from '@ngx-translate/core';
1212
import {
13+
Facility,
1314
Group,
1415
GroupsManagerService,
1516
ResourcesManagerService,
1617
RichResource,
1718
Service,
1819
} from '@perun-web-apps/perun/openapi';
19-
import { UntypedFormControl } from '@angular/forms';
20-
import { map, startWith } from 'rxjs/operators';
21-
import { Observable } from 'rxjs';
2220
import { SelectionModel } from '@angular/cdk/collections';
2321
import { MatStepper } from '@angular/material/stepper';
2422

@@ -40,13 +38,8 @@ export class AddMemberToResourceDialogComponent implements OnInit, AfterViewInit
4038
loading = false;
4139
processing = false;
4240
membersGroupsId: Set<number> = new Set<number>();
43-
44-
facilityCtrl: UntypedFormControl = new UntypedFormControl();
45-
46-
filteredFacilities: Observable<string[]>;
47-
facilitiesNames: string[] = [];
48-
49-
filteredResources: Observable<RichResource[]>;
41+
facilities: Facility[] = [];
42+
filteredResources: RichResource[] = [];
5043
resources: RichResource[] = [];
5144
selectedResource: RichResource = null;
5245

@@ -81,6 +74,7 @@ export class AddMemberToResourceDialogComponent implements OnInit, AfterViewInit
8174
this.resourceManager.getRichResources(this.data.voId).subscribe(
8275
(resources) => {
8376
this.resources = resources;
77+
this.filteredResources = resources;
8478
this.getResourceFacilities();
8579
this.loading = false;
8680
},
@@ -150,42 +144,28 @@ export class AddMemberToResourceDialogComponent implements OnInit, AfterViewInit
150144
this.stepper.next();
151145
}
152146

153-
private getResourceFacilities(): void {
154-
const distinctFacilities = new Set<string>();
155-
for (const resource of this.resources) {
156-
distinctFacilities.add(resource.facility.name);
157-
}
158-
159-
this.facilitiesNames = Array.from(distinctFacilities);
160-
161-
this.filteredFacilities = this.facilityCtrl.valueChanges.pipe(
162-
startWith(''),
163-
map((value: string) => this.filterFacilities(value))
164-
);
165-
166-
this.filteredResources = this.facilityCtrl.valueChanges.pipe(
167-
startWith(''),
168-
map((value: string) => this.filterResources(value))
169-
);
170-
}
171-
172-
private filterFacilities(value: string): string[] {
173-
const filterValue = value.toLowerCase();
174-
const filtered = this.facilitiesNames.filter((option) =>
175-
option.toLowerCase().includes(filterValue)
176-
);
177-
return filtered.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
178-
}
179-
180-
private filterResources(value: string): RichResource[] {
147+
filterResources(value: string): void {
181148
if (value == null) {
182-
return this.resources;
149+
return;
183150
}
184151

185152
const filterValue = value.toLowerCase();
186153
const filtered = this.resources.filter((option) =>
187154
option.facility.name.toLowerCase().startsWith(filterValue)
188155
);
189-
return filtered.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
156+
this.filteredResources = filtered.sort((a, b) =>
157+
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
158+
);
159+
this.setResource(this.filteredResources[0]);
160+
}
161+
162+
private getResourceFacilities(): void {
163+
const distinctFacilities = new Set<string>();
164+
for (const resource of this.resources) {
165+
distinctFacilities.add(resource.facility.name);
166+
if (this.facilities.length !== distinctFacilities.size) {
167+
this.facilities.push(resource.facility);
168+
}
169+
}
190170
}
191171
}

apps/admin-gui/src/assets/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@
18061806
"CANCEL": "Cancel",
18071807
"BACK": "Back",
18081808
"SUBMIT": "Submit",
1809-
"FILTER": "Filter by facility:",
1809+
"FILTER": "Filter by facility",
18101810
"SELECTED": "Selected resource:",
18111811
"DESCRIPTION": "Description:",
18121812
"SERVICES": "Services on resource:",

libs/perun/components/src/lib/audit-log-search-select/audit-log-search-select.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[searchFunction]="searchFunction"
55
(entitySelected)="this.auditLogsSelected.emit($event)"
66
(selectClosed)="this.selectClosed.emit($event)"
7-
[shouldRefresh]="true"
87
[mainTextFunction]="mainTextFunction"
98
[secondaryTextFunction]="secondaryTextFunction"
109
[multiple]="true"

libs/perun/components/src/lib/entity-search-select/entity-search-select.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="d-flex flex-row align-items-center gap-4">
22
<mat-form-field class="w-100 pb-0">
33
<mat-select
4+
[required]="required"
45
data-cy="search-select-input"
56
(openedChange)="openChange()"
67
(closed)="closeChange()"

libs/perun/components/src/lib/entity-search-select/entity-search-select.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class EntitySearchSelectComponent<T extends PerunBean>
3535
@Input() displayStatus = false;
3636
@Input() multiple = false;
3737
@Input() theme = '';
38-
@Input() shouldRefresh = false;
38+
@Input() required = false;
3939
@Output() entitySelected = new EventEmitter<T | T[]>();
4040
@Output() selectClosed = new EventEmitter<boolean>();
4141
@ViewChild('scrollViewport', { static: false }) scrollViewport: CdkVirtualScrollViewport;

libs/perun/components/src/lib/facility-search-select/facility-search-select.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(entitySelected)="this.facilitySelected.emit($event)"
55
[searchFunction]="nameFunction"
66
[mainTextFunction]="nameFunction"
7-
[selectPlaceholder]="'SHARED_LIB.PERUN.COMPONENTS.FACILITY_SEARCH_SELECT.SELECT_FACILITY' | translate"
7+
[selectPlaceholder]="selectPlaceholder | translate"
88
[findPlaceholder]="'SHARED_LIB.PERUN.COMPONENTS.FACILITY_SEARCH_SELECT.FIND_FACILITY' | translate"
99
[noEntriesText]="'SHARED_LIB.PERUN.COMPONENTS.FACILITY_SEARCH_SELECT.NO_FACILITY_FOUND' | translate">
1010
</perun-web-apps-entity-search-select>

libs/perun/components/src/lib/facility-search-select/facility-search-select.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { compareFnName } from '@perun-web-apps/perun/utils';
1010
export class FacilitySearchSelectComponent implements OnInit {
1111
@Input() facilities: Facility[];
1212
@Input() disableAutoSelect = false;
13+
@Input() selectPlaceholder = 'SHARED_LIB.PERUN.COMPONENTS.FACILITY_SEARCH_SELECT.SELECT_FACILITY';
1314
@Output() facilitySelected = new EventEmitter<Facility>();
1415
nameFunction = (facility: Facility): string => facility.name;
1516

libs/perun/components/src/lib/resource-search-select/resource-search-select.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<perun-web-apps-entity-search-select
22
[entity]="resource"
33
[entities]="resources"
4+
[required]="required"
45
[disableAutoSelect]="disableAutoSelect"
56
(entitySelected)="this.resourceSelected.emit($event)"
67
[displayStatus]="displayStatus"

libs/perun/components/src/lib/resource-search-select/resource-search-select.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class ResourceSearchSelectComponent implements OnInit {
1212
@Input() resources: Resource[];
1313
@Input() displayStatus = true;
1414
@Input() disableAutoSelect = false;
15+
@Input() required = false;
1516
@Output() resourceSelected = new EventEmitter<Resource>();
1617

1718
nameFunction = (resource: Resource): string => resource.name;

0 commit comments

Comments
 (0)