diff options
author | Zero~Informatique | 2020-09-12 22:33:37 +0200 |
---|---|---|
committer | G.Fouet | 2020-09-12 23:19:44 +0200 |
commit | b909ec093591b50950c0de54b2005d471ca28116 (patch) | |
tree | 6fe72175022d4e39a44e9270865f611d2e819b05 /viewer/src/services/itemComparators.ts | |
parent | 96ed5e6583a7f03d4ea7fa0512e66fffb656cc6e (diff) | |
download | ldgallery-b909ec093591b50950c0de54b2005d471ca28116.tar.gz |
viewer: make default sort order configurable. code review improvements
github: resolves #239
Diffstat (limited to 'viewer/src/services/itemComparators.ts')
-rw-r--r-- | viewer/src/services/itemComparators.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index c8fedbe..380c66a 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts | |||
@@ -16,10 +16,20 @@ | |||
16 | -- You should have received a copy of the GNU Affero General Public License | 16 | -- You should have received a copy of the GNU Affero General Public License |
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | import { TranslateResult } from "vue-i18n"; | ||
20 | import i18n from "@/plugins/i18n"; | ||
19 | 21 | ||
20 | export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; | 22 | export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; |
23 | export type ItemSort = { name: Gallery.ItemSortStr; text: TranslateResult; fn: ItemComparator }; | ||
21 | 24 | ||
22 | export default class ItemComparators { | 25 | export default class ItemComparators { |
26 | static readonly DEFAULT = ItemComparators.sortByNameAsc; | ||
27 | |||
28 | static readonly ITEM_SORTS: ItemSort[] = [ | ||
29 | { name: "name_asc", text: i18n.t("command.sort.byNameAsc"), fn: ItemComparators.sortByNameAsc }, | ||
30 | { name: "date_desc", text: i18n.t("command.sort.byDateDesc"), fn: ItemComparators.sortByDateDesc }, | ||
31 | ]; | ||
32 | |||
23 | static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { | 33 | static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { |
24 | return left.title.localeCompare(right.title); | 34 | return left.title.localeCompare(right.title); |
25 | } | 35 | } |