mirror of https://github.com/abpframework/abp.git
committed by
GitHub
4 changed files with 35 additions and 23 deletions
@ -0,0 +1,5 @@ |
|||
export interface SortableItem { |
|||
id?: string | number; |
|||
name?: string; |
|||
order?: number; |
|||
} |
|||
@ -1,27 +1,33 @@ |
|||
import { InjectionToken, inject } from '@angular/core'; |
|||
import { SortableItem } from '../models'; |
|||
import { LocalizationService } from '../services'; |
|||
|
|||
export const SORT_COMPARE_FUNC = new InjectionToken< 0 | 1 | -1 >('SORT_COMPARE_FUNC'); |
|||
export const SORT_COMPARE_FUNC = new InjectionToken<(a: SortableItem, b: SortableItem) => number>( |
|||
'SORT_COMPARE_FUNC', |
|||
); |
|||
|
|||
export function compareFuncFactory() { |
|||
const localizationService = inject(LocalizationService) |
|||
const fn = (a,b) => { |
|||
const localizationService = inject(LocalizationService); |
|||
const fn = (a: SortableItem, b: SortableItem) => { |
|||
const aName = localizationService.instant(a.name); |
|||
const bName = localizationService.instant(b.name); |
|||
const aNumber = a.order; |
|||
const bNumber = b.order; |
|||
|
|||
|
|||
if (!Number.isInteger(aNumber)) return 1; |
|||
if (!Number.isInteger(bNumber)) return -1; |
|||
|
|||
if (aNumber > bNumber) return 1 |
|||
if (aNumber < bNumber) return -1 |
|||
|
|||
if ( aName > bName ) return 1; |
|||
if ( aName < bName ) return -1; |
|||
|
|||
return 0 |
|||
} |
|||
|
|||
return fn |
|||
} |
|||
|
|||
if (aNumber > bNumber) return 1; |
|||
if (aNumber < bNumber) return -1; |
|||
|
|||
if (aName > bName) return 1; |
|||
if (aName < bName) return -1; |
|||
|
|||
if (a.id > b.id) return 1; |
|||
if (a.id < b.id) return -1; |
|||
|
|||
return 0; |
|||
}; |
|||
|
|||
return fn; |
|||
} |
|||
|
|||
Loading…
Reference in new issue