From e3c673b55e8f56f2f8cb7c72d2461f2b70f75567 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 3 Apr 2019 11:31:08 +0200 Subject: [PATCH] export recommendations with extra labels --- .../core/ui-services/csv-export.service.ts | 2 +- .../services/motion-csv-export.service.ts | 34 +++++++++++++++---- .../services/motion-xlsx-export.service.ts | 22 ++++++++++-- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/client/src/app/core/ui-services/csv-export.service.ts b/client/src/app/core/ui-services/csv-export.service.ts index d58ed6d5f..081ba38a9 100644 --- a/client/src/app/core/ui-services/csv-export.service.ts +++ b/client/src/app/core/ui-services/csv-export.service.ts @@ -29,7 +29,7 @@ function isPropertyDefinition(obj: any): obj is CsvColumnDefinitionProperty { +export interface CsvColumnDefinitionMap { label: string; map: (model: T) => string; } diff --git a/client/src/app/site/motions/services/motion-csv-export.service.ts b/client/src/app/site/motions/services/motion-csv-export.service.ts index 58f0f9848..a36031a00 100644 --- a/client/src/app/site/motions/services/motion-csv-export.service.ts +++ b/client/src/app/site/motions/services/motion-csv-export.service.ts @@ -2,8 +2,13 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { CsvExportService, CsvColumnDefinitionProperty } from 'app/core/ui-services/csv-export.service'; +import { + CsvExportService, + CsvColumnDefinitionProperty, + CsvColumnDefinitionMap +} from 'app/core/ui-services/csv-export.service'; import { InfoToExport } from './motion-pdf.service'; +import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { ViewMotion } from '../models/view-motion'; /** @@ -19,7 +24,11 @@ export class MotionCsvExportService { * @param csvExport CsvExportService * @param translate TranslateService */ - public constructor(private csvExport: CsvExportService, private translate: TranslateService) {} + public constructor( + private csvExport: CsvExportService, + private translate: TranslateService, + private motionRepo: MotionRepositoryService + ) {} /** * Export all motions as CSV @@ -30,8 +39,22 @@ export class MotionCsvExportService { */ public exportMotionList(motions: ViewMotion[], contentToExport: string[], infoToExport: InfoToExport[]): void { const propertyList = ['identifier', 'title'].concat(contentToExport, infoToExport); - const exportProperties: CsvColumnDefinitionProperty[] = propertyList.map(option => { - return { property: option } as CsvColumnDefinitionProperty; + const exportProperties: ( + | CsvColumnDefinitionProperty + | CsvColumnDefinitionMap)[] = propertyList.map(option => { + if (option === 'recommendation') { + return { + label: 'recommendation', + map: motion => this.motionRepo.getExtendedRecommendationLabel(motion) + }; + } else if (option === 'state') { + return { + label: 'state', + map: motion => this.motionRepo.getExtendedStateLabel(motion) + }; + } else { + return { property: option } as CsvColumnDefinitionProperty; + } }); this.csvExport.export(motions, exportProperties, this.translate.instant('Motions') + '.csv'); @@ -52,8 +75,7 @@ export class MotionCsvExportService { { property: 'title' }, { label: 'recommendation', - map: motion => - motion.recommendation ? this.translate.instant(motion.recommendation.recommendation_label) : '' + map: motion => (motion.recommendation ? this.motionRepo.getExtendedRecommendationLabel(motion) : '') }, { property: 'motion_block', label: 'Motion block' } ], diff --git a/client/src/app/site/motions/services/motion-xlsx-export.service.ts b/client/src/app/site/motions/services/motion-xlsx-export.service.ts index 00f1c1913..d99759d90 100644 --- a/client/src/app/site/motions/services/motion-xlsx-export.service.ts +++ b/client/src/app/site/motions/services/motion-xlsx-export.service.ts @@ -3,9 +3,10 @@ import { Injectable } from '@angular/core'; import { Workbook } from 'exceljs'; import { InfoToExport } from './motion-pdf.service'; +import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; +import { TranslateService } from '@ngx-translate/core'; import { ViewMotion } from '../models/view-motion'; import { XlsxExportServiceService } from 'app/core/ui-services/xlsx-export-service.service'; -import { TranslateService } from '@ngx-translate/core'; /** * Service to export motion elements to XLSX @@ -16,8 +17,16 @@ import { TranslateService } from '@ngx-translate/core'; export class MotionXlsxExportService { /** * Constructor + * + * @param xlsx XlsxExportServiceService + * @param translate translationService + * @param motionRepo MotionRepositoryService */ - public constructor(private xlsx: XlsxExportServiceService, private translate: TranslateService) {} + public constructor( + private xlsx: XlsxExportServiceService, + private translate: TranslateService, + private motionRepo: MotionRepositoryService + ) {} /** * Export motions as XLSX @@ -53,7 +62,14 @@ export class MotionXlsxExportService { properties.map(property => { const motionProp = motion[property]; if (motionProp) { - return this.translate.instant(motionProp.toString()); + switch (property) { + case 'state': + return this.motionRepo.getExtendedStateLabel(motion); + case 'recommendation': + return this.motionRepo.getExtendedRecommendationLabel(motion); + default: + return this.translate.instant(motionProp.toString()); + } } else { return null; }