@piveau/piveau-hub-ui-modules 4.0.25 → 4.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configurations/configureModules.mjs +3 -3
- package/dist/configurations/configureModules.mjs.map +1 -1
- package/dist/data-provider-interface/components/FileUpload.vue.mjs +43 -41
- package/dist/data-provider-interface/components/FileUpload.vue.mjs.map +1 -1
- package/dist/data-provider-interface/utils/general-helper.mjs +63 -62
- package/dist/data-provider-interface/utils/general-helper.mjs.map +1 -1
- package/dist/data-provider-interface/utils/translation-helper.mjs +12 -12
- package/dist/data-provider-interface/utils/translation-helper.mjs.map +1 -1
- package/dist/piveau-hub-ui-modules.css +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general-helper.mjs","sources":["../../../lib/data-provider-interface/utils/general-helper.js"],"sourcesContent":["import { isEmpty, isNil, has } from 'lodash';\nimport axios from 'axios';\nimport { getTranslationFor } from \"../../utils/helpers\";\n\n\n/**\n * Merges multiple Objects nested within an object into one main objects with al key-value-pairs originally located within the nested objects\n * @param {Object} data Object containing nested objects\n * @returns Object with key-value pairs merged from nested objects\n */\nfunction mergeNestedObjects(data) {\n let mergedObject = {};\n for (const key in data) {\n mergedObject = Object.assign(mergedObject, data[key]);\n }\n return mergedObject;\n}\n\n/**\n *\n * @param {*} prefix\n * @returns\n */\nfunction addNamespace(prefix, dpiConfig) {\n // the prefix had the following format: namespace:property (e.g. dct:title)\n // the short version of the namespace noe should be replaced by the long version (e.g. http://purl.org/dc/terms/title)\n let fullDescriptor;\n const colonIndex = prefix.indexOf(':');\n\n // there are also prefixes with no namespace which should sty the same\n if (colonIndex !== -1) {\n const namespaceAbbreviation = prefix.substr(0,colonIndex);\n const propertyName = prefix.substr(colonIndex + 1);\n\n // the long version of the namespace is saved within the context.json (config)\n // there is an object containing the namespace abbreviation(key) and the corresponding value is the long version of the namespace\n\n const longNamespace = dpiConfig.prefixes[namespaceAbbreviation];\n fullDescriptor = `${longNamespace}${propertyName}`;\n } else {\n fullDescriptor = prefix;\n }\n\n return fullDescriptor;\n}\n\n/**\n * Removes long namespace and replaces it with the abbreviation of the namespace\n * @param {*} longValue Long value with long namespace (e.g. https://....#type)\n * @returns Returns value with short namespace (e.g. rdf:type)\n */\nfunction removeNamespace(longValue, dpiConfig) {\n let lastIndex;\n\n // long namespace either ends with an # or a \\\n if (longValue.includes('#')) {\n lastIndex = longValue.lastIndexOf('#')\n } else {\n lastIndex = longValue.lastIndexOf('/')\n }\n\n const shortValue = longValue.substr(lastIndex + 1);\n const longPrefix = longValue.substr(0, lastIndex + 1);\n const shortPrefix = Object.keys(dpiConfig.prefixes).find(key => dpiConfig.prefixes[key] === longPrefix);\n\n return `${shortPrefix}:${shortValue}`;\n}\n\n/**\n * Returns list of keys as shortned version from given data\n * @param {*} data An array of quads with keys as predicate\n * @returns Array of shortened keys\n */\nfunction getNestedKeys(data, dpiConfig) {\n const keys = [];\n\n for (let el of data) {\n keys.push(removeNamespace(el.predicate.value, dpiConfig));\n }\n\n return keys;\n}\n\n/**\n * Creates a random string\n * @param {*} length Length of string to be created\n * @returns String formed of random characters with given length\n */\nfunction makeId(length) {\n var result = '';\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n var charactersLength = characters.length;\n for ( var i = 0; i < length; i++ ) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n return result;\n}\n\n/**\n * Methods checks if given string is an Url\n * @param {*} string String to test\n * @returns Boolean determining if given string is an Url\n */\nfunction isUrl(string) {\n let url;\n try {\n url = new URL(string);\n } catch (_) {\n return false;\n }\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n}\n\n/**\n * Fetches data from given endpoint using token and returns data\n * @param {*} url Endpoint from where to fetch the data\n * @param {*} token User token for authentication (if needed)\n * @returns Returns promise of fetched data\n */\nasync function fetchLinkedData(endpoint, token) {\n let response;\n let requestOptions;\n\n // if token is given, provide token (for drafts and other non-public elements)\n if (token !== '') {\n requestOptions = {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token}`,\n },\n url: endpoint,\n };\n } else {\n requestOptions = {\n method: 'GET',\n url: endpoint,\n };\n }\n\n try {\n response = fetch(endpoint, requestOptions)\n .then(response => {\n const reader = response?.body?.getReader();\n return new ReadableStream({\n start(controller) {\n // The following function handles each data chunk\n function push() {\n // \"done\" is a Boolean and value a \"Uint8Array\"\n reader?.read().then(({done, value}) => {\n // If there is no more data to read\n if (done) {\n controller.close();\n return;\n }\n // Get the data and send it to the browser via the controller\n controller.enqueue(value);\n // Check chunks by logging to the console\n push();\n });\n }\n\n push();\n },\n });\n }).then((stream) =>\n new Response(stream, {headers: {'Content-Type': 'text/html'}}).text()\n );\n } catch (err) {\n // TODO: Handle (network) errors\n throw Error(`Error occured during fetching endpoint: ${endpoint}`);\n }\n return response;\n}\n\n/**\n * Exracts keynames (e.g. dct:title) using the page-content-config for each element\n * @param {*} property Property (datasets/distributions/catalogues)\n * @param {*} formDefinitions Form definition of properties including name\n * @param {*} pageContent Config file containing definition of which property will be displayed on which page\n * @returns Object containing keys of properties for each page\n */\nfunction getPagePrefixedNames(property, formDefinitions, pageContent) {\n\n const prefixedNames = {\n datasets: {},\n distributions: {},\n catalogues: {}\n };\n\n // get property keys for each page\n for (let pageName in pageContent[property]) {\n prefixedNames[property][pageName] = [];\n const propertyKeys = pageContent[property][pageName];\n for (let propertyindex = 0; propertyindex < propertyKeys.length; propertyindex++) {\n const propertyName = propertyKeys[propertyindex];\n const prefixedName = formDefinitions[property][propertyName].name; // form definition includes name-property which contains key\n if (prefixedName !== undefined) prefixedNames[property][pageName].push(prefixedName);\n }\n }\n\n return prefixedNames;\n}\n\nfunction isValid(id) {\n return /^[a-z0-9-]*$/.test(id);\n}\n\n/**\n * Get file id from accessUrl, if it is a file upload url.\n * accessUrls are file upload urls, iff they start with fileUploadUrl.\n * @param {string} accessUrl\n * @param {string} fileUploadUrl\n * @returns {string|null}\n */\nfunction getFileIdByAccessUrl({ accessUrl, fileUploadUrl }) {\n const accessUrlWithTrailingSlash = accessUrl.endsWith('/')\n ? accessUrl\n : `${accessUrl}/`;\n const fileUploadUrlWithTrailingSlash = fileUploadUrl.endsWith('/')\n ? fileUploadUrl\n : `${fileUploadUrl}/`;\n\n // Check if accessUrl starts with fileUploadApi\n if (accessUrlWithTrailingSlash.startsWith(fileUploadUrlWithTrailingSlash)) {\n const accessUrlParts = accessUrlWithTrailingSlash.split('/');\n const fileId = accessUrlParts[accessUrlParts.length - 2];\n\n return fileId || null;\n }\n\n return null;\n}\n\n/**\n * Adds given key to format type \n * @param {String} key \n * @param {String} format \n * @param {String} property \n * @param {Object} typeDefinition \n */\nfunction addKeyToFormatType(key, format, property, typeDefinition) {\n typeDefinition[format][property].push(key);\n}\n\n/**\n * Removes key from format type\n * @param {String} key \n * @param {String} format \n * @param {String} property \n * @param {Object} typeDefinition \n */\nfunction removeKeyFromFormatType(key, format, property, typeDefinition) {\n typeDefinition[format][property].splice(typeDefinition[format][property].indexOf(key), 1);\n}\n\nfunction propertyObjectHasValues(objectData) {\n let objectHasValues = false;\n\n if (!isNil(objectData) && !isEmpty(objectData)) {\n // language tag is always given\n if (has(objectData, '@language')) {\n delete objectData['@language'];\n }\n\n // removing all falsy values (undefined, null, \"\", '', NaN, 0)\n const actualValues = Object.values(objectData).filter(el => el); // filters all real values\n if (!isEmpty(actualValues)) {\n // there are keys containing an object or array as value\n for (let valueIndex = 0; valueIndex < actualValues.length; valueIndex++) {\n // if at least one elemnt within the array is set, return true\n const currentValue = actualValues[valueIndex];\n\n // testing content of array\n if (Array.isArray(currentValue)) {\n // there are only objects wihtin those arrays\n for (let arrIndex = 0; arrIndex < currentValue.length; arrIndex++) {\n if (propertyObjectHasValues(currentValue[arrIndex])) objectHasValues = true;\n }\n } else if (typeof currentValue === 'object') { // testing content of object\n if (propertyObjectHasValues(currentValue)) objectHasValues = true;\n } else {\n objectHasValues = true;\n }\n }\n }\n }\n\n return objectHasValues;\n}\n\nfunction propertyHasValue(data) {\n\n let isSet = false;\n\n if (data !== undefined && data !== \"\" && !isEmpty(data) && !isNil(data)) {\n // testing array data\n if (Array.isArray(data)) {\n // there are arreay of objects or arrays of values\n if (data.every(el => typeof el === 'string')) {\n isSet = !isEmpty(data.filter(el => el)); \n } else if (data.every(el => typeof el === 'object')) {\n for (let index = 0; index < data.length; index++) {\n // if at least one array element is set, return true\n if (propertyObjectHasValues(data[index])) isSet = true; \n }\n }\n } else if (typeof data === 'object') {\n // testing object data\n isSet = propertyObjectHasValues(data);\n } else {\n isSet = true;\n }\n }\n\n return isSet;\n}\n\n/**\n * \n */\nasync function requestUriLabel(uri, dpiConfig, envs) {\n\n // get vocabulary by finding vocab-url within given URI\n const voc = Object.keys(dpiConfig.vocabPrefixes).find(key => uri.includes(dpiConfig.vocabPrefixes[key]));\n\n try {\n let req;\n\n // vocabularies for spdx checksum and inana-media-types are structured differently in the backend then other vocabularies\n if (voc === 'iana-media-types' || voc === 'spdx-checksum-algorithm') {\n req = `${envs.api.baseUrl}vocabularies/${voc}`;\n\n } else {\n const value = uri.replace(dpiConfig.vocabPrefixes[voc], '');\n req = `${envs.api.baseUrl}vocabularies/${voc}/${value}`;\n }\n\n return new Promise((resolve, reject) => {\n axios.get(req)\n .then((res) => {\n resolve(res);\n })\n .catch((err) => {\n reject(err);\n\n });\n });\n } catch (error) {\n // \n } \n}\n\n\n/**\n * \n */\nasync function getUriLabel(uri, dpiConfig, locale, envs) {\n let URIlabel;\n\n const voc = Object.keys(dpiConfig.vocabPrefixes).find(key => uri.includes(dpiConfig.vocabPrefixes[key]));\n\n // if vocabulary iana media type or spdx checksum endpoint returns values in a different way\n let vocMatch = (voc === \"iana-media-types\" || voc === \"spdx-checksum-algorithm\");\n\n await requestUriLabel(uri, dpiConfig, envs).then(\n (response) => {\n let result = vocMatch\n ? response.data.result.results\n .filter((dataset) => dataset.resource === uri)\n .map((dataset) => dataset.pref_label)[0].en\n : getTranslationFor(response.data.result.pref_label, locale, []);\n\n URIlabel = result;\n }\n );\n\n return URIlabel;\n}\n\nexport default {\n mergeNestedObjects,\n addNamespace,\n makeId,\n isUrl,\n fetchLinkedData,\n getPagePrefixedNames,\n getNestedKeys,\n removeNamespace,\n getFileIdByAccessUrl,\n addKeyToFormatType,\n removeKeyFromFormatType,\n propertyHasValue,\n getUriLabel,\n};\n"],"names":["mergeNestedObjects","data","mergedObject","key","addNamespace","prefix","dpiConfig","fullDescriptor","colonIndex","namespaceAbbreviation","propertyName","removeNamespace","longValue","lastIndex","shortValue","longPrefix","getNestedKeys","keys","el","makeId","length","result","characters","charactersLength","i","isUrl","string","url","fetchLinkedData","endpoint","token","response","requestOptions","reader","_a","controller","push","done","value","stream","getPagePrefixedNames","property","formDefinitions","pageContent","prefixedNames","pageName","propertyKeys","propertyindex","prefixedName","getFileIdByAccessUrl","accessUrl","fileUploadUrl","accessUrlWithTrailingSlash","fileUploadUrlWithTrailingSlash","accessUrlParts","addKeyToFormatType","format","typeDefinition","removeKeyFromFormatType","propertyObjectHasValues","objectData","objectHasValues","isNil","isEmpty","has","actualValues","valueIndex","currentValue","arrIndex","propertyHasValue","isSet","index","requestUriLabel","uri","envs","voc","req","resolve","reject","axios","res","err","getUriLabel","locale","URIlabel","vocMatch","dataset","getTranslationFor","generalHelper"],"mappings":";;;AAUA,SAASA,EAAmBC,GAAM;AAC9B,MAAIC,IAAe,CAAA;AACnB,aAAWC,KAAOF;AACd,IAAAC,IAAe,OAAO,OAAOA,GAAcD,EAAKE,CAAG,CAAC;AAExD,SAAOD;AACX;AAOA,SAASE,EAAaC,GAAQC,GAAW;AAGrC,MAAIC;AACJ,QAAMC,IAAaH,EAAO,QAAQ,GAAG;AAGrC,MAAIG,MAAe,IAAI;AACnB,UAAMC,IAAwBJ,EAAO,OAAO,GAAEG,CAAU,GAClDE,IAAeL,EAAO,OAAOG,IAAa,CAAC;AAMjD,IAAAD,IAAiB,GADK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,QAAAH,EAAQG,CAAG;AAAA,MAC/B,CAAiB,EACA,MAAM,CAACC,MAAQ;AACZ,QAAAH,EAAOG,CAAG;AAAA,MAE9B,CAAiB;AAAA,IACjB,CAAS;AAAA,EACJ,QAAe;AAAA,EAEf;AACL;AAMA,eAAeC,EAAYT,GAAKnE,GAAW6E,GAAQT,GAAM;AACrD,MAAIU;AAEJ,QAAMT,IAAM,OAAO,KAAKrE,EAAU,aAAa,EAAE,KAAK,CAAAH,MAAOsE,EAAI,SAASnE,EAAU,cAAcH,CAAG,CAAC,CAAC;AAGvG,MAAIkF,IAAYV,MAAQ,sBAAsBA,MAAQ;AAEtD,eAAMH,EAAgBC,GAAKnE,GAAWoE,CAAI,EAAE;AAAA,IACxC,CAAC3C,MAAa;AAOV,MAAAqD,IANaC,IACPtD,EAAS,KAAK,OAAO,QAClB,OAAO,CAACuD,MAAYA,EAAQ,aAAab,CAAG,EAC5C,IAAI,CAACa,MAAYA,EAAQ,UAAU,EAAE,CAAC,EAAE,KAC3CC,EAAkBxD,EAAS,KAAK,OAAO,YAAYoD,GAAQ,CAAA,CAAE;AAAA,IAGtE;AAAA,EACT,GAEWC;AACX;AAEA,MAAeI,IAAA;AAAA,EACX,oBAAAxF;AAAA,EACA,cAAAI;AAAA,EACA,QAAAe;AAAA,EACA,OAAAM;AAAA,EACA,iBAAAG;AAAA,EACA,sBAAAY;AAAA,EACA,eAAAxB;AAAA,EACA,iBAAAL;AAAA,EACA,sBAAAsC;AAAA,EACA,oBAAAM;AAAA,EACA,yBAAAG;AAAA,EACA,kBAAAW;AAAA,EACA,aAAAa;AACJ;"}
|
|
1
|
+
{"version":3,"file":"general-helper.mjs","sources":["../../../lib/data-provider-interface/utils/general-helper.js"],"sourcesContent":["import { isEmpty, isNil, has, cloneDeep } from 'lodash';\nimport axios from 'axios';\nimport { getTranslationFor } from \"../../utils/helpers\";\n\n\n/**\n * Merges multiple Objects nested within an object into one main objects with al key-value-pairs originally located within the nested objects\n * @param {Object} data Object containing nested objects\n * @returns Object with key-value pairs merged from nested objects\n */\nfunction mergeNestedObjects(data) {\n let mergedObject = {};\n for (const key in data) {\n mergedObject = Object.assign(mergedObject, data[key]);\n }\n return mergedObject;\n}\n\n/**\n *\n * @param {*} prefix\n * @returns\n */\nfunction addNamespace(prefix, dpiConfig) {\n // the prefix had the following format: namespace:property (e.g. dct:title)\n // the short version of the namespace noe should be replaced by the long version (e.g. http://purl.org/dc/terms/title)\n let fullDescriptor;\n const colonIndex = prefix.indexOf(':');\n\n // there are also prefixes with no namespace which should sty the same\n if (colonIndex !== -1) {\n const namespaceAbbreviation = prefix.substr(0, colonIndex);\n const propertyName = prefix.substr(colonIndex + 1);\n\n // the long version of the namespace is saved within the context.json (config)\n // there is an object containing the namespace abbreviation(key) and the corresponding value is the long version of the namespace\n\n const longNamespace = dpiConfig.prefixes[namespaceAbbreviation];\n fullDescriptor = `${longNamespace}${propertyName}`;\n } else {\n fullDescriptor = prefix;\n }\n\n return fullDescriptor;\n}\n\n/**\n * Removes long namespace and replaces it with the abbreviation of the namespace\n * @param {*} longValue Long value with long namespace (e.g. https://....#type)\n * @returns Returns value with short namespace (e.g. rdf:type)\n */\nfunction removeNamespace(longValue, dpiConfig) {\n let lastIndex;\n\n // long namespace either ends with an # or a \\\n if (longValue.includes('#')) {\n lastIndex = longValue.lastIndexOf('#')\n } else {\n lastIndex = longValue.lastIndexOf('/')\n }\n\n const shortValue = longValue.substr(lastIndex + 1);\n const longPrefix = longValue.substr(0, lastIndex + 1);\n const shortPrefix = Object.keys(dpiConfig.prefixes).find(key => dpiConfig.prefixes[key] === longPrefix);\n\n return `${shortPrefix}:${shortValue}`;\n}\n\n/**\n * Returns list of keys as shortned version from given data\n * @param {*} data An array of quads with keys as predicate\n * @returns Array of shortened keys\n */\nfunction getNestedKeys(data, dpiConfig) {\n const keys = [];\n\n for (let el of data) {\n keys.push(removeNamespace(el.predicate.value, dpiConfig));\n }\n\n return keys;\n}\n\n/**\n * Creates a random string\n * @param {*} length Length of string to be created\n * @returns String formed of random characters with given length\n */\nfunction makeId(length) {\n var result = '';\n var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n var charactersLength = characters.length;\n for (var i = 0; i < length; i++) {\n result += characters.charAt(Math.floor(Math.random() * charactersLength));\n }\n return result;\n}\n\n/**\n * Methods checks if given string is an Url\n * @param {*} string String to test\n * @returns Boolean determining if given string is an Url\n */\nfunction isUrl(string) {\n let url;\n try {\n url = new URL(string);\n } catch (_) {\n return false;\n }\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n}\n\n/**\n * Fetches data from given endpoint using token and returns data\n * @param {*} url Endpoint from where to fetch the data\n * @param {*} token User token for authentication (if needed)\n * @returns Returns promise of fetched data\n */\nasync function fetchLinkedData(endpoint, token) {\n let response;\n let requestOptions;\n\n // if token is given, provide token (for drafts and other non-public elements)\n if (token !== '') {\n requestOptions = {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token}`,\n },\n url: endpoint,\n };\n } else {\n requestOptions = {\n method: 'GET',\n url: endpoint,\n };\n }\n\n try {\n response = fetch(endpoint, requestOptions)\n .then(response => {\n const reader = response?.body?.getReader();\n return new ReadableStream({\n start(controller) {\n // The following function handles each data chunk\n function push() {\n // \"done\" is a Boolean and value a \"Uint8Array\"\n reader?.read().then(({ done, value }) => {\n // If there is no more data to read\n if (done) {\n controller.close();\n return;\n }\n // Get the data and send it to the browser via the controller\n controller.enqueue(value);\n // Check chunks by logging to the console\n push();\n });\n }\n\n push();\n },\n });\n }).then((stream) =>\n new Response(stream, { headers: { 'Content-Type': 'text/html' } }).text()\n );\n } catch (err) {\n // TODO: Handle (network) errors\n throw Error(`Error occured during fetching endpoint: ${endpoint}`);\n }\n return response;\n}\n\n/**\n * Exracts keynames (e.g. dct:title) using the page-content-config for each element\n * @param {*} property Property (datasets/distributions/catalogues)\n * @param {*} formDefinitions Form definition of properties including name\n * @param {*} pageContent Config file containing definition of which property will be displayed on which page\n * @returns Object containing keys of properties for each page\n */\nfunction getPagePrefixedNames(property, formDefinitions, pageContent) {\n\n const prefixedNames = {\n datasets: {},\n distributions: {},\n catalogues: {}\n };\n\n // get property keys for each page\n for (let pageName in pageContent[property]) {\n prefixedNames[property][pageName] = [];\n const propertyKeys = pageContent[property][pageName];\n for (let propertyindex = 0; propertyindex < propertyKeys.length; propertyindex++) {\n const propertyName = propertyKeys[propertyindex];\n const prefixedName = formDefinitions[property][propertyName].name; // form definition includes name-property which contains key\n if (prefixedName !== undefined) prefixedNames[property][pageName].push(prefixedName);\n }\n }\n\n return prefixedNames;\n}\n\nfunction isValid(id) {\n return /^[a-z0-9-]*$/.test(id);\n}\n\n/**\n * Get file id from accessUrl, if it is a file upload url.\n * accessUrls are file upload urls, iff they start with fileUploadUrl.\n * @param {string} accessUrl\n * @param {string} fileUploadUrl\n * @returns {string|null}\n */\nfunction getFileIdByAccessUrl({ accessUrl, fileUploadUrl }) {\n const accessUrlWithTrailingSlash = accessUrl.endsWith('/')\n ? accessUrl\n : `${accessUrl}/`;\n const fileUploadUrlWithTrailingSlash = fileUploadUrl.endsWith('/')\n ? fileUploadUrl\n : `${fileUploadUrl}/`;\n\n // Check if accessUrl starts with fileUploadApi\n if (accessUrlWithTrailingSlash.startsWith(fileUploadUrlWithTrailingSlash)) {\n const accessUrlParts = accessUrlWithTrailingSlash.split('/');\n const fileId = accessUrlParts[accessUrlParts.length - 2];\n\n return fileId || null;\n }\n\n return null;\n}\n\n/**\n * Adds given key to format type \n * @param {String} key \n * @param {String} format \n * @param {String} property \n * @param {Object} typeDefinition \n */\nfunction addKeyToFormatType(key, format, property, typeDefinition) {\n typeDefinition[format][property].push(key);\n}\n\n/**\n * Removes key from format type\n * @param {String} key \n * @param {String} format \n * @param {String} property \n * @param {Object} typeDefinition \n */\nfunction removeKeyFromFormatType(key, format, property, typeDefinition) {\n typeDefinition[format][property].splice(typeDefinition[format][property].indexOf(key), 1);\n}\n\nfunction propertyObjectHasValues(objectData) {\n let objectHasValues = false;\n if (!isNil(objectData) && !isEmpty(objectData)) {\n // language tag is always given\n let copiedData = cloneDeep(objectData)\n\n if (has(copiedData, '@language')) {\n delete copiedData['@language'];\n }\n\n // removing all falsy values (undefined, null, \"\", '', NaN, 0)\n const actualValues = Object.values(copiedData).filter(el => el); // filters all real values\n if (!isEmpty(actualValues)) {\n // there are keys containing an object or array as value\n for (let valueIndex = 0; valueIndex < actualValues.length; valueIndex++) {\n // if at least one elemnt within the array is set, return true\n const currentValue = actualValues[valueIndex];\n\n // testing content of array\n if (Array.isArray(currentValue)) {\n // there are only objects wihtin those arrays\n for (let arrIndex = 0; arrIndex < currentValue.length; arrIndex++) {\n if (propertyObjectHasValues(currentValue[arrIndex])) objectHasValues = true;\n }\n } else if (typeof currentValue === 'object') { // testing content of object\n if (propertyObjectHasValues(currentValue)) objectHasValues = true;\n } else {\n objectHasValues = true;\n }\n }\n }\n }\n\n return objectHasValues;\n}\n\nfunction propertyHasValue(data) {\n\n let isSet = false;\n\n if (data !== undefined && data !== \"\" && !isEmpty(data) && !isNil(data)) {\n // testing array data\n if (Array.isArray(data)) {\n // there are arreay of objects or arrays of values\n if (data.every(el => typeof el === 'string')) {\n isSet = !isEmpty(data.filter(el => el));\n } else if (data.every(el => typeof el === 'object')) {\n for (let index = 0; index < data.length; index++) {\n // if at least one array element is set, return true\n if (propertyObjectHasValues(data[index])) isSet = true;\n }\n }\n } else if (typeof data === 'object') {\n // testing object data\n isSet = propertyObjectHasValues(data);\n } else {\n isSet = true;\n }\n }\n\n return isSet;\n}\n\n/**\n * \n */\nasync function requestUriLabel(uri, dpiConfig, envs) {\n\n // get vocabulary by finding vocab-url within given URI\n const voc = Object.keys(dpiConfig.vocabPrefixes).find(key => uri.includes(dpiConfig.vocabPrefixes[key]));\n\n try {\n let req;\n\n // vocabularies for spdx checksum and inana-media-types are structured differently in the backend then other vocabularies\n if (voc === 'iana-media-types' || voc === 'spdx-checksum-algorithm') {\n req = `${envs.api.baseUrl}vocabularies/${voc}`;\n\n } else {\n const value = uri.replace(dpiConfig.vocabPrefixes[voc], '');\n req = `${envs.api.baseUrl}vocabularies/${voc}/${value}`;\n }\n\n return new Promise((resolve, reject) => {\n axios.get(req)\n .then((res) => {\n resolve(res);\n })\n .catch((err) => {\n reject(err);\n\n });\n });\n } catch (error) {\n // \n }\n}\n\n\n/**\n * \n */\nasync function getUriLabel(uri, dpiConfig, locale, envs) {\n let URIlabel;\n\n const voc = Object.keys(dpiConfig.vocabPrefixes).find(key => uri.includes(dpiConfig.vocabPrefixes[key]));\n\n // if vocabulary iana media type or spdx checksum endpoint returns values in a different way\n let vocMatch = (voc === \"iana-media-types\" || voc === \"spdx-checksum-algorithm\");\n\n await requestUriLabel(uri, dpiConfig, envs).then(\n (response) => {\n let result = vocMatch\n ? response.data.result.results\n .filter((dataset) => dataset.resource === uri)\n .map((dataset) => dataset.pref_label)[0].en\n : getTranslationFor(response.data.result.pref_label, locale, []);\n\n URIlabel = result;\n }\n );\n\n return URIlabel;\n}\n\nexport default {\n mergeNestedObjects,\n addNamespace,\n makeId,\n isUrl,\n fetchLinkedData,\n getPagePrefixedNames,\n getNestedKeys,\n removeNamespace,\n getFileIdByAccessUrl,\n addKeyToFormatType,\n removeKeyFromFormatType,\n propertyHasValue,\n getUriLabel,\n};\n"],"names":["mergeNestedObjects","data","mergedObject","key","addNamespace","prefix","dpiConfig","fullDescriptor","colonIndex","namespaceAbbreviation","propertyName","removeNamespace","longValue","lastIndex","shortValue","longPrefix","getNestedKeys","keys","el","makeId","length","result","characters","charactersLength","i","isUrl","string","url","fetchLinkedData","endpoint","token","response","requestOptions","reader","_a","controller","push","done","value","stream","getPagePrefixedNames","property","formDefinitions","pageContent","prefixedNames","pageName","propertyKeys","propertyindex","prefixedName","getFileIdByAccessUrl","accessUrl","fileUploadUrl","accessUrlWithTrailingSlash","fileUploadUrlWithTrailingSlash","accessUrlParts","addKeyToFormatType","format","typeDefinition","removeKeyFromFormatType","propertyObjectHasValues","objectData","objectHasValues","isNil","isEmpty","copiedData","cloneDeep","has","actualValues","valueIndex","currentValue","arrIndex","propertyHasValue","isSet","index","requestUriLabel","uri","envs","voc","req","resolve","reject","axios","res","err","getUriLabel","locale","URIlabel","vocMatch","dataset","getTranslationFor","generalHelper"],"mappings":";;;AAUA,SAASA,EAAmBC,GAAM;AAC9B,MAAIC,IAAe,CAAA;AACnB,aAAWC,KAAOF;AACd,IAAAC,IAAe,OAAO,OAAOA,GAAcD,EAAKE,CAAG,CAAC;AAExD,SAAOD;AACX;AAOA,SAASE,EAAaC,GAAQC,GAAW;AAGrC,MAAIC;AACJ,QAAMC,IAAaH,EAAO,QAAQ,GAAG;AAGrC,MAAIG,MAAe,IAAI;AACnB,UAAMC,IAAwBJ,EAAO,OAAO,GAAGG,CAAU,GACnDE,IAAeL,EAAO,OAAOG,IAAa,CAAC;AAMjD,IAAAD,IAAiB,GADKD,EAAU,SAASG,CAAqB,CAC7B,GAAGC,CAAY;AAAA,EACxD;AACQ,IAAAH,IAAiBF;AAGrB,SAAOE;AACX;AAOA,SAASI,EAAgBC,GAAWN,GAAW;AAC3C,MAAIO;AAGJ,EAAID,EAAU,SAAS,GAAG,IACtBC,IAAYD,EAAU,YAAY,GAAG,IAErCC,IAAYD,EAAU,YAAY,GAAG;AAGzC,QAAME,IAAaF,EAAU,OAAOC,IAAY,CAAC,GAC3CE,IAAaH,EAAU,OAAO,GAAGC,IAAY,CAAC;AAGpD,SAAO,GAFa,OAAO,KAAKP,EAAU,QAAQ,EAAE,KAAK,CAAAH,MAAOG,EAAU,SAASH,CAAG,MAAMY,CAAU,CAEjF,IAAID,CAAU;AACvC;AAOA,SAASE,EAAcf,GAAMK,GAAW;AACpC,QAAMW,IAAO,CAAA;AAEb,WAASC,KAAMjB;AACX,IAAAgB,EAAK,KAAKN,EAAgBO,EAAG,UAAU,OAAOZ,CAAS,CAAC;AAG5D,SAAOW;AACX;AAOA,SAASE,EAAOC,GAAQ;AAIpB,WAHIC,IAAS,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sD,GAAQ,CAAA,CAAE;AAAA,IAGtE;AAAA,EACT,GAEWC;AACX;AAEA,MAAeI,IAAA;AAAA,EACX,oBAAA1F;AAAA,EACA,cAAAI;AAAA,EACA,QAAAe;AAAA,EACA,OAAAM;AAAA,EACA,iBAAAG;AAAA,EACA,sBAAAY;AAAA,EACA,eAAAxB;AAAA,EACA,iBAAAL;AAAA,EACA,sBAAAsC;AAAA,EACA,oBAAAM;AAAA,EACA,yBAAAG;AAAA,EACA,kBAAAa;AAAA,EACA,aAAAa;AACJ;"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { has as c, isObject as
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
const l =
|
|
1
|
+
import { has as c, isObject as i } from "lodash-es";
|
|
2
|
+
import r from "../../store/index.mjs";
|
|
3
|
+
function m(a, s) {
|
|
4
|
+
const l = r.$app.config.globalProperties.i18n.global;
|
|
5
5
|
if (c(a, "identifier")) {
|
|
6
|
-
const e = ["label", "info", "help", "placeholder", "add-label"],
|
|
6
|
+
const e = ["label", "info", "help", "placeholder", "add-label"], o = a.identifier;
|
|
7
7
|
for (let d = 0; d < e.length; d += 1) {
|
|
8
|
-
let
|
|
9
|
-
const t = e[d], $ = l.te(`message.dataupload.${s}.${
|
|
10
|
-
c(s, t) || ($ ?
|
|
8
|
+
let n = o;
|
|
9
|
+
const t = e[d], $ = l.te(`message.dataupload.${s}.${o}.${t}`), f = l.te(`message.dataupload.${s}.${o}.${t}`, "en");
|
|
10
|
+
c(s, t) || ($ ? n = l.t(`message.dataupload.${s}.${o}.${t}`) : f ? n = l.t(`message.dataupload.${s}.${o}.${t}`, "en") : n = t, !!a.$cmp && !a.$formkit && i(a.props) && a.$cmp === "SelectControlledGroup" ? a.props[t] = n : a[t] = n), a.mandatory && t === "label" && (a[t] = `${n}*`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -18,10 +18,10 @@ function u(a, s) {
|
|
|
18
18
|
m(e, s), u(e.children, s);
|
|
19
19
|
else if (c(e, "data")) {
|
|
20
20
|
m(e, s);
|
|
21
|
-
const
|
|
22
|
-
for (let d = 0; d <
|
|
23
|
-
const
|
|
24
|
-
u(e.data[
|
|
21
|
+
const o = Object.keys(e.data);
|
|
22
|
+
for (let d = 0; d < o.length; d += 1) {
|
|
23
|
+
const n = o[d];
|
|
24
|
+
u(e.data[n], s);
|
|
25
25
|
}
|
|
26
26
|
} else
|
|
27
27
|
m(e, s);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-helper.mjs","sources":["../../../lib/data-provider-interface/utils/translation-helper.js"],"sourcesContent":["import { has, isObject } from 'lodash-es';\nimport
|
|
1
|
+
{"version":3,"file":"translation-helper.mjs","sources":["../../../lib/data-provider-interface/utils/translation-helper.js"],"sourcesContent":["import { has, isObject } from 'lodash-es';\nimport store from '../../store';\n\n/**\n * Translation of each translatable parameter within the given structure if a translation is available\n * @param {*} propertyDefinition Object containing parameters defining the form and their content\n * @param {String} property String defining which property translation should be used\n */\n\nfunction translateProperty(propertyDefinition, property) {\n\n const i18n = store.$app.config.globalProperties.i18n.global;\n if (has(propertyDefinition, 'identifier')) { // hidden fields don't need a label and have no identifier\n const translatableParameters = ['label', 'info', 'help', 'placeholder', 'add-label'];\n const propertyName = propertyDefinition.identifier;\n\n for (let valueIndex = 0; valueIndex < translatableParameters.length; valueIndex += 1) {\n let translation = propertyName;\n const parameter = translatableParameters[valueIndex];\n\n const translationExsists = i18n.te(`message.dataupload.${property}.${propertyName}.${parameter}`);\n const translationExsistsEN = i18n.te(`message.dataupload.${property}.${propertyName}.${parameter}`, 'en');\n\n // Check if translation exists\n if (!has(property, parameter)) {\n if (translationExsists) {\n translation = i18n.t(`message.dataupload.${property}.${propertyName}.${parameter}`);\n } else if (translationExsistsEN) {\n translation = i18n.t(`message.dataupload.${property}.${propertyName}.${parameter}`, 'en');\n } else {\n translation = parameter;\n }\n\n const isCustomComponentWithProps = !!propertyDefinition.$cmp\n && !propertyDefinition.$formkit\n && isObject(propertyDefinition.props);\n\n const isSelectControlledGroupCustomComponent = isCustomComponentWithProps\n && propertyDefinition.$cmp === 'SelectControlledGroup';\n\n if (isSelectControlledGroupCustomComponent) {\n propertyDefinition.props[parameter] = translation;\n } else {\n propertyDefinition[parameter] = translation;\n }\n\n // if (parameter === \"info\") {\n\n // propertyDefinition['sections-schema'] = { prefix: { $el: 'div', attrs: { class: 'infoI', }, children: [{ $el: 'div', children: translation, attrs: { class: 'tooltipFormkit' } }] } }\n // }\n }\n\n // Highlight mandatory fields\n if (propertyDefinition.mandatory && parameter === \"label\") propertyDefinition[parameter] = `${translation}*`\n }\n }\n}\n\n/**\n * Recursive translation of propertie parameters including recursive translation of nested properties\n * @param {Object} schema Object containing the forms schema\n * @param {String} property String defining which property translation should be used (datasets/ distribution/ catalogues)\n */\nfunction translate(schema, property) {\n for (let index = 0; index < schema.length; index += 1) {\n const schemaPropertyValues = schema[index];\n\n // translation of group forms and their nested properties\n if (has(schemaPropertyValues, 'children')) {\n // group attributes should be translated too\n translateProperty(schemaPropertyValues, property);\n // translated nested properties\n translate(schemaPropertyValues.children, property);\n // translation of conditional forms and their nested properties\n } else if (has(schemaPropertyValues, 'data')) {\n // group attributes should be translated too\n translateProperty(schemaPropertyValues, property);\n // translate nested data\n const dataKeys = Object.keys(schemaPropertyValues.data);\n for (let keyIndex = 0; keyIndex < dataKeys.length; keyIndex += 1) {\n const currentKey = dataKeys[keyIndex];\n translate(schemaPropertyValues.data[currentKey], property);\n }\n // translation of 'normal' singular form properties\n } else {\n translateProperty(schemaPropertyValues, property);\n }\n }\n}\n\nexport default translate;\n"],"names":["translateProperty","propertyDefinition","property","i18n","store","has","translatableParameters","propertyName","valueIndex","translation","parameter","translationExsists","translationExsistsEN","isObject","translate","schema","index","schemaPropertyValues","dataKeys","keyIndex","currentKey"],"mappings":";;AASA,SAASA,EAAkBC,GAAoBC,GAAU;AAErD,QAAMC,IAAOC,EAAM,KAAK,OAAO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