diff options
Diffstat (limited to 'viewer/src/services')
-rw-r--r-- | viewer/src/services/indexfactory.ts | 3 | ||||
-rw-r--r-- | viewer/src/services/navigation.ts | 34 |
2 files changed, 17 insertions, 20 deletions
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 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | import { Operation } from "@/@types/Operation"; | 20 | import { Operation } from "@/@types/Operation"; |
21 | import { ItemType } from "@/@types/ItemType"; | ||
21 | import Navigation from "@/services/navigation"; | 22 | import Navigation from "@/services/navigation"; |
22 | 23 | ||
23 | export default class IndexFactory { | 24 | export default class IndexFactory { |
@@ -30,7 +31,7 @@ export default class IndexFactory { | |||
30 | 31 | ||
31 | // Pushes all tags for a root item (and its children) to the index | 32 | // Pushes all tags for a root item (and its children) to the index |
32 | private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void { | 33 | private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void { |
33 | if (item.properties.type === "directory") { | 34 | if (item.properties.type === ItemType.DIRECTORY) { |
34 | item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); | 35 | item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); |
35 | return; // Directories are not indexed | 36 | return; // Directories are not indexed |
36 | } | 37 | } |
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 @@ | |||
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 | 19 | ||
20 | import { ItemType } from "@/@types/ItemType"; | ||
21 | |||
20 | export default class Navigation { | 22 | export default class Navigation { |
21 | 23 | ||
22 | // Searches for an item by path from a root item (navigation) | 24 | // Searches for an item by path from a root item (navigation) |
23 | public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] { | 25 | public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] { |
24 | if (path === root.path) return [root]; | 26 | if (path === root.path) return [root]; |
25 | if (root.properties.type === "directory" && path.startsWith(root.path)) { | 27 | if (root.properties.type === ItemType.DIRECTORY && path.startsWith(root.path)) { |
26 | const itemChain = root.properties.items | 28 | const itemChain = root.properties.items |
27 | .map(item => this.searchCurrentItemPath(item, path)) | 29 | .map(item => this.searchCurrentItemPath(item, path)) |
28 | .find(itemChain => itemChain.length > 0); | 30 | .find(itemChain => itemChain.length > 0); |
@@ -40,14 +42,14 @@ export default class Navigation { | |||
40 | } | 42 | } |
41 | 43 | ||
42 | // Checks if the type of an item matches | 44 | // Checks if the type of an item matches |
43 | public static checkType(item: Gallery.Item | null, type: Gallery.ItemType | null): boolean { | 45 | public static checkType(item: Gallery.Item | null, type: ItemType | null): boolean { |
44 | return (item?.properties.type ?? null) === type; | 46 | return (item?.properties.type ?? null) === type; |
45 | } | 47 | } |
46 | 48 | ||
47 | public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { | 49 | public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { |
48 | for (let idx = itemPath.length - 1; idx >= 0; idx--) { | 50 | for (let idx = itemPath.length - 1; idx >= 0; idx--) { |
49 | const item = itemPath[idx]; | 51 | const item = itemPath[idx]; |
50 | if (Navigation.checkType(item, "directory")) return item as Gallery.Directory; | 52 | if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as Gallery.Directory; |
51 | } | 53 | } |
52 | throw new Error("No directory found"); | 54 | throw new Error("No directory found"); |
53 | } | 55 | } |
@@ -56,11 +58,11 @@ export default class Navigation { | |||
56 | public static directoriesFirst(items: Gallery.Item[]) { | 58 | public static directoriesFirst(items: Gallery.Item[]) { |
57 | return [ | 59 | return [ |
58 | ...items | 60 | ...items |
59 | .filter(child => Navigation.checkType(child, "directory")) | 61 | .filter(child => Navigation.checkType(child, ItemType.DIRECTORY)) |
60 | .sort((a, b) => a.title.localeCompare(b.title)), | 62 | .sort((a, b) => a.title.localeCompare(b.title)), |
61 | 63 | ||
62 | ...items | 64 | ...items |
63 | .filter(child => !Navigation.checkType(child, "directory")), | 65 | .filter(child => !Navigation.checkType(child, ItemType.DIRECTORY)), |
64 | ]; | 66 | ]; |
65 | } | 67 | } |
66 | 68 | ||
@@ -68,19 +70,13 @@ export default class Navigation { | |||
68 | public static getIcon(item: Gallery.Item): string { | 70 | public static getIcon(item: Gallery.Item): string { |
69 | if (item.path.length <= 1) return "home"; | 71 | if (item.path.length <= 1) return "home"; |
70 | switch (item.properties.type) { | 72 | switch (item.properties.type) { |
71 | case "picture": | 73 | case ItemType.PICTURE: return "image"; |
72 | return "image"; | 74 | case ItemType.PLAINTEXT: return "file-alt"; |
73 | case "plaintext": | 75 | case ItemType.PDF: return "file-pdf"; |
74 | return "file-alt"; | 76 | case ItemType.VIDEO: return "file-video"; |
75 | case "pdf": | 77 | case ItemType.AUDIO: return "file-audio"; |
76 | return "file-pdf"; | 78 | case ItemType.DIRECTORY: return "folder"; |
77 | case "video": | 79 | case ItemType.OTHER: |
78 | return "file-video"; | ||
79 | case "audio": | ||
80 | return "file-audio"; | ||
81 | case "directory": | ||
82 | return "folder"; | ||
83 | case "other": | ||
84 | default: | 80 | default: |
85 | return "file"; | 81 | return "file"; |
86 | } | 82 | } |
@@ -88,7 +84,7 @@ export default class Navigation { | |||
88 | 84 | ||
89 | // Get the file name of an item, without its cache timestamp | 85 | // Get the file name of an item, without its cache timestamp |
90 | public static getFileName(item: Gallery.Item): string { | 86 | public static getFileName(item: Gallery.Item): string { |
91 | if (item.properties.type === "directory") return item.title; | 87 | if (item.properties.type === ItemType.DIRECTORY) return item.title; |
92 | const timeStamped = item.properties.resource.split("/").pop() ?? ""; | 88 | const timeStamped = item.properties.resource.split("/").pop() ?? ""; |
93 | return timeStamped.split("?")[0]; | 89 | return timeStamped.split("?")[0]; |
94 | } | 90 | } |