Merge pull request #4629 from tsiegleauq/export-order-adjustment

Adjust the export order and dialog order
This commit is contained in:
Emanuel Schütze 2019-04-26 12:15:33 +02:00 committed by GitHub
commit 7ed59a57b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 22 deletions

View File

@ -46,17 +46,12 @@
<div> <div>
<p class="toggle-group-head" translate>Meta information</p> <p class="toggle-group-head" translate>Meta information</p>
<mat-button-toggle-group class="smaller-buttons" multiple formControlName="metaInfo"> <mat-button-toggle-group class="smaller-buttons" multiple formControlName="metaInfo">
<mat-button-toggle value="submitters"> <span translate>Submitters</span> </mat-button-toggle> <mat-button-toggle *ngFor="let metaInfo of metaInfoExportOrder" [value]="metaInfo">
<mat-button-toggle value="state"> <span translate>State</span> </mat-button-toggle> <span translate>{{ getLabelForMetadata(metaInfo) }}</span>
<mat-button-toggle value="recommendation"> <span translate>Recommendation</span> </mat-button-toggle> </mat-button-toggle>
<mat-button-toggle value="category"> <span translate>Category</span> </mat-button-toggle>
<mat-button-toggle value="tags"> <span translate>Tags</span> </mat-button-toggle>
<mat-button-toggle value="origin"> <span translate>Origin</span> </mat-button-toggle>
<mat-button-toggle value="motion_block"> <span translate>Motion block</span> </mat-button-toggle>
<mat-button-toggle value="polls" #votingResultButton> <mat-button-toggle value="polls" #votingResultButton>
<span translate>Voting result</span> <span translate>Voting result</span>
</mat-button-toggle> </mat-button-toggle>
<mat-button-toggle value="id"><span translate>Sequential number</span></mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>
</div> </div>
<div *ngIf="commentsToExport.length && exportForm.get('format').value === 'pdf'"> <div *ngIf="commentsToExport.length && exportForm.get('format').value === 'pdf'">

View File

@ -7,6 +7,7 @@ import { MotionCommentSectionRepositoryService } from 'app/core/repositories/mot
import { LineNumberingMode, ChangeRecoMode } from 'app/site/motions/models/view-motion'; import { LineNumberingMode, ChangeRecoMode } from 'app/site/motions/models/view-motion';
import { InfoToExport } from 'app/site/motions/services/motion-pdf.service'; import { InfoToExport } from 'app/site/motions/services/motion-pdf.service';
import { ViewMotionCommentSection } from 'app/site/motions/models/view-motion-comment-section'; import { ViewMotionCommentSection } from 'app/site/motions/models/view-motion-comment-section';
import { motionImportExportHeaderOrder, noMetaData } from 'app/site/motions/motion-import-export-order';
/** /**
* Dialog component to determine exporting. * Dialog component to determine exporting.
@ -42,6 +43,11 @@ export class MotionExportDialogComponent implements OnInit {
*/ */
private defaultContentToExport = ['text', 'reason']; private defaultContentToExport = ['text', 'reason'];
/**
* Determine the export order of the meta data
*/
public metaInfoExportOrder: string[];
/** /**
* Determine the default meta info to export. * Determine the default meta info to export.
*/ */
@ -104,6 +110,10 @@ export class MotionExportDialogComponent implements OnInit {
) { ) {
this.defaultLnMode = this.configService.instant('motions_default_line_numbering'); this.defaultLnMode = this.configService.instant('motions_default_line_numbering');
this.defaultCrMode = this.configService.instant('motions_recommendation_text_mode'); this.defaultCrMode = this.configService.instant('motions_recommendation_text_mode');
// Get the export order, exclude everything that does not count as meta-data
this.metaInfoExportOrder = motionImportExportHeaderOrder.filter(metaData => {
return !noMetaData.some(noMeta => metaData === noMeta);
});
this.createForm(); this.createForm();
} }
@ -195,4 +205,24 @@ export class MotionExportDialogComponent implements OnInit {
public onCloseClick(): void { public onCloseClick(): void {
this.dialogRef.close(); this.dialogRef.close();
} }
/**
* Gets the untranslated label for metaData
*/
public getLabelForMetadata(metaDataName: string): string {
switch (metaDataName) {
case 'polls': {
return 'Voting result';
}
case 'id': {
return 'Sequential number';
}
case 'motion_block': {
return 'Motion block';
}
default: {
return metaDataName.charAt(0).toUpperCase() + metaDataName.slice(1);
}
}
}
} }

View File

