From dc251fffc2998f1cf4f8e9631928c4b92ac0d90e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sun, 22 Dec 2019 07:40:55 +0100 Subject: viewer: Implemented the search by tags. Pushed the special urls to ENV. --- viewer/src/store/galleryStore.ts | 21 +++++++++++++++++++-- viewer/src/store/uiStore.ts | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'viewer/src/store') 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 { // --- + // Fetches the gallery's JSON metadata @action async fetchGalleryItems(url: string) { fetch(url) .then(response => response.json()) @@ -29,14 +30,18 @@ export default class GalleryStore extends VuexModule { .then(this.indexTags); } + // Indexes the gallery @action async indexTags() { let index = {}; if (this.galleryItemsRoot) GalleryStore.pushTagsForItem(index, this.galleryItemsRoot); - console.log(index); + console.log("Index: ", index); this.setTags(index); } + // --- + + // Pushes all tags for a root item (and its children) to the index private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) { console.log("IndexingTagsFor: ", item.path); for (const tag of item.tags) { @@ -44,7 +49,7 @@ export default class GalleryStore extends VuexModule { let lastPart: string | null = null; for (const part of parts) { if (!index[part]) index[part] = { tag: part, items: [], children: {} }; - index[part].items.push(item); + if (!index[part].items.includes(item)) index[part].items.push(item); if (lastPart) index[lastPart].children[part] = index[part]; lastPart = part; } @@ -52,4 +57,16 @@ export default class GalleryStore extends VuexModule { if (item.properties.type === "directory") item.properties.items.forEach(item => this.pushTagsForItem(index, item)); } + + // Searches for an item by path from a root item (navigation) + static searchCurrentItem(item: Gallery.Item, path: string): Gallery.Item | null { + if (path === item.path) return item; + if (item.properties.type === "directory" && path.startsWith(item.path)) { + const itemFound = item.properties.items + .map(item => this.searchCurrentItem(item, path)) + .find(item => Boolean(item)); + return itemFound || null; + } + return null; + } } \ No newline at end of file diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index e04b507..4a6f487 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -8,11 +8,30 @@ const VuexModule = createModule({ export default class UIStore extends VuexModule { fullscreen: boolean = false; + mode: "navigation" | "search" = "navigation"; currentTags: Tag.Node[] = []; // --- + get isModeSearch() { + return this.mode === "search"; + } + + get isModeNavigation() { + return this.mode === "navigation"; + } + + // --- + @mutation toggleFullscreen() { this.fullscreen = !this.fullscreen; } + + @mutation setModeNavigation() { + this.mode = "navigation"; + } + + @mutation setModeSearch() { + this.mode = "search"; + } } -- cgit v1.2.3