aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store
diff options
context:
space:
mode:
authorZero~Informatique2020-02-14 09:19:53 +0100
committerZero~Informatique2020-02-24 00:04:39 +0100
commit370e3db3455f548699ff5e046e0f8dcc304991ac (patch)
treee29fe9e2afb940eea74c8ed510c46a1eb0fa4d84 /viewer/src/store
parente42f4e864bac21ed3b19d1869df2cdd4f8c3433c (diff)
downloadldgallery-370e3db3455f548699ff5e046e0f8dcc304991ac.tar.gz
viewer: major code and search mode overhaul
Updated libraries to the lastest version SCSS Formatter as suggested VSC extensions Renamed toolbar-color by scrollbar-color LD components use Props in favor of touching the stores directly (when possible) Moved most common algorithms to a "services" folder Complete search overhaul (lots of code change)
Diffstat (limited to 'viewer/src/store')
-rw-r--r--viewer/src/store/galleryStore.ts51
-rw-r--r--viewer/src/store/uiStore.ts22
2 files changed, 10 insertions, 63 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index e7d70f8..d2b28dd 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -18,7 +18,8 @@
18*/ 18*/
19 19
20import { createModule, mutation, action } from "vuex-class-component"; 20import { createModule, mutation, action } from "vuex-class-component";
21import Tools from '@/tools'; 21import IndexFactory from '@/services/indexfactory';
22import Navigation from '@/services/navigation';
22 23
23const VuexModule = createModule({ 24const VuexModule = createModule({
24 namespaced: "galleryStore", 25 namespaced: "galleryStore",
@@ -29,7 +30,7 @@ export default class GalleryStore extends VuexModule {
29 30
30 config: Gallery.Config | null = null; 31 config: Gallery.Config | null = null;
31 galleryItemsRoot: Gallery.Item | null = null; 32 galleryItemsRoot: Gallery.Item | null = null;
32 tags: Tag.Index = {}; 33 tagsIndex: Tag.Index = {};
33 currentPath: string = "/"; 34 currentPath: string = "/";
34 35
35 // --- 36 // ---
@@ -42,8 +43,8 @@ export default class GalleryStore extends VuexModule {
42 this.galleryItemsRoot = galleryItemsRoot; 43 this.galleryItemsRoot = galleryItemsRoot;
43 } 44 }
44 45
45 @mutation private setTags(tags: Tag.Index) { 46 @mutation private setTagsIndex(tagsIndex: Tag.Index) {
46 this.tags = tags; 47 this.tagsIndex = tagsIndex;
47 } 48 }
48 49
49 @mutation setCurrentPath(currentPath: string) { 50 @mutation setCurrentPath(currentPath: string) {
@@ -53,7 +54,7 @@ export default class GalleryStore extends VuexModule {
53 get currentItemPath(): Gallery.Item[] { 54 get currentItemPath(): Gallery.Item[] {
54 const root = this.galleryItemsRoot; 55 const root = this.galleryItemsRoot;
55 if (root) 56 if (root)
56 return GalleryStore.searchCurrentItemPath(root, this.currentPath); 57 return Navigation.searchCurrentItemPath(root, this.currentPath);
57 return []; 58 return [];
58 } 59 }
59 60
@@ -67,7 +68,7 @@ export default class GalleryStore extends VuexModule {
67 // Fetches the gallery's JSON config 68 // Fetches the gallery's JSON config
68 @action async fetchConfig() { 69 @action async fetchConfig() {
69 return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) 70 return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" })
70 .then(config => config.json()) 71 .then(response => response.json())
71 .then(this.setConfig); 72 .then(this.setConfig);
72 } 73 }
73 74
@@ -82,43 +83,7 @@ export default class GalleryStore extends VuexModule {
82 83
83 // Indexes the gallery 84 // Indexes the gallery
84 @action async indexTags() { 85 @action async indexTags() {
85 const root = this.galleryItemsRoot; 86 this.setTagsIndex(IndexFactory.generateTags(this.galleryItemsRoot));
86 let index = {};
87 if (root) GalleryStore.pushTagsForItem(index, root);
88 console.log("Index: ", index);
89 this.setTags(index);
90 }
91
92 // ---
93
94 // Pushes all tags for a root item (and its children) to the index
95 private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) {
96 console.log("IndexingTagsFor: ", item.path);
97 if (item.properties.type === "directory") {
98 item.properties.items.forEach(item => this.pushTagsForItem(index, item));
99 return; // Directories are not indexed
100 }
101 for (const tag of item.tags) {
102 const parts = tag.split('.');
103 let lastPart: string | null = null;
104 for (const part of parts) {
105 if (!index[part]) index[part] = { tag: part, tagfiltered: Tools.normalize(part), items: [], children: {} };
106 if (!index[part].items.includes(item)) index[part].items.push(item);
107 if (lastPart) index[lastPart].children[part] = index[part];
108 lastPart = part;
109 }
110 }
111 } 87 }
112 88
113 // Searches for an item by path from a root item (navigation)
114 private static searchCurrentItemPath(item: Gallery.Item, path: string): Gallery.Item[] {
115 if (path === item.path) return [item];
116 if (item.properties.type === "directory" && path.startsWith(item.path)) {
117 const itemChain = item.properties.items
118 .map(item => this.searchCurrentItemPath(item, path))
119 .find(itemChain => itemChain.length > 0);
120 if (itemChain) return [item, ...itemChain];
121 }
122 return [];
123 }
124} 89}
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts
index f7484de..5b6e1ca 100644
--- a/viewer/src/store/uiStore.ts
+++ b/viewer/src/store/uiStore.ts
@@ -28,18 +28,8 @@ export default class UIStore extends VuexModule {
28 28
29 fullscreen: boolean = false; 29 fullscreen: boolean = false;
30 fullWidth: boolean = true; 30 fullWidth: boolean = true;
31 mode: "navigation" | "search" = "navigation"; 31 searchMode: boolean = false;
32 currentTags: Tag.Search[] = []; 32 searchFilters: Tag.Search[] = [];
33
34 // ---
35
36 get isModeSearch() {
37 return this.mode === "search";
38 }
39
40 get isModeNavigation() {
41 return this.mode === "navigation";
42 }
43 33
44 // --- 34 // ---
45 35
@@ -50,12 +40,4 @@ export default class UIStore extends VuexModule {
50 @mutation toggleFullWidth() { 40 @mutation toggleFullWidth() {
51 this.fullWidth = !this.fullWidth; 41 this.fullWidth = !this.fullWidth;
52 } 42 }
53
54 @mutation setModeNavigation() {
55 this.mode = "navigation";
56 }
57
58 @mutation setModeSearch() {
59 this.mode = "search";
60 }
61} 43}