export recommendations with extra labels
This commit is contained in:
parent
aa9af9db8c
commit
e3c673b55e
@ -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
|
* 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.
|
* 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;
|
label: string;
|
||||||
map: (model: T) => string;
|
map: (model: T) => string;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,13 @@ import { Injectable } from '@angular/core';
|
|||||||
|
|
||||||
import { TranslateService } from '@ngx-translate/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 { InfoToExport } from './motion-pdf.service';
|
||||||
|
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
|
||||||
import { ViewMotion } from '../models/view-motion';
|
import { ViewMotion } from '../models/view-motion';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +24,11 @@ export class MotionCsvExportService {
|
|||||||
* @param csvExport CsvExportService
|
* @param csvExport CsvExportService
|
||||||
* @param translate TranslateService
|
* @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
|
* Export all motions as CSV
|
||||||
@ -30,8 +39,22 @@ export class MotionCsvExportService {
|
|||||||
*/
|
*/
|
||||||
public exportMotionList(motions: ViewMotion[], contentToExport: string[], infoToExport: InfoToExport[]): void {
|
public exportMotionList(motions: ViewMotion[], contentToExport: string[], infoToExport: InfoToExport[]): void {
|
||||||
const propertyList = ['identifier', 'title'].concat(contentToExport, infoToExport);
|
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>;
|
return { property: option } as CsvColumnDefinitionProperty<ViewMotion>;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.csvExport.export(motions, exportProperties, this.translate.instant('Motions') + '.csv');
|
this.csvExport.export(motions, exportProperties, this.translate.instant('Motions') + '.csv');
|
||||||
@ -52,8 +75,7 @@ export class MotionCsvExportService {
|
|||||||
{ property: 'title' },
|
{ property: 'title' },
|
||||||
{
|
{
|
||||||
label: 'recommendation',
|
label: 'recommendation',
|
||||||
map: motion =>
|
map: motion => (motion.recommendation ? this.motionRepo.getExtendedRecommendationLabel(motion) : '')
|
||||||
motion.recommendation ? this.translate.instant(motion.recommendation.recommendation_label) : ''
|
|
||||||
},
|
},
|
||||||
{ property: 'motion_block', label: 'Motion block' }
|
{ property: 'motion_block', label: 'Motion block' }
|
||||||
],
|
],
|
||||||
|
@ -3,9 +3,10 @@ import { Injectable } from '@angular/core';
|
|||||||
import { Workbook } from 'exceljs';
|
import { Workbook } from 'exceljs';
|
||||||
|
|
||||||
import { InfoToExport } from './motion-pdf.service';
|
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 { ViewMotion } from '../models/view-motion';
|
||||||
import { XlsxExportServiceService } from 'app/core/ui-services/xlsx-export-service.service';
|
import { XlsxExportServiceService } from 'app/core/ui-services/xlsx-export-service.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to export motion elements to XLSX
|
* Service to export motion elements to XLSX
|
||||||
@ -16,8 +17,16 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
export class MotionXlsxExportService {
|
export class MotionXlsxExportService {
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* 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
|
* Export motions as XLSX
|
||||||
@ -53,7 +62,14 @@ export class MotionXlsxExportService {
|
|||||||
properties.map(property => {
|
properties.map(property => {
|
||||||
const motionProp = motion[property];
|
const motionProp = motion[property];
|
||||||
if (motionProp) {
|
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());
|
return this.translate.instant(motionProp.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user