Reduced future code bulge

This commit is contained in:
Nicolai Ort 2020-06-11 15:37:57 +02:00
parent 90368998d4
commit 3c03ee6315
2 changed files with 12 additions and 17 deletions

View File

@ -7,17 +7,17 @@
<form (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="Title">Titel</label>
<input type="text" class="form-control" id="Title" required name="title" [(ngModel)]="title">
<input type="text" class="form-control" id="Title" required name="title" [(ngModel)]="userstory.title">
</div>
<div class="form-group">
<label for="Inhalt">Inhalt</label>
<input type="text" class="form-control" id="Content" required name="content" [(ngModel)]="content">
<input type="text" class="form-control" id="Content" required name="content" [(ngModel)]="userstory.content">
</div>
<div class="form-group">
<label for="Prio">Prio</label>
<select class="form-control" id="prio" required name="prio" [(ngModel)]="prio">
<select class="form-control" id="prio" required name="prio" [(ngModel)]="userstory.priority">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>

View File

@ -9,29 +9,26 @@ import { BackendService, ScrumUserstory, Priority } from '../services/backend.se
})
export class UserstoryFormComponent implements OnInit {
public title: string;
public content: string;
public prio: Priority;
@Input()
public userstory: ScrumUserstory;
private submitted: boolean;
private editing: boolean;
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { }
ngOnInit(): void {
if (this.userstory !== null && this.userstory !== undefined) {
this.title = this.userstory.title;
this.content = this.userstory.content;
this.prio = this.userstory.priority;
if (this.userstory === null || this.userstory === undefined) {
this.userstory = {title: ""};
this.editing = false;
}
else
{
this.editing = true;
}
}
onSubmit() {
if (this.userstory !== null && this.userstory !== undefined) {
this.userstory.title = this.title;
this.userstory.content = this.content;
this.userstory.priority = this.prio;
if (this.editing) {
this.backendService.putUserstory(this.userstory).subscribe(response => {
if (response.status > 399) {
alert('Fehler');
@ -39,14 +36,12 @@ export class UserstoryFormComponent implements OnInit {
});
}
else {
this.userstory = { title: this.title, content: this.content, priority: this.prio };
this.backendService.postUserstory(this.userstory).subscribe(response => {
if (response.status > 399) {
alert('Fehler');
}
});
}
this.submitted = true;
this.activeModalService.close(this.userstory);
}
onClose(){