Made the code for teh taskform a little sleeker

This commit is contained in:
Nicolai Ort 2020-06-11 15:33:56 +02:00
parent 3a1b8b71c7
commit 90368998d4
2 changed files with 10 additions and 6 deletions

View File

@ -17,7 +17,7 @@
<div class="form-group"> <div class="form-group">
<label for="Prio">Prio</label> <label for="Prio">Prio</label>
<select class="form-control" id="prio" required name="priority" [(ngModel)]="task.priority"> <select class="form-control" id="prio" required name="prio" [(ngModel)]="task.priority">
<option value="low">Low</option> <option value="low">Low</option>
<option value="medium">Medium</option> <option value="medium">Medium</option>
<option value="high">High</option> <option value="high">High</option>

View File

@ -11,17 +11,23 @@ export class TaskFormComponent implements OnInit {
@Input() @Input()
public task: ScrumTask; public task: ScrumTask;
private submitted: boolean; public editing: Boolean;
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { } constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { }
ngOnInit(): void { ngOnInit(): void {
if (this.task !== null && this.task !== undefined) { if (this.task === null || this.task === undefined) {
this.task = {title: ""};
this.editing = false;
}
else
{
this.editing = true;
} }
} }
onSubmit() { onSubmit() {
if (this.task !== null && this.task !== undefined) { if (this.editing) {
this.backendService.putTask(this.task).subscribe(response => { this.backendService.putTask(this.task).subscribe(response => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
@ -29,14 +35,12 @@ export class TaskFormComponent implements OnInit {
}); });
} }
else { else {
this.task = { title: this.title, content: this.content, priority: this.prio };
this.backendService.postTask(this.task).subscribe(response => { this.backendService.postTask(this.task).subscribe(response => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} }
}); });
} }
this.submitted = true;
this.activeModalService.close(this.task); this.activeModalService.close(this.task);
} }