diff options
-rw-r--r-- | viewer/src/@types/ItemType.ts | 11 | ||||
-rw-r--r-- | viewer/src/@types/gallery.d.ts | 27 | ||||
-rw-r--r-- | viewer/src/services/indexfactory.ts | 3 | ||||
-rw-r--r-- | viewer/src/services/navigation.ts | 34 | ||||
-rw-r--r-- | viewer/src/views/GalleryNavigation.vue | 26 |
5 files changed, 59 insertions, 42 deletions
diff --git a/viewer/src/@types/ItemType.ts b/viewer/src/@types/ItemType.ts new file mode 100644 index 0000000..31a395b --- /dev/null +++ b/viewer/src/@types/ItemType.ts | |||
@@ -0,0 +1,11 @@ | |||
1 | // TODO: Convert all ambiant types related to LdGallery to modules | ||
2 | |||
3 | export enum ItemType { | ||
4 | OTHER = "other", | ||
5 | PICTURE = "picture", | ||
6 | PLAINTEXT = "plaintext", | ||
7 | PDF = "pdf", | ||
8 | VIDEO = "video", | ||
9 | AUDIO = "audio", | ||
10 | DIRECTORY = "directory", | ||
11 | } | ||
diff --git a/viewer/src/@types/gallery.d.ts b/viewer/src/@types/gallery.d.ts index 2407f98..151ae92 100644 --- a/viewer/src/@types/gallery.d.ts +++ b/viewer/src/@types/gallery.d.ts | |||
@@ -60,44 +60,44 @@ declare namespace Gallery { | |||
60 | path: string, | 60 | path: string, |
61 | thumbnail?: Thumbnail | 61 | thumbnail?: Thumbnail |
62 | properties: OtherProperties | 62 | properties: OtherProperties |
63 | | PictureProperties | 63 | | PictureProperties |
64 | | PlainTextProperties | 64 | | PlainTextProperties |
65 | | PDFProperties | 65 | | PDFProperties |
66 | | VideoProperties | 66 | | VideoProperties |
67 | | AudioProperties | 67 | | AudioProperties |
68 | | DirectoryProperties, | 68 | | DirectoryProperties, |
69 | } | 69 | } |
70 | interface Resolution { | 70 | interface Resolution { |
71 | width: number, | 71 | width: number, |
72 | height: number, | 72 | height: number, |
73 | } | 73 | } |
74 | interface OtherProperties { | 74 | interface OtherProperties { |
75 | type: "other", | 75 | type: import("./ItemType").ItemType.OTHER, |
76 | resource: string | 76 | resource: string |
77 | } | 77 | } |
78 | interface PictureProperties { | 78 | interface PictureProperties { |
79 | type: "picture", | 79 | type: import("./ItemType").ItemType.PICTURE, |
80 | resource: string, | 80 | resource: string, |
81 | resolution: Resolution | 81 | resolution: Resolution |
82 | } | 82 | } |
83 | interface PlainTextProperties { | 83 | interface PlainTextProperties { |
84 | type: "plaintext", | 84 | type: import("./ItemType").ItemType.PLAINTEXT, |
85 | resource: string, | 85 | resource: string, |
86 | } | 86 | } |
87 | interface PDFProperties { | 87 | interface PDFProperties { |
88 | type: "pdf", | 88 | type: import("./ItemType").ItemType.PDF, |
89 | resource: string, | 89 | resource: string, |
90 | } | 90 | } |
91 | interface VideoProperties { | 91 | interface VideoProperties { |
92 | type: "video", | 92 | type: import("./ItemType").ItemType.VIDEO, |
93 | resource: string, | 93 | resource: string, |
94 | } | 94 | } |
95 | interface AudioProperties { | 95 | interface AudioProperties { |
96 | type: "audio", | 96 | type: import("./ItemType").ItemType.AUDIO, |
97 | resource: string, | 97 | resource: string, |
98 | } | 98 | } |
99 | interface DirectoryProperties { | 99 | interface DirectoryProperties { |
100 | type: "directory", | 100 | type: import("./ItemType").ItemType.DIRECTORY, |
101 | items: Item[] | 101 | items: Item[] |
102 | } | 102 | } |
103 | interface Thumbnail { | 103 | interface Thumbnail { |
@@ -105,5 +105,4 @@ declare namespace Gallery { | |||
105 | resolution: Resolution | 105 | resolution: Resolution |
106 | } | 106 | } |
107 | type RawTag = string; | 107 | type RawTag = string; |
108 | type ItemType = "other" | "picture" | "plaintext" | "pdf" | "video" | "audio" | "directory"; | ||
109 | } | 108 | } |
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 | } |
diff --git a/viewer/src/views/GalleryNavigation.vue b/viewer/src/views/GalleryNavigation.vue index 9fc40e1..b141d44 100644 --- a/viewer/src/views/GalleryNavigation.vue +++ b/viewer/src/views/GalleryNavigation.vue | |||
@@ -21,19 +21,26 @@ | |||
21 | <!-- TODO: eliminate intermediate div --> | 21 | <!-- TODO: eliminate intermediate div --> |
22 | <div> | 22 | <div> |
23 | <ld-error v-if="checkType(null)" icon="folder-open" :message="$t('gallery.unknown-resource')" /> | 23 | <ld-error v-if="checkType(null)" icon="folder-open" :message="$t('gallery.unknown-resource')" /> |
24 | <gallery-search v-else-if="checkType('directory') && query.length > 0" :path="path" /> | 24 | <gallery-search v-else-if="checkType(ItemType.DIRECTORY) && query.length > 0" :path="path" /> |
25 | <gallery-directory v-else-if="checkType('directory')" :directory="$galleryStore.currentItem" /> |