From f328a730b516f5e9104f85e553c083c2865660a8 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 4 May 2020 00:10:39 +0200 Subject: viewer/galleryStore: unify resource root parametrisation --- viewer/src/store/galleryStore.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 0cffdd9..a57122c 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -79,6 +79,10 @@ export default class GalleryStore extends VuexModule { return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; } + get resourceRoot(): string { + return process.env.VUE_APP_DATA_URL + this.config!.galleryRoot; + } + // --- // Fetches the gallery's JSON config -- cgit v1.2.3 From 170d7a61f720ece9dc4b347b19f5a8213f1d8984 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 20 Jun 2020 16:50:49 +0200 Subject: viewer: prettier formatting based on eslint-prettier plugin --- viewer/src/store/galleryStore.ts | 8 +++----- viewer/src/store/index.ts | 16 ++++++++-------- viewer/src/store/uiStore.ts | 5 ++--- 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index a57122c..5458f20 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -23,11 +23,10 @@ import Navigation from "@/services/navigation"; const VuexModule = createModule({ namespaced: "galleryStore", - strict: true -}) + strict: true, +}); export default class GalleryStore extends VuexModule { - config: Gallery.Config | null = null; galleryIndex: Gallery.Index | null = null; tagsIndex: Tag.Index = {}; @@ -65,8 +64,7 @@ export default class GalleryStore extends VuexModule { get currentItemPath(): Gallery.Item[] { const root = this.galleryIndex?.tree; - if (root) - return Navigation.searchCurrentItemPath(root, this.currentPath); + if (root) return Navigation.searchCurrentItemPath(root, this.currentPath); return []; } diff --git a/viewer/src/store/index.ts b/viewer/src/store/index.ts index d5339e8..f86d66b 100644 --- a/viewer/src/store/index.ts +++ b/viewer/src/store/index.ts @@ -17,30 +17,30 @@ -- along with this program. If not, see . */ -import Vue from "vue" -import Vuex from "vuex" +import Vue from "vue"; +import Vuex from "vuex"; import { extractVuexModule } from "vuex-class-component"; import { createProxy } from "vuex-class-component"; import UIStore from "@/store/uiStore"; import GalleryStore from "@/store/galleryStore"; -Vue.use(Vuex) +Vue.use(Vuex); const store = new Vuex.Store({ modules: { ...extractVuexModule(UIStore), - ...extractVuexModule(GalleryStore) + ...extractVuexModule(GalleryStore), }, strict: process.env.NODE_ENV !== "production", }); -Vue.use((vue) => vue.prototype.$uiStore = createProxy(store, UIStore)); -Vue.use((vue) => vue.prototype.$galleryStore = createProxy(store, GalleryStore)); +Vue.use(vue => (vue.prototype.$uiStore = createProxy(store, UIStore))); +Vue.use(vue => (vue.prototype.$galleryStore = createProxy(store, GalleryStore))); declare module "vue/types/vue" { interface Vue { - $uiStore: UIStore, - $galleryStore: GalleryStore + $uiStore: UIStore; + $galleryStore: GalleryStore; } } diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 892d35e..91ac338 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -21,11 +21,10 @@ import { createModule, mutation, action } from "vuex-class-component"; const VuexModule = createModule({ namespaced: "uiStore", - strict: true -}) + strict: true, +}); export default class UIStore extends VuexModule { - fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; -- cgit v1.2.3 From e6c2a8d9653ffde924632ca2f260c3a8cddc14ed Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 11 Sep 2020 00:15:04 +0200 Subject: viewer: item display order github: resolves #28 --- viewer/src/store/galleryStore.ts | 4 ++-- viewer/src/store/uiStore.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 5458f20..768adb6 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -31,7 +31,7 @@ export default class GalleryStore extends VuexModule { galleryIndex: Gallery.Index | null = null; tagsIndex: Tag.Index = {}; tagsCategories: Tag.Category[] = []; - currentPath: string = "/"; + currentPath: string | null = null; currentSearch: Tag.Search[] = []; // --- @@ -64,7 +64,7 @@ export default class GalleryStore extends VuexModule { get currentItemPath(): Gallery.Item[] { const root = this.galleryIndex?.tree; - if (root) return Navigation.searchCurrentItemPath(root, this.currentPath); + if (root && this.currentPath) return Navigation.searchCurrentItemPath(root, this.currentPath); return []; } diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 91ac338..1fe9f49 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -18,16 +18,20 @@ */ import { createModule, mutation, action } from "vuex-class-component"; +import ItemSortFn from "@/services/itemSortFn"; const VuexModule = createModule({ namespaced: "uiStore", strict: true, }); +type TItemSortFn = (left: Gallery.Item, right: Gallery.Item) => number; + export default class UIStore extends VuexModule { fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; + sortFn: TItemSortFn = ItemSortFn.sortByName; // --- @@ -42,4 +46,8 @@ export default class UIStore extends VuexModule { @mutation toggleSearchMode(value?: boolean) { this.searchMode = value ?? !this.searchMode; } + + @mutation setSortFn(sortFn: TItemSortFn) { + this.sortFn = sortFn; + } } -- cgit v1.2.3 From f89ed0bd94ea570d9e6533301783d13b13033db0 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 11 Sep 2020 20:10:56 +0200 Subject: viewer: PR #238 code review changes --- viewer/src/store/uiStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 1fe9f49..2d583fc 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -31,7 +31,7 @@ export default class UIStore extends VuexModule { fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; - sortFn: TItemSortFn = ItemSortFn.sortByName; + sortFn: TItemSortFn = ItemSortFn.sortByNameAsc; // --- -- cgit v1.2.3 From eb636568643e892491fd925f7a92fc3feba6a67e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 11 Sep 2020 21:06:31 +0200 Subject: viewer: config.json url parameter + index.json configuration github: resolves #160 --- viewer/src/store/galleryStore.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 768adb6..b672551 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -85,7 +85,7 @@ export default class GalleryStore extends VuexModule { // Fetches the gallery's JSON config @action async fetchConfig() { - return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) + return fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) .then(response => response.json()) .then(this.setConfig); } @@ -93,7 +93,8 @@ export default class GalleryStore extends VuexModule { // Fetches the gallery's JSON metadata @action async fetchGalleryItems() { const root = this.config?.galleryRoot ?? ""; - return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) + const index = this.config?.galleryIndex ?? "index.json"; + return fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) .then(response => response.json()) .then(this.setGalleryIndex) .then(this.indexTags) @@ -121,4 +122,10 @@ export default class GalleryStore extends VuexModule { this.setCurrentSearch(results); return results; } + + private static getUrlConfig() { + let search = window.location.search; + if (search.length > 1) return search.substr(1) + ".json"; + return "config.json"; + } } -- cgit v1.2.3 From 7a8eba922ad34182628f80cf2496d8654abe91e6 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 06:26:39 +0200 Subject: viewer: improved network errors handling --- viewer/src/store/galleryStore.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index b672551..5d599aa 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -85,20 +85,22 @@ export default class GalleryStore extends VuexModule { // Fetches the gallery's JSON config @action async fetchConfig() { - return fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) - .then(response => response.json()) + await fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) + .then(GalleryStore.responseToJson) .then(this.setConfig); + return this.config!; } // Fetches the gallery's JSON metadata @action async fetchGalleryItems() { const root = this.config?.galleryRoot ?? ""; const index = this.config?.galleryIndex ?? "index.json"; - return fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) - .then(response => response.json()) + await fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) + .then(GalleryStore.responseToJson) .then(this.setGalleryIndex) .then(this.indexTags) .then(this.indexTagCategories); + return this.galleryIndex!; } // Indexes the gallery @@ -128,4 +130,9 @@ export default class GalleryStore extends VuexModule { if (search.length > 1) return search.substr(1) + ".json"; return "config.json"; } + + private static responseToJson(response: Response) { + if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`); + return response.json(); + } } -- cgit v1.2.3 From 96ed5e6583a7f03d4ea7fa0512e66fffb656cc6e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 06:34:58 +0200 Subject: viewer: make default sort order configurable github: resolves #239 --- viewer/src/store/uiStore.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 2d583fc..04f14a0 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -18,20 +18,18 @@ */ import { createModule, mutation, action } from "vuex-class-component"; -import ItemSortFn from "@/services/itemSortFn"; +import ItemComparators, { ItemComparator } from "@/services/itemComparators"; const VuexModule = createModule({ namespaced: "uiStore", strict: true, }); -type TItemSortFn = (left: Gallery.Item, right: Gallery.Item) => number; - export default class UIStore extends VuexModule { fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; - sortFn: TItemSortFn = ItemSortFn.sortByNameAsc; + sortFn: ItemComparator = ItemComparators.sortByNameAsc; // --- @@ -47,7 +45,20 @@ export default class UIStore extends VuexModule { this.searchMode = value ?? !this.searchMode; } - @mutation setSortFn(sortFn: TItemSortFn) { + @mutation setSortFn(sortFn: ItemComparator) { this.sortFn = sortFn; } + + @action async initFromConfig(config: Gallery.Config) { + switch (config.initialSort ?? "") { + case "date_desc": + this.setSortFn(ItemComparators.sortByDateDesc); + break; + case "name_asc": + case "": + break; + default: + throw new Error("Unknown sort type: " + config.initialSort); + } + } } -- cgit v1.2.3 From b909ec093591b50950c0de54b2005d471ca28116 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 22:33:37 +0200 Subject: viewer: make default sort order configurable. code review improvements github: resolves #239 --- viewer/src/store/uiStore.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 04f14a0..84e7fed 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -29,7 +29,7 @@ export default class UIStore extends VuexModule { fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; - sortFn: ItemComparator = ItemComparators.sortByNameAsc; + sortFn: ItemComparator = ItemComparators.DEFAULT; // --- @@ -50,15 +50,10 @@ export default class UIStore extends VuexModule { } @action async initFromConfig(config: Gallery.Config) { - switch (config.initialSort ?? "") { - case "date_desc": - this.setSortFn(ItemComparators.sortByDateDesc); - break; - case "name_asc": - case "": - break; - default: - throw new Error("Unknown sort type: " + config.initialSort); + if (config.initialItemSort) { + const itemSort = ItemComparators.ITEM_SORTS.find(s => s.name == config.initialItemSort); + if (itemSort) this.setSortFn(itemSort.fn); + else throw new Error("Unknown sort type: " + config.initialItemSort); } } } -- cgit v1.2.3 From 26210d495aed813baac1095b5c7a7c7879d2d206 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 25 Sep 2020 10:42:33 +0200 Subject: viewer: refactor how the available sorts are stored github: resolves #259 --- viewer/src/store/uiStore.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 84e7fed..f065cdd 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -18,7 +18,7 @@ */ import { createModule, mutation, action } from "vuex-class-component"; -import ItemComparators, { ItemComparator } from "@/services/itemComparators"; +import ItemComparators, { ItemSort } from "@/services/itemComparators"; const VuexModule = createModule({ namespaced: "uiStore", @@ -29,7 +29,7 @@ export default class UIStore extends VuexModule { fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; - sortFn: ItemComparator = ItemComparators.DEFAULT; + sort: ItemSort = ItemComparators.DEFAULT; // --- @@ -45,14 +45,14 @@ export default class UIStore extends VuexModule { this.searchMode = value ?? !this.searchMode; } - @mutation setSortFn(sortFn: ItemComparator) { - this.sortFn = sortFn; + @mutation setSort(sort: ItemSort) { + this.sort = sort; } @action async initFromConfig(config: Gallery.Config) { if (config.initialItemSort) { - const itemSort = ItemComparators.ITEM_SORTS.find(s => s.name == config.initialItemSort); - if (itemSort) this.setSortFn(itemSort.fn); + const itemSort = ItemComparators.ITEM_SORTS[config.initialItemSort]; + if (itemSort) this.setSort(itemSort); else throw new Error("Unknown sort type: " + config.initialItemSort); } } -- cgit v1.2.3