Initial Commit
This commit is contained in:
16
otis/src/app/offices/office-list/office-list-datasource.ts
Normal file
16
otis/src/app/offices/office-list/office-list-datasource.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { Office } from '../../core/office';
|
||||
|
||||
export class OfficeListDataSource extends DataSource<Office> {
|
||||
constructor(public data: Office[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Office[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
40
otis/src/app/offices/office-list/office-list.component.html
Normal file
40
otis/src/app/offices/office-list/office-list.component.html
Normal file
@ -0,0 +1,40 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Offices</mat-card-title>
|
||||
<a mat-button [routerLink]="['/offices', '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]="['/offices', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Email Column -->
|
||||
<ng-container matColumnDef="email">
|
||||
<mat-header-cell *matHeaderCellDef>Email</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.email }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Address Column -->
|
||||
<ng-container matColumnDef="address">
|
||||
<mat-header-cell *matHeaderCellDef>Address</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.address }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Department Column -->
|
||||
<ng-container matColumnDef="department">
|
||||
<mat-header-cell *matHeaderCellDef>Department</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.department?.name }}</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>
|
||||
@ -0,0 +1,22 @@
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OfficeListComponent } from './office-list.component';
|
||||
|
||||
describe('OfficeListComponent', () => {
|
||||
let component: OfficeListComponent;
|
||||
let fixture: ComponentFixture<OfficeListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [OfficeListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(OfficeListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
28
otis/src/app/offices/office-list/office-list.component.ts
Normal file
28
otis/src/app/offices/office-list/office-list.component.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { Office } from '../../core/office';
|
||||
|
||||
import { OfficeListDataSource } from './office-list-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-office-list',
|
||||
templateUrl: './office-list.component.html',
|
||||
styleUrls: ['./office-list.component.css'],
|
||||
})
|
||||
export class OfficeListComponent implements OnInit {
|
||||
list: Office[] = [];
|
||||
dataSource: OfficeListDataSource = new OfficeListDataSource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'email', 'address', 'department'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: Office[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new OfficeListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user