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

360: add different context-filter for subcontexts

parent 17e21540
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"
{
var active;
var selectMap = ContextUtils.getSelectMap ()
var selectMap = ContextUtils.getSelectMap();
if(vars.exists("$local.filter") && vars.get("$local.filter") )
{
var filter = vars.get("$local.filter");
......@@ -28,7 +28,7 @@ if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"
var contextList = JSON.parse(vars.getString("$param.ObjectType_param"));
var contactId = vars.get("$param.ObjectRowId_param");
var baseContext = vars.exists("$param.BaseContextId_param") ? vars.get("$param.BaseContextId_param") : undefined;
result.object(_get360Data(baseContext, contactId, contextList, active, undefined, baseContext != undefined));
result.object(_get360Data(selectMap, baseContext, contactId, contextList, active, undefined, baseContext != undefined));
}
......@@ -38,11 +38,20 @@ else
}
/**
* load all data for the 360Degree tree.
* @param {Object} pSelectMap the select map (result of ContextUtils.getSelectMap())
* @param {String} pBaseContextId the ContextId in which this 360 Degree tree is located / for which the data should be loaded
* @param {String[]} pContactId the Contactid the 360 Degree tree should be loaded for
* @param {String[]} pContextList list of contexts to load. Note that subcontexts use their own list, defined in ContextUtils
* @param {Boolean} [pActive=undefined] if not undefined: it select only for active / inactive state
* @param {String[]} [pExcludedObjectIds=undefined] if set: this contextIds are filtered out.
* @param {Boolean} [pAlsoAddFromSubcontexts=false] if true also load data from contexts which are configured as subcontexts.
* A subcontext is for example used by Organisations, which also load the data from all Persons in this organisation into the 360°-view.
* Does not include subcontexts of subcontexts
*
* @return {String[][]} the resulting data
*/
function _get360Data(pBaseContextId, pContactId, pContextList, pActive, pExcludedObjectIds, pAlsoAddFromSubcontexts)
function _get360Data(pSelectMap, pBaseContextId, pContactId, pContextList, pActive, pExcludedObjectIds, pAlsoAddFromSubcontexts)
{
var resultList = [];
pContextList.forEach(function (context)
......@@ -60,7 +69,7 @@ function _get360Data(pBaseContextId, pContactId, pContextList, pActive, pExclude
record[5] = translate.text(pActive);
else
{
if(selectMap[context].activeStates.indexOf(row[3]) > -1)
if(pSelectMap[context].activeStates.indexOf(row[3]) > -1)
record[5] = translate.text("true");
else
record[5] = translate.text("false");
......@@ -71,7 +80,7 @@ function _get360Data(pBaseContextId, pContactId, pContextList, pActive, pExclude
if (pAlsoAddFromSubcontexts)
{
var baseContextData = ContextUtils.getSelectMap()[pBaseContextId];
var baseContextData = pSelectMap[pBaseContextId];
var subContexts = baseContextData.getSubContexts(pContactId);
if (!pExcludedObjectIds)
......@@ -81,13 +90,13 @@ function _get360Data(pBaseContextId, pContactId, pContextList, pActive, pExclude
for (subContextId in subContexts)
{
var subContextSql = subContexts[subContextId];
var subContextSql = subContexts[subContextId][0];
// select Ids from subcontexts
var subContextContactIds = db.array(db.COLUMN, subContextSql);
subContextContactIds.forEach(function(pId) {
// V-- do not add subcontexts deeper than one layer
var subcontextRes = _get360Data(undefined, pId, pContextList, pActive, pExcludedObjectIds, false);
// V-- do not add subcontexts deeper than one layer
var subcontextRes = _get360Data(pSelectMap, pBaseContextId, pId, subContexts[subContextId][1], pActive, pExcludedObjectIds, false);
logging.log(subcontextRes.toSource())
resultList = resultList.concat(subcontextRes);
});
......
......@@ -242,8 +242,9 @@ function ContextSelector(pTableName, pIdField, pTitleExpression)
* an object which contains the subcontexts and the prepared select to get the contactIds of them.
* V--With Tablename!
* { V-- before id-condition | add "and", if needed --V V-IdCollumn name V-- optional after-condition SQL (e.g. group by etc.)
* "Person": ["select PERSON_ID from CONTACT where PERSON_ID is not null and", "CONTACT.ORGANISATION_ID", ''],
* "Offer" ...
* "Person": ["select PERSON_ID from CONTACT where PERSON_ID is not null and", "CONTACT.ORGANISATION_ID", '', ["Offer", "Contract"]],
* // the contexts to show for this subcontext
* "Offer" ... // you can add as many subcontexts as you wish
* }
* read-only property; set it with a matching setter
* @property
......@@ -299,9 +300,9 @@ ContextSelector.prototype.getSubContexts = function(pParentRowId)
for (contextId in this.subContexts)
{
sqls[contextId] = SqlCondition.begin()
sqls[contextId] = [SqlCondition.begin()
.andPrepare(this.subContexts[contextId][1], pParentRowId)
.buildSql(this.subContexts[contextId][0], "1=2", this.subContexts[contextId][2], false);
.buildSql(this.subContexts[contextId][0], "1=2", this.subContexts[contextId][2], false), this.subContexts[contextId][3]];
}
return sqls;
......@@ -377,7 +378,7 @@ ContextUtils.getSelectMap = function()
.setJoinExpression("join CONTACT on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID and CONTACT.PERSON_ID is null")
.setCondition(SqlCondition.begin().and("ORGANISATION.ORGANISATIONID != '0'"))
.setSubContexts({
"Person": ["select CONTACTID from CONTACT where PERSON_ID is not null and", "CONTACT.ORGANISATION_ID", '']
"Person": ["select CONTACTID from CONTACT where PERSON_ID is not null and", "CONTACT.ORGANISATION_ID", '', ["Offer", "Contract"]]
})
,"Person": ContextSelector.create("CONTACT", "CONTACTID")
.setTitleExpression(maskingUtils.concat([
......
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