@ -260,8 +260,7 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
result.comments result.comments
); );
} else if (result.format === 'csv') { } else if (result.format === 'csv') {
const content = ['identifier', ...result.content, ...result.metaInfo]; this.motionCsvExport.exportMotionList(data, [...result.content, ...result.metaInfo]);
this.motionCsvExport.exportMotionList(data, content);
} else if (result.format === 'xlsx') { } else if (result.format === 'xlsx') {
this.motionXlsxExport.exportMotionList(data, result.metaInfo); this.motionXlsxExport.exportMotionList(data, result.metaInfo);
} }

View File

@ -4,20 +4,35 @@
export const motionImportExportHeaderOrder: string[] = [ export const motionImportExportHeaderOrder: string[] = [
'id', 'id',
'identifier', 'identifier',
'submitters',
'title', 'title',
'text', 'text',
'reason', 'reason',
'submitters',
'category', 'category',
'origin',
'motion_block',
'tags', 'tags',
'recommendation', 'recommendation',
'state' 'state',
'motion_block',
'origin'
]; ];
/**
* hints the metaData. This data will be excluded from the meta-data list in the export dialog.
* Order of this does not matter
*/
export const noMetaData: string[] = ['identifier', 'title', 'text', 'reason'];
/** /**
* Subset of {@link motionImportExportHeaderOrder} properties that are * Subset of {@link motionImportExportHeaderOrder} properties that are
* restricted to export only due to database or workflow limitations * restricted to export only due to database or workflow limitations
*/ */
export const motionExportOnly: string[] = ['id', 'recommendation', 'state', 'tags']; export const motionExportOnly: string[] = ['id', 'recommendation', 'state', 'tags'];
/**
* reorders the exported properties according to motionImportExportHeaderOrder
*
* @param propertyList A list of motion properties to be ordered
*/
export function sortMotionPropertyList(propertyList: string[]): string[] {
return motionImportExportHeaderOrder.filter(property => propertyList.includes(property));
}

View File

@ -7,7 +7,7 @@ import {
CsvColumnDefinitionProperty, CsvColumnDefinitionProperty,
CsvColumnDefinitionMap CsvColumnDefinitionMap
} from 'app/core/ui-services/csv-export.service'; } from 'app/core/ui-services/csv-export.service';
import { motionImportExportHeaderOrder } from '../motion-import-export-order'; import { sortMotionPropertyList } from '../motion-import-export-order';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
import { ViewMotion } from '../models/view-motion'; import { ViewMotion } from '../models/view-motion';
@ -37,11 +37,10 @@ export class MotionCsvExportService {
* @param contentToExport content properties to export * @param contentToExport content properties to export
*/ */
public exportMotionList(motions: ViewMotion[], contentToExport: string[]): void { public exportMotionList(motions: ViewMotion[], contentToExport: string[]): void {
// reorders the exported properties according to motionImportExportHeaderOrder const properties = sortMotionPropertyList(['identifier', 'title'].concat(contentToExport));
const propertyList = motionImportExportHeaderOrder.filter(property => contentToExport.includes(property));
const exportProperties: ( const exportProperties: (
| CsvColumnDefinitionProperty<ViewMotion> | CsvColumnDefinitionProperty<ViewMotion>
| CsvColumnDefinitionMap<ViewMotion>)[] = propertyList.map(option => { | CsvColumnDefinitionMap<ViewMotion>)[] = properties.map(option => {
if (option === 'recommendation') { if (option === 'recommendation') {
return { return {
label: 'recommendation', label: 'recommendation',

View File

@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { Workbook } from 'exceljs/dist/exceljs.min.js'; import { Workbook } from 'exceljs/dist/exceljs.min.js';
import { InfoToExport } from './motion-pdf.service'; import { InfoToExport } from './motion-pdf.service';
import { motionImportExportHeaderOrder } from '../motion-import-export-order'; import { sortMotionPropertyList } from '../motion-import-export-order';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ViewMotion } from '../models/view-motion'; import { ViewMotion } from '../models/view-motion';
@ -52,9 +52,8 @@ export class MotionXlsxExportService {
*/ */
public exportMotionList(motions: ViewMotion[], infoToExport: InfoToExport[]): void { public exportMotionList(motions: ViewMotion[], infoToExport: InfoToExport[]): void {
const workbook = new Workbook(); const workbook = new Workbook();
const propertyList = ['identifier', 'title'].concat(infoToExport); const properties = sortMotionPropertyList(['identifier', 'title'].concat(infoToExport));
// reorders the exported properties according to motionImportExportHeaderOrder
const properties = motionImportExportHeaderOrder.filter(property => propertyList.includes(property));
const worksheet = workbook.addWorksheet(this.translate.instant('Motions'), { const worksheet = workbook.addWorksheet(this.translate.instant('Motions'), {
pageSetup: { pageSetup: {
paperSize: 9, paperSize: 9,