From cfc09d8cad583a19de02c38c086c4c2f339450e3 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Fri, 28 Jun 2019 13:39:16 +0200 Subject: [PATCH] Add motion PDF TOC subcategories Adjust the motion catalog PDF TOC to indicate Subcategories --- .../core/ui-services/pdf-document.service.ts | 5 ++ .../services/motion-pdf-catalog.service.ts | 89 +++++++++---------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/client/src/app/core/ui-services/pdf-document.service.ts b/client/src/app/core/ui-services/pdf-document.service.ts index a28577c05..ae15850f9 100644 --- a/client/src/app/core/ui-services/pdf-document.service.ts +++ b/client/src/app/core/ui-services/pdf-document.service.ts @@ -532,6 +532,11 @@ export class PdfDocumentService { margin: [0, 0, 0, 4], bold: true }, + tocSubcategoryTitle: { + fontSize: pageSize === 'A5' ? 9 : 10, + margin: [0, 0, 0, 4], + bold: true + }, tocCategorySection: { margin: [0, 0, 0, 10] }, diff --git a/client/src/app/site/motions/services/motion-pdf-catalog.service.ts b/client/src/app/site/motions/services/motion-pdf-catalog.service.ts index ad773197b..e19aac3d9 100644 --- a/client/src/app/site/motions/services/motion-pdf-catalog.service.ts +++ b/client/src/app/site/motions/services/motion-pdf-catalog.service.ts @@ -1,13 +1,15 @@ import { Injectable } from '@angular/core'; +import { BehaviorSubject } from 'rxjs'; import { TranslateService } from '@ngx-translate/core'; -import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion'; -import { MotionPdfService, InfoToExport } from './motion-pdf.service'; +import { CategoryRepositoryService } from 'app/core/repositories/motions/category-repository.service'; import { ConfigService } from 'app/core/ui-services/config.service'; -import { ViewCategory } from '../models/view-category'; -import { PdfError, PdfDocumentService, StyleType, BorderType } from 'app/core/ui-services/pdf-document.service'; +import { MotionPdfService, InfoToExport } from './motion-pdf.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. @@ -21,6 +23,8 @@ import { MotionRepositoryService } from 'app/core/repositories/motions/motion-re providedIn: 'root' }) export class MotionPdfCatalogService { + private categoryObserver: BehaviorSubject; + /** * Constructor * @@ -33,8 +37,11 @@ export class MotionPdfCatalogService { private configService: ConfigService, private motionPdfService: MotionPdfService, 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. @@ -111,7 +118,7 @@ export class MotionPdfCatalogService { */ private createToc(motions: ViewMotion[], sorting?: string): object { const toc = []; - const categories: ViewCategory[] = this.getUniqueCategories(motions); + const categories = this.categoryObserver.value; // Create the toc title const tocTitle = { @@ -129,15 +136,13 @@ export class MotionPdfCatalogService { if (categories && categories.length) { const catTocBody = []; 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({ table: { body: [ [ { - text: category.prefixedNameWithParents, - style: 'tocCategoryTitle' + text: category.getTitle(), + style: !!category.parent ? 'tocSubcategoryTitle' : 'tocCategoryTitle' } ] ] @@ -145,23 +150,31 @@ export class MotionPdfCatalogService { layout: exportSubmitterRecommendation ? 'lightHorizontalLines' : 'noBorders' }); - const tocBody = []; - for (const motion of 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 - ) - ); - } - } + // find out if the category has any motions + const motionToCurrentCat = motions.filter(motionIn => category === motionIn.category); - 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 @@ -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. *