Users
This commit is contained in:
17
bookie/src/app/users/user-list/user-list-datasource.ts
Normal file
17
bookie/src/app/users/user-list/user-list-datasource.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { User } from '../../core/user';
|
||||
|
||||
export class UserListDataSource extends DataSource<User> {
|
||||
|
||||
constructor(public data: User[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<User[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
||||
38
bookie/src/app/users/user-list/user-list.component.html
Normal file
38
bookie/src/app/users/user-list/user-list.component.html
Normal file
@ -0,0 +1,38 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Users</mat-card-title>
|
||||
<a mat-button [routerLink]="['/users', 'new']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/users', row.name]">{{row.name}}</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Locked Out Column -->
|
||||
<ng-container matColumnDef="lockedOut">
|
||||
<mat-header-cell *matHeaderCellDef>Is Locked Out?</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.lockedOut}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Groups Column -->
|
||||
<ng-container matColumnDef="roles">
|
||||
<mat-header-cell *matHeaderCellDef>Roles</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<ul>
|
||||
<li *ngFor="let role of row.roles">{{role}}</li>
|
||||
</ul>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
27
bookie/src/app/users/user-list/user-list.component.ts
Normal file
27
bookie/src/app/users/user-list/user-list.component.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { UserListDataSource } from './user-list-datasource';
|
||||
import { User } from '../../core/user';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-list',
|
||||
templateUrl: './user-list.component.html',
|
||||
styleUrls: ['./user-list.component.css']
|
||||
})
|
||||
export class UserListComponent implements OnInit {
|
||||
dataSource: UserListDataSource;
|
||||
list: User[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'lockedOut', 'roles'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: User[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new UserListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user