104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import {Component} from '@angular/core';
|
|
import {BackendService, ScrumTask} from '../services/backend.service';
|
|
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
|
import {TaskFormComponent} from '../task-form/task-form.component';
|
|
import {TableComponentBase} from '../services/table-component.base';
|
|
import {ActivatedRoute, ParamMap, Router} from '@angular/router';
|
|
import {getNumberForPriority} from '../services/sorting.service';
|
|
|
|
@Component({
|
|
selector: 'app-userstory-table',
|
|
templateUrl: './task-table.component.html',
|
|
styleUrls: ['./task-table.component.css']
|
|
})
|
|
export class TaskTableComponent extends TableComponentBase<ScrumTask> {
|
|
public filterUserstoryId: number | null = null;
|
|
public filterPriority: string | null = null;
|
|
public highlightId: number;
|
|
|
|
public get filteredItems() {
|
|
return this.items.filter(task =>
|
|
(this.filterUserstoryId === null || task.userstoryid === this.filterUserstoryId)
|
|
&& (this.filterPriority === null || task.priority === this.filterPriority)
|
|
);
|
|
}
|
|
|
|
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.getTasks().subscribe(response => {
|
|
if (response.status > 399) {
|
|
alert('Fehler');
|
|
} else {
|
|
this.items.push(...response.body);
|
|
}
|
|
});
|
|
}
|
|
|
|
private applyFilterParameters(params: ParamMap) {
|
|
if (params.has('userstoryId')) {
|
|
this.filterUserstoryId = parseInt(params.get('userstoryId'));
|
|
} else {
|
|
this.filterUserstoryId = null;
|
|
}
|
|
if (params.has('id')) {
|
|
this.highlightId = parseInt(params.get('id'));
|
|
}
|
|
}
|
|
|
|
public deleteTask(task: ScrumTask) {
|
|
this.backendService.deleteTask(task).subscribe(response => {
|
|
if (response.status > 399) {
|
|
alert('Fehler');
|
|
}
|
|
});
|
|
const index = this.items.indexOf(task);
|
|
if (index !== -1) {
|
|
this.items.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
public openTaskForm(editTask?: ScrumTask) {
|
|
const modalRef = this.modalService.open(TaskFormComponent, {
|
|
backdrop: 'static',
|
|
keyboard: true,
|
|
});
|
|
if (editTask === null) {
|
|
modalRef.result.then(result => {
|
|
this.items.push(result);
|
|
});
|
|
}
|
|
modalRef.componentInstance.task = editTask;
|
|
}
|
|
|
|
sortById() {
|
|
this.doNumericSort('id', task => task.id);
|
|
}
|
|
|
|
sortByTitle() {
|
|
this.doStringSort('title', task => task.title);
|
|
}
|
|
|
|
sortByContent() {
|
|
this.doStringSort('content', task => task.content);
|
|
}
|
|
|
|
sortByPrio() {
|
|
this.doNumericSort('priority', task => getNumberForPriority(task.priority));
|
|
}
|
|
|
|
sortByTasks() {
|
|
this.doNumericSort('userstory', task => task.userstoryid);
|
|
}
|
|
|
|
private findTaskById(id: number): ScrumTask {
|
|
return this.items.find(t => t.id === id);
|
|
}
|
|
}
|