Added dates to table and date Sorting

This commit is contained in:
2020-06-29 16:51:49 +02:00
parent 5fb7122aa7
commit cf0e8ee2cd
4 changed files with 42 additions and 1 deletions

View File

@@ -8,6 +8,10 @@ export function sortByStringAscending<T>(items: T[], key: (T) => string) {
return items.sort((a, b) => key(a).localeCompare(key(b)));
}
export function sortByDateAscending<T>(items: T[], key: (T) => Date) {
return items.sort((a, b) => <any>key(b) - <any>key(a));
}
export function getNumberForPriority(priority: Priority): number {
switch (priority) {
case Priority.High:

View File

@@ -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<T> {
@@ -32,6 +32,19 @@ export abstract class TableComponentBase<T> {
}
}
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);
}