Merge pull request #5017 from GabrielInTheWorld/fixElection

Fixes the elections and prepares for future changes
This commit is contained in:
Emanuel Schütze 2019-09-13 10:25:05 +02:00 committed by GitHub
commit 5af32999ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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