From 902b39c04cf536a083d8e548ac6858c73e22f973 Mon Sep 17 00:00:00 2001 From: Vinzenz Rosenkranz Date: Fri, 29 Nov 2024 11:23:56 +0100 Subject: [PATCH] fix plugin stores Signed-off-by: Vinzenz Rosenkranz --- resources/js/bootstrap/plugins.js | 2 ++ resources/js/bootstrap/stores/system.js | 8 ++++++-- resources/js/helpers/helpers.js | 4 +--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/resources/js/bootstrap/plugins.js b/resources/js/bootstrap/plugins.js index 9e8d7acc6..57c79d3e5 100644 --- a/resources/js/bootstrap/plugins.js +++ b/resources/js/bootstrap/plugins.js @@ -1,5 +1,6 @@ import { only } from '@/helpers/helpers'; import useSystemStore from './stores/system.js'; +import useEntityStore from './stores/entity.js'; import i18n from './i18n.js'; import { router, @@ -126,6 +127,7 @@ export const SpPS = { SpPS.data.app = app; SpPS.data.t = t; SpPS.api.store.systemStore = useSystemStore(); + SpPS.api.store.entityStore = useEntityStore(); }, registerI18n: (id, messages) => { for(let k in messages) { diff --git a/resources/js/bootstrap/stores/system.js b/resources/js/bootstrap/stores/system.js index 9ac286f75..ceb190534 100644 --- a/resources/js/bootstrap/stores/system.js +++ b/resources/js/bootstrap/stores/system.js @@ -30,6 +30,7 @@ import { } from '@/open_api.js'; import { + only, slugify, } from '@/helpers/helpers.js'; @@ -105,6 +106,9 @@ export const useSystemStore = defineStore('system', { hasPlugin: state => nameId => { return state.plugins.some(plugin => plugin.name == nameId); }, + getPluginStore: state => id => { + return state.pluginStores[id] ? state.pluginStores[id]() : {}; + }, getSlotPlugins: state => slot => { const plugins = state.registeredPluginSlots; return slot ? plugins[slot] : plugins; @@ -121,13 +125,13 @@ export const useSystemStore = defineStore('system', { addCachedConceptSelection(data) { this.cachedConceptSelections[data.id] = data.selection; }, - addPluginStore(id, storeFn) { + addPluginStore(id, store) { if(this.pluginStores[id]) { console.error(`A Plugin with id="${id}" already registered a store!`); return; } - this.pluginStores[id] = storeFn(); + this.pluginStores[id] = defineStore(`plugin_${id}`, store); }, async initialize(locale) { resetState(this); diff --git a/resources/js/helpers/helpers.js b/resources/js/helpers/helpers.js index 84808ed66..3a27800bf 100644 --- a/resources/js/helpers/helpers.js +++ b/resources/js/helpers/helpers.js @@ -157,9 +157,7 @@ export function getConceptLabel(concept) { } export function translateEntityType(id) { - console.error("Re-Implement translateEntityType(id) due to missing getEntityType(id) method"); - return; - // return translateConcept(getEntityType(id).thesaurus_url); + return translateConcept(useEntityStore().getEntityType(id).thesaurus_url); } export function getEntityTypeAttributes(id, exclude = false) {