Merge pull request #4816 from tsiegleauq/motion-pdf-sub-categories

Add motion PDF TOC subcategories
This commit is contained in:
Emanuel Schütze 2019-07-03 12:08:41 +02:00 committed by GitHub
commit 47f1ca9691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 49 deletions

View File

@ -532,6 +532,11 @@ export class PdfDocumentService {
margin: [0, 0, 0, 4], margin: [0, 0, 0, 4],
bold: true bold: true
}, },
tocSubcategoryTitle: {
fontSize: pageSize === 'A5' ? 9 : 10,
margin: [0, 0, 0, 4],
bold: true
},
tocCategorySection: { tocCategorySection: {
margin: [0, 0, 0, 10] margin: [0, 0, 0, 10]
}, },

View File

@ -1,13 +1,15 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion'; import { CategoryRepositoryService } from 'app/core/repositories/motions/category-repository.service';
import { MotionPdfService, InfoToExport } from './motion-pdf.service';
import { ConfigService } from 'app/core/ui-services/config.service'; import { ConfigService } from 'app/core/ui-services/config.service';
import { ViewCategory } from '../models/view-category'; import { MotionPdfService, InfoToExport } from './motion-pdf.service';
import { PdfError, PdfDocumentService, StyleType, BorderType } from 'app/core/ui-services/pdf-document.service';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
import { PdfError, PdfDocumentService, StyleType, BorderType } from 'app/core/ui-services/pdf-document.service';
import { ViewCategory } from '../models/view-category';
import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion';
/** /**
* Service to export a list of motions. * Service to export a list of motions.
@ -21,6 +23,8 @@ import { MotionRepositoryService } from 'app/core/repositories/motions/motion-re
providedIn: 'root' providedIn: 'root'
}) })
export class MotionPdfCatalogService { export class MotionPdfCatalogService {
private categoryObserver: BehaviorSubject<ViewCategory[]>;
/** /**
* Constructor * Constructor
* *
@ -33,8 +37,11 @@ export class MotionPdfCatalogService {
private configService: ConfigService, private configService: ConfigService,
private motionPdfService: MotionPdfService, private motionPdfService: MotionPdfService,
private pdfService: PdfDocumentService, private pdfService: PdfDocumentService,
private motionRepo: MotionRepositoryService private motionRepo: MotionRepositoryService,
) {} private categoryRepo: CategoryRepositoryService
) {
this.categoryObserver = this.categoryRepo.getViewModelListBehaviorSubject();
}
/** /**
* Converts the list of motions to pdfmake doc definition. * Converts the list of motions to pdfmake doc definition.
@ -111,7 +118,7 @@ export class MotionPdfCatalogService {
*/ */
private createToc(motions: ViewMotion[], sorting?: string): object { private createToc(motions: ViewMotion[], sorting?: string): object {
const toc = []; const toc = [];
const categories: ViewCategory[] = this.getUniqueCategories(motions); const categories = this.categoryObserver.value;
// Create the toc title // Create the toc title
const tocTitle = { const tocTitle = {
@ -129,15 +136,13 @@ export class MotionPdfCatalogService {
if (categories && categories.length) { if (categories && categories.length) {
const catTocBody = []; const catTocBody = [];
for (const category of categories.sort((a, b) => a.weight - b.weight)) { for (const category of categories.sort((a, b) => a.weight - b.weight)) {
// push the name of the category
// make a table for correct alignment
catTocBody.push({ catTocBody.push({
table: { table: {
body: [ body: [
[ [
{ {
text: category.prefixedNameWithParents, text: category.getTitle(),
style: 'tocCategoryTitle' style: !!category.parent ? 'tocSubcategoryTitle' : 'tocCategoryTitle'
} }
] ]
] ]
@ -145,23 +150,31 @@ export class MotionPdfCatalogService {
layout: exportSubmitterRecommendation ? 'lightHorizontalLines' : 'noBorders' layout: exportSubmitterRecommendation ? 'lightHorizontalLines' : 'noBorders'
}); });
const tocBody = []; // find out if the category has any motions
for (const motion of motions.filter(motionIn => category === motionIn.category)) { const motionToCurrentCat = motions.filter(motionIn => category === motionIn.category);
if (exportSubmitterRecommendation) {
tocBody.push(this.appendSubmittersAndRecommendation(motion, StyleType.CATEGORY_SECTION));
} else {
tocBody.push(
this.pdfService.createTocLine(
`${motion.identifier ? motion.identifier : ''}`,
motion.title,
`${motion.id}`,
StyleType.CATEGORY_SECTION
)
);
}
}
catTocBody.push(this.pdfService.createTocTableDef(tocBody, StyleType.CATEGORY_SECTION, layout, header)); if (motionToCurrentCat && motionToCurrentCat.length) {
const tocBody = [];
for (const motion of motionToCurrentCat) {
if (exportSubmitterRecommendation) {
tocBody.push(this.appendSubmittersAndRecommendation(motion, StyleType.CATEGORY_SECTION));
} else {
tocBody.push(
this.pdfService.createTocLine(
`${motion.identifier ? motion.identifier : ''}`,
motion.title,
`${motion.id}`,
StyleType.CATEGORY_SECTION
)
);
}
}
catTocBody.push(
this.pdfService.createTocTableDef(tocBody, StyleType.CATEGORY_SECTION, layout, header)
);
}
} }
// handle those without category // handle those without category
@ -223,28 +236,6 @@ export class MotionPdfCatalogService {
]; ];
} }
/**
* Extract the used categories from the given motion list.
*
* @param motions the list of motions
* @returns Unique list of categories
*/
private getUniqueCategories(motions: ViewMotion[]): ViewCategory[] {
const categories: ViewCategory[] = motions
// remove motions without category
.filter(motion => !!motion.category)
// map motions their categories
.map(motion => motion.category)
// remove redundancies
.filter(
(category, index, self) =>
index ===
self.findIndex(compare => compare.prefix === category.prefix && compare.name === category.name)
);
return categories;
}
/** /**
* Creates lines for the `Table of contents` containing submitters and recommendation. * Creates lines for the `Table of contents` containing submitters and recommendation.
* *