Skip to content

Commit

Permalink
Call token service with user in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tsschmidt committed Jun 28, 2019
1 parent 11b993d commit a1ae1ef
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {OAuthToken} from '../domain/sessions';
})
export class TokensService extends Service {

getTokens(): Observable<OAuthToken[]> {
return this.get<OAuthToken[]>('api/tokens');
getTokens(user: string): Observable<OAuthToken[]> {
return this.get<OAuthToken[]>('api/tokens/' + user);
}

revokeToken(id: string): Observable<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ <h4 style="display: inline;position: relative;top: -5px;" i18n>OAuth Tokens</h4>
</div>

<div style="display: flex; flex-direction: column; margin-right:10px;margin-left:10px;">
<mat-form-field floatLabel="never" style="margin-left: 10px">
<input matInput (keyup)="doLookup($event.target.value)" placeholder="Enter user id to find tokens" >
</mat-form-field>
<mat-table #table [dataSource]="dataSource">

<ng-container matColumnDef="actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -13,18 +16,43 @@ export class TokensComponent implements OnInit {
displayedColumns = ['actions', 'id', 'user', 'creation', 'uses'];
dataSource: MatTableDataSource<OAuthToken>;
selectedItem: OAuthToken;
searched: string;

private searchText = new Subject<string>();

@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<OAuthToken>(r);
this.dataSource.paginator = this.paginator.paginator;
this.dataSource = new MatTableDataSource<OAuthToken>([]);
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();
}
});
}

Expand All @@ -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();
});
Expand All @@ -46,4 +74,7 @@ export class TokensComponent implements OnInit {
this.dataSource.filter = val;
}

doLookup(val: string) {
this.searchText.next(val);
}
}

0 comments on commit a1ae1ef

Please sign in to comment.