2019-01-31 11:21:02 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
2019-01-31 13:40:27 +01:00
|
|
|
import { CsvExportService, CsvColumnDefinitionProperty } from 'app/core/ui-services/csv-export.service';
|
2019-01-31 11:21:02 +01:00
|
|
|
import { ViewStatuteParagraph } from '../models/view-statute-paragraph';
|
2019-01-31 13:40:27 +01:00
|
|
|
import { FileExportService } from 'app/core/ui-services/file-export.service';
|
2019-01-31 11:21:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports CSVs for statute paragraphs.
|
|
|
|
*/
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class StatuteCsvExportService {
|
|
|
|
/**
|
|
|
|
* Does nothing.
|
|
|
|
*
|
|
|
|
* @param csvExport CsvExportService
|
|
|
|
* @param translate TranslateService
|
|
|
|
* @param fileExport FileExportService
|
|
|
|
*/
|
|
|
|
public constructor(
|
|
|
|
private csvExport: CsvExportService,
|
|
|
|
private translate: TranslateService,
|
|
|
|
private fileExport: FileExportService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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' }
|
|
|
|
];
|
2019-02-02 17:06:23 +01:00
|
|
|
this.csvExport.export(statutes, exportProperties, this.translate.instant('Statute') + '.csv');
|
2019-01-31 11:21:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports a short example file
|
|
|
|
*/
|
|
|
|
public exportDummyCSV(): void {
|
|
|
|
const headerRow = ['Title', 'Text'].map(item => this.translate.instant(item)).join(',');
|
|
|
|
const rows = [
|
|
|
|
headerRow,
|
|
|
|
'§1,"This is the first section"',
|
|
|
|
'"§1, A 3", "This is another important aspect"',
|
|
|
|
'§2,Yet another'
|
|
|
|
];
|
|
|
|
this.fileExport.saveFile(
|
|
|
|
rows.join('\n'),
|
2019-02-02 17:06:23 +01:00
|
|
|
`${this.translate.instant('Statute')}-${this.translate.instant('example')}.csv`,
|
2019-02-01 14:20:00 +01:00
|
|
|
'text/csv'
|
2019-01-31 11:21:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|