Skip to content

Commit

Permalink
fix plugin stores
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Rosenkranz <[email protected]>
  • Loading branch information
v1r0x committed Nov 29, 2024
1 parent 2e88e45 commit 902b39c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions resources/js/bootstrap/plugins.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions resources/js/bootstrap/stores/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '@/open_api.js';

import {
only,
slugify,
} from '@/helpers/helpers.js';

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions resources/js/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 902b39c

Please sign in to comment.