feat: sidebar modifiable par les jdrs
This commit is contained in:
parent
bce09a78a8
commit
e4d9766b1c
9 changed files with 74 additions and 8 deletions
10
package-lock.json
generated
10
package-lock.json
generated
|
@ -8,8 +8,10 @@
|
||||||
"name": "pelican-jdr",
|
"name": "pelican-jdr",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/lodash": "^4.14.191",
|
||||||
"@types/marked": "^4.0.8",
|
"@types/marked": "^4.0.8",
|
||||||
"axios": "^1.3.2",
|
"axios": "^1.3.2",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"marked": "^4.2.12",
|
"marked": "^4.2.12",
|
||||||
"pinia": "^2.0.28",
|
"pinia": "^2.0.28",
|
||||||
"sass": "^1.58.0",
|
"sass": "^1.58.0",
|
||||||
|
@ -498,6 +500,11 @@
|
||||||
"integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
|
"integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/@types/marked": {
|
||||||
"version": "4.0.8",
|
"version": "4.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/marked/-/marked-4.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@types/marked/-/marked-4.0.8.tgz",
|
||||||
|
@ -2578,8 +2585,7 @@
|
||||||
"node_modules/lodash": {
|
"node_modules/lodash": {
|
||||||
"version": "4.17.21",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/lodash.merge": {
|
"node_modules/lodash.merge": {
|
||||||
"version": "4.6.2",
|
"version": "4.6.2",
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/lodash": "^4.14.191",
|
||||||
"@types/marked": "^4.0.8",
|
"@types/marked": "^4.0.8",
|
||||||
"axios": "^1.3.2",
|
"axios": "^1.3.2",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"marked": "^4.2.12",
|
"marked": "^4.2.12",
|
||||||
"pinia": "^2.0.28",
|
"pinia": "^2.0.28",
|
||||||
"sass": "^1.58.0",
|
"sass": "^1.58.0",
|
||||||
|
|
23
public/jdr/erratum.json
Normal file
23
public/jdr/erratum.json
Normal file
|
@ -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" }
|
||||||
|
]
|
||||||
|
}
|
|
@ -66,16 +66,20 @@
|
||||||
"title": "Magie et surnaturel",
|
"title": "Magie et surnaturel",
|
||||||
"links": [
|
"links": [
|
||||||
{"title": "Éclat", "path": "rules/magie/eclat"},
|
{"title": "Éclat", "path": "rules/magie/eclat"},
|
||||||
{"title": "Éléments", "path": "rules/magie/eclat"},
|
{"title": "Éléments", "path": "rules/magie/eclat"}
|
||||||
{"title": "Métaphysique", "path": "rules/magie/eclat"},
|
|
||||||
{"title": "Anomie", "path": "rules/magie/anomie"}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 60,
|
"id": 60,
|
||||||
"title": "Divers",
|
"title": "Divers",
|
||||||
"links": [
|
"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"}
|
{"title": "Jeu de plateau", "path": "rules/bases/plateau"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ const linkBase = computed(() => {
|
||||||
:to="`/${linkBase}/${link.path}`"
|
:to="`/${linkBase}/${link.path}`"
|
||||||
class="menu-item"
|
class="menu-item"
|
||||||
:replace="true"
|
:replace="true"
|
||||||
|
v-if="!link.isHidden"
|
||||||
>{{ link.title }}</router-link
|
>{{ link.title }}</router-link
|
||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type PelicanConfig from "@/types/PelicanConfig";
|
||||||
import type LinkList from "@/types/LinkList";
|
import type LinkList from "@/types/LinkList";
|
||||||
import type JdrConfig from "@/types/JdrConfig";
|
import type JdrConfig from "@/types/JdrConfig";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { cloneDeep } from "lodash";
|
||||||
|
|
||||||
export const useConfigStore = defineStore("config", () => {
|
export const useConfigStore = defineStore("config", () => {
|
||||||
const config = ref(null as PelicanConfig | null);
|
const config = ref(null as PelicanConfig | null);
|
||||||
|
@ -12,11 +13,31 @@ export const useConfigStore = defineStore("config", () => {
|
||||||
const sidebar = ref([{ id: 0, links: [] }] as LinkList[]);
|
const sidebar = ref([{ id: 0, links: [] }] as LinkList[]);
|
||||||
|
|
||||||
function computeSidebar() {
|
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) {
|
function setConfig(newConfig: PelicanConfig) {
|
||||||
config.value = newConfig;
|
config.value = newConfig;
|
||||||
|
sidebar.value = computeSidebar();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadJdr(newJdr: string) {
|
function loadJdr(newJdr: string) {
|
||||||
|
@ -43,7 +64,9 @@ export const useConfigStore = defineStore("config", () => {
|
||||||
if (isJdrLoaded()) {
|
if (isJdrLoaded()) {
|
||||||
return sidebar.value;
|
return sidebar.value;
|
||||||
} else {
|
} else {
|
||||||
return config.value?.jdr ?? [{ id: 0, links: [] }];
|
return (
|
||||||
|
config.value?.jdr?.sort((a, b) => a.id - b.id) ?? [{ id: 0, links: [] }]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
src/types/HideLink.ts
Normal file
4
src/types/HideLink.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export default interface HideLink {
|
||||||
|
menu: number;
|
||||||
|
link: string;
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
|
import type HideLink from "./HideLink";
|
||||||
import type LinkList from "./LinkList";
|
import type LinkList from "./LinkList";
|
||||||
|
|
||||||
export default interface JdrConfig {
|
export default interface JdrConfig {
|
||||||
name: string;
|
name: string;
|
||||||
sidebar: LinkList[];
|
sidebar: LinkList[];
|
||||||
|
hideLinks: HideLink[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export default interface Link {
|
export default interface Link {
|
||||||
title: string;
|
title: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
isHidden?: boolean;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue