From 6b66cce7df6f56affa02ffa1794fa2d15592d0ba Mon Sep 17 00:00:00 2001 From: Johannes Hoermann <j.hoermann@adito.de> Date: Thu, 4 Apr 2019 12:17:28 +0200 Subject: [PATCH] some objectrelationtree fixes --- .../recordcontainers/jdito/contentProcess.js | 60 +++++++++++++------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js index 24743025b7..f653935431 100644 --- a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js @@ -8,6 +8,7 @@ import("system.logging"); import("ObjectRelation_lib"); import("Context_lib"); import("Sql_lib"); +import("system.tools"); var relationTypesCache = {}; var tree = [] @@ -21,12 +22,15 @@ if (filter) selectedRelationType = filter.childs[0].value; } } - -_loadObjectRelationTree(vars.get("$param.ObjectId_param"), vars.get("$param.ObjectType_param"), selectedRelationType); +var originalObjectId = vars.get("$param.ObjectId_param"); +_loadObjectRelationTree(originalObjectId, vars.get("$param.ObjectType_param"), selectedRelationType); result.object(tree); -function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, pNodeId, pLayer) +function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, pNodeId, pLayer, pObjectRelationId) { + if (pLayer > 20) + return; + if (pLayer == undefined) pLayer = 0; @@ -49,6 +53,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, // use always reverse-type relationTypeData = ObjectRelationUtils.getRelationType(relationTypeData[8]); currentObjectId = _getRootID(currentObjectId, relationTypeData); + originalObjectId = currentObjectId; } let uids = _insertEntry(tree, [[currentObjectId, "", "", "", ""]], pNodeId, pLayer, pObjectType, relationTypeData) @@ -93,7 +98,6 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, { var myData = _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2) - // wenn typ-side 1 dann die eine Richtung, sonnst die andere? let uids = _insertEntry(tree, myData, pNodeId, pLayer, destObjectType, typeData) for (let i = 0; i < uids.length; i++) { @@ -102,12 +106,26 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, } else { - // get ObjectRelationType from nodeId - //if (!pObjectRelationTypeId) - //{ - _insertEntry(tree, _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2), pNodeId, pLayer, destObjectType, typeData) - //} - // TODO: wenn relationtype selected + var prevObjectId; + if (pNodeId[4] != undefined) + { + prevObjectId = pNodeId[4][0]; + } + + var entryData = _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2, prevObjectId, true); + + // add both sides. Only one will succeed, because the prevObjectId will be filtered and it will just return [] + let uids = _insertEntry(tree, entryData, pNodeId, pLayer, destObjectType, typeData, 0); + if (direction == "same") + { + var otherEntryData = _getEntryData(pNodeId[0], typeId, "normal", relationType1, relationType2, prevObjectId, true); + uids =uids.concat(_insertEntry(tree, otherEntryData, pNodeId, pLayer, destObjectType, typeData, 1)); + } + + for (let i = 0; i < uids.length; i++) + { + _loadObjectRelationTree(uids[i][0], uids[i][3], pObjectRelationTypeId, uids[i], pLayer+1, uids[i][6]); + } } } } @@ -117,11 +135,11 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, * load data for a relation. * OBJECT_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE */ -function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, pRelationType2, pRecursion) +function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, pRelationType2, pPrevId, pRecursion) { if (pRelationType1 == undefined || pRelationType2 == undefined) return []; - + var myNum; var otherNum; @@ -141,12 +159,14 @@ function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, p .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1) .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2) .andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId); - + // exclude previous node - if (!pRelationTypeId) + if (!pPrevId) cond.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null"); else - cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pObjectId, "# <> ?"); + { + cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?"); + } // TODO: BINDATA? // var image = getImageObject("Beziehung"); @@ -156,10 +176,10 @@ function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, p "select OBJECT" + otherNum + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE \n\ from AB_OBJECTRELATION \n\ join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false)); - + if (data.length == 0 && pDirection == "same" && !pRecursion) { - return _getEntryData (pObjectId, pRelationTypeId, "normal", pRelationType1, pRelationType2, true) + return _getEntryData (pObjectId, pRelationTypeId, "normal", pRelationType1, pRelationType2, pPrevId, true) } // TODO: BINDATA? @@ -176,7 +196,7 @@ function _getRelationTypes(pObjectType) return relationTypesCache[pObjectType]; } -function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelationTypeData) +function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelationTypeData, pNum) { var expanded = true; if (pLayer > 10) expanded = false; @@ -186,7 +206,9 @@ function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelatio { var display = db.cell(ContextUtils.getNameSql(pObjectType, pEntryData[i][0])); // TODO: Icon - var uid = [pEntryData[i][0], i, pRelationTypeData, pObjectType, pNodeId, pEntryData[i][2]] + var uid = [pEntryData[i][0], i, pRelationTypeData, pObjectType, pNodeId, pEntryData[i][2], pEntryData[i][1]] + if (pNum) + uid.push(pNum); uids.push(uid); pTree.push([JSON.stringify(uid), display, JSON.stringify(pNodeId), expanded, pEntryData[i][0], pObjectType, ""]); } -- GitLab