Added comments and cleaned stuff up

This commit is contained in:
Nicolai Ort 2020-07-10 17:25:38 +02:00
parent 33b24cd746
commit 13fda66525

View File

@ -1,17 +1,12 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { import {
BackendService, BackendService,
ScrumTask,
ScrumUserstory, ScrumUserstory,
ScrumStatus, ScrumStatus,
ScrumCategory, ScrumCategory,
ScrumSprint, ScrumSprint,
} from '../../services/backend.service'; } from '../../services/backend.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; 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'; import { SprintFormComponent } from '../sprint-form/sprint-form.component';
@ -20,24 +15,24 @@ import { SprintFormComponent } from '../sprint-form/sprint-form.component';
templateUrl: './backlog.component.html', templateUrl: './backlog.component.html',
styleUrls: ['./backlog.component.css'], styleUrls: ['./backlog.component.css'],
}) })
export class BacklogComponent extends TableComponentBase<
ScrumUserstory
> { export class BacklogComponent{
public tasks: ScrumTask[] = [];
public filterPriority: string | null = null;
public status: ScrumStatus[] = []; public status: ScrumStatus[] = [];
public categories: ScrumCategory[] = []; public categories: ScrumCategory[] = [];
public sprints: ScrumSprint[] = []; public sprints: ScrumSprint[] = [];
public storys: ScrumUserstory[] = []; public storys: ScrumUserstory[] = [];
public selectedSprint: ScrumSprint; public selectedSprint: ScrumSprint;
/**
* Constructor of the class that initialized the communication with the backend
* @param backendService
* @param modalService
*/
constructor( constructor(
private backendService: BackendService, private backendService: BackendService,
private modalService: NgbModal, private modalService: NgbModal,
private route: ActivatedRoute,
) { ) {
super();
backendService.getSprints().subscribe((response) => { backendService.getSprints().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
@ -53,13 +48,6 @@ export class BacklogComponent extends TableComponentBase<
this.storys.push(...response.body); this.storys.push(...response.body);
} }
}); });
backendService.getTasks().subscribe((response) => {
if (response.status > 399) {
alert('Fehler');
} else {
this.tasks.push(...response.body);
}
});
backendService.getAllStatus().subscribe((response) => { backendService.getAllStatus().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
@ -76,46 +64,54 @@ export class BacklogComponent extends TableComponentBase<
}); });
} }
public deleteUserstory(userstory: ScrumUserstory) { /**
this.backendService.deleteUserstory(userstory).subscribe((response) => { * Formats an ISO DateString to a simple date string in the format "DD.MM.YYYY"
if (response.status > 399) { * @param isoFormatString date formatted as an ISO DateString (Date objects get converted implicitly)
alert('Fehler'); */
} public toDateString(isoFormatString) {
}); const date = new Date(isoFormatString);
const index = this.items.indexOf(userstory); return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
if (index !== -1) {
this.items.splice(index, 1);
}
} }
public openUserstoryForm(editUserstory?: ScrumUserstory) { //#region getters
const modalRef = this.modalService.open(UserstoryFormComponent, {
backdrop: 'static', /**
keyboard: true, * Getter that returns an array with all userstories that are in the currently selected sprint.
size: 'lg' * The relation to the sprint is determined by the userstory's sprintid.
}); * If no sprint is selected it just returns an empty array.
if (editUserstory === null) { */
modalRef.result.then((result) => { public get choosen(): ScrumUserstory[]
this.items.push(result); {
}); if(this.selectedSprint === undefined){return null;}
} return this.storys.filter(u => u.sprintid == this.selectedSprint.id);
modalRef.componentInstance.userstory = editUserstory;
} }
public getNumberOfTasks(userstory: ScrumUserstory) { /**
return this.tasks.filter((t) => t.userstoryid === userstory.id).length; * Getter that returns an array with all userstories that aren't in any sprint.
* The relation to no sprint is determined by the userstory's sprintid being undefined.
*/
public get backlog(): ScrumUserstory[]
{
return this.storys.filter(u => u.sprintid === undefined);
} }
getCategoryTitleById(id) { /**
var category = this.categories.find((x) => x.id === id); * Getter that returns the current sprint.
if (!category) { * The current sprint is selected by determining if todays date is between the startDate and the endDate of the sprint.
return 'N/A'; */
} public get currentSprint(): ScrumSprint {
return category.title; const now = Date.now();
return this.sprints.find(s => Date.parse(s.startDate) < now && Date.parse(s.endDate) > now);
} }
// Sprint-Backlog //#endregion getters
//#region backlogFunctions
/**
* Adds a userstory to the currently selected sprint by changing it's sprintid to the current sprint's id
* @param userstory userstory object that shall be added to the selected sprint's backlog
*/
public addToSprintBacklog(userstory: ScrumUserstory) { public addToSprintBacklog(userstory: ScrumUserstory) {
userstory.sprintid = this.selectedSprint.id; userstory.sprintid = this.selectedSprint.id;
this.backendService.putUserstory(userstory).subscribe((response) => { this.backendService.putUserstory(userstory).subscribe((response) => {
@ -125,6 +121,10 @@ export class BacklogComponent extends TableComponentBase<
}); });
} }
/**
* Deletes a userstory from the currently selected sprint by changing it's sprintid to undefined
* @param userstory userstory object that shall be removed from the selected sprint's backlog
*/
public deleteFromSprintBacklog(userstory: ScrumUserstory){ public deleteFromSprintBacklog(userstory: ScrumUserstory){
userstory.sprintid = undefined; userstory.sprintid = undefined;
this.backendService.putUserstory(userstory).subscribe((response) => { this.backendService.putUserstory(userstory).subscribe((response) => {
@ -134,37 +134,23 @@ export class BacklogComponent extends TableComponentBase<
}); });
} }
public get choosen(): ScrumUserstory[] //#endregion backlogFunctions
{
if(this.selectedSprint === undefined){return null;}
return this.storys.filter(u => u.sprintid == this.selectedSprint.id);
}
public get backlog(): ScrumUserstory[] //#region modals
{ /**
return this.storys.filter(u => u.sprintid === undefined); * Opens the SprintForm Modal to let the user create a new sprint.
} * The created sprint get pushed to the database and the local sprints array.
*/
public get currentSprint(): ScrumSprint { public openSprintForm() {
const now = Date.now();
return this.sprints.find(s => Date.parse(s.startDate) < now && Date.parse(s.endDate) > now);
}
public toDateString(isoFormatString) {
const date = new Date(isoFormatString);
return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
}
public openSprintForm(editSprint?: ScrumSprint) {
const modalRef = this.modalService.open(SprintFormComponent, { const modalRef = this.modalService.open(SprintFormComponent, {
backdrop: 'static', backdrop: 'static',
keyboard: true, keyboard: true,
size: "lg",
});
modalRef.result.then(result => {
this.sprints.push(result);
}); });
if (editSprint === null) {
modalRef.result.then(result => {
this.items.push(result);
});
} }
modalRef.componentInstance.sprint = editSprint; //#endregion modals
}
} }