aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store/galleryStore.ts
diff options
context:
space:
mode:
authorZero~Informatique2019-12-22 03:50:40 +0100
committerZero~Informatique2019-12-22 03:50:40 +0100
commite34be1261d9219e5b2b92ebe271f609f11d55f63 (patch)
treef9bb705d0b7ec819b48ddfd5a318642ca239aff3 /viewer/src/store/galleryStore.ts
parentc2b4c5d144db17ebf2dc9de32ba25cc836831ae2 (diff)
downloadldgallery-e34be1261d9219e5b2b92ebe271f609f11d55f63.tar.gz
vewer: Tags indexing and search input
Diffstat (limited to 'viewer/src/store/galleryStore.ts')
-rw-r--r--viewer/src/store/galleryStore.ts41
1 files changed, 37 insertions, 4 deletions
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({
7 7
8export default class GalleryStore extends VuexModule { 8export default class GalleryStore extends VuexModule {
9 9
10 galleryItems: Gallery.Item | null = null; 10 galleryItemsRoot: Gallery.Item | null = null;
11 tags: Tag.Index = {};
11 12
12 @mutation setGalleryItems(galleryItems: Gallery.Item) { 13 // ---
13 this.galleryItems = galleryItems; 14
15 @mutation setGalleryItemsRoot(galleryItemsRoot: Gallery.Item) {
16 this.galleryItemsRoot = galleryItemsRoot;
17 }
18
19 @mutation private setTags(tags: Tag.Index) {
20 this.tags = tags;
14 } 21 }
15 22
23 // ---
24
16 @action async fetchGalleryItems(url: string) { 25 @action async fetchGalleryItems(url: string) {
17 fetch(url) 26 fetch(url)
18 .then(response => response.json()) 27 .then(response => response.json())
19 .then(this.setGalleryItems); 28 .then(this.setGalleryItemsRoot)
29 .then(this.indexTags);
20 } 30 }
21 31
32 @action async indexTags() {
33 let index = {};
34 if (this.galleryItemsRoot)
35 GalleryStore.pushTagsForItem(index, this.galleryItemsRoot);
36 console.log(index);
37 this.setTags(index);
38 }
39
40 private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) {
41 console.log("IndexingTagsFor: ", item.path);
42 for (const tag of item.tags) {
43 const parts = tag.split('.');
44 let lastPart: string | null = null;
45 for (const part of parts) {
46 if (!index[part]) index[part] = { tag: part, items: [], children: {} };
47 index[part].items.push(item);
48 if (lastPart) index[lastPart].children[part] = index[part];
49 lastPart = part;
50 }
51 }
52 if (item.properties.type === "directory")
53 item.properties.items.forEach(item => this.pushTagsForItem(index, item));
54 }
22} \ No newline at end of file 55} \ No newline at end of file