Merge pull request #4333 from MaximilianKrambach/amendmentFix2

Create amendment fix
This commit is contained in:
Emanuel Schütze 2019-02-14 20:03:12 +01:00 committed by GitHub
commit 2e385228b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 11 deletions

View File

@ -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 => {

View File

@ -11,7 +11,7 @@
<section
*ngFor="let paragraph of paragraphs"
class="paragraph-row"
[class.active]="selectedParagraph === paragraph.paragraphNo"
[class.active]="contentForm.value.selectedParagraph === paragraph.paragraphNo"
(click)="selectParagraph(paragraph)"
>
<mat-radio-button

View File

@ -94,7 +94,7 @@ export class MotionBlockListComponent extends ListViewBaseComponent<ViewMotionBl
this.createBlockForm = this.formBuilder.group({
title: ['', Validators.required],
agenda_type: ['', Validators.required],
agenda_parent_id: ['']
agenda_parent_id: []
});
}

View File

@ -14,7 +14,8 @@
<span>&nbsp;</span> <span *ngIf="!editMotion">{{ motion.identifier }}</span>
<span *ngIf="editMotion">{{ contentForm.get('identifier').value }}</span>
</h2>
<h2 *ngIf="newMotion" translate>New motion</h2>
<h2 *ngIf="newMotion && !amendmentEdit" translate>New motion</h2>
<h2 *ngIf="amendmentEdit" translate>New amendment</h2>
</div>
<!-- Back and forth buttons -->

View File

@ -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<CreateMotion> = {
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<string>('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>, motion: ViewMotion): Promise<void> {
@ -884,7 +917,15 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* Goes to the amendment creation wizard. Executed via click.
*/
public createAmendment(): void {
const mode = this.configService.instant<string>('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 }
});
}
}
/**