Fixed prio sort nnot working

This commit is contained in:
Nicolai Ort 2020-07-15 15:04:10 +02:00
parent bffbe6dffa
commit 7d78c14033
2 changed files with 388 additions and 388 deletions

View File

@ -1,198 +1,198 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { import {
BackendService, BackendService,
ScrumTask, ScrumTask,
ScrumStatus, ScrumStatus,
ScrumUser, ScrumUser,
ScrumCategory, ScrumCategory,
} from '../../../services/backend.service'; } from '../../../services/backend.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TaskFormComponent } from '../../task-form/task-form.component'; import { TaskFormComponent } from '../../task-form/task-form.component';
import { TableComponentBase } from '../table-component.base'; import { TableComponentBase } from '../table-component.base';
import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { getNumberForPriority } from '../../../services/sorting.service'; import { getNumberForPriority } from '../../../services/sorting.service';
@Component({ @Component({
selector: 'app-task-table', selector: 'app-task-table',
templateUrl: './task-table.component.html', templateUrl: './task-table.component.html',
styleUrls: ['./task-table.component.css'], styleUrls: ['./task-table.component.css'],
}) })
export class TaskTableComponent extends TableComponentBase<ScrumTask> { export class TaskTableComponent extends TableComponentBase<ScrumTask> {
public filterUserstoryId: number | null = null; public filterUserstoryId: number | null = null;
public filterPriority: string | null = null; public filterPriority: string | null = null;
public status: ScrumStatus[] = []; public status: ScrumStatus[] = [];
public users: ScrumUser[] = []; public users: ScrumUser[] = [];
public categories: ScrumCategory[] = []; public categories: ScrumCategory[] = [];
/** /**
* Constructor that establishes the initial backend communication. * Constructor that establishes the initial backend communication.
* @param backendService backendService object for backend communication * @param backendService backendService object for backend communication
* @param modalService angular modalService to handle modals for the Form popups * @param modalService angular modalService to handle modals for the Form popups
* @param route route object to extract parameters from * @param route route object to extract parameters from
*/ */
constructor( constructor(
private backendService: BackendService, private backendService: BackendService,
private modalService: NgbModal, private modalService: NgbModal,
protected route: ActivatedRoute protected route: ActivatedRoute
) { ) {
super(route); super(route);
backendService.getTasks().subscribe((response) => { backendService.getTasks().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.items.push(...response.body); this.items.push(...response.body);
} }
}); });
backendService.getAllStatus().subscribe((response) => { backendService.getAllStatus().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.status.push(...response.body); this.status.push(...response.body);
} }
}); });
backendService.getUsers().subscribe((response) => { backendService.getUsers().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.users.push(...response.body); this.users.push(...response.body);
} }
}); });
backendService.getCategories().subscribe((response) => { backendService.getCategories().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.categories.push(...response.body); this.categories.push(...response.body);
} }
}); });
} }
//#region getters //#region getters
/** /**
* Returns a filtered list of all tasks that have a selected priority or belong to a certain userstory. * Returns a filtered list of all tasks that have a selected priority or belong to a certain userstory.
* If no pritority or userstory to be filtered for is defined it just returns all tasks. * If no pritority or userstory to be filtered for is defined it just returns all tasks.
*/ */
public get filteredItems() { public get filteredItems() {
return this.items.filter( return this.items.filter(
(task) => (task) =>
(this.filterUserstoryId === null || (this.filterUserstoryId === null ||
task.userstoryId === this.filterUserstoryId) && task.userstoryId === this.filterUserstoryId) &&
(this.filterPriority === null || task.priority === this.filterPriority) (this.filterPriority === null || task.priority.toLowerCase() == this.filterPriority.toLowerCase())
); );
} }
/** /**
* Returns the title of the status that has the provided id. * Returns the title of the status that has the provided id.
* @param id id of the searched status * @param id id of the searched status
*/ */
getStatusTitleById(id) { getStatusTitleById(id) {
var status = this.status.find((x) => x.id === id); var status = this.status.find((x) => x.id === id);
if (!status) { if (!status) {
return 'N/A'; return 'N/A';
} }
return status.title; return status.title;
} }
/** /**
* Returns the name of the iser that has the provided id. * Returns the name of the iser that has the provided id.
* @param id id of the searched user * @param id id of the searched user
*/ */
getUserNameById(id) { getUserNameById(id) {
var user = this.users.find((x) => x.id === id); var user = this.users.find((x) => x.id === id);
if (!user) { if (!user) {
return 'N/A'; return 'N/A';
} }
return user.name; return user.name;
} }
/** /**
* Returns the title of the category that has the provided id. * Returns the title of the category that has the provided id.
* @param id id of the searched category * @param id id of the searched category
*/ */
getCategoryTitleById(id) { getCategoryTitleById(id) {
var category = this.categories.find((x) => x.id === id); var category = this.categories.find((x) => x.id === id);
if (!category) { if (!category) {
return 'N/A'; return 'N/A';
} }
return category.title; return category.title;
} }
//#endregion getters //#endregion getters
//#region taskTableFunctions //#region taskTableFunctions
/** /**
* Deletes a task by calling the delete method via the backendService and removing it from the tabel's items array. * Deletes a task by calling the delete method via the backendService and removing it from the tabel's items array.
* @param task task that will be deleted * @param task task that will be deleted
*/ */
public deleteTask(task: ScrumTask) { public deleteTask(task: ScrumTask) {
this.backendService.deleteTask(task).subscribe((response) => { this.backendService.deleteTask(task).subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} }
}); });
const index = this.items.indexOf(task); const index = this.items.indexOf(task);
if (index !== -1) { if (index !== -1) {
this.items.splice(index, 1); this.items.splice(index, 1);
} }
} }
//#endregion taskTableFunctions //#endregion taskTableFunctions
//#region sorters //#region sorters
/** /**
* Sorts the tabel's items by priority. * Sorts the tabel's items by priority.
*/ */
sortByPrio() { sortByPrio() {
this.doNumericSort('priority', (task) => this.doNumericSort('priority', (task) =>
getNumberForPriority(task.priority) getNumberForPriority(task.priority)
); );
} }
/** /**
* Sorts the tabel's items by userstoryId. * Sorts the tabel's items by userstoryId.
*/ */
sortByTasks() { sortByTasks() {
this.doNumericSort('userstory', (task) => task.userstoryId); this.doNumericSort('userstory', (task) => task.userstoryId);
} }
/** /**
* Sorts the tabel's items by statusId * Sorts the tabel's items by statusId
*/ */
sortByStatus() { sortByStatus() {
this.doNumericSort('statusId', (task) => task.statusId); this.doNumericSort('statusId', (task) => task.statusId);
} }
/** /**
* Sorts the tabel's items by assignedtoid * Sorts the tabel's items by assignedtoid
*/ */
sortByAssigned() { sortByAssigned() {
this.doNumericSort('assignedtoid', (task) => task.assignedtoId); this.doNumericSort('assignedtoid', (task) => task.assignedtoId);
} }
/** /**
* Sorts the tabel's items by categoryId * Sorts the tabel's items by categoryId
*/ */
sortByCategory() { sortByCategory() {
this.doNumericSort('categoryId', (task) => task.categoryId); this.doNumericSort('categoryId', (task) => task.categoryId);
} }
//#endregion sorters //#endregion sorters
//#region modals //#region modals
/** /**
* Opens a TaskForm popup for editing a existing task or creating a new one. * Opens a TaskForm popup for editing a existing task or creating a new one.
* @param editTask optional: task to edit (only needed if a task should be edited, not newly created) * @param editTask optional: task to edit (only needed if a task should be edited, not newly created)
*/ */
public openTaskForm(editTask?: ScrumTask) { public openTaskForm(editTask?: ScrumTask) {
const modalRef = this.modalService.open(TaskFormComponent, { const modalRef = this.modalService.open(TaskFormComponent, {
backdrop: 'static', backdrop: 'static',
keyboard: true, keyboard: true,
size: 'lg', size: 'lg',
}); });
if (editTask == null) { if (editTask == null) {
modalRef.result.then((result) => { modalRef.result.then((result) => {
this.items.push(result); this.items.push(result);
}); });
} }
modalRef.componentInstance.task = editTask; modalRef.componentInstance.task = editTask;
} }
//#endregion modals //#endregion modals
} }

