55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
|
import { BackendService, ScrumUserstory } from '../services/backend.service';
|
|
import { UserstoryFormComponent } from '../userstory-form/userstory-form.component';
|
|
|
|
@Component({
|
|
selector: 'app-userstory-list',
|
|
templateUrl: './userstory-list.component.html',
|
|
styleUrls: ['./userstory-list.component.css']
|
|
})
|
|
export class UserstoryListComponent implements OnInit {
|
|
|
|
public userstories: ScrumUserstory[] = [];
|
|
|
|
constructor(private backendService: BackendService, private modalService: NgbModal) {
|
|
backendService.getUserstories().subscribe(response => {
|
|
if (response.status > 399) {
|
|
alert('Fehler');
|
|
}
|
|
else {
|
|
this.userstories.push(...response.body);
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
public deleteUserstory(userstory: ScrumUserstory) {
|
|
this.backendService.deleteUserstory(userstory).subscribe(response => {
|
|
if (response.status > 399) {
|
|
alert('Fehler');
|
|
}
|
|
});
|
|
const index = this.userstories.indexOf(userstory);
|
|
if (index !== -1) {
|
|
this.userstories.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
public openUserstoryForm(editUserstory: ScrumUserstory) {
|
|
const modalRef = this.modalService.open(UserstoryFormComponent, {
|
|
backdrop: 'static',
|
|
keyboard: true,
|
|
});
|
|
if (editUserstory === null) {
|
|
modalRef.result.then(result => {
|
|
this.userstories.push(result);
|
|
});
|
|
}
|
|
modalRef.componentInstance.userstory = editUserstory;
|
|
}
|
|
|
|
}
|