Adds amount of waiting speakers for xlsx-export

This commit is contained in:
GabrielMeyer 2019-09-11 15:38:07 +02:00
parent 11922c2a12
commit cc3047a284
5 changed files with 74 additions and 21 deletions

View File

@ -49,6 +49,9 @@
<mat-button-toggle *ngFor="let metaInfo of metaInfoExportOrder" [value]="metaInfo">
<span>{{ getLabelForMetadata(metaInfo) | translate }}</span>
</mat-button-toggle>
<mat-button-toggle *osPerms="'agenda.can_see_list_of_speakers'" value="speakers" #speakersButton>
<span translate>Speakers</span>
</mat-button-toggle>
<mat-button-toggle value="polls" #votingResultButton>
<span translate>Voting result</span>
</mat-button-toggle>

View File

@ -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
*/

View File

@ -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 {

View File

@ -31,6 +31,7 @@ export type InfoToExport =
| 'origin'
| 'tags'
| 'polls'
| 'speakers'
| 'id'
| 'allcomments';

View File

@ -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) {