Skip to content
Snippets Groups Projects
Commit 2afe97ca authored by Adrien Kirják's avatar Adrien Kirják
Browse files

Merge branch titan.Libraries.Web_GUI:master into master

parents f46a4706 5d67ba27
No related branches found
No related tags found
No related merge requests found
// Copyright (c) 2000-2025 Ericsson Telecom AB Telecom AB // // Copyright (c) 2000-2023 Ericsson Telecom AB Telecom AB //
// All rights reserved. This program and the accompanying materials are made available under the // // All rights reserved. This program and the accompanying materials are made available under the //
// terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at // // terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html // // https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
function CViewModel_UnionTable(aViewModel, aOptions) { function CViewModel_UnionTable(aViewModel, aOptions) {
"use strict"; "use strict";
...@@ -9,9 +9,10 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -9,9 +9,10 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
/** private members */ /** private members */
var mViewModel = aViewModel; var mViewModel = aViewModel;
var mOptions = aOptions; var mOptions = aOptions;
//var mRq = mViewModel.getRequest();
var mBinder; var mBinder;
var mResponseDataPaths = []; var mResponseDataPaths = [];
var mSelections = []; // mSelections is a list of references to objects, each containing a field named "selection" var mSelections = []; // mSelectionss is a list of references to objects, each containing a field named "selection"
var mThis = this; var mThis = this;
var mEnlistElementName = mOptions.enlistElementName; var mEnlistElementName = mOptions.enlistElementName;
if (mEnlistElementName === undefined) if (mEnlistElementName === undefined)
...@@ -21,7 +22,7 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -21,7 +22,7 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
this.setSelectionToControl = function (aSelection) { this.setSelectionToControl = function (aSelection) {
/** aSelection is a reference to an object containing a "selection" field */ /** aSelection is a reference to an object containing a "selection" field */
mSelections.push(aSelection); mSelections.push(aSelection);
}; };
this.setReponseDataPath = function (aExpectedReponseDataIndex, aReponseDataPath) { this.setReponseDataPath = function (aExpectedReponseDataIndex, aReponseDataPath) {
...@@ -29,7 +30,7 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -29,7 +30,7 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
}; };
this.setBinder = function (aBinder) { this.setBinder = function (aBinder) {
mBinder = aBinder; mBinder = aBinder;
}; };
/** public functions - Interface for views */ /** public functions - Interface for views */
...@@ -64,7 +65,7 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -64,7 +65,7 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
"heading": header[i], "heading": header[i],
"elementIndex": i "elementIndex": i
}; };
} }
return header; return header;
}; };
...@@ -72,20 +73,22 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -72,20 +73,22 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
return mViewModel.getRequestFromPath(mResponseDataPaths[0]).getData.element; return mViewModel.getRequestFromPath(mResponseDataPaths[0]).getData.element;
}; };
this.getResponseElement = function (aFullTableSelection) { this.getResponseElement = function (aReponseDataPath, aFullTableSelection) {
var lElement; var lElement;
if (aFullTableSelection.path) { if (aFullTableSelection) {
var pathIdx = 0; aFullTableSelection.parents = [];
lElement = mViewModel.getResponseElement(); aFullTableSelection.depth = aReponseDataPath.length;
if (lElement != undefined) { aFullTableSelection.path = aReponseDataPath;
lElement = lElement[aFullTableSelection.path[pathIdx]]; }
} if (aReponseDataPath) {
lElement = mViewModel.getResponseElement();
if (lElement != undefined) {
lElement = lElement[aReponseDataPath[0]];
}
if (lElement) { if (lElement) {
var lRq = mViewModel.getRequest()[aFullTableSelection.path[pathIdx]]; var lRq = mViewModel.getRequest()[aReponseDataPath[0]];
for (var i = 1; i < aReponseDataPath.length && lElement; ++i) {
// need to select the table data from the path, which is the last two element if (lElement.list && lRq.getData.selection && lRq.getData.selection.length > 0) {
for (; pathIdx < aFullTableSelection.path.length - 1 && lElement; ++pathIdx) {
if (lElement.list && lRq.getData.selection && lRq.getData.selection.length > 0) {
if (aFullTableSelection) { if (aFullTableSelection) {
aFullTableSelection.depth--; aFullTableSelection.depth--;
if (lElement.list[lRq.getData.selection[0]] != undefined) { if (lElement.list[lRq.getData.selection[0]] != undefined) {
...@@ -96,24 +99,23 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -96,24 +99,23 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
aFullTableSelection.path = aFullTableSelection.path.slice(1); aFullTableSelection.path = aFullTableSelection.path.slice(1);
} }
if (lElement.list[lRq.getData.selection[0]] && lElement.list[lRq.getData.selection[0]].node.childVals) { if (lElement.list[lRq.getData.selection[0]] && lElement.list[lRq.getData.selection[0]].node.childVals) {
lElement = lElement.list[lRq.getData.selection[0]].node.childVals[aFullTableSelection.path[pathIdx]]; lElement = lElement.list[lRq.getData.selection[0]].node.childVals[aReponseDataPath[i]];
} else { } else {
lElement = undefined; lElement = undefined;
break; break;
} }
} else if (lElement.node && lElement.node.childVals) { } else if (lElement.node && lElement.node.childVals) {
aFullTableSelection.path.shift(); lElement = lElement.node.childVals[aReponseDataPath[i]];
aFullTableSelection.depth--; aFullTableSelection.depth--;
lElement = lElement.node.childVals[aFullTableSelection.path[pathIdx]]; aFullTableSelection.path = aFullTableSelection.path.slice(1);
} else if (!lRq.getData.selection || lRq.getData.selection.length === 0) { } else if (!lRq.getData.selection || lRq.getData.selection.length === 0) {
// intentionally blank /**/
} else } else
lElement = { lElement = {
"error" : "cannot determine node" "error" : "cannot determine node"
}; };
if (lRq.getData.children) { if (lRq.getData.children)
lRq = lRq.getData.children[aFullTableSelection.path[pathIdx]]; lRq = lRq.getData.children[aReponseDataPath[i]];
}
} }
} }
} }
...@@ -121,51 +123,45 @@ function CViewModel_UnionTable(aViewModel, aOptions) { ...@@ -121,51 +123,45 @@ function CViewModel_UnionTable(aViewModel, aOptions) {
}; };
this.getTable = function () { this.getTable = function () {
var pathCopy = mcopy(mResponseDataPaths[0]); var aFullTableSelection = {};
var aFullTableSelection = { var response = mThis.getResponseElement(mResponseDataPaths[0], aFullTableSelection);
parents: [],
depth: pathCopy.length,
path: pathCopy
};
var response = mThis.getResponseElement(aFullTableSelection);
return { return {
selection : mSelections[0] ? mSelections[0].selection : undefined, selection : mSelections[0] ? mSelections[0].selection : undefined,
table : (response === undefined) ? [] : flattenResponseElement(response.list, aFullTableSelection.depth, 0, aFullTableSelection.parents, aFullTableSelection.path.slice(1)) table : (response === undefined) ? [] : flattenResponseElement(response.list, aFullTableSelection.depth, 0, aFullTableSelection.parents, aFullTableSelection.path.slice(1))
}; };
}; };
this.setValue = function() {}; this.setValue = function() {};
/** private functions */ /** private functions */
function flattenResponseElement(arr, limit, depth, parents, path) { function flattenResponseElement(arr, limit, depth, parents, path) {
if (arr) { if (arr) {
limit = limit || 0; limit = limit || 0;
depth = depth || 0; depth = depth || 0;
parents = parents || []; parents = parents || [];
path = path || []; path = path || [];
return arr.reduce(function _reduce(flat, toFlatten) { return arr.reduce(function _reduce(flat, toFlatten) {
if (limit === depth && toFlatten.node) if (limit === depth && toFlatten.node)
return flat.concat({"val": toFlatten.node.val}); return flat.concat({"val": toFlatten.node.val});
else if (limit === depth && toFlatten.list) else if (limit === depth && toFlatten.list)
return flat.concat([flattenResponseElement(toFlatten.list, limit, depth, parents, path)].join()); return flat.concat([flattenResponseElement(toFlatten.list, limit, depth, parents, path)].join());
else if (limit === depth + 1 && toFlatten.node) { else if (limit === depth + 1 && toFlatten.node) {
if (mEnlistElementName) if (mEnlistElementName)
return flat.concat([parents.concat([{"val": toFlatten.node.val}].concat(flattenResponseElement(toFlatten.node.childVals, limit, depth + 1, [], path)))]); return flat.concat([parents.concat([{"val": toFlatten.node.val}].concat(flattenResponseElement(toFlatten.node.childVals, limit, depth + 1, [], path)))]);
else else
return flat.concat([flattenResponseElement(toFlatten.node.childVals, limit, depth + 1, [], path)]); return flat.concat([flattenResponseElement(toFlatten.node.childVals, limit, depth + 1, [], path)]);
} else if (Array.isArray(toFlatten)) } else if (Array.isArray(toFlatten))
return flat.concat(flattenResponseElement(toFlatten, limit, depth, parents, path)); return flat.concat(flattenResponseElement(toFlatten, limit, depth, parents, path));
else if (toFlatten.node && toFlatten.node.childVals && limit !== depth) else if (toFlatten.node && toFlatten.node.childVals && limit !== depth)
return flat.concat(flattenResponseElement([toFlatten.node.childVals[path[depth]]], limit, depth + 1, parents.concat([{"val": toFlatten.node.val}]), path)); return flat.concat(flattenResponseElement([toFlatten.node.childVals[path[depth]]], limit, depth + 1, parents.concat([{"val": toFlatten.node.val}]), path));
else if (toFlatten.node && toFlatten.node.childVals) else if (toFlatten.node && toFlatten.node.childVals)
return flat.concat(flattenResponseElement(toFlatten.node.childVals, limit, depth + 1, parents.concat([{"val": toFlatten.node.val}]), path)); return flat.concat(flattenResponseElement(toFlatten.node.childVals, limit, depth + 1, parents.concat([{"val": toFlatten.node.val}]), path));
else if (toFlatten.list) else if (toFlatten.list)
return flat.concat(flattenResponseElement(toFlatten.list, limit, depth, parents, path)); return flat.concat(flattenResponseElement(toFlatten.list, limit, depth, parents, path));
else else
console.error("flattenResponseElement met an unexpected condition. Reason: The response object is nonconformant OR not all parents have a selection!"); console.error("flattenResponseElement met an unexpected condition. Reason: The response object is nonconformant OR not all parents have a selection!");
}, []); }, []);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment