From e4d9766b1c3dbf254f0f43e22dfd565dd66378a0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 8 Feb 2023 00:40:10 +0100 Subject: [PATCH] feat: sidebar modifiable par les jdrs --- package-lock.json | 10 ++++++++-- package.json | 2 ++ public/jdr/erratum.json | 23 +++++++++++++++++++++++ public/pelican.json | 12 ++++++++---- src/components/layout/SideBar.vue | 1 + src/stores/config.ts | 27 +++++++++++++++++++++++++-- src/types/HideLink.ts | 4 ++++ src/types/JdrConfig.ts | 2 ++ src/types/Link.ts | 1 + 9 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 public/jdr/erratum.json create mode 100644 src/types/HideLink.ts diff --git a/package-lock.json b/package-lock.json index ae24675..fe01adb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,8 +8,10 @@ "name": "pelican-jdr", "version": "0.0.0", "dependencies": { + "@types/lodash": "^4.14.191", "@types/marked": "^4.0.8", "axios": "^1.3.2", + "lodash": "^4.17.21", "marked": "^4.2.12", "pinia": "^2.0.28", "sass": "^1.58.0", @@ -498,6 +500,11 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.14.191", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz", + "integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==" + }, "node_modules/@types/marked": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/@types/marked/-/marked-4.0.8.tgz", @@ -2578,8 +2585,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash.merge": { "version": "4.6.2", diff --git a/package.json b/package.json index 22e6758..b4e733d 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,10 @@ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, "dependencies": { + "@types/lodash": "^4.14.191", "@types/marked": "^4.0.8", "axios": "^1.3.2", + "lodash": "^4.17.21", "marked": "^4.2.12", "pinia": "^2.0.28", "sass": "^1.58.0", diff --git a/public/jdr/erratum.json b/public/jdr/erratum.json new file mode 100644 index 0000000..0177fee --- /dev/null +++ b/public/jdr/erratum.json @@ -0,0 +1,23 @@ +{ + "name": "Règles de bases", + "sidebar": [ + { + "id": 50, + "title": "Magie et surnaturel", + "links": [ + {"title": "Métaphysique", "path": "rules/magie/eclat"}, + {"title": "Anomie", "path": "rules/magie/anomie"} + ] + }, + { + "id": 60, + "title": "Divers", + "links": [ + {"title": "Malédiction antiques", "path": "rules/erratum/maledictions"} + ] + } + ], + "hideLinks":[ + { "menu":10, "link":"rules/personnages/niveaux" } + ] +} \ No newline at end of file diff --git a/public/pelican.json b/public/pelican.json index 3251a61..0466e8c 100644 --- a/public/pelican.json +++ b/public/pelican.json @@ -66,16 +66,20 @@ "title": "Magie et surnaturel", "links": [ {"title": "Éclat", "path": "rules/magie/eclat"}, - {"title": "Éléments", "path": "rules/magie/eclat"}, - {"title": "Métaphysique", "path": "rules/magie/eclat"}, - {"title": "Anomie", "path": "rules/magie/anomie"} + {"title": "Éléments", "path": "rules/magie/eclat"} ] }, { "id": 60, "title": "Divers", "links": [ - {"title": "Afflictions et effets", "path": "rules/divers/afflictions"}, + {"title": "Afflictions et effets", "path": "rules/divers/afflictions"} + ] + }, + { + "id": 70, + "title": "", + "links": [ {"title": "Jeu de plateau", "path": "rules/bases/plateau"} ] } diff --git a/src/components/layout/SideBar.vue b/src/components/layout/SideBar.vue index a3754da..d1dbcb9 100644 --- a/src/components/layout/SideBar.vue +++ b/src/components/layout/SideBar.vue @@ -27,6 +27,7 @@ const linkBase = computed(() => { :to="`/${linkBase}/${link.path}`" class="menu-item" :replace="true" + v-if="!link.isHidden" >{{ link.title }} diff --git a/src/stores/config.ts b/src/stores/config.ts index 82d588b..3271b31 100644 --- a/src/stores/config.ts +++ b/src/stores/config.ts @@ -4,6 +4,7 @@ import type PelicanConfig from "@/types/PelicanConfig"; import type LinkList from "@/types/LinkList"; import type JdrConfig from "@/types/JdrConfig"; import axios from "axios"; +import { cloneDeep } from "lodash"; export const useConfigStore = defineStore("config", () => { const config = ref(null as PelicanConfig | null); @@ -12,11 +13,31 @@ export const useConfigStore = defineStore("config", () => { const sidebar = ref([{ id: 0, links: [] }] as LinkList[]); function computeSidebar() { - return config.value?.sidebar ?? [{ id: 0, links: [] }]; + const baseSideBar = cloneDeep(config.value?.sidebar ?? []); + for (const cat of jdrConfig.value?.sidebar ?? []) { + const sidebarItem = baseSideBar.find((a) => a.id === cat.id); + if (sidebarItem) { + sidebarItem.links = sidebarItem.links.concat(cat.links); + } else { + baseSideBar.push(cat); + } + } + for (const hideLink of jdrConfig.value?.hideLinks ?? []) { + const sidebarItem = baseSideBar.find((a) => a.id === hideLink.menu); + if (sidebarItem) { + const link = sidebarItem.links.find((a) => a.path === hideLink.link); + if (link) { + link.isHidden = true; + } + } + } + + return baseSideBar; } function setConfig(newConfig: PelicanConfig) { config.value = newConfig; + sidebar.value = computeSidebar(); } function loadJdr(newJdr: string) { @@ -43,7 +64,9 @@ export const useConfigStore = defineStore("config", () => { if (isJdrLoaded()) { return sidebar.value; } else { - return config.value?.jdr ?? [{ id: 0, links: [] }]; + return ( + config.value?.jdr?.sort((a, b) => a.id - b.id) ?? [{ id: 0, links: [] }] + ); } } diff --git a/src/types/HideLink.ts b/src/types/HideLink.ts new file mode 100644 index 0000000..e02dc0c --- /dev/null +++ b/src/types/HideLink.ts @@ -0,0 +1,4 @@ +export default interface HideLink { + menu: number; + link: string; +} diff --git a/src/types/JdrConfig.ts b/src/types/JdrConfig.ts index 2ff1230..72a044d 100644 --- a/src/types/JdrConfig.ts +++ b/src/types/JdrConfig.ts @@ -1,6 +1,8 @@ +import type HideLink from "./HideLink"; import type LinkList from "./LinkList"; export default interface JdrConfig { name: string; sidebar: LinkList[]; + hideLinks: HideLink[]; } diff --git a/src/types/Link.ts b/src/types/Link.ts index 4eca35f..5eecc00 100644 --- a/src/types/Link.ts +++ b/src/types/Link.ts @@ -1,4 +1,5 @@ export default interface Link { title: string; path: string; + isHidden?: boolean; }