From 6dc44be4eb7f3d46300ce1eaab46dfba1415f332 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 16 Mar 2021 20:13:48 +0300 Subject: [PATCH] Add list of users from public keys. --- src/app/_models/staff.ts | 5 +++ src/app/_services/auth.service.ts | 6 +++ src/app/app.component.ts | 4 +- .../pages/settings/settings.component.html | 41 ++++--------------- src/app/pages/settings/settings.component.ts | 37 +++++------------ 5 files changed, 31 insertions(+), 62 deletions(-) diff --git a/src/app/_models/staff.ts b/src/app/_models/staff.ts index fbc504a..1dfdb07 100644 --- a/src/app/_models/staff.ts +++ b/src/app/_models/staff.ts @@ -1,2 +1,7 @@ export interface Staff { + comment: string; + email: string; + name: string; + tag: number; + userid: string; } diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index d0e19fa..cee95c4 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -138,6 +138,12 @@ export class AuthService { window.location.reload(true); } + getTrustedUsers(): any { + let trustedUsers = []; + this.mutableKeyStore.getPublicKeys().forEach(key => trustedUsers.push(key.users[0].userId)); + return trustedUsers; + } + async getPublicKeys(): Promise { this.httpWrapperService.get(`${environment.publicKeysUrl}`).pipe(first()).subscribe(async res => { await this.mutableKeyStore.importPublicKey(res.body); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index cbf9dc1..42504ab 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,5 @@ import {ChangeDetectionStrategy, Component, HostListener} from '@angular/core'; import {AuthService, LoggingService, TokenService, TransactionService} from '@app/_services'; -import {NGXLogger} from 'ngx-logger'; @Component({ selector: 'app-root', @@ -18,10 +17,9 @@ export class AppComponent { private authService: AuthService, private tokenService: TokenService, private transactionService: TransactionService, - private logger: NGXLogger, private loggingService: LoggingService, ) { - this.authService.mutableKeyStore.loadKeyring().then(r => this.authService.getPublicKeys().then()); + this.authService.mutableKeyStore.loadKeyring().then(() => this.authService.getPublicKeys().then()); this.tokenService.getTokens().then(async r => loggingService.sendInfoLevelMessage(await r)); this.mediaQuery.addListener(this.onResize); this.onResize(this.mediaQuery); diff --git a/src/app/pages/settings/settings.component.html b/src/app/pages/settings/settings.component.html index 24fcdaa..7fdd713 100644 --- a/src/app/pages/settings/settings.component.html +++ b/src/app/pages/settings/settings.component.html @@ -58,8 +58,7 @@
- USERS - + TRUSTED USERS
@@ -70,46 +69,24 @@ + NAME {{user.name}} - - ACCOUNT TYPE - {{user.accountType}} + + EMAIL + {{user.email}} - - CREATED - {{user.created}} - - - - STATUS - - {{user.status}} - {{user.status}} - - - - - OPTIONS - - - - - - - - - - - + + USER ID + {{user.userid}} - + diff --git a/src/app/pages/settings/settings.component.ts b/src/app/pages/settings/settings.component.ts index fb95121..2154554 100644 --- a/src/app/pages/settings/settings.component.ts +++ b/src/app/pages/settings/settings.component.ts @@ -2,8 +2,8 @@ import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/co import {MatTableDataSource} from '@angular/material/table'; import {MatPaginator} from '@angular/material/paginator'; import {MatSort} from '@angular/material/sort'; -import {UserService} from '@app/_services'; -import {first} from 'rxjs/operators'; +import {AuthService} from '@app/_services'; +import {Staff} from '@app/_models/staff'; @Component({ selector: 'app-settings', @@ -14,43 +14,26 @@ import {first} from 'rxjs/operators'; export class SettingsComponent implements OnInit { date: string; dataSource: MatTableDataSource; - displayedColumns = ['name', 'accountType', 'created', 'status', 'options']; + displayedColumns = ['name', 'email', 'userId']; + trustedUsers: Staff[]; @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; constructor( - private userService: UserService - ) { - this.userService.getStaff(); - } + private authService: AuthService + ) { } ngOnInit(): void { - this.userService.staffSubject.subscribe(staff => { - this.dataSource = new MatTableDataSource(staff); - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; - }); const d = new Date(); this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`; + this.trustedUsers = this.authService.getTrustedUsers(); + this.dataSource = new MatTableDataSource(this.trustedUsers); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; } doFilter(value: string): void { this.dataSource.filter = value.trim().toLocaleLowerCase(); } - - activateStaff(id: string): void { - this.userService.activateStaff(id).pipe(first()).subscribe(res => console.log(res.body)); - this.userService.getStaff(); - } - - deactivateStaff(id: string): void { - this.userService.deactivateStaff(id).pipe(first()).subscribe(res => console.log(res.body)); - this.userService.getStaff(); - } - - changeStaffType(id: string, type: string): void { - this.userService.changeStaffType(id, type).pipe(first()).subscribe(res => console.log(res.body)); - this.userService.getStaff(); - } }