brewman/overlord/src/app/daybook/daybook.component.ts
Amritanshu 72044476a8 Feature: Lazy loading
Lazy loaded everything
TODO: The cash flow module when clicking on sub-links, it reloads the whole page, it needs to be diagnosed and fixed, this problem also exists in the other modules
TODO: Rename folders and modules such as account to accounts to match the url
2019-06-13 16:36:43 +05:30

88 lines
2.4 KiB
TypeScript

import {Component, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import {ActivatedRoute, Router} from '@angular/router';
import * as moment from 'moment';
import {DaybookDataSource} from './daybook-datasource';
import {Daybook} from './daybook';
import {DaybookService} from './daybook.service';
@Component({
selector: 'app-daybook',
templateUrl: './daybook.component.html',
styleUrls: ['./daybook.component.css']
})
export class DaybookComponent implements OnInit {
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
dataSource: DaybookDataSource;
form: FormGroup;
info: Daybook;
selectedRowId: string;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['date', 'type', 'narration', 'debitText', 'debitAmount', 'creditText', 'creditAmount'];
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private ser: DaybookService
) {
this.createForm();
}
ngOnInit() {
this.route.data
.subscribe((data: { info: Daybook }) => {
this.info = data.info;
this.form.setValue({
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
});
this.dataSource = new DaybookDataSource(this.paginator, this.sort, this.info.body);
});
}
selectRow(id: string): void {
this.selectedRowId = id;
}
getRowClass(id: string, posted: boolean): string {
if (this.selectedRowId === id) {
return 'selected';
} else if (!posted) {
return 'unposted';
} else {
return '';
}
}
show() {
const l = this.prepareSubmit();
this.router.navigate(['daybook'], {
queryParams: {
startDate: l.startDate,
finishDate: l.finishDate
}
});
}
createForm() {
this.form = this.fb.group({
startDate: '',
finishDate: '',
});
}
prepareSubmit(): Daybook {
const formModel = this.form.value;
return {
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
body: []
};
}
}