From cf0e8ee2cde96ca4f2ff54f4f1c803f2a920c39a Mon Sep 17 00:00:00 2001 From: Niggl Date: Mon, 29 Jun 2020 16:51:49 +0200 Subject: [PATCH] Added dates to table and date Sorting --- src/app/services/sorting.service.ts | 4 ++++ src/app/services/table-component.base.ts | 15 ++++++++++++++- src/app/sprint-table/sprint-table.component.html | 16 ++++++++++++++++ src/app/sprint-table/sprint-table.component.ts | 8 ++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/app/services/sorting.service.ts b/src/app/services/sorting.service.ts index 9837ffe..59b90e6 100644 --- a/src/app/services/sorting.service.ts +++ b/src/app/services/sorting.service.ts @@ -8,6 +8,10 @@ export function sortByStringAscending(items: T[], key: (T) => string) { return items.sort((a, b) => key(a).localeCompare(key(b))); } +export function sortByDateAscending(items: T[], key: (T) => Date) { + return items.sort((a, b) => key(b) - key(a)); +} + export function getNumberForPriority(priority: Priority): number { switch (priority) { case Priority.High: diff --git a/src/app/services/table-component.base.ts b/src/app/services/table-component.base.ts index d62d356..6206c42 100644 --- a/src/app/services/table-component.base.ts +++ b/src/app/services/table-component.base.ts @@ -1,4 +1,4 @@ -import {sortByNumberAscending, sortByStringAscending} from './sorting.service'; +import {sortByNumberAscending, sortByStringAscending, sortByDateAscending} from './sorting.service'; import {Priority} from './backend.service'; export abstract class TableComponentBase { @@ -32,6 +32,19 @@ export abstract class TableComponentBase { } } + protected doDateSort(by: string, key: (item: T) => Date) { + if (this.sortBy === by) { + this.sortDescending = !this.sortDescending; + } else { + this.sortBy = by; + } + + this.items = sortByDateAscending(this.items, key); + if (this.sortDescending) { + this.items = this.items.reverse(); + } + } + public getAllPriorities(): string[] { return Object.values(Priority); } diff --git a/src/app/sprint-table/sprint-table.component.html b/src/app/sprint-table/sprint-table.component.html index 32e1da9..ad80d25 100644 --- a/src/app/sprint-table/sprint-table.component.html +++ b/src/app/sprint-table/sprint-table.component.html @@ -22,6 +22,20 @@ + + Start + + + + + + + End + + + + + @@ -30,6 +44,8 @@ {{sprint.id}} {{sprint.title}} + {{sprint.startDate | date:'dd.MM.yyyy'}} + {{sprint.endDate | date:'dd.MM.yyyy'}} diff --git a/src/app/sprint-table/sprint-table.component.ts b/src/app/sprint-table/sprint-table.component.ts index aa17134..fc53bfc 100644 --- a/src/app/sprint-table/sprint-table.component.ts +++ b/src/app/sprint-table/sprint-table.component.ts @@ -76,4 +76,12 @@ export class SprintTableComponent extends TableComponentBase { sortByTitle() { this.doStringSort('title', sprint => sprint.title); } + + sortByStartDate() { + this.doDateSort('startDate', sprint => sprint.startDate); + } + + sortByEndDate() { + this.doDateSort('endDate', sprint => sprint.endDate); + } }