ToCsvService to escape the fields during exportCsv.

Auth Interceptor to check for logged out user.
This commit is contained in:
tanshu
2018-06-11 22:14:04 +05:30
parent a811a121cc
commit 4530052a22
6 changed files with 84 additions and 34 deletions

View File

@ -10,6 +10,7 @@ import {Ledger} from './ledger';
import {Account} from '../account/account';
import {LedgerService} from './ledger.service';
import {AccountService} from '../account/account.service';
import {ToCsvService} from '../shared/to-csv.service';
@Component({
selector: 'app-ledger',
@ -36,6 +37,7 @@ export class LedgerComponent implements OnInit, AfterViewInit {
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private toCsv: ToCsvService,
private ser: LedgerService,
private accountSer: AccountService
) {
@ -140,13 +142,17 @@ export class LedgerComponent implements OnInit, AfterViewInit {
}
exportCsv() {
const data: string[] = ['Date , Name , Type , Narration , Debit , Credit , Running , Posted'];
data.push(
...this.dataSource.data.map(x => x.date + ', ' + x.name + ', ' + x.type + ', ' +
x.narration + ', ' + x.debit + ', ' + x.credit + ', ' + x.running + ', ' + x.posted)
);
const csvData = new Blob([data.join('\n')], {type: 'text/csv;charset=utf-8;'});
const headers = {
Date: 'date',
Name: 'name',
Type: 'type',
Narration: 'narration',
Debit: 'debit',
Credit: 'credit',
Running: 'running',
Posted: 'posted'
};
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', 'ledger.csv');