From 3e598aec7ecf55e1effbcf91c0489118ac639526 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 13 Feb 2019 15:23:38 +0100 Subject: [PATCH] create motion amendment with fulltext or metainfo only --- .../app/core/core-services/http.service.ts | 5 +- .../amendment-create-wizard.component.html | 2 +- .../motion-block-list.component.ts | 2 +- .../motion-detail.component.html | 3 +- .../motion-detail/motion-detail.component.ts | 51 +++++++++++++++++-- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/client/src/app/core/core-services/http.service.ts b/client/src/app/core/core-services/http.service.ts index 1f580f273..690c0898e 100644 --- a/client/src/app/core/core-services/http.service.ts +++ b/client/src/app/core/core-services/http.service.ts @@ -100,8 +100,7 @@ export class HttpService { */ private handleError(e: any): string { let error = this.translate.instant('Error') + ': '; - - // If the rror is a string already, return it. + // If the error is a string already, return it. if (typeof e === 'string') { return error + e; } @@ -117,7 +116,7 @@ export class HttpService { error += this.translate.instant("The server didn't respond."); } else if (typeof e.error === 'object') { if (e.error.detail) { - error += this.processErrorTexts(this.translate.instant(e.error.detail)); + error += this.translate.instant(this.processErrorTexts(e.error.detail)); } else { error = Object.keys(e.error) .map(key => { diff --git a/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.html b/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.html index 71e2cceb0..f7e188448 100644 --- a/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.html +++ b/client/src/app/site/motions/components/amendment-create-wizard/amendment-create-wizard.component.html @@ -11,7 +11,7 @@
  {{ motion.identifier }} {{ contentForm.get('identifier').value }} -

New motion

+

New motion

+

New amendment

diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index a730a7274..3f2baa926 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -73,6 +73,11 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { */ public editMotion = false; + /** + * Determine if the motion is a new (unsent) amendment to another motion + */ + public amendmentEdit = false; + /** * Determine if the motion is new */ @@ -512,10 +517,33 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { this.newMotion = true; this.editMotion = true; // prevent 'undefined' to appear in the ui - const defaultMotion = { + const defaultMotion: Partial = { title: '', - origin: '' + origin: '', + identifier: '' }; + if (this.route.snapshot.queryParams.parent) { + this.amendmentEdit = true; + const parentMotion = this.repo.getViewModel(this.route.snapshot.queryParams.parent); + const defaultTitle = `${this.translate.instant('Amendment to')} ${parentMotion.identifierOrTitle}`; + const mode = this.configService.instant('motions_amendments_text_mode'); + if (mode === 'freestyle' || mode === 'fulltext') { + defaultMotion.title = defaultTitle; + defaultMotion.parent_id = parentMotion.id; + defaultMotion.category_id = parentMotion.category_id; + defaultMotion.motion_block_id = parentMotion.motion_block_id; + this.contentForm.patchValue({ + title: defaultTitle, + category_id: parentMotion.category_id, + motion_block_id: parentMotion.motion_block_id, + parent_id: parentMotion.id + }); + } + if (mode === 'fulltext') { + defaultMotion.text = parentMotion.text; + this.contentForm.patchValue({ text: parentMotion.text }); + } + } this.motion = new ViewCreateMotion(new CreateMotion(defaultMotion)); this.motionCopy = new ViewCreateMotion(new CreateMotion(defaultMotion)); } else { @@ -595,7 +623,9 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { workflow_id: [], origin: [''], statute_amendment: [''], // Internal value for the checkbox, not saved to the model - statute_paragraph_id: [''] + statute_paragraph_id: [''], + motion_block_id: [], + parent_id: [] }); this.updateWorkflowIdForCreateForm(); @@ -684,7 +714,10 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { */ private updateMotionFromForm(): void { const newMotionValues = { ...this.contentForm.value }; - this.updateMotion(newMotionValues, this.motionCopy).then(() => (this.editMotion = false), this.raiseError); + this.updateMotion(newMotionValues, this.motionCopy).then(() => { + this.editMotion = false; + this.amendmentEdit = false; + }, this.raiseError); } private async updateMotion(newMotionValues: Partial, motion: ViewMotion): Promise { @@ -884,7 +917,15 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { * Goes to the amendment creation wizard. Executed via click. */ public createAmendment(): void { - this.router.navigate(['./create-amendment'], { relativeTo: this.route }); + const mode = this.configService.instant('motions_amendments_text_mode'); + if (mode === 'paragraph') { + this.router.navigate(['./create-amendment'], { relativeTo: this.route }); + } else { + this.router.navigate(['./motions/new'], { + relativeTo: this.route.snapshot.params.relativeTo, + queryParams: { parent: this.motion.id || null } + }); + } } /**