From 34bcf9339c86f145442b9edc799416462bf21fc5 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 8 May 2020 19:28:07 +0200 Subject: viewer/GalleryNavigation: revert to static template component dispatching We'll see for dynamic component loading later. --- viewer/src/services/navigation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index fa17990..aa7ef5e 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -40,8 +40,8 @@ export default class Navigation { } // Checks if the type of an item matches - public static checkType(item: Gallery.Item | null, type: Gallery.ItemType): boolean { - return item?.properties.type === type ?? false; + public static checkType(item: Gallery.Item | null, type: Gallery.ItemType | null): boolean { + return item?.properties.type === type; } public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { -- cgit v1.2.3 From 0e2a0e0ff6fd4818eea1be5bc139d99642e5daef Mon Sep 17 00:00:00 2001 From: Notkea Date: Sun, 10 May 2020 15:12:18 +0200 Subject: viewer/navigation: fix undefined check item? may return undefined, and undefined === null returns false. Co-authored-by: OzoneGrif --- viewer/src/services/navigation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index aa7ef5e..1869702 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -41,7 +41,7 @@ export default class Navigation { // Checks if the type of an item matches public static checkType(item: Gallery.Item | null, type: Gallery.ItemType | null): boolean { - return item?.properties.type === type; + return (item?.properties.type ?? null) === type; } public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { -- cgit v1.2.3 From acffcad3f554be95ff728fb84df96d26094d0cc5 Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 13 May 2020 00:43:40 +0200 Subject: viewer: use different icon for plain text files --- viewer/src/services/navigation.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index 1869702..4d3b376 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -70,6 +70,8 @@ export default class Navigation { switch (item.properties.type) { case "picture": return "image"; + case "plaintext": + return "file-alt"; case "directory": return "folder"; case "other": -- cgit v1.2.3 From 185b84fbed180e4d2da7d4cc2ee91a3481f47406 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 18 May 2020 20:05:32 +0200 Subject: viewer: add icon for pdf files --- viewer/src/services/navigation.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index 4d3b376..7d1ae50 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -72,6 +72,8 @@ export default class Navigation { return "image"; case "plaintext": return "file-alt"; + case "pdf": + return "file-pdf"; case "directory": return "folder"; case "other": -- cgit v1.2.3 From a2e06f0a217b12d92cecdad77c20de88037f9912 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 19 May 2020 21:05:28 +0200 Subject: viewer/navigation: factorise item file name extraction --- viewer/src/services/navigation.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index 7d1ae50..f96904d 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -81,4 +81,11 @@ export default class Navigation { return "file"; } } + + // Get the file name of an item, without its cache timestamp + public static getFileName(item: Gallery.Item): string { + if (item.properties.type === "directory") return item.title; + const timeStamped = item.properties.resource.split("/").pop() ?? ""; + return timeStamped.split("?")[0]; + } } -- cgit v1.2.3 From 932d6449094920d7ca10f76eeaac58e142d2763b Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 19 May 2020 21:09:58 +0200 Subject: viewer: add audio and video icons --- viewer/src/services/navigation.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index f96904d..068d081 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -74,6 +74,10 @@ export default class Navigation { return "file-alt"; case "pdf": return "file-pdf"; + case "video": + return "file-video"; + case "audio": + return "file-audio"; case "directory": return "folder"; case "other": -- cgit v1.2.3 From 74c1c5e34787ac57299c8cbd874e9dcc56da406d Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 22 May 2020 04:14:48 +0200 Subject: viewer: Enumerated item types --- viewer/src/services/indexfactory.ts | 3 ++- viewer/src/services/navigation.ts | 34 +++++++++++++++------------------- 2 files changed, 17 insertions(+), 20 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index e402185..00abc05 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts @@ -18,6 +18,7 @@ */ import { Operation } from "@/@types/Operation"; +import { ItemType } from "@/@types/ItemType"; import Navigation from "@/services/navigation"; export default class IndexFactory { @@ -30,7 +31,7 @@ export default class IndexFactory { // Pushes all tags for a root item (and its children) to the index private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void { - if (item.properties.type === "directory") { + if (item.properties.type === ItemType.DIRECTORY) { item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); return; // Directories are not indexed } diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index 068d081..a7e752c 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -17,12 +17,14 @@ -- along with this program. If not, see . */ +import { ItemType } from "@/@types/ItemType"; + export default class Navigation { // Searches for an item by path from a root item (navigation) public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] { if (path === root.path) return [root]; - if (root.properties.type === "directory" && path.startsWith(root.path)) { + if (root.properties.type === ItemType.DIRECTORY && path.startsWith(root.path)) { const itemChain = root.properties.items .map(item => this.searchCurrentItemPath(item, path)) .find(itemChain => itemChain.length > 0); @@ -40,14 +42,14 @@ export default class Navigation { } // Checks if the type of an item matches - public static checkType(item: Gallery.Item | null, type: Gallery.ItemType | null): boolean { + public static checkType(item: Gallery.Item | null, type: ItemType | null): boolean { return (item?.properties.type ?? null) === type; } public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { for (let idx = itemPath.length - 1; idx >= 0; idx--) { const item = itemPath[idx]; - if (Navigation.checkType(item, "directory")) return item as Gallery.Directory; + if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as Gallery.Directory; } throw new Error("No directory found"); } @@ -56,11 +58,11 @@ export default class Navigation { public static directoriesFirst(items: Gallery.Item[]) { return [ ...items - .filter(child => Navigation.checkType(child, "directory")) + .filter(child => Navigation.checkType(child, ItemType.DIRECTORY)) .sort((a, b) => a.title.localeCompare(b.title)), ...items - .filter(child => !Navigation.checkType(child, "directory")), + .filter(child => !Navigation.checkType(child, ItemType.DIRECTORY)), ]; } @@ -68,19 +70,13 @@ export default class Navigation { public static getIcon(item: Gallery.Item): string { if (item.path.length <= 1) return "home"; switch (item.properties.type) { - case "picture": - return "image"; - case "plaintext": - return "file-alt"; - case "pdf": - return "file-pdf"; - case "video": - return "file-video"; - case "audio": - return "file-audio"; - case "directory": - return "folder"; - case "other": + case ItemType.PICTURE: return "image"; + case ItemType.PLAINTEXT: return "file-alt"; + case ItemType.PDF: return "file-pdf"; + case ItemType.VIDEO: return "file-video"; + case ItemType.AUDIO: return "file-audio"; + case ItemType.DIRECTORY: return "folder"; + case ItemType.OTHER: default: return "file"; } @@ -88,7 +84,7 @@ export default class Navigation { // Get the file name of an item, without its cache timestamp public static getFileName(item: Gallery.Item): string { - if (item.properties.type === "directory") return item.title; + if (item.properties.type === ItemType.DIRECTORY) return item.title; const timeStamped = item.properties.resource.split("/").pop() ?? ""; return timeStamped.split("?")[0]; } -- cgit v1.2.3 From 170d7a61f720ece9dc4b347b19f5a8213f1d8984 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 20 Jun 2020 16:50:49 +0200 Subject: viewer: prettier formatting based on eslint-prettier plugin --- viewer/src/services/dragscrollclickfix.ts | 3 +-- viewer/src/services/indexfactory.ts | 21 ++++++++++++++++----- viewer/src/services/indexsearch.ts | 1 - viewer/src/services/ldzoom.ts | 6 ++++-- viewer/src/services/navigation.ts | 24 +++++++++++------------- 5 files changed, 32 insertions(+), 23 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/dragscrollclickfix.ts b/viewer/src/services/dragscrollclickfix.ts index 38eb106..7125510 100644 --- a/viewer/src/services/dragscrollclickfix.ts +++ b/viewer/src/services/dragscrollclickfix.ts @@ -19,7 +19,6 @@ // https://github.com/donmbelembe/vue-dragscroll/issues/61 export default class DragScrollClickFix { - readonly DRAG_DELAY = 250; // This is the minimal delay to consider a click to be a drag, mostly usefull for touch devices timer: NodeJS.Timeout | null = null; @@ -39,7 +38,7 @@ export default class DragScrollClickFix { clearTimeout(this.timer); this.timer = null; } - setTimeout(() => this.dragging = false); + setTimeout(() => (this.dragging = false)); } onClickCapture(e: MouseEvent) { diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index 00abc05..c4b6d51 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts @@ -22,7 +22,6 @@ import { ItemType } from "@/@types/ItemType"; import Navigation from "@/services/navigation"; export default class IndexFactory { - public static generateTags(root: Gallery.Item | null): Tag.Index { let tagsIndex: Tag.Index = {}; if (root) IndexFactory.pushTagsForItem(tagsIndex, root); @@ -51,7 +50,15 @@ export default class IndexFactory { } private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node { - if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, childPart: !rootPart, items: [], children: {} }; + if (!index) + index = { + tag: part, + tagfiltered: Navigation.normalize(part), + rootPart, + childPart: !rootPart, + items: [], + children: {}, + }; else if (rootPart) index.rootPart = true; else index.childPart = true; @@ -61,7 +68,6 @@ export default class IndexFactory { // --- - public static searchTags(tagsIndex: Tag.Index, filter: string, strict: boolean): Tag.Search[] { let search: Tag.Search[] = []; if (tagsIndex && filter) { @@ -106,7 +112,12 @@ export default class IndexFactory { ); } - private static searchTagsFromFilter(tagsIndex: Tag.Index, operation: Operation, filter: string, strict: boolean): Tag.Search[] { + private static searchTagsFromFilter( + tagsIndex: Tag.Index, + operation: Operation, + filter: string, + strict: boolean + ): Tag.Search[] { filter = Navigation.normalize(filter); return Object.values(tagsIndex) .filter(node => IndexFactory.matches(node, filter, strict)) @@ -115,7 +126,7 @@ export default class IndexFactory { private static matches(node: Tag.Node, filter: string, strict: boolean): boolean { if (strict) return node.tagfiltered === filter; - return node.tagfiltered.includes(filter) + return node.tagfiltered.includes(filter); } // --- diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts index a55a829..e6d7eed 100644 --- a/viewer/src/services/indexsearch.ts +++ b/viewer/src/services/indexsearch.ts @@ -20,7 +20,6 @@ import { Operation } from "@/@types/Operation"; export default class IndexSearch { - // Results of the search (by tags) public static search(searchTags: Tag.Search[]): Gallery.Item[] { const byOperation = this.extractTagsByOperation(searchTags); diff --git a/viewer/src/services/ldzoom.ts b/viewer/src/services/ldzoom.ts index ddf57c0..22d4699 100644 --- a/viewer/src/services/ldzoom.ts +++ b/viewer/src/services/ldzoom.ts @@ -33,9 +33,11 @@ export default class LdZoom { scaleFactor: number = 0.0; constructor( - containerElement: HTMLDivElement, imageElement: HTMLImageElement, + containerElement: HTMLDivElement, + imageElement: HTMLImageElement, pictureProperties: Gallery.PictureProperties, - maxScaleFactor: number, scrollZoomSpeed: number + maxScaleFactor: number, + scrollZoomSpeed: number ) { this.containerElement = containerElement; this.imageElement = imageElement; diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index a7e752c..5b0716d 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -20,6 +20,15 @@ import { ItemType } from "@/@types/ItemType"; export default class Navigation { + static readonly ICON_BY_TYPE: Record = { + directory: "folder", + picture: "image", + plaintext: "file-alt", + pdf: "file-pdf", + video: "file-video", + audio: "file-audio", + other: "file", + }; // Searches for an item by path from a root item (navigation) public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] { @@ -61,25 +70,14 @@ export default class Navigation { .filter(child => Navigation.checkType(child, ItemType.DIRECTORY)) .sort((a, b) => a.title.localeCompare(b.title)), - ...items - .filter(child => !Navigation.checkType(child, ItemType.DIRECTORY)), + ...items.filter(child => !Navigation.checkType(child, ItemType.DIRECTORY)), ]; } // Get the icon for an item public static getIcon(item: Gallery.Item): string { if (item.path.length <= 1) return "home"; - switch (item.properties.type) { - case ItemType.PICTURE: return "image"; - case ItemType.PLAINTEXT: return "file-alt"; - case ItemType.PDF: return "file-pdf"; - case ItemType.VIDEO: return "file-video"; - case ItemType.AUDIO: return "file-audio"; - case ItemType.DIRECTORY: return "folder"; - case ItemType.OTHER: - default: - return "file"; - } + return Navigation.ICON_BY_TYPE[item.properties.type]; } // Get the file name of an item, without its cache timestamp -- cgit v1.2.3 From 303929136ca6446f538fcfc80ce26626c726f759 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sun, 28 Jun 2020 14:03:04 +0200 Subject: viewer: dependancies update --- viewer/src/services/indexfactory.ts | 2 +- viewer/src/services/indexsearch.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index c4b6d51..4b28a60 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts @@ -23,7 +23,7 @@ import Navigation from "@/services/navigation"; export default class IndexFactory { public static generateTags(root: Gallery.Item | null): Tag.Index { - let tagsIndex: Tag.Index = {}; + const tagsIndex: Tag.Index = {}; if (root) IndexFactory.pushTagsForItem(tagsIndex, root); return tagsIndex; } diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts index e6d7eed..00f8cfc 100644 --- a/viewer/src/services/indexsearch.ts +++ b/viewer/src/services/indexsearch.ts @@ -29,7 +29,7 @@ export default class IndexSearch { } private static extractTagsByOperation(searchTags: Tag.Search[]): Tag.SearchByOperation { - let byOperation: Tag.SearchByOperation = {}; + const byOperation: Tag.SearchByOperation = {}; Object.values(Operation).forEach( operation => (byOperation[operation] = searchTags.filter(tag => tag.operation === operation)) ); @@ -37,7 +37,7 @@ export default class IndexSearch { } private static extractIntersection(byOperation: Tag.SearchByOperation): Set { - let intersection = new Set(); + const intersection = new Set(); if (byOperation[Operation.INTERSECTION].length > 0) { byOperation[Operation.INTERSECTION] .map(tag => tag.items) @@ -49,7 +49,7 @@ export default class IndexSearch { } private static extractSubstraction(byOperation: Tag.SearchByOperation): Set { - let substraction = new Set(); + const substraction = new Set(); if (byOperation[Operation.SUBSTRACTION].length > 0) { byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); } -- cgit v1.2.3 From e6c2a8d9653ffde924632ca2f260c3a8cddc14ed Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 11 Sep 2020 00:15:04 +0200 Subject: viewer: item display order github: resolves #28 --- viewer/src/services/itemSortFn.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 viewer/src/services/itemSortFn.ts (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemSortFn.ts b/viewer/src/services/itemSortFn.ts new file mode 100644 index 0000000..ec9942c --- /dev/null +++ b/viewer/src/services/itemSortFn.ts @@ -0,0 +1,28 @@ +/* ldgallery - A static generator which turns a collection of tagged +-- pictures into a searchable web gallery. +-- +-- Copyright (C) 2019-2020 Guillaume FOUET +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . +*/ + +export default class ItemSortFn { + static sortByName(left: Gallery.Item, right: Gallery.Item): number { + return left.title.localeCompare(right.title); + } + + static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { + return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones + } +} -- cgit v1.2.3 From f89ed0bd94ea570d9e6533301783d13b13033db0 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 11 Sep 2020 20:10:56 +0200 Subject: viewer: PR #238 code review changes --- viewer/src/services/itemSortFn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemSortFn.ts b/viewer/src/services/itemSortFn.ts index ec9942c..a7e0883 100644 --- a/viewer/src/services/itemSortFn.ts +++ b/viewer/src/services/itemSortFn.ts @@ -18,7 +18,7 @@ */ export default class ItemSortFn { - static sortByName(left: Gallery.Item, right: Gallery.Item): number { + static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { return left.title.localeCompare(right.title); } -- cgit v1.2.3 From 96ed5e6583a7f03d4ea7fa0512e66fffb656cc6e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 06:34:58 +0200 Subject: viewer: make default sort order configurable github: resolves #239 --- viewer/src/services/itemComparators.ts | 30 ++++++++++++++++++++++++++++++ viewer/src/services/itemSortFn.ts | 28 ---------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 viewer/src/services/itemComparators.ts delete mode 100644 viewer/src/services/itemSortFn.ts (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts new file mode 100644 index 0000000..c8fedbe --- /dev/null +++ b/viewer/src/services/itemComparators.ts @@ -0,0 +1,30 @@ +/* ldgallery - A static generator which turns a collection of tagged +-- pictures into a searchable web gallery. +-- +-- Copyright (C) 2019-2020 Guillaume FOUET +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . +*/ + +export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; + +export default class ItemComparators { + static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { + return left.title.localeCompare(right.title); + } + + static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { + return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones + } +} diff --git a/viewer/src/services/itemSortFn.ts b/viewer/src/services/itemSortFn.ts deleted file mode 100644 index a7e0883..0000000 --- a/viewer/src/services/itemSortFn.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* ldgallery - A static generator which turns a collection of tagged --- pictures into a searchable web gallery. --- --- Copyright (C) 2019-2020 Guillaume FOUET --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU Affero General Public License as --- published by the Free Software Foundation, either version 3 of the --- License, or (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Affero General Public License for more details. --- --- You should have received a copy of the GNU Affero General Public License --- along with this program. If not, see . -*/ - -export default class ItemSortFn { - static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { - return left.title.localeCompare(right.title); - } - - static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { - return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones - } -} -- cgit v1.2.3 From b909ec093591b50950c0de54b2005d471ca28116 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 22:33:37 +0200 Subject: viewer: make default sort order configurable. code review improvements github: resolves #239 --- viewer/src/services/itemComparators.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'viewer/src/services') 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 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . */ +import { TranslateResult } from "vue-i18n"; +import i18n from "@/plugins/i18n"; export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; +export type ItemSort = { name: Gallery.ItemSortStr; text: TranslateResult; fn: ItemComparator }; export default class ItemComparators { + static readonly DEFAULT = ItemComparators.sortByNameAsc; + + static readonly ITEM_SORTS: ItemSort[] = [ + { name: "name_asc", text: i18n.t("command.sort.byNameAsc"), fn: ItemComparators.sortByNameAsc }, + { name: "date_desc", text: i18n.t("command.sort.byDateDesc"), fn: ItemComparators.sortByDateDesc }, + ]; + static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { return left.title.localeCompare(right.title); } -- cgit v1.2.3 From 254858f632bbfd4eb45d0315ed39e0a631e64104 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sun, 13 Sep 2020 10:23:05 +0200 Subject: viewer: natural sort github: resolves #243 --- viewer/src/services/itemComparators.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index 380c66a..6a7c81c 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts @@ -31,7 +31,11 @@ export default class ItemComparators { ]; static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { - return left.title.localeCompare(right.title); + return left.title.localeCompare(right.title, undefined, { + sensitivity: "base", + ignorePunctuation: true, + numeric: true, + }); } static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { -- cgit v1.2.3 From ab97f64575f1b51bacced6ce1bc6bf22e0354615 Mon Sep 17 00:00:00 2001 From: zeroinformatique Date: Thu, 17 Sep 2020 15:51:42 +0200 Subject: viewer: sort by date ascending (#249) * viewer: sort by date ascending * viewer: sort by date ascending--- viewer/src/services/itemComparators.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index 6a7c81c..64ce288 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts @@ -27,7 +27,12 @@ export default class ItemComparators { static readonly ITEM_SORTS: ItemSort[] = [ { name: "name_asc", text: i18n.t("command.sort.byNameAsc"), fn: ItemComparators.sortByNameAsc }, - { name: "date_desc", text: i18n.t("command.sort.byDateDesc"), fn: ItemComparators.sortByDateDesc }, + { name: "date_asc", text: i18n.t("command.sort.byDateAsc"), fn: ItemComparators.sortByDateAsc }, + { + name: "date_desc", + text: i18n.t("command.sort.byDateDesc"), + fn: ItemComparators.reverse(ItemComparators.sortByDateAsc), + }, ]; static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { @@ -38,7 +43,11 @@ export default class ItemComparators { }); } - static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { - return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones + static sortByDateAsc(left: Gallery.Item, right: Gallery.Item): number { + return left.datetime.localeCompare(right.datetime); // TODO: handle timezones + } + + static reverse(fn: ItemComparator): ItemComparator { + return (l, r) => -fn(l, r); } } -- cgit v1.2.3 From d9e51ff55ef494d37c5e23ef8fb79500fa5585c5 Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 19 Sep 2020 22:25:54 +0200 Subject: viewer: rename title sort order To avoid confusion with filenames. --- viewer/src/services/itemComparators.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index 64ce288..e131b8b 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts @@ -23,10 +23,10 @@ export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number export type ItemSort = { name: Gallery.ItemSortStr; text: TranslateResult; fn: ItemComparator }; export default class ItemComparators { - static readonly DEFAULT = ItemComparators.sortByNameAsc; + static readonly DEFAULT = ItemComparators.sortByTitleAsc; static readonly ITEM_SORTS: ItemSort[] = [ - { name: "name_asc", text: i18n.t("command.sort.byNameAsc"), fn: ItemComparators.sortByNameAsc }, + { name: "title_asc", text: i18n.t("command.sort.byTitleAsc"), fn: ItemComparators.sortByTitleAsc }, { name: "date_asc", text: i18n.t("command.sort.byDateAsc"), fn: ItemComparators.sortByDateAsc }, { name: "date_desc", @@ -35,7 +35,7 @@ export default class ItemComparators { }, ]; - static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { + static sortByTitleAsc(left: Gallery.Item, right: Gallery.Item): number { return left.title.localeCompare(right.title, undefined, { sensitivity: "base", ignorePunctuation: true, -- cgit v1.2.3 From c108a99e128c02d20930775222f6118a460f80b1 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 24 Sep 2020 22:18:44 +0200 Subject: viewer/services/itemComparators: make the orders linear By using the item path as a tie-breaker. GitHub: closes #255 --- viewer/src/services/itemComparators.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index e131b8b..ab1036d 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts @@ -23,18 +23,34 @@ export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number export type ItemSort = { name: Gallery.ItemSortStr; text: TranslateResult; fn: ItemComparator }; export default class ItemComparators { - static readonly DEFAULT = ItemComparators.sortByTitleAsc; - static readonly ITEM_SORTS: ItemSort[] = [ - { name: "title_asc", text: i18n.t("command.sort.byTitleAsc"), fn: ItemComparators.sortByTitleAsc }, - { name: "date_asc", text: i18n.t("command.sort.byDateAsc"), fn: ItemComparators.sortByDateAsc }, + { + name: "title_asc", + text: i18n.t("command.sort.byTitleAsc"), + fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), + }, + { + name: "date_asc", + text: i18n.t("command.sort.byDateAsc"), + fn: ItemComparators.chain(ItemComparators.sortByDateAsc, ItemComparators.sortByPathAsc), + }, { name: "date_desc", text: i18n.t("command.sort.byDateDesc"), - fn: ItemComparators.reverse(ItemComparators.sortByDateAsc), + fn: ItemComparators.reverse(ItemComparators.chain(ItemComparators.sortByDateAsc, ItemComparators.sortByPathAsc)), }, ]; + static readonly DEFAULT = ItemComparators.ITEM_SORTS[0].fn; + + static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number { + return left.path.localeCompare(right.path, undefined, { + sensitivity: "base", + ignorePunctuation: true, + numeric: true, + }); + } + static sortByTitleAsc(left: Gallery.Item, right: Gallery.Item): number { return left.title.localeCompare(right.title, undefined, { sensitivity: "base", @@ -50,4 +66,11 @@ export default class ItemComparators { static reverse(fn: ItemComparator): ItemComparator { return (l, r) => -fn(l, r); } + + static chain(primary: ItemComparator, tieBreaker: ItemComparator): ItemComparator { + return (l, r) => { + const primaryComparison = primary(l, r); + return primaryComparison !== 0 ? primaryComparison : tieBreaker(l, r); + }; + } } -- cgit v1.2.3 From 25a9af7212d757a53258990668620157c8ebe2e5 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 25 Sep 2020 09:22:44 +0200 Subject: viewer/services/itemComparators: set default item sort order to date_asc It's the most reasonable default that doesn't break the order of sequence of photos. --- viewer/src/services/itemComparators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index ab1036d..82757ca 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts @@ -41,7 +41,7 @@ export default class ItemComparators { }, ]; - static readonly DEFAULT = ItemComparators.ITEM_SORTS[0].fn; + static readonly DEFAULT = ItemComparators.ITEM_SORTS[1].fn; static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number { return left.path.localeCompare(right.path, undefined, { -- cgit v1.2.3 From 26210d495aed813baac1095b5c7a7c7879d2d206 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 25 Sep 2020 10:42:33 +0200 Subject: viewer: refactor how the available sorts are stored github: resolves #259 --- viewer/src/services/itemComparators.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index 82757ca..bd9accb 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts @@ -20,28 +20,25 @@ import { TranslateResult } from "vue-i18n"; import i18n from "@/plugins/i18n"; export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; -export type ItemSort = { name: Gallery.ItemSortStr; text: TranslateResult; fn: ItemComparator }; +export type ItemSort = { text: TranslateResult; fn: ItemComparator }; export default class ItemComparators { - static readonly ITEM_SORTS: ItemSort[] = [ - { - name: "title_asc", + static readonly ITEM_SORTS: Record = { + title_asc: { text: i18n.t("command.sort.byTitleAsc"), fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), }, - { - name: "date_asc", + date_asc: { text: i18n.t("command.sort.byDateAsc"), fn: ItemComparators.chain(ItemComparators.sortByDateAsc, ItemComparators.sortByPathAsc), }, - { - name: "date_desc", + date_desc: { text: i18n.t("command.sort.byDateDesc"), fn: ItemComparators.reverse(ItemComparators.chain(ItemComparators.sortByDateAsc, ItemComparators.sortByPathAsc)), }, - ]; + }; - static readonly DEFAULT = ItemComparators.ITEM_SORTS[1].fn; + static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc; static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number { return left.path.localeCompare(right.path, undefined, { -- cgit v1.2.3