From 8796d728d9cdea7812a15cd0f25fcf48d4a4b9e7 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 28 Jan 2019 16:48:49 +0100 Subject: [PATCH] category prefix is currently optional --- .../src/app/shared/models/motions/category.ts | 2 +- .../category-list.component.html | 10 ++-------- .../category-list/category-list.component.ts | 19 ++++++++++++++----- .../app/site/motions/models/view-category.ts | 2 +- .../services/motion-pdf-catalog.service.ts | 2 +- .../motions/services/motion-pdf.service.ts | 4 +++- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/client/src/app/shared/models/motions/category.ts b/client/src/app/shared/models/motions/category.ts index aed2a86fb..36f0dcad3 100644 --- a/client/src/app/shared/models/motions/category.ts +++ b/client/src/app/shared/models/motions/category.ts @@ -16,7 +16,7 @@ export class Category extends BaseModel implements Searchable { } public getTitle(): string { - return this.prefix + ' - ' + this.name; + return this.prefix ? this.prefix + ' - ' + this.name : this.name; } /** diff --git a/client/src/app/site/motions/components/category-list/category-list.component.html b/client/src/app/site/motions/components/category-list/category-list.component.html index a980d511e..a9ff1d63e 100644 --- a/client/src/app/site/motions/components/category-list/category-list.component.html +++ b/client/src/app/site/motions/components/category-list/category-list.component.html @@ -14,10 +14,7 @@

- - - Required - + @@ -78,10 +75,7 @@ Edit category:
- - - Required - + diff --git a/client/src/app/site/motions/components/category-list/category-list.component.ts b/client/src/app/site/motions/components/category-list/category-list.component.ts index dc78b02b1..10e585f13 100644 --- a/client/src/app/site/motions/components/category-list/category-list.component.ts +++ b/client/src/app/site/motions/components/category-list/category-list.component.ts @@ -78,12 +78,12 @@ export class CategoryListComponent extends BaseViewComponent implements OnInit { super(titleService, translate, matSnackBar); this.createForm = this.formBuilder.group({ - prefix: ['', Validators.required], + prefix: [''], name: ['', Validators.required] }); this.updateForm = this.formBuilder.group({ - prefix: ['', Validators.required], + prefix: [''], name: ['', Validators.required] }); } @@ -131,7 +131,12 @@ export class CategoryListComponent extends BaseViewComponent implements OnInit { */ public onCreateButton(): void { if (this.createForm.valid) { - this.categoryToCreate.patchValues(this.createForm.value as Category); + const cat: Partial = { name: this.createForm.get('name').value }; + if (this.createForm.get('prefix').value) { + cat.prefix = this.createForm.get('prefix').value; + } + this.categoryToCreate.patchValues(cat); + this.repo.create(this.categoryToCreate).then(() => (this.categoryToCreate = null), this.raiseError); } } @@ -144,7 +149,7 @@ export class CategoryListComponent extends BaseViewComponent implements OnInit { this.editId = viewCategory.id; this.updateForm.reset(); this.updateForm.patchValue({ - prefix: viewCategory.prefix, + prefix: viewCategory.category.prefix, name: viewCategory.name }); } @@ -167,8 +172,12 @@ export class CategoryListComponent extends BaseViewComponent implements OnInit { } if (this.updateForm.valid) { + const cat: Partial = { name: this.updateForm.get('name').value }; + if (this.updateForm.get('prefix').value) { + cat.prefix = this.updateForm.get('prefix').value; + } // wait for the category to update; then the (maybe) changed prefix can be applied to the motions - await this.repo.update(this.updateForm.value as Partial, viewCategory); + await this.repo.update(cat, viewCategory); this.onCancelButton(); if (this.sortSelector) { diff --git a/client/src/app/site/motions/models/view-category.ts b/client/src/app/site/motions/models/view-category.ts index c4feb38ba..728e14a4b 100644 --- a/client/src/app/site/motions/models/view-category.ts +++ b/client/src/app/site/motions/models/view-category.ts @@ -24,7 +24,7 @@ export class ViewCategory extends BaseViewModel { } public get prefix(): string { - return this.category ? this.category.prefix : null; + return this.category && this.category.prefix ? this.category.prefix : null; } public set prefix(pref: string) { 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 d4d3ea887..69d9c64f2 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 @@ -150,7 +150,7 @@ export class MotionPdfCatalogService { body: [ [ { - text: category.prefix + ' - ' + category.name, + text: category.prefix ? category.prefix + ' - ' + category.name : category.name, 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 aa108d030..d48aae026 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -199,7 +199,9 @@ export class MotionPdfService { style: 'boldText' }, { - text: `${motion.category.prefix} - ${motion.category.name}` + text: motion.category.prefix + ? `${motion.category.prefix} - ${motion.category.name}` + : `${motion.category.name}` } ]); }