srumboard_frontend/src/app/services/table-component.base.ts

34 lines
974 B
TypeScript

import {sortByNumberAscending, sortByStringAscending} from './sorting.service';
export abstract class TableComponentBase<T> {
public sortBy: string;
public sortDescending = false;
public items: T[] = [];
protected doNumericSort(by: string, key: (ScrumTask) => number) {
if (this.sortBy === by) {
this.sortDescending = !this.sortDescending;
} else {
this.sortBy = by;
}
this.items = sortByNumberAscending(this.items, key);
if (this.sortDescending) {
this.items = this.items.reverse();
}
}
protected doStringSort(by: string, key: (ScrumTask) => string) {
if (this.sortBy === by) {
this.sortDescending = !this.sortDescending;
} else {
this.sortBy = by;
}
this.items = sortByStringAscending(this.items, key);
if (this.sortDescending) {
this.items = this.items.reverse();
}
}
}