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="container">
<div class="card-body">
@ -9,28 +11,25 @@
<div class="form-group">
<label for="Title">Titel</label>
<input type="text" class="form-control" id="Title" required name="title" [(ngModel)]="sprint.title"
id="titleField">
id="titleField">
</div>
<div class="form-group">
<label for="date">Startdatum</label>
<input #startDate type="Date" class="form-control" id="Date" required name="date"
[value]="sprint.startDate | date: 'yyyy-MM-dd'" (change)="sprint.startDate=startDate.value"
id="startDateField">
[value]="sprint.startDate | date: 'yyyy-MM-dd'" (change)="sprint.startDate=startDate.value"
id="startDateField">
</div>
<div class="form-group">
<label for="Date">Enddatum</label>
<input #endDate type="date" class="form-control" id="Date" required name="date"
[value]="sprint.endDate | date: 'yyyy-MM-dd'" (change)="sprint.endDate=endDate.value"
id="endDateField">
[value]="sprint.endDate | date: 'yyyy-MM-dd'" (change)="sprint.endDate=endDate.value" id="endDateField">
</div>
<div>
<button (click)="onClose()" type="dismiss" class="btn btn-secondary"
data-dismiss="modal">Abbrechen
<button (click)="onClose()" type="dismiss" class="btn btn-secondary" data-dismiss="modal">Abbrechen
</button>
<button type="submit" class="btn btn-primary">Sprint starten</button>
</div>
</form>
</div>
</div>
</div>
</div>

View File

@ -1,3 +1,4 @@
// Importing necessary components and interfaces.
import { Component, OnInit, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import {
@ -8,25 +9,31 @@ import {
@Component({
selector: 'app-task-form',
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 {
@Input() public sprint: ScrumSprint;
public editing: Boolean;
public sprintid: string;
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) {}
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { }
ngOnInit(): void {
if (this.sprint === null || this.sprint === undefined) {
this.sprint = { title: '', startDate: '', endDate: ''}; //project id missing...
this.editing = false;
} else {
this.editing = true;
}
document.getElementById('titleField').focus();
}
// If no sprint exists a new one will be created.
// In other cases the sprint exists and gets modifiable.
ngOnInit(): void {
if (this.sprint === null || this.sprint === undefined) {
this.sprint = { title: '', startDate: '', endDate: '' };
this.editing = false;
} else {
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() {
if (this.editing) {
this.backendService.putSprint(this.sprint).subscribe((response) => {
@ -42,10 +49,12 @@ export class SprintFormComponent implements OnInit {
}
});
}
// Closes the popup window after submitting/canceling.
this.activeModalService.close(this.sprint);
}
// Closes the popup form window (by clicking "close button").
onClose() {
this.activeModalService.dismiss(this.sprint);
}
}
}