Skip to content
Snippets Groups Projects
Commit 1058f0e1 authored by kbeyro's avatar kbeyro
Browse files

change cacheDomain

parent 820242c4
Branches
Tags
No related merge requests found
...@@ -8,7 +8,7 @@ import {Observable, of} from 'rxjs'; ...@@ -8,7 +8,7 @@ import {Observable, of} from 'rxjs';
import {Role, UserRole} from '../../../model/userrole'; import {Role, UserRole} from '../../../model/userrole';
import {UserDataService} from '../../../service/userdata.service'; import {UserDataService} from '../../../service/userdata.service';
import {AuthService} from '../../../auth/auth.service'; import {AuthService} from '../../../auth/auth.service';
import {map, shareReplay, take} from 'rxjs/operators'; import {debounceTime, map, shareReplay, take} from 'rxjs/operators';
import {UntypedFormControl} from '@angular/forms'; import {UntypedFormControl} from '@angular/forms';
import {ComponentMode} from '../../common/componentmode'; import {ComponentMode} from '../../common/componentmode';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
...@@ -93,23 +93,28 @@ export class UsersListComponent extends BaseComponent implements OnInit, OnChang ...@@ -93,23 +93,28 @@ export class UsersListComponent extends BaseComponent implements OnInit, OnChang
) )
this.userDataService.selectedDomainId.subscribe(domain => this.domainId = domain); this.userDataService.selectedDomainId.subscribe(domain => this.domainId = domain);
this.getAllDomain();
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
this.displayUsers = this.users; this.displayUsers = this.users;
// this.getAllDomain();
}
public getAllDomain() {
this.domainService.getAll().subscribe(domains => {
domains.forEach(domain => {
this.domainCache.setData(domain.id, domain)
})
})
} }
public getDomainName(domainId: number): Observable<string> { public getDomainName(domainId: number): Observable<string> {
if (this.domainCache.hasData(domainId)) { if (this.domainCache.hasData(domainId)) {
return of(this.domainCache.getData(domainId).name); return of(this.domainCache.getData(domainId).name);
} else { } else {
return this.domainService.getOne(domainId).pipe( return new Observable<string>()
map((domain) => {
this.domainCache.setData(domainId, domain);
return domain.name
}),
shareReplay(1),
take(1));
} }
} }
......
...@@ -10,7 +10,7 @@ import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms'; ...@@ -10,7 +10,7 @@ import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms';
import {Observable, of} from 'rxjs'; import {Observable, of} from 'rxjs';
import {CacheService} from '../../../service/cache.service'; import {CacheService} from '../../../service/cache.service';
import {UserDataService} from '../../../service/userdata.service'; import {UserDataService} from '../../../service/userdata.service';
import {map, shareReplay, take} from 'rxjs/operators'; import {debounceTime, map, shareReplay, take} from 'rxjs/operators';
@Component({ @Component({
selector: 'nmaas-userprivileges', selector: 'nmaas-userprivileges',
...@@ -103,6 +103,15 @@ export class UserPrivilegesComponent extends BaseComponent implements OnInit { ...@@ -103,6 +103,15 @@ export class UserPrivilegesComponent extends BaseComponent implements OnInit {
this.domainService.getOne(domainId).subscribe((domain) => this.domains.push(domain)); this.domainService.getOne(domainId).subscribe((domain) => this.domains.push(domain));
}); });
} }
this.getAllDomain();
}
public getAllDomain() {
this.domainService.getAll().subscribe(domains => {
domains.forEach(domain => {
if (!this.domainCache.hasData(domain.id)) this.domainCache.setData(domain.id, domain)
})
})
} }
public add(): void { public add(): void {
...@@ -124,14 +133,6 @@ export class UserPrivilegesComponent extends BaseComponent implements OnInit { ...@@ -124,14 +133,6 @@ export class UserPrivilegesComponent extends BaseComponent implements OnInit {
public getDomainName(domainId: number): Observable<string> { public getDomainName(domainId: number): Observable<string> {
if (this.domainCache.hasData(domainId)) { if (this.domainCache.hasData(domainId)) {
return of(this.domainCache.getData(domainId).name); return of(this.domainCache.getData(domainId).name);
} else {
return this.domainService.getOne(domainId).pipe(
map((domain) => {
this.domainCache.setData(domainId, domain);
return domain.name
}),
shareReplay(1),
take(1));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment