diff options
author | zeroinformatique | 2021-07-03 00:48:53 +0200 |
---|---|---|
committer | GitHub | 2021-07-03 00:48:53 +0200 |
commit | b6605e2c4ee73ac8b994624098344db5e44ac07d (patch) | |
tree | 5ed06cc5ecdabe070f6fdb9bc4f9a8a3b435cbe6 /viewer/src/services/itemComparators.ts | |
parent | 08ac32103fb5f8cca1861267dfd07a7c0d2faf62 (diff) | |
parent | 1f0377c1b4c2959c73fe4e368673f057ef369917 (diff) | |
download | ldgallery-b6605e2c4ee73ac8b994624098344db5e44ac07d.tar.gz |
Merge pull request #302 from ldgallery/oz-types-normalization
viewer: types normalization
Diffstat (limited to 'viewer/src/services/itemComparators.ts')
-rw-r--r-- | viewer/src/services/itemComparators.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index bd9accb..aceff79 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts | |||
@@ -16,14 +16,15 @@ | |||
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"; | 19 | import { Item, ItemSortStr } from "@/@types/gallery"; |
20 | import i18n from "@/plugins/i18n"; | 20 | import i18n from "@/plugins/i18n"; |
21 | import { TranslateResult } from "vue-i18n"; | ||
21 | 22 | ||
22 | export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; | 23 | export type ItemComparator = (left: Item, right: Item) => number; |
23 | export type ItemSort = { text: TranslateResult; fn: ItemComparator }; | 24 | export type ItemSort = { text: TranslateResult; fn: ItemComparator }; |
24 | 25 | ||
25 | export default class ItemComparators { | 26 | export default class ItemComparators { |
26 | static readonly ITEM_SORTS: Record<Gallery.ItemSortStr, ItemSort> = { | 27 | static readonly ITEM_SORTS: Record<ItemSortStr, ItemSort> = { |
27 | title_asc: { | 28 | title_asc: { |
28 | text: i18n.t("command.sort.byTitleAsc"), | 29 | text: i18n.t("command.sort.byTitleAsc"), |
29 | fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), | 30 | fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), |
@@ -40,7 +41,7 @@ export default class ItemComparators { | |||
40 | 41 | ||
41 | static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc; | 42 | static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc; |
42 | 43 | ||
43 | static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number { | 44 | static sortByPathAsc(left: Item, right: Item): number { |
44 | return left.path.localeCompare(right.path, undefined, { | 45 | return left.path.localeCompare(right.path, undefined, { |
45 | sensitivity: "base", | 46 | sensitivity: "base", |
46 | ignorePunctuation: true, | 47 | ignorePunctuation: true, |
@@ -48,7 +49,7 @@ export default class ItemComparators { | |||
48 | }); | 49 | }); |
49 | } | 50 | } |
50 | 51 | ||
51 | static sortByTitleAsc(left: Gallery.Item, right: Gallery.Item): number { | 52 | static sortByTitleAsc(left: Item, right: Item): number { |
52 | return left.title.localeCompare(right.title, undefined, { | 53 | return left.title.localeCompare(right.title, undefined, { |
53 | sensitivity: "base", | 54 | sensitivity: "base", |
54 | ignorePunctuation: true, | 55 | ignorePunctuation: true, |
@@ -56,7 +57,7 @@ export default class ItemComparators { | |||
56 | }); | 57 | }); |
57 | } | 58 | } |
58 | 59 | ||
59 | static sortByDateAsc(left: Gallery.Item, right: Gallery.Item): number { | 60 | static sortByDateAsc(left: Item, right: Item): number { |
60 | return left.datetime.localeCompare(right.datetime); // TODO: handle timezones | 61 | return left.datetime.localeCompare(right.datetime); // TODO: handle timezones |
61 | } | 62 | } |
62 | 63 | ||