diff --git a/client/src/app/core/repositories/motions/category-repository.service.ts b/client/src/app/core/repositories/motions/category-repository.service.ts index 8041431cc..0eb54a060 100644 --- a/client/src/app/core/repositories/motions/category-repository.service.ts +++ b/client/src/app/core/repositories/motions/category-repository.service.ts @@ -63,7 +63,8 @@ export class CategoryRepositoryService extends BaseRepository implements CategoryTit return this.category.level; } - /** - * TODO: Where is this used? Try to avoid this. - */ - /*public set prefix(prefix: string) { - this._model.prefix = prefix; - }*/ - - /** - * TODO: Where is this used? Try to avoid this. - */ - /*public set name(name: string) { - this._model.name = name; - }*/ - public get prefixedName(): string { return this.prefix ? this.prefix + ' - ' + this.name : this.name; } + /** + * @returns the name with all parents in brackets: " (, )" + */ + public get prefixedNameWithParents(): string { + const parents = this.collectParents(); + let name = this.prefixedName; + if (parents.length) { + name += ' (' + parents.map(parent => parent.prefixedName).join(', ') + ')'; + } + return name; + } + public constructor(category: Category, parent?: ViewCategory) { super(Category.COLLECTIONSTRING, category); this._parent = parent; @@ -79,6 +77,21 @@ export class ViewCategory extends BaseViewModel implements CategoryTit return '/motions/category'; } + /** + * @returns an array with all parents. The ordering is the direct parent + * is in front of the array and the "highest" parent the last entry. Returns + * an empty array if the category does not have any parents. + */ + public collectParents(): ViewCategory[] { + if (this.parent) { + const parents = this.parent.collectParents(); + parents.unshift(this.parent); + return parents; + } else { + return []; + } + } + /** * Updates the local objects if required * @param update diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html index 42dcffb4a..d5a818452 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html @@ -321,7 +321,7 @@ (click)="setCategory(category.id)" > check - {{ category }} + {{ category.prefixedNameWithParents }} - {{ motion.category || '–' }} + {{ motion.category.prefixedNameWithParents || '–' }} - {{ motion.category }} + {{ motion.category.prefixedNameWithParents }} diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html index b9bb92395..f40205d58 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html @@ -104,7 +104,7 @@
- {{ motion.category }} + {{ motion.category.prefixedNameWithParents }}
{{ @@ -153,7 +153,7 @@
- {{ motion.category }} + {{ motion.category.prefixedNameWithParents }}
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 6e0b5fbf2..ad773197b 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 @@ -128,7 +128,7 @@ export class MotionPdfCatalogService { if (categories && categories.length) { const catTocBody = []; - for (const category of categories) { + 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({ @@ -136,7 +136,7 @@ export class MotionPdfCatalogService { body: [ [ { - text: category.prefix ? category.prefix + ' - ' + category.name : category.name, + text: category.prefixedNameWithParents, style: 'tocCategoryTitle' } ] diff --git a/client/src/app/site/motions/services/motion-pdf.service.ts b/client/src/app/site/motions/services/motion-pdf.service.ts index 2f6ccc30d..90f32efa3 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -271,9 +271,7 @@ export class MotionPdfService { style: 'boldText' }, { - text: motion.category.prefix - ? `${motion.category.prefix} - ${motion.category.name}` - : `${motion.category.name}` + text: motion.category.prefixedNameWithParents } ]); }