From ccecfd9421f4550a71134cd46e1388e486f8c564 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Tue, 28 Apr 2020 03:47:39 +0200 Subject: viewer: global formatting unification --- viewer/src/store/galleryStore.ts | 190 +++++++++++++++++++-------------------- viewer/src/store/index.ts | 10 +-- viewer/src/store/uiStore.ts | 30 +++---- 3 files changed, 115 insertions(+), 115 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 352a266..0cffdd9 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -18,105 +18,105 @@ */ import { createModule, mutation, action } from "vuex-class-component"; -import IndexFactory from '@/services/indexfactory'; -import Navigation from '@/services/navigation'; +import IndexFactory from "@/services/indexfactory"; +import Navigation from "@/services/navigation"; const VuexModule = createModule({ - namespaced: "galleryStore", - strict: true + namespaced: "galleryStore", + strict: true }) export default class GalleryStore extends VuexModule { - config: Gallery.Config | null = null; - galleryIndex: Gallery.Index | null = null; - tagsIndex: Tag.Index = {}; - tagsCategories: Tag.Category[] = []; - currentPath: string = "/"; - currentSearch: Tag.Search[] = []; - - // --- - - @mutation private setConfig(config: Gallery.Config) { - this.config = config; - } - - @mutation setGalleryIndex(galleryIndex: Gallery.Index) { - this.galleryIndex = Object.freeze(galleryIndex); - } - - @mutation private setTagsIndex(tagsIndex: Tag.Index) { - this.tagsIndex = Object.freeze(tagsIndex); - } - - @mutation private setTagsCategories(tagsCategories: Tag.Category[]) { - this.tagsCategories = tagsCategories; - } - - @mutation setCurrentPath(currentPath: string) { - this.currentPath = currentPath; - } - - @mutation setCurrentSearch(currentSearch: Tag.Search[]) { - this.currentSearch = currentSearch; - } - - // --- - - get currentItemPath(): Gallery.Item[] { - const root = this.galleryIndex?.tree; - if (root) - return Navigation.searchCurrentItemPath(root, this.currentPath); - return []; - } - - get currentItem(): Gallery.Item | null { - const path = this.currentItemPath; - return path.length > 0 ? path[path.length - 1] : null; - } - - get galleryTitle(): string { - return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; - } - - // --- - - // Fetches the gallery's JSON config - @action async fetchConfig() { - return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) - .then(response => response.json()) - .then(this.setConfig); - } - - // 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" }) - .then(response => response.json()) - .then(this.setGalleryIndex) - .then(this.indexTags) - .then(this.indexTagCategories); - } - - // Indexes the gallery - @action async indexTags() { - const root = this.galleryIndex?.tree ?? null; - const index = IndexFactory.generateTags(root); - this.setTagsIndex(index); - return index; - } - - // Indexes the proposed categories - @action async indexTagCategories() { - const categories = IndexFactory.generateCategories(this.tagsIndex, this.galleryIndex?.properties.tagCategories); - this.setTagsCategories(categories); - return categories; - } - - // Searches for tags - @action async search(filters: string[]) { - const results = filters.flatMap(filter => IndexFactory.searchTags(this.tagsIndex, filter, true)); - this.setCurrentSearch(results); - return results; - } + config: Gallery.Config | null = null; + galleryIndex: Gallery.Index | null = null; + tagsIndex: Tag.Index = {}; + tagsCategories: Tag.Category[] = []; + currentPath: string = "/"; + currentSearch: Tag.Search[] = []; + + // --- + + @mutation private setConfig(config: Gallery.Config) { + this.config = config; + } + + @mutation setGalleryIndex(galleryIndex: Gallery.Index) { + this.galleryIndex = Object.freeze(galleryIndex); + } + + @mutation private setTagsIndex(tagsIndex: Tag.Index) { + this.tagsIndex = Object.freeze(tagsIndex); + } + + @mutation private setTagsCategories(tagsCategories: Tag.Category[]) { + this.tagsCategories = tagsCategories; + } + + @mutation setCurrentPath(currentPath: string) { + this.currentPath = currentPath; + } + + @mutation setCurrentSearch(currentSearch: Tag.Search[]) { + this.currentSearch = currentSearch; + } + + // --- + + get currentItemPath(): Gallery.Item[] { + const root = this.galleryIndex?.tree; + if (root) + return Navigation.searchCurrentItemPath(root, this.currentPath); + return []; + } + + get currentItem(): Gallery.Item | null { + const path = this.currentItemPath; + return path.length > 0 ? path[path.length - 1] : null; + } + + get galleryTitle(): string { + return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; + } + + // --- + + // Fetches the gallery's JSON config + @action async fetchConfig() { + return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) + .then(response => response.json()) + .then(this.setConfig); + } + + // 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" }) + .then(response => response.json()) + .then(this.setGalleryIndex) + .then(this.indexTags) + .then(this.indexTagCategories); + } + + // Indexes the gallery + @action async indexTags() { + const root = this.galleryIndex?.tree ?? null; + const index = IndexFactory.generateTags(root); + this.setTagsIndex(index); + return index; + } + + // Indexes the proposed categories + @action async indexTagCategories() { + const categories = IndexFactory.generateCategories(this.tagsIndex, this.galleryIndex?.properties.tagCategories); + this.setTagsCategories(categories); + return categories; + } + + // Searches for tags + @action async search(filters: string[]) { + const results = filters.flatMap(filter => IndexFactory.searchTags(this.tagsIndex, filter, true)); + this.setCurrentSearch(results); + return results; + } } diff --git a/viewer/src/store/index.ts b/viewer/src/store/index.ts index 956d4fd..d5339e8 100644 --- a/viewer/src/store/index.ts +++ b/viewer/src/store/index.ts @@ -17,12 +17,12 @@ -- 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'; +import UIStore from "@/store/uiStore"; +import GalleryStore from "@/store/galleryStore"; Vue.use(Vuex) @@ -37,7 +37,7 @@ const store = new Vuex.Store({ Vue.use((vue) => vue.prototype.$uiStore = createProxy(store, UIStore)); Vue.use((vue) => vue.prototype.$galleryStore = createProxy(store, GalleryStore)); -declare module 'vue/types/vue' { +declare module "vue/types/vue" { interface Vue { $uiStore: UIStore, $galleryStore: GalleryStore diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 2bd315c..892d35e 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -20,27 +20,27 @@ import { createModule, mutation, action } from "vuex-class-component"; const VuexModule = createModule({ - namespaced: "uiStore", - strict: true + namespaced: "uiStore", + 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; + fullscreen: boolean = false; + fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); + searchMode: boolean = false; - // --- + // --- - @mutation toggleFullscreen(value?: boolean) { - this.fullscreen = value ?? !this.fullscreen; - } + @mutation toggleFullscreen(value?: boolean) { + this.fullscreen = value ?? !this.fullscreen; + } - @mutation toggleFullWidth(value?: boolean) { - this.fullWidth = value ?? !this.fullWidth; - } + @mutation toggleFullWidth(value?: boolean) { + this.fullWidth = value ?? !this.fullWidth; + } - @mutation toggleSearchMode(value?: boolean) { - this.searchMode = value ?? !this.searchMode; - } + @mutation toggleSearchMode(value?: boolean) { + this.searchMode = value ?? !this.searchMode; + } } -- cgit v1.2.3