Skip to content
Snippets Groups Projects
Commit 01736915 authored by Andre Loreth's avatar Andre Loreth
Browse files

#1035095: Object tree

parent c38a1f33
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.2.1">
<name>ObjectTree_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<recordContainer>jdito</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
</entityProvider>
<entityProvider>
<name>TreeProvider</name>
<fieldType>DEPENDENCY_IN</fieldType>
<dependencies>
<entityDependency>
<name>b92be69f-056c-41fb-8367-9f235bfe66e0</name>
<entityName>Organisation_entity</entityName>
<fieldName>ObjectTrees</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
</entityProvider>
<entityParameter>
<name>ObjectId_param</name>
<expose v="true" />
<mandatory v="true" />
<description>PARAMETER</description>
</entityParameter>
<entityField>
<name>UID</name>
</entityField>
<entityField>
<name>PARENT_ID</name>
</entityField>
<entityField>
<name>TITLE</name>
</entityField>
<entityField>
<name>ICON</name>
<valueProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/icon/valueProcess.js</valueProcess>
</entityField>
<entityField>
<name>DESCRIPTION</name>
<valueProcess>%aditoprj%/entity/ObjectTree_entity/entityfields/description/valueProcess.js</valueProcess>
</entityField>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
<name>jdito</name>
<jDitoRecordAlias>Data_alias</jDitoRecordAlias>
<contentProcess>%aditoprj%/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
<recordFields>
<element>UID.value</element>
<element>PARENT_ID.value</element>
<element>TITLE.value</element>
<element>DESCRIPTION.value</element>
<element>ICON.value</element>
</recordFields>
</jDitoRecordContainer>
</recordContainers>
</entity>
import("system.result");
import("system.result");
result.string("VAADIN:TASKS");
\ No newline at end of file
import("system.logging");
import("system.db");
import("system.vars");
import("system.result");
import("system.translate");
import("Context_lib");
import("Sql_lib")
var thisObjectId = vars.get("$param.ObjectId_param");
var objectRelations = fetchObjectRelations(thisObjectId);
var mappedObjectRelations = mapObjectRelations(objectRelations);
var treeData = buildTreeData(mappedObjectRelations);
logging.log(JSON.stringify(treeData));
result.object(treeData);
/**
* Will fetch all objects relations which are in relation with the given
* object ID. It will compare the given object ID with `OBJECT1_ROWID` and
* `OBJECT2_ROWID`.
*
* It will always return the following array signature:
* (0) OBJECT1_ROWID | (1) OBJECT2_ROWID | (2) AB_OBJECTRELATIONTYPE1 |(3) type1.OBJECT_TYPE | (4) type1.RELATION_TITLE
* (5) AB_OBJECTRELATIONTYPE2 | (6) type2.OBJECT_TYPE | (7) type2.RELATION_TITLE | (8) Name of object 1 | (9) Name of object 2
*
* @return Will return the given schema above. You can assume, that there will always
* be an array.
*/
function fetchObjectRelations (pObjectID) {
var databaseResult = db.table(
"SELECT OBJECT1_ROWID, OBJECT2_ROWID, AB_OBJECTRELATIONTYPE1, type1.OBJECT_TYPE, type1.RELATION_TITLE, AB_OBJECTRELATIONTYPE2, type2.OBJECT_TYPE, type2.RELATION_TITLE, "
+ ContextUtils.getNameSubselectSql("type1.OBJECT_TYPE", "OBJECT1_ROWID") + ", " + ContextUtils.getNameSubselectSql("type2.OBJECT_TYPE", "OBJECT2_ROWID") + " "
+ "FROM ADITO.AB_OBJECTRELATION as relation "
+ "left join AB_OBJECTRELATIONTYPE as type1 on AB_OBJECTRELATIONTYPE1 = type1.AB_OBJECTRELATIONTYPEID "
+ "left join AB_OBJECTRELATIONTYPE as type2 on AB_OBJECTRELATIONTYPE2 = type2.AB_OBJECTRELATIONTYPEID "
+ "where OBJECT1_ROWID = '" + thisObjectId + "' or OBJECT2_ROWID = '" + thisObjectId + "'");
return databaseResult;
}
/**
* Will map the given object relations into a valid schema for the tree.
* The requried schema for the param can be found in function
* {@link fetchObjectRelations}.
* This function is required for additional filtering an mapping of the data.
*
* It will always return the following array signature:
* (0) Object type ID | (1) Object type name | (2) Relation
*
*
* @param pObjectRelations Array with object relations in specific schema.
* @return Will return the given schema above. You can assume, that there will
* always be an array.
*
* @return The mapped Array with object relations in the following format:
* ObjectTypeID | ObjectType | RelationTitle | ObjectID
*/
function mapObjectRelations (pObjectRelations) {
var resultSet = [];
for (var i = 0; i < pObjectRelations.length; i++) {
var currentRecord = pObjectRelations[i];
var objectRowId1 = currentRecord[0];
var objectRowId2 = currentRecord[1];
if (objectRowId1 === thisObjectId) {
resultSet.push([currentRecord[5], currentRecord[6], currentRecord[7], currentRecord[1], currentRecord[9]]);
} else if (objectRowId2 === thisObjectId) {
resultSet.push([currentRecord[2], currentRecord[3], currentRecord[4], currentRecord[0], currentRecord[8]]);
}
}
return resultSet
}
function buildTreeData (pObjectRelations) {
// Group each relation type
var relationTypeMapping = {}
var i = 0;
for (i = 0; i < pObjectRelations.length; i++) {
var currentRelation = pObjectRelations[i];
if (relationTypeMapping[currentRelation[0]] === undefined)
relationTypeMapping[currentRelation[0]] = currentRelation[2];
}
var treeRows = []
for (i = 0; i < pObjectRelations.length; i++) {
var currentRelation = pObjectRelations[i];
logging.log(JSON.stringify(currentRelation))
treeRows.push([currentRelation[3], currentRelation[0], currentRelation[4]]);
}
// Root elements
for (i = 0 ; i < Object.keys(relationTypeMapping).length; i++) {
var currentKey = Object.keys(relationTypeMapping)[i];
var translatedTitle = translate.text(relationTypeMapping[currentKey])
treeRows.push([currentKey, null, translatedTitle]);
}
return treeRows;
}
\ No newline at end of file
......@@ -535,6 +535,23 @@
</entityParameter>
</children>
</entityConsumer>
<entityConsumer>
<name>ObjectTrees</name>
<title>Beziehungsbaum</title>
<fieldType>DEPENDENCY_OUT</fieldType>
<dependency>
<name>dependency</name>
<entityName>ObjectTree_entity</entityName>
<fieldName>TreeProvider</fieldName>
</dependency>
<children>
<entityParameter>
<name>ObjectId_param</name>
<title></title>
<valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/objecttrees/children/objectid_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
</entityFields>
<recordContainers>
<dbRecordContainer>
......
import("system.result");
import("system.vars");
result.string(vars.get("$field.ORGANISATION_ID"));
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.0.0">
<name>ObjectTree</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<entity>ObjectTree_entity</entity>
<references>
<neonViewReference>
<name>0c9fc36e-e3f7-4198-b675-5d9ddb177611</name>
<view>ObjectTree_view</view>
</neonViewReference>
</references>
</neonContext>
<?xml version="1.0" encoding="UTF-8"?>
<neonView xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.0.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.0.1">
<name>ObjectTree_view</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<layout>
<boxLayout>
<name>layout</name>
</boxLayout>
</layout>
<children>
<treetableViewTemplate>
<name>Treetable</name>
<parentField>PARENT_ID</parentField>
<titleField>TITLE</titleField>
<descriptionField>DESCRIPTION</descriptionField>
<iconField>ICON</iconField>
<entityField>#ENTITY</entityField>
<title></title>
</treetableViewTemplate>
</children>
</neonView>
......@@ -55,5 +55,10 @@
<entityField>Salesprojects</entityField>
<view>SalesprojectFilter_view</view>
</neonViewReference>
<neonViewReference>
<name>c54ae5b7-7e9e-40c7-8d64-b1d75fbafa57</name>
<entityField>ObjectTrees</entityField>
<view>ObjectTree_view</view>
</neonViewReference>
</children>
</neonView>
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