ToCsvService to escape the fields during exportCsv.
Auth Interceptor to check for logged out user.
This commit is contained in:
@@ -7,6 +7,7 @@ import * as moment from 'moment';
|
||||
import {RawMaterialCostDataSource} from './raw-material-cost-datasource';
|
||||
import {RawMaterialCost} from './raw-material-cost';
|
||||
import {Product} from '../product/product';
|
||||
import {ToCsvService} from '../shared/to-csv.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-raw-material-cost',
|
||||
@@ -32,11 +33,7 @@ export class RawMaterialCostComponent implements OnInit {
|
||||
|
||||
products: Observable<Product[]>;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder
|
||||
) {
|
||||
constructor(private route: ActivatedRoute, private router: Router, private fb: FormBuilder, private toCsv: ToCsvService) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
@@ -80,21 +77,20 @@ export class RawMaterialCostComponent implements OnInit {
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
const data: string[] = [];
|
||||
if (this.info.id) {
|
||||
data.push(
|
||||
'Name, Group, Quantity, Net, Gross',
|
||||
...this.dataSource.data.map(x => x.name + ', ' + x.group + ', ' + x.quantity + ', ' + x.net + ', ' + x.gross)
|
||||
);
|
||||
} else {
|
||||
data.push(
|
||||
'Name, Issue, Sale, RMC',
|
||||
...this.dataSource.data.map(x => x.name + ', ' + x.issue + ', ' + x.sale + ', ' + x.rmc),
|
||||
this.info.footer.name + ', ' + this.info.footer.issue + ', ' + this.info.footer.sale + ', ' + this.info.footer.rmc
|
||||
);
|
||||
}
|
||||
const headers = (this.info.id) ? {
|
||||
Name: 'name',
|
||||
Group: 'group',
|
||||
Quantity: 'quantity',
|
||||
Net: 'net',
|
||||
Gross: 'gross'
|
||||
} : {
|
||||
Name: 'name',
|
||||
Issue: 'issue',
|
||||
Sale: 'sale',
|
||||
RMC: 'rmc'
|
||||
};
|
||||
|
||||
const csvData = new Blob([data.join('\n')], {type: 'text/csv;charset=utf-8;'});
|
||||
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(csvData);
|
||||
link.setAttribute('download', 'raw-material-cost.csv');
|
||||
|
||||
Reference in New Issue
Block a user