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

object tree choose type

parent 6b3bfbd2
No related branches found
No related tags found
No related merge requests found
import("system.translate");
import("system.vars");
import("system.result");
result.string(vars.get("$field.RELATION_TITLE"))
\ No newline at end of file
result.string(translate.text(vars.get("$field.RELATION_TITLE")))
\ No newline at end of file
......@@ -16,7 +16,7 @@ _loadObjectRelationTree(vars.get("$param.ObjectId_param"), vars.get("$param.Obje
result.object(tree);
function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, pNodeId, pLayer)
function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, pNodeId, pLayer)
{
if (pLayer == undefined)
pLayer = 0;
......@@ -30,14 +30,22 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, pN
{
if (pLayer == 0)
{
if (pObjectRelationType)
if (pObjectRelationTypeId)
{
var relationTypeData = ObjectRelationUtils.getRelationType(pObjectRelationTypeId);
relationTypeData = ObjectRelationUtils.getRelationType(relationTypeData[8]);
// if hirachy: get most top id else use the current currentObjectId
if (_getHierarchy(pObjectRelationType))
if (relationTypeData[4] == "1")
{
currentObjectId = _getRootID(currentObjectId, pObjectType);
// ??? set type also ???
currentObjectId = _getRootID(currentObjectId, relationTypeData);
}
let uids = _insertEntry(tree, [[currentObjectId, "", "", "", ""]], pNodeId, pLayer, pObjectType, relationTypeData)
for (let i = 0; i < uids.length; i++)
{
_loadObjectRelationTree(uids[i][0], uids[i][3], relationTypeData[0], uids[i], pLayer+1);
}
}
else // no ObjectType chosen
{
......@@ -53,10 +61,10 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, pN
{
// TODO: Icons, BINDATA
// var icon = getIcon...
var uid = [currentObjectId, i, relationTypes[i]];
let uid = [currentObjectId, i, relationTypes[i]];
tree.push([JSON.stringify(uid), translate.text(relationTypes[i][1]), JSON.stringify(pNodeId), true, null, null]);
_loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, uid, pLayer+1);
_loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationTypeId, uid, pLayer+1);
}
}
}
......@@ -71,7 +79,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, pN
var relationType2 = typeData[8];
var direction = typeData[3];
if (hierarchy == "1" && !pObjectRelationType)
if (hierarchy == "1")
{
var myData = _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2)
......@@ -79,16 +87,16 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, pN
let uids = _insertEntry(tree, myData, pNodeId, pLayer, destObjectType, typeData)
for (let i = 0; i < uids.length; i++)
{
_loadObjectRelationTree(uids[i][0], uids[i][3], pObjectRelationType, uids[i], pLayer+1);
_loadObjectRelationTree(uids[i][0], uids[i][3], pObjectRelationTypeId, uids[i], pLayer+1);
}
}
else
{
// get ObjectRelationType from nodeId
if (!pObjectRelationType)
{
//if (!pObjectRelationTypeId)
//{
_insertEntry(tree, _getEntryData(pNodeId[0], typeId, direction, relationType1, relationType2), pNodeId, pLayer, destObjectType, typeData)
}
//}
// TODO: wenn relationtype selected
}
}
......@@ -97,7 +105,7 @@ function _loadObjectRelationTree(pObjectId, pObjectType, pObjectRelationType, pN
/**
* load data for a relation.
* OBJECT_ROWID, AB_OBJECTRELATIONID, AB_OBJECTRELATIONTYPEID, RELATION_TITLE
* OBJECT_ROWID, AB_OBJECTRELATIONID, OBJECT_TYPE, RELATION_TITLE
*/
function _getEntryData(pObjectId, pRelationTypeId, pDirection, pRelationType1, pRelationType2, pRecursion)
{
......@@ -171,8 +179,25 @@ function _insertEntry (pTree, pEntryData, pNodeId, pLayer, pObjectType, pRelatio
return uids;
}
function _getHierarchy(pObjectRelationType)
/*
* get most top root of a node
*
* @param {String} pObjectId
* @param {String[]} pObjectRelationTypeData
*
* @return {String} RootObjectId
*/
function _getRootID(pObjectId, pObjectRelationTypeData)
{
return db.cell(SqlCondition.begin().andPrepare("AB_OBJECTRELATIONTYPE.AB_OBJECTRELATIONTYPEID", pObjectRelationType)
.buildSql("select HIERARCHY from AB_OBJECTRELATIONTYPE", "1=2")) == "1";
var sourceid = pObjectId;
var max = 100;
do
{
var rootid = sourceid;
max--;
sourceid = db.cell("select OBJECT1_ROWID from AB_OBJECTRELATION where OBJECT2_ROWID = '" + sourceid + "' and AB_OBJECTRELATIONTYPE1 = '" + pObjectRelationTypeData[7] + "' and AB_OBJECTRELATIONTYPE2 = '" + pObjectRelationTypeData[8] + "'");
}
while( sourceid != "" && max > 0 );
return rootid;
return currentObjectId;
}
\ No newline at end of file
......@@ -8,6 +8,17 @@
</boxLayout>
</layout>
<children>
<genericViewTemplate>
<name>Selector</name>
<editMode v="true" />
<entityField>#ENTITY</entityField>
<fields>
<entityFieldLink>
<name>50eef5d6-418b-411b-a585-8633119b2fb0</name>
<entityField>Selector</entityField>
</entityFieldLink>
</fields>
</genericViewTemplate>
<treeViewTemplate>
<name>ObjectRelations</name>
<parentField>PARENT_ID</parentField>
......
......@@ -40,7 +40,6 @@ ObjectRelationUtils.getPossibleRelationTypes = function(pObjectType, pFullInfo)
}
// full info:
// TODO: add hierarchy
var relationTypes = (db.table(
["select main.AB_OBJECTRELATIONTYPEID, main.RELATION_TITLE, main.RELATION_TYPE, \n\
case when type2.AB_OBJECTRELATIONTYPEID is null then 'same' \n\
......@@ -63,15 +62,45 @@ ObjectRelationUtils.getPossibleRelationTypes = function(pObjectType, pFullInfo)
]
]));
// switch the object types, if the direction is normal so that the first one is dest and the second one is source.
return relationTypes;
/*.map(function(relationType)
{
if (relationType[3] == "normal")
{
return relationType.slice(0, 6).concat(relationType[7], relationType[6]);
}
return relationType;
});*/
}
/**
* Get all possible relationTypes by a objectType.
* returns the id, title, RELATION_TYPE, direction (normal, reverse, same), hierarchy, OBJECT_TYPE dest, OBJECT_TYPE source, objectrelationtypeId1, objectrelationtypeId2, side
*
* @param {String} pObjectTypeId the object type to load the relation types for.]
*
* @return {String[][]}
*/
ObjectRelationUtils.getRelationType = function(pObjectTypeId)
{
// TODO: funktionen evtl. zusammenfassen
var sql = " from AB_OBJECTRELATIONTYPE main \n\
left join AB_OBJECTRELATIONTYPE type2 on (type2.AB_OBJECTRELATIONTYPEID <> main.AB_OBJECTRELATIONTYPEID and type2.RELATION_TYPE = main.RELATION_TYPE) \n\
where main.AB_OBJECTRELATIONTYPEID = ?"
// full info:
var relationType = (db.array(db.ROW,
["select main.AB_OBJECTRELATIONTYPEID, main.RELATION_TITLE, main.RELATION_TYPE, \n\
case when type2.AB_OBJECTRELATIONTYPEID is null then 'same' \n\
when main.SIDE = 1 then 'normal'\n\
else 'reverse'\n\
end direction,\n\
main.HIERARCHY, \n\
type2.OBJECT_TYPE objectType, \n\
main.OBJECT_TYPE objectType, \n\
-- typeId of Object2\n\
case when main.SIDE = 1 then main.AB_OBJECTRELATIONTYPEID\n\
else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId1,\n\
-- typeId of Object1\n\
case when type2.AB_OBJECTRELATIONTYPEID is null or main.SIDE = 2 then main.AB_OBJECTRELATIONTYPEID\n\
else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId2, \n\
main.SIDE" + sql,
[
[pObjectTypeId, db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["AB_OBJECTRELATIONTYPEID"])[0]],
]
]));
return relationType;
}
\ No newline at end of file
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