Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
67 lines
2.1 KiB
TypeScript
67 lines
2.1 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 { StockMovementDataSource } from './stock-movement-datasource';
|
|
import { StockMovement } from './stock-movement';
|
|
|
|
@Component({
|
|
selector: 'app-stock-movement',
|
|
templateUrl: './stock-movement.component.html',
|
|
styleUrls: ['./stock-movement.component.css'],
|
|
})
|
|
export class StockMovementComponent implements OnInit {
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
dataSource: StockMovementDataSource;
|
|
form: FormGroup;
|
|
info: StockMovement;
|
|
selectedRowId: string;
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = ['group', 'name', 'opening', 'purchase', 'issue', 'closing'];
|
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private fb: FormBuilder) {
|
|
this.createForm();
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((data: { info: StockMovement }) => {
|
|
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 StockMovementDataSource(this.paginator, this.sort, this.info.body);
|
|
});
|
|
}
|
|
|
|
show() {
|
|
const l = this.prepareSubmit();
|
|
this.router.navigate(['stock-movement'], {
|
|
queryParams: {
|
|
startDate: l.startDate,
|
|
finishDate: l.finishDate,
|
|
},
|
|
});
|
|
}
|
|
|
|
createForm() {
|
|
this.form = this.fb.group({
|
|
startDate: '',
|
|
finishDate: '',
|
|
});
|
|
}
|
|
|
|
prepareSubmit(): StockMovement {
|
|
const formModel = this.form.value;
|
|
|
|
return {
|
|
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
|
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
|
body: [],
|
|
};
|
|
}
|
|
}
|