From 0ce248c3aae48fc9805fafbe204ff7671d1c8910 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 27 Feb 2023 01:11:12 +0800 Subject: [PATCH] Use params for pages, simplify sidebar css --- frontend/src/app/dependencies-data.ts | 44 +++++- frontend/src/app/dependency-store.ts | 13 ++ frontend/src/app/mappings-data.ts | 71 +++++++++- frontend/src/app/mappings-store.ts | 46 +++++-- frontend/src/components/Block.vue | 6 +- frontend/src/components/LoadingSection.vue | 33 +++++ frontend/src/components/PageContent.vue | 17 +++ frontend/src/components/PageSidebar.vue | 19 +++ frontend/src/components/PageWidthLimiter.vue | 17 +++ .../dependencies/DependencyBlock.vue | 23 ---- .../dependencies/DependencyFilterBlock.vue | 20 +-- .../src/components/dependencies/SubHeader.vue | 8 +- .../mappings/MappingsEntryBlock.vue | 2 +- .../mappings/MappingsFilterBlock.vue | 52 +------- .../mappings/MappingsSearchBlock.vue | 42 +++--- frontend/src/routes/Dependencies.vue | 125 +++++++----------- frontend/src/routes/Home.vue | 30 ++--- frontend/src/routes/Mappings.vue | 75 ++++------- frontend/src/routes/OpenSourceLicenses.vue | 65 ++++----- 19 files changed, 386 insertions(+), 322 deletions(-) create mode 100644 frontend/src/components/LoadingSection.vue create mode 100644 frontend/src/components/PageContent.vue create mode 100644 frontend/src/components/PageSidebar.vue create mode 100644 frontend/src/components/PageWidthLimiter.vue delete mode 100644 frontend/src/components/dependencies/DependencyBlock.vue diff --git a/frontend/src/app/dependencies-data.ts b/frontend/src/app/dependencies-data.ts index 93d5884..1f2c375 100644 --- a/frontend/src/app/dependencies-data.ts +++ b/frontend/src/app/dependencies-data.ts @@ -1,6 +1,6 @@ import {reqVersions} from "./backend" import {addAlert} from "./alerts" -import {useDependencySearchStore} from "./dependency-store" +import {applicableDependencyVersions, useDependencySearchStore} from "./dependency-store" import {DependencyType} from "./dep-format" import {defineStore} from "pinia" @@ -36,6 +36,7 @@ export interface DependencySearchData { export interface State { reqVersionsPromise: Promise | undefined, searchData: DependencySearchData, + hasFirstLoaded: boolean, } function newState(): State { @@ -44,20 +45,21 @@ function newState(): State { searchData: { versions: {}, }, + hasFirstLoaded: false, } } export const useDependenciesDataStore = defineStore({ id: "dependencies-data", - state: newState + state: newState, }) -export function updateDependencyData() { +export function updateDependencyData(applyURL: boolean = false) { let store = useDependenciesDataStore() - if (Object.keys(store.searchData.versions).length == 0 && !store.reqVersionsPromise) { + if (applyURL || (Object.keys(store.searchData.versions).length == 0 && !store.reqVersionsPromise)) { store.reqVersionsPromise = reqVersions().then(value => { store.searchData.versions = value.data - ensureDependencyData() + ensureDependencyData(applyURL) }).catch(reason => { addAlert({ type: "error", @@ -69,8 +71,26 @@ export function updateDependencyData() { } } -export function ensureDependencyData() { +export function ensureDependencyData(applyURL: boolean = false) { let store = useDependenciesDataStore() + + if (applyURL) { + const urlParams = new URLSearchParams(window.location.search) + let {searchData} = useDependenciesDataStore() + let loaders = Object.keys(searchData.versions) + + if (loaders.includes(urlParams.get("loader") ?? "")) { + useDependencySearchStore().loader = (urlParams.get("loader") ?? "") as string + useDependencySearchStore().version = undefined + } + + if (applicableDependencyVersions().includes(urlParams.get("version") ?? "")) { + useDependencySearchStore().version = (urlParams.get("version") ?? "") as string + } + + useDependenciesDataStore().hasFirstLoaded = true + } + let {loader, version, allowSnapshots} = useDependencySearchStore() if (!loader) { loader = Object.keys(store.searchData.versions)[0] @@ -86,4 +106,16 @@ export function ensureDependencyData() { useDependencySearchStore().version = version } } + + if (useDependenciesDataStore().hasFirstLoaded) { + updateDependenciesWindowUrl() + } +} + +export function updateDependenciesWindowUrl() { + let {loader, version} = useDependencySearchStore() + let url = new URL(window.location.href) + url.searchParams.set("loader", loader ?? "") + url.searchParams.set("version", version ?? "") + window.history.replaceState({}, "", url.toString()) } diff --git a/frontend/src/app/dependency-store.ts b/frontend/src/app/dependency-store.ts index 8c23dee..36255c2 100644 --- a/frontend/src/app/dependency-store.ts +++ b/frontend/src/app/dependency-store.ts @@ -1,4 +1,5 @@ import {defineStore} from "pinia" +import {useDependenciesDataStore} from "./dependencies-data" interface State { loader?: string, @@ -19,3 +20,15 @@ export const useDependencySearchStore = defineStore({ state: newState, persist: true, }) + +export function applicableDependencyVersions(): string[] { + let {loader, allowSnapshots} = useDependencySearchStore() + let {searchData} = useDependenciesDataStore() + + if (!loader) return [] + let versions = searchData.versions[loader] ?? [] + if (versions && !allowSnapshots) { + versions = versions.filter(entry => entry.stable) + } + return versions.map(entry => entry.version) +} diff --git a/frontend/src/app/mappings-data.ts b/frontend/src/app/mappings-data.ts index 10da886..41c1893 100644 --- a/frontend/src/app/mappings-data.ts +++ b/frontend/src/app/mappings-data.ts @@ -1,7 +1,7 @@ import {defineStore} from "pinia" import {reqNamespaces, reqSearch} from "./backend" import {addAlert} from "./alerts" -import {useMappingsStore} from "./mappings-store" +import {applicableMappingsVersions, useMappingsStore} from "./mappings-store" import axios from "axios" import {VersionEntry} from "./dependencies-data" @@ -60,6 +60,7 @@ export interface State { infoData: InfoData, reqNamespacesPromise: Promise | undefined, searchController: AbortController | undefined, + hasFirstLoaded: boolean, } function newState(): State { @@ -74,20 +75,21 @@ function newState(): State { }, reqNamespacesPromise: undefined, searchController: undefined, + hasFirstLoaded: false, } } export const useMappingsDataStore = defineStore({ id: "mappings-data", - state: newState + state: newState, }) -export function updateMappingsData() { +export function updateMappingsData(applyURL: boolean = false) { let store = useMappingsDataStore() - if (Object.keys(store.mappingsData.namespaces).length == 0 && !store.reqNamespacesPromise) { + if (applyURL || (Object.keys(store.mappingsData.namespaces).length == 0 && !store.reqNamespacesPromise)) { store.reqNamespacesPromise = reqNamespaces().then(value => { store.mappingsData.namespaces = value.data - ensureMappingsData() + ensureMappingsData(applyURL) }).catch(reason => { addAlert({ type: "error", @@ -99,8 +101,34 @@ export function updateMappingsData() { } } -export function ensureMappingsData() { +export function ensureMappingsData(applyURL: boolean = false) { let store = useMappingsDataStore() + if (applyURL) { + const urlParams = new URLSearchParams(window.location.search) + + if (store.mappingsData.namespaces.map(namespace => namespace.id).includes(urlParams.get("namespace") ?? "")) { + useMappingsStore().namespace = (urlParams.get("namespace") ?? "") as string + useMappingsStore().translateAs = undefined + useMappingsStore().version = undefined + } + + if (store.mappingsData.namespaces.map(namespace => namespace.id).includes(urlParams.get("translateAs") ?? "") + && useMappingsStore().namespace && useMappingsStore().namespace !== urlParams.get("translateAs")) { + useMappingsStore().translateAs = (urlParams.get("translateAs") ?? "") as string + } + + if (applicableMappingsVersions().map(version => version.version).includes(urlParams.get("version") ?? "")) { + useMappingsStore().version = (urlParams.get("version") ?? "") as string + } + + if (urlParams.has("search")) useMappingsStore().searchText = urlParams.get("search") ?? "" + if (urlParams.has("allowClasses")) useMappingsStore().allowClasses = urlParams.get("allowClasses") === "true" + if (urlParams.has("allowMethods")) useMappingsStore().allowMethods = urlParams.get("allowMethods") === "true" + if (urlParams.has("allowFields")) useMappingsStore().allowFields = urlParams.get("allowFields") === "true" + + useMappingsDataStore().hasFirstLoaded = true + } + let {namespace, version, allowSnapshots, translateAs} = useMappingsStore() if (!namespace) { namespace = store.mappingsData.namespaces[0]?.id @@ -122,6 +150,10 @@ export function ensureMappingsData() { useMappingsStore().version = version } } + + if (useMappingsDataStore().hasFirstLoaded) { + updateMappingsWindowUrl() + } } export function updateMappingsInfo() { @@ -149,6 +181,9 @@ export function updateMappingsInfo() { } store.infoData.fuzzy = value.data.fuzzy store.infoData.entries = (value.data.entries as any[]).map(mapEntryToMappingEntry) + if (useMappingsDataStore().hasFirstLoaded) { + updateMappingsWindowUrl() + } }).catch(reason => { if (!axios.isCancel(reason)) { addAlert({ @@ -209,4 +244,26 @@ export function mapEntryToMappingEntry(obj: any): MappingEntry { type, translatedTo, } as MappingEntry -} \ No newline at end of file +} + +export function updateMappingsWindowUrl() { + let {namespace, version, searchText, allowClasses, allowFields, allowMethods, translateAs} = useMappingsStore() + let url = new URL(window.location.href) + url.searchParams.set("namespace", namespace ?? "") + url.searchParams.set("version", version ?? "") + url.searchParams.set("search", searchText ?? "") + + if (!allowClasses) url.searchParams.set("allowClasses", "false") + else url.searchParams.delete("allowClasses") + + if (!allowFields) url.searchParams.set("allowFields", "false") + else url.searchParams.delete("allowFields") + + if (!allowMethods) url.searchParams.set("allowMethods", "false") + else url.searchParams.delete("allowMethods") + + if (translateAs) url.searchParams.set("translateAs", translateAs) + else url.searchParams.delete("translateAs") + + window.history.replaceState({}, "", url.toString()) +} diff --git a/frontend/src/app/mappings-store.ts b/frontend/src/app/mappings-store.ts index 29c3eb8..cd8a153 100644 --- a/frontend/src/app/mappings-store.ts +++ b/frontend/src/app/mappings-store.ts @@ -1,4 +1,5 @@ import {defineStore} from "pinia" +import {useMappingsDataStore} from "./mappings-data" interface State { namespace?: string, @@ -11,6 +12,11 @@ interface State { translateAs?: string, } +export interface VersionPossible { + version: string + hasTranslation: boolean +} + function newState(): State { return { namespace: undefined, @@ -27,16 +33,34 @@ function newState(): State { export const useMappingsStore = defineStore({ id: "mappings", state: newState, - actions: { - setNamespace(namespace: string | undefined) { - this.namespace = namespace - }, - setVersion(version: string | undefined) { - this.version = version - }, - setAllowSnapshots(allowSnapshots: boolean) { - this.allowSnapshots = allowSnapshots - }, - }, persist: true, }) + +export function applicableMappingsVersions(): VersionPossible[] { + let {namespace, allowSnapshots, translateAs} = useMappingsStore() + let {mappingsData} = useMappingsDataStore() + if (!namespace) return [] + let namespaceObj = mappingsData.namespaces.find(value => value.id === namespace) + if (!namespaceObj) return [] + let versions = namespaceObj.versions + if (versions && !allowSnapshots) { + versions = versions.filter(entry => entry.stable) + } + if (versions && translateAs) { + let translateAsObj = mappingsData.namespaces.find(value => value.id === translateAs) + let retain = translateAsObj?.versions?.map(entry => entry.version) ?? [] + return versions.map(entry => { + return { + version: entry.version, + hasTranslation: retain.includes(entry.version), + } + }) + } else { + return versions.map(entry => { + return { + version: entry.version, + hasTranslation: true, + } + }) + } +} \ No newline at end of file diff --git a/frontend/src/components/Block.vue b/frontend/src/components/Block.vue index 33a874f..6f92f3a 100644 --- a/frontend/src/components/Block.vue +++ b/frontend/src/components/Block.vue @@ -1,8 +1,6 @@ diff --git a/frontend/src/components/LoadingSection.vue b/frontend/src/components/LoadingSection.vue new file mode 100644 index 0000000..ccc6e60 --- /dev/null +++ b/frontend/src/components/LoadingSection.vue @@ -0,0 +1,33 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/components/PageContent.vue b/frontend/src/components/PageContent.vue new file mode 100644 index 0000000..e204634 --- /dev/null +++ b/frontend/src/components/PageContent.vue @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/components/PageSidebar.vue b/frontend/src/components/PageSidebar.vue new file mode 100644 index 0000000..a20ff2f --- /dev/null +++ b/frontend/src/components/PageSidebar.vue @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/components/PageWidthLimiter.vue b/frontend/src/components/PageWidthLimiter.vue new file mode 100644 index 0000000..c64d191 --- /dev/null +++ b/frontend/src/components/PageWidthLimiter.vue @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/components/dependencies/DependencyBlock.vue b/frontend/src/components/dependencies/DependencyBlock.vue deleted file mode 100644 index e1f9796..0000000 --- a/frontend/src/components/dependencies/DependencyBlock.vue +++ /dev/null @@ -1,23 +0,0 @@ - - - - - \ No newline at end of file diff --git a/frontend/src/components/dependencies/DependencyFilterBlock.vue b/frontend/src/components/dependencies/DependencyFilterBlock.vue index 43c4439..5e5efb0 100644 --- a/frontend/src/components/dependencies/DependencyFilterBlock.vue +++ b/frontend/src/components/dependencies/DependencyFilterBlock.vue @@ -1,6 +1,6 @@