import { Component } from '@angular/core'; import { BackendService, ScrumTask, ScrumUserstory, ScrumStatus, ScrumCategory, ScrumSprint, } 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 } 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 sprints: ScrumSprint[] = []; public backlog: ScrumUserstory[] = []; public choosen: ScrumUserstory[] = []; constructor( private backendService: BackendService, private modalService: NgbModal, private route: ActivatedRoute, ) { super(); backendService.getSprints().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.sprints.push(...response.body); } }); backendService.getUserstories().subscribe((response) => { if (response.status > 399) { alert('Fehler'); } else { this.backlog = response.body.filter(u => u.sprintid == null); this.choosen = response.body.filter(u => u.sprintid == this.currentSprint.id); } }); 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); } }); } 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; } 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); const index = this.backlog.indexOf(userstory); this.backlog.splice(index, 1); userstory.sprintid = this.currentSprint.id; this.backendService.putUserstory(userstory).subscribe((response) => { if (response.status > 399) { alert('Fehler'); } }); } public deleteFromSprintBacklog(userstory: ScrumUserstory){ const index = this.choosen.indexOf(userstory); this.choosen.splice(index, 1); this.backlog.push(userstory) userstory.sprintid = null; this.backendService.putUserstory(userstory).subscribe((response) => { if (response.status > 399) { alert('Fehler'); } }); } public get currentSprint(): ScrumSprint { const now = Date.now(); return this.sprints.find(s => Date.parse(s.startDate) < now && Date.parse(s.endDate) > now); } 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; } }