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');
|
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) {
|
if (format === FileFormat.CSV || format === FileFormat.XLSX) {
|
||||||
this.disableControl('lnMode');
|
this.disableControl('lnMode');
|
||||||
this.disableControl('crMode');
|
this.disableControl('crMode');
|
||||||
this.disableControl('comments');
|
|
||||||
this.disableControl('pdfOptions');
|
this.disableControl('pdfOptions');
|
||||||
|
|
||||||
// remove the selection of "votingResult"
|
// remove the selection of "votingResult"
|
||||||
@ -168,7 +174,6 @@ export class MotionExportDialogComponent implements OnInit {
|
|||||||
if (format === FileFormat.PDF) {
|
if (format === FileFormat.PDF) {
|
||||||
this.enableControl('lnMode');
|
this.enableControl('lnMode');
|
||||||
this.enableControl('crMode');
|
this.enableControl('crMode');
|
||||||
this.enableControl('comments');
|
|
||||||
this.enableControl('pdfOptions');
|
this.enableControl('pdfOptions');
|
||||||
this.votingResultButton.disabled = false;
|
this.votingResultButton.disabled = false;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ export class MotionListComponent extends BaseListViewComponent<ViewMotion> imple
|
|||||||
exportInfo.crMode
|
exportInfo.crMode
|
||||||
);
|
);
|
||||||
} else if (exportInfo.format === FileFormat.XLSX) {
|
} 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 { TranslateService } from '@ngx-translate/core';
|
||||||
import { ViewMotion } from '../models/view-motion';
|
import { ViewMotion } from '../models/view-motion';
|
||||||
import { XlsxExportServiceService, CellFillingDefinition } from 'app/core/ui-services/xlsx-export-service.service';
|
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
|
* Service to export motion elements to XLSX
|
||||||
@ -64,7 +67,8 @@ export class MotionXlsxExportService {
|
|||||||
public constructor(
|
public constructor(
|
||||||
private xlsx: XlsxExportServiceService,
|
private xlsx: XlsxExportServiceService,
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private motionRepo: MotionRepositoryService
|
private motionRepo: MotionRepositoryService,
|
||||||
|
private commentRepo: MotionCommentSectionRepositoryService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,8 +77,9 @@ export class MotionXlsxExportService {
|
|||||||
* @param motions
|
* @param motions
|
||||||
* @param contentToExport
|
* @param contentToExport
|
||||||
* @param infoToExport
|
* @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 workbook = new Workbook();
|
||||||
const properties = sortMotionPropertyList(['identifier', 'title'].concat(infoToExport));
|
const properties = sortMotionPropertyList(['identifier', 'title'].concat(infoToExport));
|
||||||
|
|
||||||
@ -97,15 +102,21 @@ export class MotionXlsxExportService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
worksheet.columns = properties.map(property => {
|
const columns = [];
|
||||||
const propertyHeader =
|
columns.push(
|
||||||
property === 'motion_block'
|
...properties.map(property => {
|
||||||
? 'Motion block'
|
const propertyHeader =
|
||||||
: property.charAt(0).toLocaleUpperCase() + property.slice(1);
|
property === 'motion_block'
|
||||||
return {
|
? 'Motion block'
|
||||||
header: this.translate.instant(propertyHeader)
|
: 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 => {
|
worksheet.getRow(1).eachCell(cell => {
|
||||||
cell.font = {
|
cell.font = {
|
||||||
@ -118,23 +129,36 @@ export class MotionXlsxExportService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// map motion data to properties
|
// map motion data to properties
|
||||||
const motionData = motions.map(motion =>
|
const motionData = motions.map(motion => {
|
||||||
properties.map(property => {
|
const data = [];
|
||||||
const motionProp = motion[property];
|
data.push(
|
||||||
if (motionProp) {
|
...properties.map(property => {
|
||||||
switch (property) {
|
const motionProp = motion[property];
|
||||||
case 'state':
|
if (motionProp) {
|
||||||
return this.motionRepo.getExtendedStateLabel(motion);
|
switch (property) {
|
||||||
case 'recommendation':
|
case 'state':
|
||||||
return this.motionRepo.getExtendedRecommendationLabel(motion);
|
return this.motionRepo.getExtendedStateLabel(motion);
|
||||||
default:
|
case 'recommendation':
|
||||||
return this.translate.instant(motionProp.toString());
|
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
|
// add to sheet
|
||||||
for (let i = 0; i < motionData.length; i++) {
|
for (let i = 0; i < motionData.length; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user