Feature: Added the customer module to list / edit customers. This is needed to add the customer discount functionality
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { Customer } from '../../core/customer';
|
||||
|
||||
export class CustomerListDatasource extends DataSource<Customer> {
|
||||
constructor(public data: Customer[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Customer[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Customers</mat-card-title>
|
||||
<a mat-button [routerLink]="['/customers', '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]="['/customers', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Phone Column -->
|
||||
<ng-container matColumnDef="phone">
|
||||
<mat-header-cell *matHeaderCellDef>Phone</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.phone }}</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>
|
||||
|
||||
<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,28 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { Customer } from '../../core/customer';
|
||||
|
||||
import { CustomerListDatasource } from './customer-list-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-customer-list',
|
||||
templateUrl: './customer-list.component.html',
|
||||
styleUrls: ['./customer-list.component.css'],
|
||||
})
|
||||
export class CustomerListComponent implements OnInit {
|
||||
dataSource: CustomerListDatasource = new CustomerListDatasource([]);
|
||||
list: Customer[] = [];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'phone', 'address'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: Customer[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new CustomerListDatasource(this.list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user