Merge pull request #4847 from GabrielInTheWorld/csvCommentsExport
Exporting comments for XLSX
This commit is contained in:
commit
19f47e1bef
18
client/src/app/shared/utils/reconvert-chars.ts
Normal file
18
client/src/app/shared/utils/reconvert-chars.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* This function converts german umlauts back.
|
||||
*
|
||||
* @param text
|
||||
*
|
||||
* @returns {string} The whole text with german umlauts.
|
||||
*/
|
||||
export function reconvertChars(text: string): string {
|
||||
return text
|
||||
.replace(/ä|ä/g, 'ä')
|
||||
.replace(/Ä|Ä/g, 'Ä')
|
||||
.replace(/ö|ö/g, 'ö')
|
||||
.replace(/Ö|Ö/g, 'Ö')
|
||||
.replace(/ü/g, 'ü')
|
||||
.replace(/Ü/g, 'Ü')
|
||||
.replace(/å|å/g, 'å')
|
||||
.replace(/Å|Å/g, 'Å');
|
||||
}
|
@ -148,10 +148,16 @@ export class MotionExportDialogComponent implements OnInit {
|
||||
this.enableControl('content');
|
||||
}
|
||||
|
||||
// At the moment the csv can't export comments.
|
||||
if (format === FileFormat.CSV) {
|
||||
this.disableControl('comments');
|
||||
} else {
|
||||
this.enableControl('comments');
|
||||
}
|
||||
|
||||
if (format === FileFormat.CSV || format === FileFormat.XLSX) {
|
||||
this.disableControl('lnMode');
|
||||
this.disableControl('crMode');
|
||||
this.disableControl('comments');
|
||||
this.disableControl('pdfOptions');
|
||||
|
||||
// remove the selection of "votingResult"
|
||||
@ -168,7 +174,6 @@ export class MotionExportDialogComponent implements OnInit {
|
||||
if (format === FileFormat.PDF) {
|
||||
this.enableControl('lnMode');
|
||||
this.enableControl('crMode');
|
||||
this.enableControl('comments');
|
||||
this.enableControl('pdfOptions');
|
||||
this.votingResultButton.disabled = false;
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ export class MotionListComponent extends BaseListViewComponent<ViewMotion> imple
|
||||
exportInfo.crMode
|
||||
);
|
||||
} else if (exportInfo.format === FileFormat.XLSX) {
|
||||
this.motionXlsxExport.exportMotionList(data, exportInfo.metaInfo);
|
||||
this.motionXlsxExport.exportMotionList(data, exportInfo.metaInfo, exportInfo.comments);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -8,6 +8,9 @@ import { MotionRepositoryService } from 'app/core/repositories/motions/motion-re
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ViewMotion } from '../models/view-motion';
|
||||
import { XlsxExportServiceService, CellFillingDefinition } from 'app/core/ui-services/xlsx-export-service.service';
|
||||
import { MotionCommentSectionRepositoryService } from 'app/core/repositories/motions/motion-comment-section-repository.service';
|
||||
import { stripHtmlTags } from 'app/shared/utils/strip-html-tags';
|
||||
import { reconvertChars } from 'app/shared/utils/reconvert-chars';
|
||||
|
||||
/**
|
||||
* Service to export motion elements to XLSX
|
||||
@ -64,7 +67,8 @@ export class MotionXlsxExportService {
|
||||
public constructor(
|
||||
private xlsx: XlsxExportServiceService,
|
||||
private translate: TranslateService,
|
||||
private motionRepo: MotionRepositoryService
|
||||
private motionRepo: MotionRepositoryService,
|
||||
private commentRepo: MotionCommentSectionRepositoryService
|
||||
) {}
|
||||
|
||||
/**
|
||||
@ -73,8 +77,9 @@ export class MotionXlsxExportService {
|
||||
* @param motions
|
||||
* @param contentToExport
|
||||
* @param infoToExport
|
||||
* @param comments The ids of the comments, that will be exported, too.
|
||||
*/
|
||||
public exportMotionList(motions: ViewMotion[], infoToExport: InfoToExport[]): void {
|
||||
public exportMotionList(motions: ViewMotion[], infoToExport: InfoToExport[], comments: number[]): void {
|
||||
const workbook = new Workbook();
|
||||
const properties = sortMotionPropertyList(['identifier', 'title'].concat(infoToExport));
|
||||
|
||||
@ -97,15 +102,21 @@ export class MotionXlsxExportService {
|
||||
}
|
||||
});
|
||||
|
||||
worksheet.columns = properties.map(property => {
|
||||
const propertyHeader =
|
||||
property === 'motion_block'
|
||||
? 'Motion block'
|
||||
: property.charAt(0).toLocaleUpperCase() + property.slice(1);
|
||||
return {
|
||||
header: this.translate.instant(propertyHeader)
|
||||
};
|
||||
});
|
||||
const columns = [];
|
||||
columns.push(
|
||||
...properties.map(property => {
|
||||
const propertyHeader =
|
||||
property === 'motion_block'
|
||||
? 'Motion block'
|
||||
: property.charAt(0).toLocaleUpperCase() + property.slice(1);
|
||||
return {
|
||||
header: this.translate.instant(propertyHeader)
|
||||
};
|
||||
})
|
||||
);
|
||||
columns.push(...comments.map(commentId => ({ header: this.commentRepo.getViewModel(commentId).getTitle() })));
|
||||
|
||||
worksheet.columns = columns;
|
||||
|
||||
worksheet.getRow(1).eachCell(cell => {
|
||||
cell.font = {
|
||||
@ -118,23 +129,36 @@ export class MotionXlsxExportService {
|
||||
});
|
||||
|
||||
// map motion data to properties
|
||||
const motionData = motions.map(motion =>
|
||||
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());
|
||||
const motionData = motions.map(motion => {
|
||||
const data = [];
|
||||
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 {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
data.push(
|
||||
...comments.map(commentId => {
|
||||
const section = this.commentRepo.getViewModel(commentId);
|
||||
const motionComment = motion.getCommentForSection(section);
|
||||
return motionComment && motionComment.comment
|
||||
? reconvertChars(stripHtmlTags(motionComment.comment))
|
||||
: '';
|
||||
})
|
||||
);
|
||||
return data;
|
||||
});
|
||||
|
||||
// add to sheet
|
||||
for (let i = 0; i < motionData.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user