From e34be1261d9219e5b2b92ebe271f609f11d55f63 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sun, 22 Dec 2019 03:50:40 +0100 Subject: vewer: Tags indexing and search input --- viewer/src/store/galleryStore.ts | 41 ++++++++++++++++++++++++++++++++++++---- viewer/src/store/uiStore.ts | 5 ++++- 2 files changed, 41 insertions(+), 5 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 4751561..c875837 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -7,16 +7,49 @@ const VuexModule = createModule({ export default class GalleryStore extends VuexModule { - galleryItems: Gallery.Item | null = null; + galleryItemsRoot: Gallery.Item | null = null; + tags: Tag.Index = {}; - @mutation setGalleryItems(galleryItems: Gallery.Item) { - this.galleryItems = galleryItems; + // --- + + @mutation setGalleryItemsRoot(galleryItemsRoot: Gallery.Item) { + this.galleryItemsRoot = galleryItemsRoot; + } + + @mutation private setTags(tags: Tag.Index) { + this.tags = tags; } + // --- + @action async fetchGalleryItems(url: string) { fetch(url) .then(response => response.json()) - .then(this.setGalleryItems); + .then(this.setGalleryItemsRoot) + .then(this.indexTags); } + @action async indexTags() { + let index = {}; + if (this.galleryItemsRoot) + GalleryStore.pushTagsForItem(index, this.galleryItemsRoot); + console.log(index); + this.setTags(index); + } + + private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) { + console.log("IndexingTagsFor: ", item.path); + for (const tag of item.tags) { + const parts = tag.split('.'); + 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 (lastPart) index[lastPart].children[part] = index[part]; + lastPart = part; + } + } + if (item.properties.type === "directory") + item.properties.items.forEach(item => this.pushTagsForItem(index, item)); + } } \ No newline at end of file diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index c4143a1..e04b507 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -2,12 +2,15 @@ import { createModule, mutation, action } from "vuex-class-component"; const VuexModule = createModule({ namespaced: "uiStore", - strict: true + strict: false }) export default class UIStore extends VuexModule { fullscreen: boolean = false; + currentTags: Tag.Node[] = []; + + // --- @mutation toggleFullscreen() { this.fullscreen = !this.fullscreen; -- cgit v1.2.3