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 fc81a13dd..5f80e3cd6 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 @@ -322,7 +322,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 }}