Merge pull request #5308 from tsiegleauq/sort-categories-by-weight

Sort motion list by category weight
This commit is contained in:
Emanuel Schütze 2020-04-08 22:35:31 +02:00 committed by GitHub
commit b7566fcc69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,28 +89,19 @@ export class MotionSortListService extends BaseSortListService<ViewMotion> {
} }
/** /**
* 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 itemA The first item to sort
* @param itemB The second 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 * @param ascending If the sorting should be in ascended or descended order
* *
* @returns {number} The result of comparing. * @returns {number} The result of comparing.
*/ */
private categorySortFn(itemA: ViewMotion, itemB: ViewMotion, ascending: boolean, intl: Intl.Collator): number { private categorySortFn(itemA: ViewMotion, itemB: ViewMotion, ascending: boolean): number {
const property = 'category'; if (itemA.category.weight < itemB.category.weight === ascending) {
const subProperty = 'category_weight'; return -1;
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;
} else { } else {
return diff; return 1;
} }
} }
} }