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

some objectrelationtree fixes

parent fa9626b5
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import("system.logging"); ...@@ -8,6 +8,7 @@ import("system.logging");
import("ObjectRelation_lib"); import("ObjectRelation_lib");
import("Context_lib"); import("Context_lib");
import("Sql_lib"); import("Sql_lib");
import("system.tools");
var relationTypesCache = {}; var relationTypesCache = {};
var tree = [] var tree = []
...@@ -21,12 +22,15 @@ if (filter) ...@@ -21,12 +22,15 @@ if (filter)
selectedRelationType = filter.childs[0].value; selectedRelationType = filter.childs[0].value;
} }
} }
var originalObjectId = vars.get("$param.ObjectId_param");
_loadObjectRelationTree(vars.get("$param.ObjectId_param"), vars.get("$param.ObjectType_param"), selectedRelationType); _loadObjectRelationTree(originalObjectId, vars.get("$param.ObjectType_param"), selectedRelationType);
result.object(tree); 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) if (pLayer == undefined)
pLayer = 0; pLayer = 0;
...@@ -49,6 +53,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, ...@@ -49,6 +53,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
// use always reverse-type // use always reverse-type
relationTypeData = ObjectRelationUtils.getRelationType(relationTypeData[8]); relationTypeData = ObjectRelationUtils.getRelationType(relationTypeData[8]);
currentObjectId = _getRootID(currentObjectId, relationTypeData); currentObjectId = _getRootID(currentObjectId, relationTypeData);
originalObjectId = currentObjectId;
} }
let uids = _insertEntry(tree, [[currentObjectId, "", "", "", ""]], pNodeId, pLayer, pObjectType, relationTypeData) let uids = _insertEntry(tree, [[currentObjectId, "", "", "", ""]], pNodeId, pLayer, pObjectType, relationTypeData)
...@@ -93,7 +98,6 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, ...@@ -93,7 +98,6 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
{ {
var myData = _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2) 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) let uids = _insertEntry(tree, myData, pNodeId, pLayer, destObjectType, typeData)
for (let i = 0; i < uids.length; i++) for (let i = 0; i < uids.length; i++)
{ {
...@@ -102,12 +106,26 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, ...@@ -102,12 +106,26 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
} }
else else
{ {
// get ObjectRelationType from nodeId var prevObjectId;
//if (!pObjectRelationTypeId) if (pNodeId[4] != undefined)
//{ {
_insertEntry(tree, _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2), pNodeId, pLayer, destObjectType, typeData) prevObjectId = pNodeId[4][0];
//} }
// TODO: wenn relationtype selected
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, ...@@ -117,11 +135,11 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId,
* load data for a relation. * load data for a relation.
* OBJECT_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE * 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) if (pRelationType1 == undefined || pRelationType2 == undefined)
return []; return [];
var myNum; var myNum;
var otherNum; var otherNum;
...@@ -141,12 +159,14 @@ function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, p ...@@ -141,12 +159,14 @@ function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, p
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1) .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE1", pRelationType1)
.andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2) .andPrepare("AB_OBJECTRELATION.AB_OBJECTRELATIONTYPE2", pRelationType2)
.andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId); .andPrepare("AB_OBJECTRELATION.OBJECT" + myNum + "_ROWID", pObjectId);
// exclude previous node // exclude previous node
if (!pRelationTypeId) if (!pPrevId)
cond.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null"); cond.and("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID is not null");
else else
cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pObjectId, "# <> ?"); {
cond.andPrepare("AB_OBJECTRELATION.OBJECT" + otherNum + "_ROWID", pPrevId, "# <> ?");
}
// TODO: BINDATA? // TODO: BINDATA?
// var image = getImageObject("Beziehung"); // var image = getImageObject("Beziehung");
...@@ -156,10 +176,10 @@ function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, p ...@@ -156,10 +176,10 @@ function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, p
"select OBJECT" + otherNum + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE \n\ "select OBJECT" + otherNum + "_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE \n\
from AB_OBJECTRELATION \n\ from AB_OBJECTRELATION \n\
join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false)); join AB_OBJECTRELATIONTYPE on AB_OBJECTRELATIONTYPEID = AB_OBJECTRELATIONTYPE" + myNum + " and ","1=2", "", false));
if (data.length == 0 && pDirection == "same" && !pRecursion) 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? // TODO: BINDATA?
...@@ -176,7 +196,7 @@ function _getRelationTypes(pObjectType) ...@@ -176,7 +196,7 @@ function _getRelationTypes(pObjectType)
return relationTypesCache[pObjectType]; return relationTypesCache[pObjectType];
} }
function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelationTypeData) function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelationTypeData, pNum)
{ {
var expanded = true; var expanded = true;
if (pLayer > 10) expanded = false; if (pLayer > 10) expanded = false;
...@@ -186,7 +206,9 @@ function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelatio ...@@ -186,7 +206,9 @@ function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelatio
{ {
var display = db.cell(ContextUtils.getNameSql(pObjectType, pEntryData[i][0])); var display = db.cell(ContextUtils.getNameSql(pObjectType, pEntryData[i][0]));
// TODO: Icon // 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); uids.push(uid);
pTree.push([JSON.stringify(uid), display, JSON.stringify(pNodeId), expanded, pEntryData[i][0], pObjectType, ""]); pTree.push([JSON.stringify(uid), display, JSON.stringify(pNodeId), expanded, pEntryData[i][0], pObjectType, ""]);
} }
......
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