OpenSlides/client/src/app/site/motions/services/statute-csv-export.service.ts
Maximilian Krambach 0ddded4a86 csv example export refactor
- make csv example data respect config separators
- refactor at a more central place
2019-03-06 11:03:51 +01:00

50 lines
1.5 KiB
TypeScript

import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CsvExportService, CsvColumnDefinitionProperty } from 'app/core/ui-services/csv-export.service';
import { ViewStatuteParagraph } from '../models/view-statute-paragraph';
/**
* Exports CSVs for statute paragraphs.
*/
@Injectable({
providedIn: 'root'
})
export class StatuteCsvExportService {
/**
* Does nothing.
*
* @param csvExport CsvExportService
* @param translate TranslateService
*/
public constructor(private csvExport: CsvExportService, private translate: TranslateService) {}
/**
* Export all statute paragraphs as CSV
*
* @param statute statute PParagraphs to export
*/
public exportStatutes(statutes: ViewStatuteParagraph[]): void {
const exportProperties: CsvColumnDefinitionProperty<ViewStatuteParagraph>[] = [
{ property: 'title' },
{ property: 'text' }
];
this.csvExport.export(statutes, exportProperties, this.translate.instant('Statute') + '.csv');
}
/**
* Exports a short example file
*/
public exportDummyCSV(): void {
const header = ['Title', 'Text'];
const rows = [
['§1', 'This is the first section'],
['§1, A 3', 'This is another important aspect'],
['§2', 'Yet another']
];
const filename = `${this.translate.instant('Statute')}-${this.translate.instant('example')}.csv`;
this.csvExport.dummyCSVExport(header, rows, filename);
}
}