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

show data of persons in organisation 360

parent 3b258521
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,12 @@
<entityParameter>
<name>ObjectType_param</name>
<valueProcess>%aditoprj%/entity/360Degree_entity/entityfields/organisationobjects/children/objecttype_param/valueProcess.js</valueProcess>
<expose v="false" />
</entityParameter>
<entityParameter>
<name>BaseContextId_param</name>
<valueProcess>%aditoprj%/entity/360Degree_entity/entityfields/organisationobjects/children/basecontextid_param/valueProcess.js</valueProcess>
<expose v="false" />
</entityParameter>
</children>
</entityProvider>
......@@ -82,6 +88,12 @@
<entityParameter>
<name>ObjectType_param</name>
<valueProcess>%aditoprj%/entity/360Degree_entity/entityfields/personobjects/children/objecttype_param/valueProcess.js</valueProcess>
<expose v="false" />
</entityParameter>
<entityParameter>
<name>BaseContextId_param</name>
<valueProcess>%aditoprj%/entity/360Degree_entity/entityfields/personobjects/children/basecontextid_param/valueProcess.js</valueProcess>
<expose v="false" />
</entityParameter>
</children>
</entityProvider>
......@@ -142,6 +154,10 @@
<dropDownProcess>%aditoprj%/entity/360Degree_entity/entityfields/active/dropDownProcess.js</dropDownProcess>
<searchable v="true" />
</entityField>
<entityParameter>
<name>BaseContextId_param</name>
<expose v="true" />
</entityParameter>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
......
import("system.result");
result.string("Organisation");
\ No newline at end of file
import("system.result");
result.string("Person");
\ No newline at end of file
......@@ -6,7 +6,6 @@ import("system.result");
import("Context_lib");
import("system.translate");
var resultList = [];
if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param") && vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param"))
{
......@@ -27,9 +26,28 @@ if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"
}
var contextList = JSON.parse(vars.getString("$param.ObjectType_param"));
contextList.forEach(function (context)
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));
}
else
{
result.object([]);
}
/**
* @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
*/
function _get360Data(pBaseContextId, pContactId, pContextList, pActive, pExcludedObjectIds, pAlsoAddFromSubcontexts)
{
var resultList = [];
pContextList.forEach(function (context)
{
var data = db.table(ContextUtils.getContextDataSql(context, vars.get("$param.ObjectRowId_param"), true, active, true));
var data = db.table(ContextUtils.getContextDataSql(context, pContactId, true, pActive, true, pExcludedObjectIds));
data.forEach(function (row)
{
var record = [];
......@@ -38,8 +56,8 @@ if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"
record[2] = context; // TARGET_CONTEXT
record[3] = row[1]; // TITLE
record[4] = row[2]; //DATE
if(active != undefined) //ACTIVE
record[5] = translate.text(active);
if(pActive != undefined) //ACTIVE
record[5] = translate.text(pActive);
else
{
if(selectMap[context].activeStates.indexOf(row[3]) > -1)
......@@ -48,12 +66,33 @@ if (vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"
record[5] = translate.text("false");
}
resultList.push(record);
});
});
result.object(resultList)
}
else
{
result.object(resultList);
});
});
if (pAlsoAddFromSubcontexts)
{
var baseContextData = ContextUtils.getSelectMap()[pBaseContextId];
var subContexts = baseContextData.getSubContexts(pContactId);
if (!pExcludedObjectIds)
pExcludedObjectIds = [];
pExcludedObjectIds.push(pBaseContextId);
for (subContextId in subContexts)
{
var subContextSql = subContexts[subContextId];
// 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);
logging.log(subcontextRes.toSource())
resultList = resultList.concat(subcontextRes);
});
}
}
return resultList;
}
\ No newline at end of file
......@@ -237,6 +237,18 @@ function ContextSelector(pTableName, pIdField, pTitleExpression)
*/
this.activeStates = null; ProtoPropertyUtils.makeSemiReadOnly(this, "activeStates");
this.condition = null; ProtoPropertyUtils.makeSemiReadOnly(this, "condition");
/**
* 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" ...
* }
* read-only property; set it with a matching setter
* @property
*/
this.subContexts = null; ProtoPropertyUtils.makeSemiReadOnly(this, "subContexts");
}
/**
* creates a new instance of a ContextSelector and returns it
......@@ -275,6 +287,28 @@ ContextSelector.prototype.getFullFromClause = function()
else
return this.tableName;
};
/**
* @return {String} full from-expression with tablename and join-part
*/
ContextSelector.prototype.getSubContexts = function(pParentRowId)
{
if (this.subContexts)
{
var sqls = {};
for (contextId in this.subContexts)
{
sqls[contextId] = SqlCondition.begin()
.andPrepare(this.subContexts[contextId][1], pParentRowId)
.buildSql(this.subContexts[contextId][0], "1=2", this.subContexts[contextId][2], false);
}
return sqls;
}
else
return {};
};
//setters which to nothing special; no need to document them
ContextSelector.prototype.setTitleExpression = function(pValue)
......@@ -326,6 +360,11 @@ ContextSelector.prototype.setCondition = function(pSqlCondition)
this._condition = pSqlCondition;
return this;
};
ContextSelector.prototype.setSubContexts = function(pContexts)
{
this._subContexts = pContexts;
return this;
};
/**
* TODO: !!!temporary function until you can get fields from another Entity!!!
......@@ -337,6 +376,9 @@ ContextUtils.getSelectMap = function()
"Organisation": ContextSelector.create("ORGANISATION", "CONTACT.CONTACTID", "ORGANISATION.NAME")
.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": ContextSelector.create("CONTACT", "CONTACTID")
.setTitleExpression(maskingUtils.concat([
new ContactTitleRenderer(Contact.createWithColumnPreset()).asSql()
......
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