Section
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
import { DataSource} from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf} from 'rxjs';
|
||||
import { Section} from '../../core/section';
|
||||
|
||||
export class SectionListDataSource extends DataSource<Section> {
|
||||
|
||||
constructor(public data: Section[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Section[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Sections</mat-card-title>
|
||||
<a mat-button [routerLink]="['/sections', '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]="['/sections', row.id]">{{row.name}}</a></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,23 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {SectionListComponent} from './section-list.component';
|
||||
|
||||
describe('SectionListComponent', () => {
|
||||
let component: SectionListComponent;
|
||||
let fixture: ComponentFixture<SectionListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SectionListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SectionListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,27 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { SectionListDataSource } from './section-list-datasource';
|
||||
import { Section } from '../../core/section';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-section-list',
|
||||
templateUrl: './section-list.component.html',
|
||||
styleUrls: ['./section-list.component.css']
|
||||
})
|
||||
export class SectionListComponent implements OnInit {
|
||||
dataSource: SectionListDataSource;
|
||||
list: Section[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Section[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new SectionListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user