diff options
author | pacien | 2020-09-25 16:01:49 +0200 |
---|---|---|
committer | pacien | 2020-09-25 16:01:49 +0200 |
commit | e93f7b1eb84c083d67567115284c0002a3a7d5fc (patch) | |
tree | 8d373e8f7f571485e1330928f43b090ed004c525 /viewer/src/store/galleryStore.ts | |
parent | 8e3ac8fe44bebb38e1882ca7f06b8100078ad88d (diff) | |
parent | fd542f75a1d94ee5f804d0925823276b97f38581 (diff) | |
download | ldgallery-2.0.tar.gz |
Merge branch 'develop' for release v2.0v2.0
Diffstat (limited to 'viewer/src/store/galleryStore.ts')
-rw-r--r-- | viewer/src/store/galleryStore.ts | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 0cffdd9..5d599aa 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts | |||
@@ -23,16 +23,15 @@ import Navigation from "@/services/navigation"; | |||
23 | 23 | ||
24 | const VuexModule = createModule({ | 24 | const VuexModule = createModule({ |
25 | namespaced: "galleryStore", | 25 | namespaced: "galleryStore", |
26 | strict: true | 26 | strict: true, |
27 | }) | 27 | }); |
28 | 28 | ||
29 | export default class GalleryStore extends VuexModule { | 29 | export default class GalleryStore extends VuexModule { |
30 | |||
31 | config: Gallery.Config | null = null; | 30 | config: Gallery.Config | null = null; |
32 | galleryIndex: Gallery.Index | null = null; | 31 | galleryIndex: Gallery.Index | null = null; |
33 | tagsIndex: Tag.Index = {}; | 32 | tagsIndex: Tag.Index = {}; |
34 | tagsCategories: Tag.Category[] = []; | 33 | tagsCategories: Tag.Category[] = []; |
35 | currentPath: string = "/"; | 34 | currentPath: string | null = null; |
36 | currentSearch: Tag.Search[] = []; | 35 | currentSearch: Tag.Search[] = []; |
37 | 36 | ||
38 | // --- | 37 | // --- |
@@ -65,8 +64,7 @@ export default class GalleryStore extends VuexModule { | |||
65 | 64 | ||
66 | get currentItemPath(): Gallery.Item[] { | 65 | get currentItemPath(): Gallery.Item[] { |
67 | const root = this.galleryIndex?.tree; | 66 | const root = this.galleryIndex?.tree; |
68 | if (root) | 67 | if (root && this.currentPath) return Navigation.searchCurrentItemPath(root, this.currentPath); |
69 | return Navigation.searchCurrentItemPath(root, this.currentPath); | ||
70 | return []; | 68 | return []; |
71 | } | 69 | } |
72 | 70 | ||
@@ -79,23 +77,30 @@ export default class GalleryStore extends VuexModule { | |||
79 | return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; | 77 | return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; |
80 | } | 78 | } |
81 | 79 | ||
80 | get resourceRoot(): string { | ||
81 | return process.env.VUE_APP_DATA_URL + this.config!.galleryRoot; | ||
82 | } | ||
83 | |||
82 | // --- | 84 | // --- |
83 | 85 | ||
84 | // Fetches the gallery's JSON config | 86 | // Fetches the gallery's JSON config |
85 | @action async fetchConfig() { | 87 | @action async fetchConfig() { |
86 | return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) | 88 | await fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) |
87 | .then(response => response.json()) | 89 | .then(GalleryStore.responseToJson) |
88 | .then(this.setConfig); | 90 | .then(this.setConfig); |
91 | return this.config!; | ||
89 | } | 92 | } |
90 | 93 | ||
91 | // Fetches the gallery's JSON metadata | 94 | // Fetches the gallery's JSON metadata |
92 | @action async fetchGalleryItems() { | 95 | @action async fetchGalleryItems() { |
93 | const root = this.config?.galleryRoot ?? ""; | 96 | const root = this.config?.galleryRoot ?? ""; |
94 | return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) | 97 | const index = this.config?.galleryIndex ?? "index.json"; |
95 | .then(response => response.json()) | 98 | await fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) |
99 | .then(GalleryStore.responseToJson) | ||
96 | .then(this.setGalleryIndex) | 100 | .then(this.setGalleryIndex) |
97 | .then(this.indexTags) | 101 | .then(this.indexTags) |
98 | .then(this.indexTagCategories); | 102 | .then(this.indexTagCategories); |
103 | return this.galleryIndex!; | ||
99 | } | 104 | } |
100 | 105 | ||
101 | // Indexes the gallery | 106 | // Indexes the gallery |
@@ -119,4 +124,15 @@ export default class GalleryStore extends VuexModule { | |||
119 | this.setCurrentSearch(results); | 124 | this.setCurrentSearch(results); |
120 | return results; | 125 | return results; |
121 | } | 126 | } |
127 | |||
128 | private static getUrlConfig() { | ||
129 | let search = window.location.search; | ||
130 | if (search.length > 1) return search.substr(1) + ".json"; | ||
131 | return "config.json"; | ||
132 | } | ||
133 | |||
134 | private static responseToJson(response: Response) { | ||
135 | if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`); | ||
136 | return response.json(); | ||
137 | } | ||
122 | } | 138 | } |