import { Component } from '@angular/core'; import { BackendService, ScrumSprint } from '../../../services/backend.service'; import { TableComponentBase } from '../table-component.base'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { SprintFormComponent } from '../../sprint-form/sprint-form.component'; @Component({ selector: 'app-sprint', templateUrl: './sprint-table.component.html', styleUrls: ['./sprint-table.component.css'], }) export class SprintTableComponent extends TableComponentBase { /** * Constructor that establishes the initial backend communication. * @param backendService backendService object for backend communication * @param modalService angular modalService to handle modals for the Form popups * @param route route object to extract parameters from */ constructor( private backendService: BackendService, private modalService: NgbModal, protected route: ActivatedRoute ) { super(route); backendService.getSprints().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.items.push(...response.body); } }); } //#region getters //#endregion getters //#region sprintTableFunctions /** * Deletes a sprint by calling the delete method via the backendService and removing it from the tabel's items array. * @param sprint sprint that will be deleted */ public deleteSprint(sprint: ScrumSprint) { this.backendService.deleteSprint(sprint).subscribe((response) => { if (response.status > 399) { alert('Fehler'); } }); const index = this.items.indexOf(sprint); if (index !== -1) { this.items.splice(index, 1); } } //#endregion sprintTableFunctions //#region sorters /** * Sorts the tabel's items by startDate */ sortByStartDate() { this.doStringSort('startDate', (sprint) => sprint.startDate); } /** * Sorts the tabel's items by endDate */ sortByEndDate() { this.doStringSort('endDate', (sprint) => sprint.endDate); } //#endregion sorters //#region modals /** * Opens a SprintForm popup for editing a existing sprint or creating a new one. * @param editSprint optional: sprint to edit (only needed if a task should be edited, not newly created) */ public openSprintForm(editSprint?: ScrumSprint) { const modalRef = this.modalService.open(SprintFormComponent, { backdrop: 'static', keyboard: true, size: 'md', }); if (editSprint == null) { modalRef.result.then((result) => { alert("hi"); this.items.push(result); }); } modalRef.componentInstance.sprint = editSprint; } //#endregion modals }