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

fix ObjectRelation, add some documentation

parent 05fa5562
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ import("ObjectRelation_lib");
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.ObjectIds_param") && vars.get("$param.ObjectIds_param"))
{
var targetContext = vars.get("$field.TARGET_CONTEXT");
var targetContext = ObjectRelationUtils.getRelationType(vars.get("$field.OBJECTRELATIONTYPEID"))[5];
var myObjectIds = JSON.parse(vars.getString("$param.ObjectIds_param"))
var myContextTypes = JSON.parse(vars.getString("$param.ObjectTypes_param"))
......
import("system.logging");
import("system.db");
import("system.translate");
import("system.result");
......@@ -7,6 +8,40 @@ import("Context_lib");
import("Sql_lib");
import("Contact_lib");
/**
* Rough functioning of the code:
* - get parameters
* - load data via _loadObjectRelationTree
* * _loadObjectRelationTree calls itself recursively
* - data is insertet into the tree which is passed as REFERENCE to _loadObjectRelationTree
* -> each "push" to pTree in _loadObjectRelationTree updates automaticaly tree
* -> Do not use something like pTree = pTree.concat(...) as this would create a new Array with a new reference which does not point to "tree" anymore.
* - the "tree" is returned
*/
// some info about how the arrays are filled
var ENTRY_DATA = {
objectId: 0,
objectRelationId: 1,
objectType: 2,
relationTitle: 3,
info: 4,
onjectRelationTypeId: 5
}
var UID = {
objectId: 0,
layer: 1,
onjectRelationTypeId: 2,
otherObjectType: 3,
relationTypeData: 4,
myObjectType: 5,
objectRelationId: 6,
hierarchy: 7
}
var tree = []
// uidParam: if only one row should be loaded
......@@ -22,7 +57,8 @@ else if(vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.ge
if (uidParam)
{
// load one
// load one by uid.
// Basically the data to return is also encoded in the uid itself -> no extra data loading is needed.
let uid = JSON.parse(uidParam);
let isObjectRelationNode = uid != null && typeof uid[2] == "string";
......@@ -30,7 +66,6 @@ if (uidParam)
{
let relationTypeData = ObjectRelationUtils.getRelationType(uid[2]);
_insertEntry(tree, _getEntryData(uid[0], relationTypeData[3], relationTypeData[7], relationTypeData[8], undefined, false, uid[6]), "", 0, uid[3], relationTypeData[10], relationTypeData[12], relationTypeData[4]);
}
}
else
......@@ -49,6 +84,7 @@ else
}
}
// get the base object types / ids to load the tree fo
if (vars.get("$param.ObjectIds_param") && vars.get("$param.ObjectTypes_param"))
{
var originalObjectIds = JSON.parse(vars.getString("$param.ObjectIds_param"));
......@@ -58,15 +94,29 @@ else
{
throw "the parameters ObjectIds_param and ObjectTypes_param do not contain a json array of the same length";
}
// load the object relations for each given objectId / Type
for (let i = 0; i < originalObjectIds.length; i++)
{
_loadObjectRelationTree(tree, originalObjectIds[i], originalObjectTypes[i], selectedRelationType);
}
}
}
result.object(tree);
/**
* This function loads the whole tree and calls itself recursively
* @param {String[][]} pTree the tree array. NOTE: it is passed BY REFERENCE and will be altered by this function
* @param {String} pObjectId The id of the object to load the tree for (e.g. a ContactId)
* @param {String} pObjectType The type of the object to load the tree for (e.g. "Person")
* @param {String} [pObjectRelationTypeId=undefined] if given: the tree is filtered by this relation type and only nodes with this type are added
* @param {String} [pNodeId=null] the current nodeid is the node for which the next childrens are loaded. Needed for Recursion.
* @param {Integer} [pLayer=0] this is the current layer to load. Needed for Recursion.
* @param {String[][]} [pRelationTypeData=undefined] NOT ESSENTIAL it is just needed to not load the type data every time the function is called.
* If it is missing, it's loaded via the id encoded inside of the uid
* It only exists for better performance
*/
function _loadObjectRelationTree(pTree, pObjectId, pObjectType, pObjectRelationTypeId, pNodeId, pLayer, pRelationTypeData)
{
// prevent stack overflows
......@@ -145,6 +195,13 @@ function _loadObjectRelationTree(pTree, pObjectId, pObjectType, pObjectRelationT
// if no relationType given, load from nodeId
if (!pRelationTypeData)
pRelationTypeData = pNodeId[2];
// if it's only the id, load via function
if (typeof pRelationTypeData == "string")
{
pRelationTypeData = ObjectRelationUtils.getRelationType(pRelationTypeData);
}
var thisRelationTypeId = pRelationTypeData[0];
var otherRelationTypeId = pRelationTypeData[10];
var hierarchy = pRelationTypeData[4];
......@@ -297,6 +354,7 @@ function _insertEntry(pTree, pEntryData, pNodeId, pLayer, pObjectType, pNewRelat
var display = db.cell(ContextUtils.getNameSql(pObjectType, pEntryData[i][0]));
// TODO: Icon
var uid = [pEntryData[i][0], i, pEntryData[i][5], pObjectType, pNodeId, pEntryData[i][2], pEntryData[i][1], pHierarchy]
if (pNum)
uid.push(pNum);
uids.push(uid);
......
import("system.logging");
import("Contact_lib");
import("system.util");
import("ObjectRelation_lib");
......@@ -30,6 +31,8 @@ if (selectedObjectRelationTypeId)
objectId2 = vars.get("$field.TARGET_ID");
}
logging.log(JSON.stringify([side, objectId1, objectId2], null, "\t"))
db.insertData("AB_OBJECTRELATION", [
"AB_OBJECTRELATIONID",
"OBJECT1_ROWID",
......
......@@ -91,7 +91,7 @@ ObjectRelationUtils.getPossibleRelationTypes = function(pObjectTypes, pFullInfo,
else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId2, \n\
main.SIDE,\n\
case when type2.AB_OBJECTRELATIONTYPEID is null then main.AB_OBJECTRELATIONTYPEID else type2.AB_OBJECTRELATIONTYPEID end,\n\
type2.RELATION_TITLE" + (pDummyField ? ", ''" : "") + ", main.ICON" + sql; // Icon is only savid in type1
type2.RELATION_TITLE" + (pDummyField ? ", ''" : "") + ", main.ICON" + sql; // Icon is only saved in type1
}
// full info:
......
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