aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store/galleryStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/store/galleryStore.ts')
-rw-r--r--viewer/src/store/galleryStore.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index c875837..ca36a32 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -22,6 +22,7 @@ export default class GalleryStore extends VuexModule {
22 22
23 // --- 23 // ---
24 24
25 // Fetches the gallery's JSON metadata
25 @action async fetchGalleryItems(url: string) { 26 @action async fetchGalleryItems(url: string) {
26 fetch(url) 27 fetch(url)
27 .then(response => response.json()) 28 .then(response => response.json())
@@ -29,14 +30,18 @@ export default class GalleryStore extends VuexModule {
29 .then(this.indexTags); 30 .then(this.indexTags);
30 } 31 }
31 32
33 // Indexes the gallery
32 @action async indexTags() { 34 @action async indexTags() {
33 let index = {}; 35 let index = {};
34 if (this.galleryItemsRoot) 36 if (this.galleryItemsRoot)
35 GalleryStore.pushTagsForItem(index, this.galleryItemsRoot); 37 GalleryStore.pushTagsForItem(index, this.galleryItemsRoot);
36 console.log(index); 38 console.log("Index: ", index);
37 this.setTags(index); 39 this.setTags(index);
38 } 40 }
39 41
42 // ---
43
44 // Pushes all tags for a root item (and its children) to the index
40 private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) { 45 private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) {
41 console.log("IndexingTagsFor: ", item.path); 46 console.log("IndexingTagsFor: ", item.path);
42 for (const tag of item.tags) { 47 for (const tag of item.tags) {
@@ -44,7 +49,7 @@ export default class GalleryStore extends VuexModule {
44 let lastPart: string | null = null; 49 let lastPart: string | null = null;
45 for (const part of parts) { 50 for (const part of parts) {
46 if (!index[part]) index[part] = { tag: part, items: [], children: {} }; 51 if (!index[part]) index[part] = { tag: part, items: [], children: {} };
47 index[part].items.push(item); 52 if (!index[part].items.includes(item)) index[part].items.push(item);
48 if (lastPart) index[lastPart].children[part] = index[part]; 53 if (lastPart) index[lastPart].children[part] = index[part];
49 lastPart = part; 54 lastPart = part;
50 } 55 }
@@ -52,4 +57,16 @@ export default class GalleryStore extends VuexModule {
52 if (item.properties.type === "directory") 57 if (item.properties.type === "directory")
53 item.properties.items.forEach(item => this.pushTagsForItem(index, item)); 58 item.properties.items.forEach(item => this.pushTagsForItem(index, item));
54 } 59 }
60
61 // Searches for an item by path from a root item (navigation)
62 static searchCurrentItem(item: Gallery.Item, path: string): Gallery.Item | null {
63 if (path === item.path) return item;
64 if (item.properties.type === "directory" && path.startsWith(item.path)) {
65 const itemFound = item.properties.items
66 .map(item => this.searchCurrentItem(item, path))
67 .find(item => Boolean(item));
68 return itemFound || null;
69 }
70 return null;
71 }
55} \ No newline at end of file 72} \ No newline at end of file