From cc3047a284a494cbbc455619a02ff3171bab337a Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Wed, 11 Sep 2019 15:38:07 +0200 Subject: [PATCH] Adds amount of waiting speakers for xlsx-export --- .../motion-export-dialog.component.html | 3 ++ .../motion-export-dialog.component.ts | 45 ++++++++++++++++--- .../motions/services/motion-export.service.ts | 3 ++ .../motions/services/motion-pdf.service.ts | 1 + .../services/motion-xlsx-export.service.ts | 43 +++++++++++------- 5 files changed, 74 insertions(+), 21 deletions(-) diff --git a/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.html b/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.html index fe8b4c603..414945c2b 100644 --- a/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.html +++ b/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.html @@ -49,6 +49,9 @@ {{ getLabelForMetadata(metaInfo) | translate }} + + Speakers + Voting result diff --git a/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.ts b/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.ts index b6b173ba8..6d868b3de 100644 --- a/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.ts +++ b/client/src/app/site/motions/modules/shared-motion/motion-export-dialog/motion-export-dialog.component.ts @@ -83,6 +83,12 @@ export class MotionExportDialogComponent implements OnInit { @ViewChild('votingResultButton', { static: true }) public votingResultButton: MatButtonToggle; + /** + * To deactivate the speakers button. + */ + @ViewChild('speakersButton', { static: false }) + public speakersButton: MatButtonToggle; + /** * Constructor * Sets the default values for the lineNumberingMode and changeRecoMode and creates the form. @@ -134,8 +140,10 @@ export class MotionExportDialogComponent implements OnInit { // XLSX cannot have "content" if (format === ExportFileFormat.XLSX) { this.disableControl('content'); + this.changeStateOfButton(this.speakersButton, false); } else { this.enableControl('content'); + this.changeStateOfButton(this.speakersButton, true); } if (format === ExportFileFormat.CSV || format === ExportFileFormat.XLSX) { @@ -144,12 +152,10 @@ export class MotionExportDialogComponent implements OnInit { this.disableControl('pdfOptions'); // remove the selection of "votingResult" - let metaInfoVal: string[] = this.exportForm.get('metaInfo').value; - if (metaInfoVal) { - metaInfoVal = metaInfoVal.filter(info => { - return info !== 'polls'; - }); - this.exportForm.get('metaInfo').setValue(metaInfoVal); + if (format === ExportFileFormat.CSV) { + this.disableMetaInfoControl('polls', 'speakers'); + } else { + this.disableMetaInfoControl('polls'); } this.votingResultButton.disabled = true; } @@ -162,6 +168,20 @@ export class MotionExportDialogComponent implements OnInit { } } + /** + * Function to change the state of the property `disabled` of a given button. + * + * Ensures, that the button exists. + * + * @param button The button whose state will change. + * @param nextState The next state the button will assume. + */ + private changeStateOfButton(button: MatButtonToggle, nextState: boolean): void { + if (!!button) { + button.disabled = nextState; + } + } + /** * Helper function to easier enable a control * @param name @@ -196,6 +216,19 @@ export class MotionExportDialogComponent implements OnInit { } } + /** + * Function to deactivate at least one field of the meta-info. + * + * @param fields All fields to deactivate. + */ + private disableMetaInfoControl(...fields: string[]): void { + let metaInfoVal: string[] = this.exportForm.get('metaInfo').value; + if (metaInfoVal) { + metaInfoVal = metaInfoVal.filter(info => !fields.includes(info)); + this.exportForm.get('metaInfo').setValue(metaInfoVal); + } + } + /** * Creates the form with default values */ diff --git a/client/src/app/site/motions/services/motion-export.service.ts b/client/src/app/site/motions/services/motion-export.service.ts index fb2c08568..e249459c7 100644 --- a/client/src/app/site/motions/services/motion-export.service.ts +++ b/client/src/app/site/motions/services/motion-export.service.ts @@ -43,6 +43,9 @@ export class MotionExportService { ) {} public evaluateExportRequest(exportInfo: MotionExportInfo, data: ViewMotion[]): void { + if (!exportInfo) { + return; + } if (!!exportInfo.format) { if (exportInfo.format === ExportFileFormat.PDF) { try { diff --git a/client/src/app/site/motions/services/motion-pdf.service.ts b/client/src/app/site/motions/services/motion-pdf.service.ts index b2f30d08c..e37a0106c 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -31,6 +31,7 @@ export type InfoToExport = | 'origin' | 'tags' | 'polls' + | 'speakers' | 'id' | 'allcomments'; 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 77ca86459..ce74a9954 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 @@ -81,7 +81,9 @@ export class MotionXlsxExportService { */ public exportMotionList(motions: ViewMotion[], infoToExport: InfoToExport[], comments: number[]): void { const workbook = new Workbook(); - const properties = sortMotionPropertyList(['identifier', 'title'].concat(infoToExport)); + const properties = infoToExport.includes('speakers') + ? sortMotionPropertyList(['identifier', 'title'].concat(infoToExport)).concat('speakers') + : sortMotionPropertyList(['identifier', 'title'].concat(infoToExport)); const worksheet = workbook.addWorksheet(this.translate.instant('Motions'), { pageSetup: { @@ -105,10 +107,17 @@ export class MotionXlsxExportService { const columns = []; columns.push( ...properties.map(property => { - const propertyHeader = - property === 'motion_block' - ? 'Motion block' - : property.charAt(0).toLocaleUpperCase() + property.slice(1); + let propertyHeader = ''; + switch (property) { + case 'motion_block': + propertyHeader = 'Motion block'; + break; + case 'speakers': + propertyHeader = 'List of next speakers'; + break; + default: + propertyHeader = property.charAt(0).toUpperCase() + property.slice(1); + } return { header: this.translate.instant(propertyHeader) }; @@ -138,18 +147,22 @@ export class MotionXlsxExportService { data.push( ...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 { + if (property === 'speakers') { + return motion.listOfSpeakers && motion.listOfSpeakers.waitingSpeakerAmount > 0 + ? motion.listOfSpeakers.waitingSpeakerAmount + : ''; + } + if (!motionProp) { return ''; } + switch (property) { + case 'state': + return this.motionRepo.getExtendedStateLabel(motion); + case 'recommendation': + return this.motionRepo.getExtendedRecommendationLabel(motion); + default: + return this.translate.instant(motionProp.toString()); + } }) ); if (comments) {