From 82c6929a8db6bf0e22840537d1ae29ecf050e0c0 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 8 Apr 2020 18:41:29 +0200 Subject: [PATCH] Sort motion list by category weight Sorts the motion list by the weight of the category rather than by name --- .../services/motion-sort-list.service.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/client/src/app/site/motions/services/motion-sort-list.service.ts b/client/src/app/site/motions/services/motion-sort-list.service.ts index e49fb6136..bf79798ed 100644 --- a/client/src/app/site/motions/services/motion-sort-list.service.ts +++ b/client/src/app/site/motions/services/motion-sort-list.service.ts @@ -89,28 +89,19 @@ export class MotionSortListService extends BaseSortListService { } /** - * Custom function to sort the categories internal by the `category_weight` of the motion. + * Custom function to sort the categories by the `category_weight` of the motion. * * @param itemA The first item to sort * @param itemB The second item to sort - * @param intl The localizer to compare strings * @param ascending If the sorting should be in ascended or descended order * * @returns {number} The result of comparing. */ - private categorySortFn(itemA: ViewMotion, itemB: ViewMotion, ascending: boolean, intl: Intl.Collator): number { - const property = 'category'; - const subProperty = 'category_weight'; - const firstValue = ascending ? itemA[property] : itemB[property]; - const secondValue = ascending ? itemB[property] : itemA[property]; - - const diff = intl.compare(firstValue.toString(), secondValue.toString()); - if (diff === 0) { - const firstSubValue = ascending ? itemA[subProperty] : itemB[subProperty]; - const secondSubValue = ascending ? itemB[subProperty] : itemA[subProperty]; - return firstSubValue > secondSubValue ? 1 : -1; + private categorySortFn(itemA: ViewMotion, itemB: ViewMotion, ascending: boolean): number { + if (itemA.category.weight < itemB.category.weight === ascending) { + return -1; } else { - return diff; + return 1; } } }