Skip to content
Snippets Groups Projects
Commit ddef830f authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

treetable lib

parent b1f5890b
No related branches found
No related tags found
No related merge requests found
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
<entityField> <entityField>
<name>PARENTID</name> <name>PARENTID</name>
<title>Parent</title> <title>Parent</title>
<groupable v="true" />
</entityField> </entityField>
<entityField> <entityField>
<name>PROD2PRODID</name> <name>PROD2PRODID</name>
...@@ -98,7 +99,6 @@ ...@@ -98,7 +99,6 @@
<name>jdito</name> <name>jdito</name>
<jDitoRecordAlias>Data_alias</jDitoRecordAlias> <jDitoRecordAlias>Data_alias</jDitoRecordAlias>
<contentProcess>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js</contentProcess> <contentProcess>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
<isPageable v="false" />
<isSortable v="false" /> <isSortable v="false" />
<rowCountProcess>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/rowCountProcess.js</rowCountProcess> <rowCountProcess>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/rowCountProcess.js</rowCountProcess>
<onInsert>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js</onInsert> <onInsert>%aditoprj%/entity/Prod2prod_entity/recordcontainers/jdito/onInsert.js</onInsert>
......
import("system.logging");
import("system.result"); import("system.result");
import("system.vars"); import("system.vars");
import("system.db"); import("system.db");
...@@ -10,5 +11,6 @@ var prodid = vars.exists("$param.ProductId_param") ...@@ -10,5 +11,6 @@ var prodid = vars.exists("$param.ProductId_param")
if(prodid != "") if(prodid != "")
{ {
var p2pUtils = new Prod2ProdUtils(prodid); var p2pUtils = new Prod2ProdUtils(prodid);
logging.log("casllllldsfasdf")
result.object(p2pUtils.getPartsListForRecordContainer()); result.object(p2pUtils.getPartsListForRecordContainer());
} }
\ No newline at end of file
...@@ -9,36 +9,12 @@ ...@@ -9,36 +9,12 @@
</boxLayout> </boxLayout>
</layout> </layout>
<children> <children>
<tableViewTemplate> <treetableViewTemplate>
<name>Prod2prod_table</name> <name>partlist</name>
<autoNewRow v="true" /> <parentField>PARENTID</parentField>
<titleField>PRODUCTCODE</titleField>
<descriptionField>QUANTITY</descriptionField>
<entityField>#ENTITY</entityField> <entityField>#ENTITY</entityField>
<columns> </treetableViewTemplate>
<neonTableColumn>
<name>1c681134-4741-4dd6-b4c3-899d98216b72</name>
<entityField>PARENTID</entityField>
</neonTableColumn>
<neonTableColumn>
<name>5a884b06-880a-4ec4-9405-909548cedd41</name>
<entityField>PRODUCTCODE</entityField>
</neonTableColumn>
<neonTableColumn>
<name>723600d0-7d3b-4d96-9880-cb5b9ea90002</name>
<entityField>SOURCE_ID</entityField>
</neonTableColumn>
<neonTableColumn>
<name>3975b280-3f16-413c-8613-4de277cd8ece</name>
<entityField>QUANTITY</entityField>
</neonTableColumn>
<neonTableColumn>
<name>295adb8f-c639-4e5a-b02d-7f61756992ff</name>
<entityField>OPTIONAL</entityField>
</neonTableColumn>
<neonTableColumn>
<name>892a56f5-4417-4ece-9d94-70b1d9f0c4d4</name>
<entityField>TAKEPRICE</entityField>
</neonTableColumn>
</columns>
</tableViewTemplate>
</children> </children>
</neonView> </neonView>
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.7" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.1.7">
<name>Data_lib</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/Data_lib/process.js</process>
<variants>
<element>LIBRARY</element>
</variants>
</process>
/**
*
* @class
*/
function DataTree()
{
this._dataTree = {
root: {
ids: []
}
};
this._resultData = [];
}
/**
* @return {DataTree}
*/
DataTree.begin = function()
{
var tree = new DataTree();
return tree;
}
/**
*
* @param {String[]} pData
* @param {manipulateNodeCallback} pManipulateNodeFn
*
*/
DataTree.prototype.getTreeObject = function()
{
return this._dataTree;
}
DataTree.prototype.add = function(pUid, pParentId, pData, pManipulateNodeFn)
{
logging.log(pUid + " " + pParentId + " ")
/*if (!pParentId || pParentId == "root")
{
pParentId = "root";
this._dataTree[pParentId].ids.push(pUid);
// callback to provide a hook for manipulating the node. (e.g. for adding additional node data)
if (pManipulateNodeFn != undefined)
pManipulateNodeFn(pParentId, this._dataTree[pParentId]);
}
else
{
if (this._dataTree[pParentId] == undefined)
this._dataTree[pParentId] = {
data: [],
ids: []
}
this._dataTree[pParentId].ids.push(pUid);
}
this._dataTree[pUid] = {
data: pData,
parent: pParentId
}
if (this._dataTree[pUid].ids == undefined)
{
this._dataTree[pUid].ids = [];
}
// callback to provide a hook for manipulating the node. (e.g. for adding additional node data)
if (pManipulateNodeFn != undefined)
pManipulateNodeFn(pUid, this._dataTree[pUid]);
*/
return this;
}
/**
*
* @param {String[]} pData
* @param {manipulateNodeCallback} pManipulateNodeFn
*
*/
DataTree.prototype.addArray = function(pData, pManipulateNodeFn)
{
logging.log(pData.toSource())
pData.forEach(function(pRow)
{
this.add(pRow[0], pRow[1], pRow.splice(2), pManipulateNodeFn);
}, this);
return this;
}
DataTree.prototype.toArray = function(pRootId)
{
var result = [];
var tree = this._dataTree;
// in this function Ids are just concatenated. This is bad, because it results in very long strings.
// Because of this the concatenated id's are maped to new uids in the resulting array
var uidMap = {};
logging.log(tree.toSource())
//__push(pRootId, tree.root);
function __push(pParent, pNode) {
for (var i = 0; i < pNode.ids.length; i++) {
var nextUid = pParent + pNode.ids[i];
__addRow(nextUid, pParent, tree[pNode.ids[i]].data)
logging.log(nextUid + "\n---- " + tree[pNode.ids[i]])
__push(nextUid, tree[pNode.ids[i]])
}
}
function __addRow(pUid, pParentId, pRowdata)
{
uidMap[pUid] = util.getNewUUID();
if (uidMap[pParentId] == undefined) {
uidMap[pParentId] = util.getNewUUID();
}
result.push([uidMap[pUid], uidMap[pParentId]].concat(pRowdata));
}
return result;
}
\ No newline at end of file
import("system.logging");
import("system.util"); import("system.util");
import("system.SQLTYPES"); import("system.SQLTYPES");
import("system.datetime"); import("system.datetime");
...@@ -8,7 +9,7 @@ import("Util_lib"); ...@@ -8,7 +9,7 @@ import("Util_lib");
import("Binary_lib"); import("Binary_lib");
import("Sql_lib"); import("Sql_lib");
import("Keyword_lib"); import("Keyword_lib");
import("Data_lib");
/** /**
* utility functions for products * utility functions for products
...@@ -408,7 +409,7 @@ function Prod2ProdUtils(productId) { ...@@ -408,7 +409,7 @@ function Prod2ProdUtils(productId) {
* } } * } }
*/ */
Prod2ProdUtils.prototype.getPartsListObject = function() { Prod2ProdUtils.prototype.getPartsListObject = function() {
return this._relateChilds(); return this._relateChilds().getTreeObject();
} }
/** /**
...@@ -430,24 +431,44 @@ Prod2ProdUtils.prototype.getPartsListObject = function() { ...@@ -430,24 +431,44 @@ Prod2ProdUtils.prototype.getPartsListObject = function() {
* , "PRODUCTCODE"] ] * , "PRODUCTCODE"] ]
*/ */
Prod2ProdUtils.prototype.getPartsListForRecordContainer = function() { Prod2ProdUtils.prototype.getPartsListForRecordContainer = function() {
var ret = []; var tree = this._relateChilds();
var childs = this._relateChilds(); return tree.toArray("");
// var ret = [];
__push(childs.root); // var childs = this._relateChilds();
//
function __push(obj) { // // map internal, (uids used in this function) concatenated ids to new random generated uuids.
for (var i = 0; i < obj.ids.length; i++) { // // Without this every depth would make the uid significantly longer.
var rowdata = childs[obj.ids[i]].rowdata; // var uidMap = {};
var UID = util.getNewUUID(); //
var PARENTID = childs[obj.ids[i]].destid; // __push("", childs.root, 0);
//
rowdata = [UID, PARENTID].concat(rowdata); //
ret.push(rowdata); //
__push(childs[obj.ids[i]]); //
} // function __push(parent, obj) {
} // logging.log(obj.toSource())
// //
return ret; //
// for (var i = 0; i < obj.ids.length; i++) {
// logging.log(childs[obj.ids[i]].toSource())
// var nextUid = parent + obj.ids[i];
// __addRow(nextUid, parent, childs[obj.ids[i]].rowdata)
//
// __push(nextUid, childs[obj.ids[i]])
// }
// }
//
// function __addRow(uid, parentId, rowdata)
// {
// uidMap[uid] = util.getNewUUID();
// if (uidMap[parentId] == undefined) {
// uidMap[parentId] = util.getNewUUID();
// }
//
// ret.push([uidMap[uid], uidMap[parentId]].concat(rowdata));
// }
//
// return ret;
} }
/** /**
...@@ -459,7 +480,7 @@ Prod2ProdUtils.prototype.getPartsListForRecordContainer = function() { ...@@ -459,7 +480,7 @@ Prod2ProdUtils.prototype.getPartsListForRecordContainer = function() {
*/ */
Prod2ProdUtils.prototype.getPartsListProdIds = function() { Prod2ProdUtils.prototype.getPartsListProdIds = function() {
var ret = []; var ret = [];
var childs = this._relateChilds(); var childs = this._relateChilds().getTreeObject();
__push(childs.root); __push(childs.root);
...@@ -515,6 +536,29 @@ Prod2ProdUtils.prototype._initProd2ProdData = function() { ...@@ -515,6 +536,29 @@ Prod2ProdUtils.prototype._initProd2ProdData = function() {
**/ **/
Prod2ProdUtils.prototype._buildTree = function(supervised) { Prod2ProdUtils.prototype._buildTree = function(supervised) {
this._initProd2ProdData(); this._initProd2ProdData();
var tree = DataTree.begin().addArray(this.data,
function(pUid, pNode)
{
if (pUid == "root")
{
pNode["sourceid"] = this.productId;
if (supervised)
{
pNode["destid"] = this.productId;
}
}
else
{
pNode["destid"] = pNode.parent;
pNode["sourceid"] = pNode.data[0];
pNode["quantity"] = pNode.data[1];
pNode["optional"] = pNode.data[2];
pNode["takeprice"] = pNode.data[3];
pNode["productcode"] = pNode.data[4];
}
}
);
/*
var tree = { root: {ids: [], sourceid: this.productId } }; var tree = { root: {ids: [], sourceid: this.productId } };
...@@ -536,7 +580,7 @@ Prod2ProdUtils.prototype._buildTree = function(supervised) { ...@@ -536,7 +580,7 @@ Prod2ProdUtils.prototype._buildTree = function(supervised) {
}; };
} }
} }
*/
return tree; return tree;
} }
...@@ -547,11 +591,12 @@ Prod2ProdUtils.prototype._relateChilds = function() { ...@@ -547,11 +591,12 @@ Prod2ProdUtils.prototype._relateChilds = function() {
return tree; return tree;
function __relate(id) { function __relate(id) {
for (var treeId in tree) { var treeObject = tree.getTreeObject();
if (tree[treeId].destid == tree[id].sourceid && tree[id].ids.indexOf(treeId) == -1) { for (var treeId in treeObject) {
tree[id].ids.push(treeId); if (treeObject[treeId].destid == treeObject[id].sourceid && treeObject[id].ids.indexOf(treeId) == -1) {
if (treeId != "root")
treeObject[id].ids.push(treeId);
__relate(treeId); __relate(treeId);
} }
} }
...@@ -567,9 +612,10 @@ Prod2ProdUtils.prototype._relateParents = function() { ...@@ -567,9 +612,10 @@ Prod2ProdUtils.prototype._relateParents = function() {
function __relate(id) { function __relate(id) {
for (var treeId in tree) { var treeObject = tree.getTreeObject();
if (tree[treeId].sourceid == tree[id].destid && tree[id].ids.indexOf(treeId) == -1) { for (var treeId in treeObject) {
tree[id].ids.push(treeId); if (treeObject[treeId].sourceid == treeObject[id].destid && treeObject[id].ids.indexOf(treeId) == -1) {
treeObject[id].ids.push(treeId);
__relate(treeId); __relate(treeId);
} }
} }
......
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