Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@@ -5,6 +5,7 @@ import * as moment from 'moment';
|
||||
|
||||
import { ToCsvService } from '../shared/to-csv.service';
|
||||
|
||||
import { BeerSaleExportHeaderInterface } from './beer-sale-export-header-interface';
|
||||
import { BeerSaleReport } from './beer-sale-report';
|
||||
import { BeerSaleReportDataSource } from './beer-sale-report-datasource';
|
||||
|
||||
@@ -14,9 +15,9 @@ import { BeerSaleReportDataSource } from './beer-sale-report-datasource';
|
||||
styleUrls: ['./beer-sale-report.component.css'],
|
||||
})
|
||||
export class BeerSaleReportComponent implements OnInit {
|
||||
dataSource: BeerSaleReportDataSource;
|
||||
info: BeerSaleReport = new BeerSaleReport();
|
||||
dataSource: BeerSaleReportDataSource = new BeerSaleReportDataSource(this.info.data);
|
||||
form: FormGroup;
|
||||
info: BeerSaleReport;
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns: string[] = ['date'];
|
||||
@@ -27,11 +28,16 @@ export class BeerSaleReportComponent implements OnInit {
|
||||
private fb: FormBuilder,
|
||||
private toCsv: ToCsvService,
|
||||
) {
|
||||
this.createForm();
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { info: BeerSaleReport }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { info: BeerSaleReport };
|
||||
this.info = data.info;
|
||||
this.displayedColumns = ['date'].concat(this.info.headers);
|
||||
this.form.setValue({
|
||||
@@ -52,32 +58,21 @@ export class BeerSaleReportComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): BeerSaleReport {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return {
|
||||
return new BeerSaleReport({
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
const headers = this.info.headers.reduce(
|
||||
(a, c) => {
|
||||
a[c] = c;
|
||||
return a;
|
||||
},
|
||||
{
|
||||
Date: 'date',
|
||||
},
|
||||
);
|
||||
const init: BeerSaleExportHeaderInterface = { Date: 'date' };
|
||||
const headers = this.info.headers.reduce((a, c) => {
|
||||
a[c] = c;
|
||||
return a;
|
||||
}, init);
|
||||
const csvData = new Blob([this.toCsv.toCsv(headers, this.info.data)], {
|
||||
type: 'text/csv;charset=utf-8;',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user