Fixes the elections and prepares for future changes

This commit is contained in:
GabrielMeyer 2019-09-13 09:43:44 +02:00
parent 7d307e5ffe
commit ba2bfdbf04

View File

@ -290,15 +290,11 @@ export class AssignmentDetailComponent extends BaseViewComponent implements OnIn
*/ */
private patchForm(assignment: ViewAssignment): void { private patchForm(assignment: ViewAssignment): void {
this.assignmentCopy = assignment; this.assignmentCopy = assignment;
this.assignmentForm.patchValue({ const contentPatch: { [key: string]: any } = {};
title: assignment.title || '', Object.keys(this.assignmentForm.controls).forEach(control => {
tags_id: assignment.assignment.tags_id || [], contentPatch[control] = assignment[control];
attachments_id: assignment.assignment.attachments_id || [],
phase: assignment.phase, // todo default: 0?
description: assignment.assignment.description || '',
poll_description_default: assignment.assignment.poll_description_default,
open_posts: assignment.assignment.open_posts || 1
}); });
this.assignmentForm.patchValue(contentPatch);
} }
/** /**
@ -387,10 +383,10 @@ export class AssignmentDetailComponent extends BaseViewComponent implements OnIn
} else { } else {
super.setTitle('New election'); super.setTitle('New election');
this.newAssignment = true; this.newAssignment = true;
this.editAssignment = true;
// TODO set defaults? // TODO set defaults?
this.assignment = new ViewAssignment(new Assignment()); this.assignment = new ViewAssignment(new Assignment());
this.patchForm(this.assignment); this.assignmentCopy = new ViewAssignment(new Assignment());
this.setEditMode(true);
} }
} }
@ -444,9 +440,9 @@ export class AssignmentDetailComponent extends BaseViewComponent implements OnIn
} }
public updateAssignmentFromForm(): void { public updateAssignmentFromForm(): void {
this.repo.patch({ ...this.assignmentForm.value }, this.assignmentCopy).then(() => { this.repo
this.editAssignment = false; .patch({ ...this.assignmentForm.value }, this.assignmentCopy)
}, this.raiseError); .then(() => (this.editAssignment = false), this.raiseError);
} }
/** /**