sprint form code clean up

This commit is contained in:
test 2020-07-07 12:04:59 +02:00
parent f1ab3156e5
commit 62730d53b6
2 changed files with 29 additions and 21 deletions

View File

@ -1,3 +1,5 @@
<!--Popup form to create a new sprint-->
<div class="card" style="width: 100%;"> <div class="card" style="width: 100%;">
<div class="container"> <div class="container">
<div class="card-body"> <div class="card-body">
@ -9,24 +11,21 @@
<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)]="sprint.title" <input type="text" class="form-control" id="Title" required name="title" [(ngModel)]="sprint.title"
id="titleField"> id="titleField">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="date">Startdatum</label> <label for="date">Startdatum</label>
<input #startDate type="Date" class="form-control" id="Date" required name="date" <input #startDate type="Date" class="form-control" id="Date" required name="date"
[value]="sprint.startDate | date: 'yyyy-MM-dd'" (change)="sprint.startDate=startDate.value" [value]="sprint.startDate | date: 'yyyy-MM-dd'" (change)="sprint.startDate=startDate.value"
id="startDateField"> id="startDateField">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="Date">Enddatum</label> <label for="Date">Enddatum</label>
<input #endDate type="date" class="form-control" id="Date" required name="date" <input #endDate type="date" class="form-control" id="Date" required name="date"
[value]="sprint.endDate | date: 'yyyy-MM-dd'" (change)="sprint.endDate=endDate.value" [value]="sprint.endDate | date: 'yyyy-MM-dd'" (change)="sprint.endDate=endDate.value" id="endDateField">
id="endDateField">
</div> </div>
<div> <div>
<button (click)="onClose()" type="dismiss" class="btn btn-secondary" <button (click)="onClose()" type="dismiss" class="btn btn-secondary" data-dismiss="modal">Abbrechen
data-dismiss="modal">Abbrechen
</button> </button>
<button type="submit" class="btn btn-primary">Sprint starten</button> <button type="submit" class="btn btn-primary">Sprint starten</button>
</div> </div>

View File

@ -1,3 +1,4 @@
// Importing necessary components and interfaces.
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { import {
@ -8,25 +9,31 @@ import {
@Component({ @Component({
selector: 'app-task-form', selector: 'app-task-form',
templateUrl: './sprint-form.component.html', templateUrl: './sprint-form.component.html',
styleUrls: [ './sprint-form.component.css' ] styleUrls: ['./sprint-form.component.css']
}) })
// Class implements the logic for a popup window form to create and modify sprints.
export class SprintFormComponent implements OnInit { export class SprintFormComponent implements OnInit {
@Input() public sprint: ScrumSprint; @Input() public sprint: ScrumSprint;
public editing: Boolean; public editing: Boolean;
public sprintid: string; public sprintid: string;
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) {} constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { }
ngOnInit(): void { // If no sprint exists a new one will be created.
if (this.sprint === null || this.sprint === undefined) { // In other cases the sprint exists and gets modifiable.
this.sprint = { title: '', startDate: '', endDate: ''}; //project id missing... ngOnInit(): void {
this.editing = false; if (this.sprint === null || this.sprint === undefined) {
} else { this.sprint = { title: '', startDate: '', endDate: '' };
this.editing = true; this.editing = false;
} } else {
document.getElementById('titleField').focus(); this.editing = true;
} }
document.getElementById('titleField').focus();
}
// A new created sprint will be saved in backend (POST).
// If a sprint already exists, modifying results an update (PUT) to the backend.
onSubmit() { onSubmit() {
if (this.editing) { if (this.editing) {
this.backendService.putSprint(this.sprint).subscribe((response) => { this.backendService.putSprint(this.sprint).subscribe((response) => {
@ -42,9 +49,11 @@ export class SprintFormComponent implements OnInit {
} }
}); });
} }
// Closes the popup window after submitting/canceling.
this.activeModalService.close(this.sprint); this.activeModalService.close(this.sprint);
} }
// Closes the popup form window (by clicking "close button").
onClose() { onClose() {
this.activeModalService.dismiss(this.sprint); this.activeModalService.dismiss(this.sprint);
} }