88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import {Component} from '@angular/core';
|
|
import {BackendService, ScrumSprint} from '../services/backend.service';
|
|
import {TableComponentBase} from '../services/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<ScrumSprint> {
|
|
public filterSprintId: number | null = null;
|
|
public highlightId: number;
|
|
|
|
public get filteredItems() {
|
|
return this.items.filter(sprint =>
|
|
(this.filterSprintId === null || sprint.id === this.filterSprintId)
|
|
);
|
|
}
|
|
|
|
constructor(
|
|
private backendService: BackendService, private modalService: NgbModal,
|
|
private route: ActivatedRoute, private router: Router
|
|
) {
|
|
super();
|
|
|
|
this.applyFilterParameters(route.snapshot.paramMap);
|
|
route.paramMap.subscribe(map => this.applyFilterParameters(map));
|
|
|
|
backendService.getSprints().subscribe(response => {
|
|
if (response.status > 399) {
|
|
alert('Fehler');
|
|
} else {
|
|
this.items.push(...response.body);
|
|
}
|
|
});
|
|
}
|
|
|
|
private applyFilterParameters(params: ParamMap) {
|
|
if (params.has('id')) {
|
|
this.highlightId = parseInt(params.get('id'));
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
sortById() {
|
|
this.doNumericSort('id', sprint => sprint.id);
|
|
}
|
|
|
|
sortByTitle() {
|
|
this.doStringSort('title', sprint => sprint.title);
|
|
}
|
|
|
|
sortByStartDate() {
|
|
this.doDateSort('startDate', sprint => sprint.startDate);
|
|
}
|
|
|
|
sortByEndDate() {
|
|
this.doDateSort('endDate', sprint => sprint.endDate);
|
|
}
|
|
}
|