/** * Importing necessary components and interfaces. * */ import { Component, OnInit, Input } from '@angular/core'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { BackendService, ScrumSprint } from '../../../services/backend.service'; @Component({ selector: 'app-task-form', 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; public sprintId: string; 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: '' }; this.editing = false; } else { this.editing = true; } document.getElementById('titleField').focus(); } /** * A new created sprint will be saved in the backend (POST). * If a sprint already exists, modifiying results an update (PUT) to the backend. */ onSubmit() { if (this.editing) { this.backendService.putSprint(this.sprint).subscribe((response) => { if (response.status > 399) { alert('Fehler'); } }); } else { this.backendService.postSprint(this.sprint).subscribe((response) => { console.log('Sprint gespeichert!'); if (response.status > 399) { alert('Fehler'); } else { // Copy properties returned by the API Object.assign(this.sprint, response.body); } }); } // 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); } }