Merge pull request #4786 from GabrielInTheWorld/FinnStutzenstein/categoryNameWithParents

Labelling of subcategories
This commit is contained in:
Emanuel Schütze 2019-06-19 08:15:47 +02:00 committed by GitHub
commit c7088a4b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 25 deletions

View File

@ -63,7 +63,8 @@ export class CategoryRepositoryService extends BaseRepository<ViewCategory, Cate
};
protected createViewModel(category: Category): ViewCategory {
return new ViewCategory(category);
const parent = this.viewModelStoreService.get(ViewCategory, category.parent_id);
return new ViewCategory(category, parent);
}
/**

View File

@ -48,24 +48,22 @@ export class ViewCategory extends BaseViewModel<Category> 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: "<Cat> (<CatParent>, <CatParentParent>)"
*/
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<Category> 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

View File

@ -321,7 +321,7 @@
(click)="setCategory(category.id)"
>
<mat-icon *ngIf="motion.category_id === category.id">check</mat-icon>
{{ category }}
{{ category.prefixedNameWithParents }}
</button>
</mat-menu>
<mat-basic-chip
@ -330,14 +330,14 @@
class="grey"
disableRipple
>
{{ motion.category || '' }}
{{ motion.category.prefixedNameWithParents || '' }}
</mat-basic-chip>
<mat-basic-chip
*ngIf="!perms.isAllowed('change_metadata', motion) && motion.category"
class="grey"
disableRipple
>
{{ motion.category }}
{{ motion.category.prefixedNameWithParents }}
</mat-basic-chip>
</div>

View File

@ -104,7 +104,7 @@
<div class="fill">
<div class="innerTable state-column">
<div class="ellipsis-overflow" *ngIf="motion.category">
<os-icon-container icon="device_hub">{{ motion.category }}</os-icon-container>
<os-icon-container icon="device_hub">{{ motion.category.prefixedNameWithParents }}</os-icon-container>
</div>
<div class="ellipsis-overflow spacer-top-5" *ngIf="motion.motion_block">
<os-icon-container icon="widgets">{{
@ -153,7 +153,7 @@
<div class="column-state innerTable">
<!-- Category -->
<div class="ellipsis-overflow" *ngIf="motion.category">
<os-icon-container icon="device_hub">{{ motion.category }}</os-icon-container>
<os-icon-container icon="device_hub">{{ motion.category.prefixedNameWithParents }}</os-icon-container>
</div>
<!-- Motion Block -->

View File

@ -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'
}
]

View File

@ -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
}
]);
}