Merge pull request #4567 from MaximilianKrambach/csvExportLabeledRecommend
export recommendations with extra labels
This commit is contained in:
commit
028c358a7f
@ -29,7 +29,7 @@ function isPropertyDefinition<T>(obj: any): obj is CsvColumnDefinitionProperty<T
|
||||
* all the models. This map function is called for every model and the user should return a string that is
|
||||
* put into the csv. Also a column label must be given, that is capitalized and translated.
|
||||
*/
|
||||
interface CsvColumnDefinitionMap<T> {
|
||||
export interface CsvColumnDefinitionMap<T> {
|
||||
label: string;
|
||||
map: (model: T) => string;
|
||||
}
|
||||
|
@ -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<ViewMotion>[] = propertyList.map(option => {
|
||||
const exportProperties: (
|
||||
| CsvColumnDefinitionProperty<ViewMotion>
|
||||
| CsvColumnDefinitionMap<ViewMotion>)[] = 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<ViewMotion>;
|
||||
}
|
||||
});
|
||||
|
||||
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' }
|
||||
],
|
||||
|
@ -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) {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user