aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store
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
parentc2b4c5d144db17ebf2dc9de32ba25cc836831ae2 (diff)
downloadldgallery-e34be1261d9219e5b2b92ebe271f609f11d55f63.tar.gz
vewer: Tags indexing and search input
Diffstat (limited to 'viewer/src/store')
-rw-r--r--viewer/src/store/galleryStore.ts41
-rw-r--r--viewer/src/store/uiStore.ts5
2 files changed, 41 insertions, 5 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
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";
2 2
3const VuexModule = createModule({ 3const VuexModule = createModule({
4 namespaced: "uiStore", 4 namespaced: "uiStore",
5 strict: true 5 strict: false
6}) 6})
7 7
8export default class UIStore extends VuexModule { 8export default class UIStore extends VuexModule {
9 9
10 fullscreen: boolean = false; 10 fullscreen: boolean = false;
11 currentTags: Tag.Node[] = [];
12
13 // ---
11 14
12 @mutation toggleFullscreen() { 15 @mutation toggleFullscreen() {
13 this.fullscreen = !this.fullscreen; 16 this.fullscreen = !this.fullscreen;