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">
@ -20,13 +22,10 @@
<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>

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 {
@ -10,6 +11,8 @@ import {
templateUrl: './sprint-form.component.html',
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;
@ -17,9 +20,11 @@ export class SprintFormComponent implements OnInit {
constructor(private backendService: BackendService, private activeModalService: NgbActiveModal) { }
// 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: ''}; //project id missing...
this.sprint = { title: '', startDate: '', endDate: '' };
this.editing = false;
} else {
this.editing = true;
@ -27,6 +32,8 @@ export class SprintFormComponent implements OnInit {
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,9 +49,11 @@ 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);
}