Exporting comments for XLSX
This commit is contained in:
parent
3fe18bad7b
commit
07fb4e2167
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,7 +102,9 @@ export class MotionXlsxExportService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
worksheet.columns = properties.map(property => {
|
const columns = [];
|
||||||
|
columns.push(
|
||||||
|
...properties.map(property => {
|
||||||
const propertyHeader =
|
const propertyHeader =
|
||||||
property === 'motion_block'
|
property === 'motion_block'
|
||||||
? 'Motion block'
|
? 'Motion block'
|
||||||
@ -105,7 +112,11 @@ export class MotionXlsxExportService {
|
|||||||
return {
|
return {
|
||||||
header: this.translate.instant(propertyHeader)
|
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,8 +129,10 @@ 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 = [];
|
||||||
|
data.push(
|
||||||
|
...properties.map(property => {
|
||||||
const motionProp = motion[property];
|
const motionProp = motion[property];
|
||||||
if (motionProp) {
|
if (motionProp) {
|
||||||
switch (property) {
|
switch (property) {
|
||||||
@ -135,6 +148,17 @@ export class MotionXlsxExportService {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
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