{"version":3,"file":"formSchemaStore.mjs","sources":["../../../../lib/data-provider-interface/store/modules/formSchemaStore.ts"],"sourcesContent":["// @ts-nocheck\n/* eslint-disable no-param-reassign, no-shadow, no-console */\nimport { isEmpty } from 'lodash-es';\n\n// external translation method\nimport translate from '../../utils/translation-helper';\n\nconst state = {\n    schema: {\n        datasets: {},\n        distributions: {},\n        catalogues: {}\n    },\n    usersCatalogs: {}\n};\n\nconst getters = {\n    getSchema: (state) => (property) => {     \n        return state.schema[property];\n    },\n};\n\nconst actions = {\n    /**\n     * Commits page properties and related DCATAP property definitions for current view for later building of schema\n     * @param {Object} param0\n     * @param {Object} param1 Object containing property (datasets/catalogues), page (step1/step2/step3) and subpage (distribution1/distribution2/distribution3) of current view\n     */\n    createSchema({ commit, state, rootGetters }, { property, page }) {\n\n        const dpiConfig = rootGetters['dpiStore/getSpecification'];\n        const pageProperties = dpiConfig.pageConent[property][page]\n        const propertyDefinitions = dpiConfig.inputDefinition[property]\n        commit('extractSchema', { pageProperties, propertyDefinitions, property, page });\n\n    },\n    /**\n     * Calls mutation function for translating translatable properties of schema\n     * @param {*} param0\n     */\n    translateSchema({ commit }, { property, page }) {\n\n        commit('translateSchemaProperties', { property, page });\n    },\n    /**\n     * Commits current property and users catalogs to mutation function\n     * @param {*} param0\n     * @param {*} param1 Object containing curren tproperty (datasets/catalogues) and all catalog options the user has permissions for\n     */\n    addCatalogOptions({ commit }, { property, catalogs }) {\n        commit('saveCatalogOptions', { property, catalogs });\n    },\n};\n\nconst mutations = {\n    /**\n     * Builds schema based on given pageProperties and their definitions provided by propertyDefinition\n     * @param {Object} state\n     * @param {Object} param1 Object containing the properties which should be displayed within the view\n     * (pageProperties) and the form definitions of the properties defined by DCATAP (propertyDefinition)\n     */\n    extractSchema(state, { pageProperties, propertyDefinitions, property, page }) {\n        // important: create new empty schema each time so already existing schema will be overwritten on route/view-change\n        const newSchema = [];\n\n        for (let index = 0; index < pageProperties.length; index += 1) {\n            const propertyKey = pageProperties[index];\n            try {\n                newSchema.push(propertyDefinitions[propertyKey]);\n            } catch (err) {\n                console.warn(`DCATAP doens't include a property called: ${propertyKey}`);\n            }\n        }\n\n        state.schema[property][page] = newSchema;\n    },\n    /**\n     * All translatable properties within the existing schema will be translated and added to the schema\n     * @param {*} state\n     * @param {String} property String defining current property (datasets/ distribution/ catalogues)\n     */\n    translateSchemaProperties(state, { property, page }) {\n        translate(state.schema[property][page], property);\n    },\n    /**\n     * Saves all catalogs the current user has permissions for as options within the schema\n     * @param {*} state\n     * @param {*} param1 Object containing current property and the users catalog options\n     */\n    saveCatalogOptions(state, { property, catalogs }) {\n        if (property === 'datasets') {\n\n            let catalogSchema;\n            for (let key in state.schema[property]) {\n                const currentSchema = state.schema[property][key].filter(dataset => dataset.name === \"dcat:catalog\");\n                if (!isEmpty(currentSchema)) catalogSchema = currentSchema[0];\n            }\n\n            if (!isEmpty(catalogSchema)) {\n                const catalogOptions = {};\n                for (let index = 0; index < catalogs.length; index += 1) {\n                    const value = catalogs[index];\n                    catalogOptions[value] = value;\n                }\n                catalogSchema.options = catalogOptions;\n            }\n        }\n    },\n};\n\nconst formModule = {\n    state,\n    getters,\n    actions,\n    mutations\n};\n\nexport default formModule;\n"],"names":["state","getters","property","actions","commit","rootGetters","page","dpiConfig","pageProperties","propertyDefinitions","catalogs","mutations","newSchema","index","propertyKey","translate","catalogSchema","key","currentSchema","dataset","isEmpty","catalogOptions","value","formModule"],"mappings":";;AAOA,MAAMA,IAAQ;AAAA,EACV,QAAQ;AAAA,IACJ,UAAU,CAAC;AAAA,IACX,eAAe,CAAC;AAAA,IAChB,YAAY,CAAC;AAAA,EACjB;AAAA,EACA,eAAe,CAAC;AACpB,GAEMC,IAAU;AAAA,EACZ,WAAW,CAACD,MAAU,CAACE,MACZF,EAAM,OAAOE,CAAQ;AAEpC,GAEMC,IAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMZ,aAAa,EAAE,QAAAC,GAAQ,OAAAJ,GAAO,aAAAK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