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()"> <form (ngSubmit)="onSubmit()">
<div class="form-group"> <div class="form-group">
<label for="Title">Titel</label> <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>
<div class="form-group"> <div class="form-group">
<label for="Inhalt">Inhalt</label> <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>
<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="prio" [(ngModel)]="prio"> <select class="form-control" id="prio" required name="prio" [(ngModel)]="userstory.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

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