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");
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, ""]);
}
......
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