mirror of
https://github.com/salexdv/bsl_console.git
synced 2025-02-01 13:08:06 +02:00
Обновление метаданных с указанием адреса (пути) обновления, что позволит обновлять не все объекты целиком, а даже отдельные блоки конкретного объекта
This commit is contained in:
parent
7c9ceefe1b
commit
2232ab5b45
@ -482,6 +482,53 @@ class bslHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the object contains properties from array
|
||||
*
|
||||
* @param {object} obj the object for checking
|
||||
* @param {array} props array of properties
|
||||
*
|
||||
* @returns {boolean} true - the object contains every poperty, fasle - otherwise
|
||||
*/
|
||||
objectHasPropertiesFromArray(obj, props) {
|
||||
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
|
||||
if (!obj || !obj.hasOwnProperty(props[i])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
obj = obj[props[i]];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets property of object
|
||||
*
|
||||
* @param {Object} obj the object to setting property
|
||||
* @param {string} path the path to property
|
||||
* @param {Object} value the value of property
|
||||
*/
|
||||
setObjectProperty(obj, path, value) {
|
||||
|
||||
if (Object(obj) !== obj) return obj;
|
||||
|
||||
if (!Array.isArray(path))
|
||||
path = path.toString().match(/[^.[\]]+/g) || [];
|
||||
|
||||
path.slice(0,-1).reduce((a, c, i) =>
|
||||
Object(a[c]) === a[c]
|
||||
? a[c]
|
||||
: a[c] = Math.abs(path[i+1])>>0 === +path[i+1]
|
||||
? []
|
||||
: {},
|
||||
obj)[path[path.length-1]] = value;
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the list of methods owned by object
|
||||
* and fills the suggestions by it
|
||||
@ -2923,18 +2970,35 @@ class bslHelper {
|
||||
*
|
||||
* @returns {true|object} true - metadata was updated, {errorDescription} - not
|
||||
*/
|
||||
static updateMetadata(metadata) {
|
||||
updateMetadata(metadata, path) {
|
||||
|
||||
try {
|
||||
|
||||
let metadataObj = JSON.parse(metadata);
|
||||
if (metadataObj.hasOwnProperty('catalogs') || metadataObj.hasOwnProperty('customObjects')) {
|
||||
for (const [key, value] of Object.entries(metadataObj)) {
|
||||
bslMetadata[key].items = value;
|
||||
|
||||
if (path) {
|
||||
|
||||
if (this.objectHasPropertiesFromArray(bslMetadata, path.split('.'))) {
|
||||
this.setObjectProperty(bslMetadata, path, metadataObj);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
else {
|
||||
throw new TypeError("Wrong path");
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
throw new TypeError("Wrong structure of metadata");
|
||||
|
||||
if (metadataObj.hasOwnProperty('catalogs') || metadataObj.hasOwnProperty('customObjects')) {
|
||||
for (const [key, value] of Object.entries(metadataObj)) {
|
||||
bslMetadata[key].items = value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new TypeError("Wrong structure of metadata");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,9 +76,10 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
|
||||
}
|
||||
|
||||
updateMetadata = function (metadata) {
|
||||
updateMetadata = function (metadata, path = '') {
|
||||
|
||||
return bslHelper.updateMetadata(metadata);
|
||||
let bsl = new bslHelper(editor.getModel(), editor.getPosition());
|
||||
return bsl.updateMetadata(metadata, path);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user