diff --git a/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens-service.ts b/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens-service.ts index 96ab8f6c33..57d496b66f 100644 --- a/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens-service.ts +++ b/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens-service.ts @@ -8,8 +8,8 @@ import {OAuthToken} from '../domain/sessions'; }) export class TokensService extends Service { - getTokens(): Observable { - return this.get('api/tokens'); + getTokens(user: string): Observable { + return this.get('api/tokens/' + user); } revokeToken(id: string): Observable { diff --git a/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.html b/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.html index ec7aded24d..e71f625e97 100644 --- a/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.html +++ b/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.html @@ -8,6 +8,9 @@

OAuth Tokens

+ + + diff --git a/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.ts b/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.ts index 29bc019f1c..36a2b2b1da 100644 --- a/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.ts +++ b/webapp/cas-mgmt-webapp-client/projects/dashboard/src/app/tokens/tokens.component.ts @@ -2,7 +2,10 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import {OAuthToken} from '../domain/sessions'; import {TokensService} from './tokens-service'; import { MatTableDataSource } from '@angular/material/table'; -import {PaginatorComponent} from 'mgmt-lib'; +import {PaginatorComponent, SpinnerService} from 'mgmt-lib'; +import {Observable, Subject} from 'rxjs'; +import {debounceTime, distinctUntilChanged, finalize, switchMap} from 'rxjs/operators'; +import {MatDialog} from '@angular/material'; @Component({ selector: 'app-tokens', @@ -13,18 +16,43 @@ export class TokensComponent implements OnInit { displayedColumns = ['actions', 'id', 'user', 'creation', 'uses']; dataSource: MatTableDataSource; selectedItem: OAuthToken; + searched: string; + + private searchText = new Subject(); @ViewChild(PaginatorComponent, {static: true}) paginator: PaginatorComponent; - constructor(private service: TokensService) { + constructor(private service: TokensService, + private spinner: SpinnerService, + private dialog: MatDialog) { } ngOnInit() { - this.service.getTokens().subscribe(r => { - this.dataSource = new MatTableDataSource(r); - this.dataSource.paginator = this.paginator.paginator; + this.dataSource = new MatTableDataSource([]); + this.dataSource.paginator = this.paginator.paginator; + this.searchText.pipe( + debounceTime(500), + distinctUntilChanged(), + switchMap((user: string) => { + if (user && user !== '') { + this.spinner.start('Searching'); + this.searched = user; + return this.service.getTokens(user) + .pipe(finalize(() => this.spinner.stop())); + } else { + return new Observable((observer) => observer.next(null)); + } + }) + ).subscribe((resp: OAuthToken[]) => { + if (resp !== null) { + this.dataSource.data = resp; + this.dataSource._updateChangeSubscription(); + } else { + this.dataSource.data = []; + this.dataSource._updateChangeSubscription(); + } }); } @@ -34,7 +62,7 @@ export class TokensComponent implements OnInit { delete() { this.service.revokeToken(this.selectedItem.id).subscribe(r => { - this.service.getTokens().subscribe(v => { + this.service.getTokens(this.searched).subscribe(v => { this.dataSource.data = v; this.dataSource._updateChangeSubscription(); }); @@ -46,4 +74,7 @@ export class TokensComponent implements OnInit { this.dataSource.filter = val; } + doLookup(val: string) { + this.searchText.next(val); + } }