View File

@ -1,190 +1,190 @@
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { import {
BackendService, BackendService,
ScrumTask, ScrumTask,
ScrumUserstory, ScrumUserstory,
ScrumStatus, ScrumStatus,
ScrumCategory, ScrumCategory,
} 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 '../table-component.base'; import { TableComponentBase } from '../table-component.base';
import { getNumberForPriority } from '../../../services/sorting.service'; import { getNumberForPriority } from '../../../services/sorting.service';
import { UserstoryFormComponent } from '../../userstory-form/userstory-form.component'; import { UserstoryFormComponent } from '../../userstory-form/userstory-form.component';
import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { ActivatedRoute, ParamMap, Router } from '@angular/router';
@Component({ @Component({
selector: 'app-userstory-inner-table', selector: 'app-userstory-inner-table',
templateUrl: './userstory-inner-table.component.html', templateUrl: './userstory-inner-table.component.html',
styleUrls: ['./userstory-inner-table.component.css'], styleUrls: ['./userstory-inner-table.component.css'],
}) })
export class UserstoryInnerTableComponent extends TableComponentBase<ScrumUserstory> { export class UserstoryInnerTableComponent extends TableComponentBase<ScrumUserstory> {
public tasks: ScrumTask[] = []; public tasks: ScrumTask[] = [];
public filterPriority: string | null = null; public filterPriority: string | null = null;
public status: ScrumStatus[] = []; public status: ScrumStatus[] = [];
public categories: ScrumCategory[] = []; public categories: ScrumCategory[] = [];
@Input() public items: ScrumUserstory[] = []; @Input() public items: ScrumUserstory[] = [];
/** /**
* Constructor that establishes the initial backend communication. * Constructor that establishes the initial backend communication.
* It also sets the tabel's items according to the "storys" input (needed for the dashboard). * It also sets the tabel's items according to the "storys" input (needed for the dashboard).
* @param backendService backendService object for backend communication * @param backendService backendService object for backend communication
* @param modalService angular modalService to handle modals for the Form popups * @param modalService angular modalService to handle modals for the Form popups
* @param route route object to extract parameters from * @param route route object to extract parameters from
*/ */
constructor( constructor(
private backendService: BackendService, private backendService: BackendService,
private modalService: NgbModal, private modalService: NgbModal,
protected route: ActivatedRoute protected route: ActivatedRoute
) { ) {
super(route); super(route);
backendService.getUserstories().subscribe((response) => { backendService.getUserstories().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.items.push(...response.body); this.items.push(...response.body);
} }
}); });
backendService.getTasks().subscribe((response) => { backendService.getTasks().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.tasks.push(...response.body); 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');
} else { } else {
this.status.push(...response.body); this.status.push(...response.body);
} }
}); });
backendService.getCategories().subscribe((response) => { backendService.getCategories().subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} else { } else {
this.categories.push(...response.body); this.categories.push(...response.body);
} }
}); });
} }
//#region getters //#region getters
/** /**
* Returns a filtered list of all userstories that have a selected priority. * Returns a filtered list of all userstories that have a selected priority.
* If no pritority to be filtered for is defined it just returns all userstories. * If no pritority to be filtered for is defined it just returns all userstories.
*/ */
public get filteredItems() { public get filteredItems() {
if (this.filterPriority == null) { if (this.filterPriority == null) {
return this.items; return this.items;
} }
return this.items.filter((t) => t.priority == this.filterPriority); return this.items.filter((t) => t.priority.toLowerCase() == this.filterPriority.toLowerCase());
} }
/** /**
* Returns the number of related tasks of a given userstory. * Returns the number of related tasks of a given userstory.
* The relation is defined by the userstoryId property of the task object and the id property of the userstory object. * The relation is defined by the userstoryId property of the task object and the id property of the userstory object.
* @param userstory The userstory for which the number of related tasks gets calculated * @param userstory The userstory for which the number of related tasks gets calculated
*/ */
public getNumberOfTasks(userstory: ScrumUserstory) { public getNumberOfTasks(userstory: ScrumUserstory) {
return this.tasks.filter((t) => t.userstoryId === userstory.id).length; return this.tasks.filter((t) => t.userstoryId === userstory.id).length;
} }
/** /**
* Returns the title of the status that has the provided id. * Returns the title of the status that has the provided id.
* @param id id of the searched status * @param id id of the searched status
*/ */
getStatusTitleById(id) { getStatusTitleById(id) {
var status = this.status.find((x) => x.id === id); var status = this.status.find((x) => x.id === id);
if (!status) { if (!status) {
return 'N/A'; return 'N/A';
} }
return status.title; return status.title;
} }
/** /**
* Returns the title of the category that has the provided id. * Returns the title of the category that has the provided id.
* @param id id of the searched category * @param id id of the searched category
*/ */
getCategoryTitleById(id) { getCategoryTitleById(id) {
var category = this.categories.find((x) => x.id === id); var category = this.categories.find((x) => x.id === id);
if (!category) { if (!category) {
return 'N/A'; return 'N/A';
} }
return category.title; return category.title;
} }
//#endregion getters //#endregion getters
//#region userstoryTableFunctions //#region userstoryTableFunctions
/** /**
* Deletes a userstory by calling the delete method via the backendService and removing it from the tabel's items array. * Deletes a userstory by calling the delete method via the backendService and removing it from the tabel's items array.
* @param userstory userstory that will be deleted * @param userstory userstory that will be deleted
*/ */
public deleteUserstory(userstory: ScrumUserstory) { public deleteUserstory(userstory: ScrumUserstory) {
this.backendService.deleteUserstory(userstory).subscribe((response) => { this.backendService.deleteUserstory(userstory).subscribe((response) => {
if (response.status > 399) { if (response.status > 399) {
alert('Fehler'); alert('Fehler');
} }
}); });
const index = this.items.indexOf(userstory); const index = this.items.indexOf(userstory);
if (index !== -1) { if (index !== -1) {
this.items.splice(index, 1); this.items.splice(index, 1);
} }
} }
//#endregion userstoryTableFunctions //#endregion userstoryTableFunctions
//#region sorters //#region sorters
/** /**
* Sorts the tabel's items by priority * Sorts the tabel's items by priority
*/ */
public sortByPrio() { public sortByPrio() {
this.doNumericSort('priority', (us) => getNumberForPriority(us.priority)); this.doNumericSort('priority', (us) => getNumberForPriority(us.priority));
} }
/** /**
* Sorts the tabel's items by amount of related tasks * Sorts the tabel's items by amount of related tasks
*/ */
public sortByTasks() { public sortByTasks() {
this.doNumericSort('tasks', (us) => this.getNumberOfTasks(us)); this.doNumericSort('tasks', (us) => this.getNumberOfTasks(us));
} }
/** /**
* Sorts the tabel's items by statusId * Sorts the tabel's items by statusId
*/ */
public sortByStatus() { public sortByStatus() {
this.doNumericSort('statusId', (us) => us.statusId); this.doNumericSort('statusId', (us) => us.statusId);
} }
/** /**
* Sorts the tabel's items by categoryId * Sorts the tabel's items by categoryId
*/ */
public sortByCategory() { public sortByCategory() {
this.doNumericSort('categoryId', (us) => us.categoryId); this.doNumericSort('categoryId', (us) => us.categoryId);
} }
//#endregion sorters //#endregion sorters
//#region modals //#region modals
/** /**
* Opens a UserstoryForm popup for editing a existing userstory or creating a new one. * Opens a UserstoryForm popup for editing a existing userstory or creating a new one.
* @param editUserstory optional: userstory to edit (only needed if a userstory should be edited, not newly created) * @param editUserstory optional: userstory to edit (only needed if a userstory should be edited, not newly created)
*/ */
public openUserstoryForm(editUserstory?: ScrumUserstory) { public openUserstoryForm(editUserstory?: ScrumUserstory) {
const modalRef = this.modalService.open(UserstoryFormComponent, { const modalRef = this.modalService.open(UserstoryFormComponent, {
backdrop: 'static', backdrop: 'static',
keyboard: true, keyboard: true,
size: 'lg', size: 'lg',
}); });
if (editUserstory == null) { if (editUserstory == null) {
modalRef.result.then((result) => { modalRef.result.then((result) => {
this.items.push(result); this.items.push(result);
}); });
} }
modalRef.componentInstance.userstory = editUserstory; modalRef.componentInstance.userstory = editUserstory;
} }
//#endregion modals //#endregion modals
} }