Commit 56a1e571 authored by Samir Sadyhov's avatar Samir Sadyhov 🤔

interpreter_library - add parseAsfTable

parent 7fa22411
......@@ -247,6 +247,56 @@ UTILS.getParams = function(str){
});
};
UTILS.parseAsfValue = function(asfDataValue){
if(!asfDataValue) return null;
if(asfDataValue.hasOwnProperty('key')) {
return {
type: asfDataValue.type,
value: asfDataValue.value || '',
key: asfDataValue.key || ''
}
} else {
return {
type: asfDataValue.type,
value: asfDataValue.value || ''
}
}
}
UTILS.parseAsfTable = function(asfTable){
let result = [];
try {
if(!asfTable || !asfTable.hasOwnProperty('data')) return result;
let data = asfTable.data.filter(function(x){
if(x.type != 'label') return x;
});
if(!data.length) return result;
let tmpids = [];
data.forEach(function(x){
tmpids.push(x.id.slice(0, x.id.indexOf('-b')));
});
let ids = tmpids.uniq();
let tbi = data.slice(-1)[0].id;
tbi = Number(tbi.slice(tbi.indexOf('-b') + 2));
for(let i = 1; i <= tbi; i++) {
let item = {};
ids.forEach(function(id){
let cmpID = id + '-b' + i;
let parseValue = UTILS.parseAsfValue(UTILS.getValue(asfTable, cmpID));
if(parseValue) item[id] = parseValue;
});
result.push(item);
}
return result;
} catch (err) {
return result;
}
}
//выпиливыние из массива повторяющихся елементов
Array.prototype.uniq = function() {
return this.filter(function(v, i, a){ return i == a.indexOf(v) });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment