import { Component } from '@angular/core'; import { BackendService, ScrumTask, ScrumUserstory, ScrumStatus, ScrumCategory, ScrumSprint, ScrumUser, } from '../services/backend.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { TableComponentBase } from '../services/table-component.base'; import { getNumberForPriority } from '../services/sorting.service'; import { UserstoryFormComponent } from '../userstory-form/userstory-form.component'; import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { SprintFormComponent } from '../sprint-form/sprint-form.component'; @Component({ selector: 'app-backlog', templateUrl: './backlog.component.html', styleUrls: ['./backlog.component.css'], }) export class BacklogComponent extends TableComponentBase< ScrumUserstory > { public tasks: ScrumTask[] = []; public filterPriority: string | null = null; public status: ScrumStatus[] = []; public categories: ScrumCategory[] = []; public currentSprint: ScrumSprint; public choosen: ScrumUserstory[] = []; constructor( private backendService: BackendService, private modalService: NgbModal, private route: ActivatedRoute, ) { super(); backendService.getUserstories().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.items.push(...response.body); } }); backendService.getTasks().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.tasks.push(...response.body); } }); backendService.getAllStatus().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.status.push(...response.body); } }); backendService.getCategories().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.categories.push(...response.body); } }); this.getCurrentSprint(); } public deleteUserstory(userstory: ScrumUserstory) { this.backendService.deleteUserstory(userstory).subscribe((response) => { if (response.status > 399) { alert('Fehler'); } }); const index = this.items.indexOf(userstory); if (index !== -1) { this.items.splice(index, 1); } } public openUserstoryForm(editUserstory?: ScrumUserstory) { const modalRef = this.modalService.open(UserstoryFormComponent, { backdrop: 'static', keyboard: true, size: 'lg' }); if (editUserstory === null) { modalRef.result.then((result) => { this.items.push(result); }); } modalRef.componentInstance.userstory = editUserstory; } public getNumberOfTasks(userstory: ScrumUserstory) { return this.tasks.filter((t) => t.userstoryid === userstory.id).length; } public sortById() { this.doNumericSort('id', (us) => us.id); } public sortByTitle() { this.doStringSort('title', (us) => us.title); } public sortByPrio() { this.doNumericSort('priority', (us) => getNumberForPriority(us.priority)); } public sortByTasks() { this.doNumericSort('tasks', (us) => this.getNumberOfTasks(us)); } sortByStatus() { this.doNumericSort('statusid', (us) => us.statusid); } sortByCategory() { this.doNumericSort('categoryid', (us) => us.categoryid); } getStatusTitleById(id) { var status = this.status.find((x) => x.id === id); if (!status) { return 'N/A'; } return status.title; } getCategoryTitleById(id) { var category = this.categories.find((x) => x.id === id); if (!category) { return 'N/A'; } return category.title; } // Sprint-Backlog public addToSprintBacklog(userstory: ScrumUserstory) { this.choosen.push(userstory); } public deleteFromSprintBacklog(userstory: ScrumUserstory){ const index = this.choosen.indexOf(userstory); this.choosen.splice(index, 1); } public getCurrentSprint() { this.backendService.getSprints().subscribe((response) => { if (response.status > 399) { } else { var currentDate = new Date(); this.currentSprint = response.body.find(x => x.startDate < currentDate); alert(this.currentSprint); }}); } public openSprintForm(editSprint?: ScrumSprint) { const modalRef = this.modalService.open(SprintFormComponent, { backdrop: 'static', keyboard: true, }); if (editSprint === null) { modalRef.result.then(result => { this.items.push(result); }); } modalRef.componentInstance.sprint = editSprint; } }