Skip to content
Snippets Groups Projects
Commit 081939b7 authored by pgiertych's avatar pgiertych
Browse files

add searching on domain switcher

parent 029b03de
Branches
Tags
No related merge requests found
......@@ -3,7 +3,8 @@
<span style="color: gray;">{{ "FILTER.DOMAIN" | translate }}: {{ getCurrent() }}<span class="caret"></span></span>
</a>
<ul class="dropdown-menu">
<li *ngFor="let domain of domains | async; let last = isLast" [ngClass]="{'active': getCurrent() == domain?.name}">
<input type="text" [(ngModel)]="searchTerm" placeholder="Search by name" (input)="updateFilter()">
<li *ngFor="let domain of filteredDomains | async; let last = isLast" [ngClass]="{'active': getCurrent() == domain?.name}">
<a (click)="changeDomain(domain?.id, domain?.name)">
<span>{{domain?.name}}</span>
</a>
......
......@@ -3,7 +3,7 @@ import {Domain} from '../../../model/domain';
import {DomainService} from '../../../service';
import {UserDataService} from '../../../service/userdata.service';
import {Component, OnInit} from '@angular/core';
import {Subscription, Observable, of, interval} from 'rxjs';
import {BehaviorSubject, interval, Observable, of, Subscription} from 'rxjs';
import {map} from 'rxjs/operators';
import {ProfileService} from '../../../service/profile.service';
......@@ -26,6 +26,12 @@ export class DomainFilterComponent implements OnInit {
public profile: User;
public searchTerm = '';
private filteredDomainsSub = new BehaviorSubject<any[]>([]);
public filteredDomains = this.filteredDomainsSub.asObservable();
constructor(private authService: AuthService,
private domainService: DomainService,
private userData: UserDataService,
......@@ -49,6 +55,7 @@ export class DomainFilterComponent implements OnInit {
this.domains.subscribe(domain => {
this.domainName = domain[0].name;
this.userData.selectDomainId(domain[0].id)
this.filteredDomainsSub.next(domain);
});
}
);
......@@ -56,6 +63,13 @@ export class DomainFilterComponent implements OnInit {
this.userData.selectedDomainId.subscribe(id => this.domainId = id);
}
public updateFilter() {
this.domains.subscribe(data => {
const filtered = data.filter(obj => obj.name.toLowerCase().includes(this.searchTerm.toLowerCase()));
this.filteredDomainsSub.next(filtered);
});
}
public updateDomains(): void {
if (this.authService.hasRole('ROLE_SYSTEM_ADMIN')) {
this.domains = this.domainService.getAll();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment