srumboard_frontend/src/app/task-form/task-form.component.ts

53 lines
1.7 KiB
TypeScript

import { Component, OnInit, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { BackendService, ScrumTask, Priority } from '../services/backend.service';
@Component({
selector: 'app-task-form',
templateUrl: './task-form.component.html',
styleUrls: ['./task-form.component.css']
})
export class TaskFormComponent implements OnInit {
public title: string;
public content: string;
public prio: Priority;
@Input()
public task: ScrumTask;
private submitted: boolean;
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { }
ngOnInit(): void {
if (this.task !== null && this.task !== undefined) {
this.title = this.task.title;
this.content = this.task.content;
this.prio = this.task.priority;
}
}
onSubmit() {
if (this.task !== null && this.task !== undefined) {
this.task.title = this.title;
this.task.content = this.content;
this.task.priority = this.prio;
this.backendService.putTask(this.task).subscribe(response => {
if (response.status > 399) {
alert('Fehler');
}
});
}
else {
this.task = { title: this.title, content: this.content, priority: this.prio };
this.backendService.postTask(this.task).subscribe(response => {
if (response.status > 399) {
alert('Fehler');
}
});
}
this.submitted = true;
this.activeModalService.close(this.task);
}
}