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/navigation.ts') 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/navigation.ts') 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/navigation.ts') 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/navigation.ts') 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/navigation.ts') 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/navigation.ts') 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/navigation.ts | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'viewer/src/services/navigation.ts') 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/navigation.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'viewer/src/services/navigation.ts') 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