From 01736915dc07b64aa46052af00a67568f7e09683 Mon Sep 17 00:00:00 2001 From: Andre Loreth <a.loreth@adito.de> Date: Fri, 15 Mar 2019 10:42:45 +0100 Subject: [PATCH] #1035095: Object tree --- .../ObjectTree_entity/ObjectTree_entity.aod | 60 ++++++++++ .../entityfields/description/valueProcess.js | 1 + .../entityfields/icon/valueProcess.js | 2 + .../recordcontainers/jdito/contentProcess.js | 111 ++++++++++++++++++ .../Organisation_entity.aod | 17 +++ .../children/objectid_param/valueProcess.js | 4 + neonContext/ObjectTree/ObjectTree.aod | 12 ++ neonView/ObjectTree_view/ObjectTree_view.aod | 21 ++++ .../OrganisationMain_view.aod | 5 + 9 files changed, 233 insertions(+) create mode 100644 entity/ObjectTree_entity/ObjectTree_entity.aod create mode 100644 entity/ObjectTree_entity/entityfields/description/valueProcess.js create mode 100644 entity/ObjectTree_entity/entityfields/icon/valueProcess.js create mode 100644 entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js create mode 100644 entity/Organisation_entity/entityfields/objecttrees/children/objectid_param/valueProcess.js create mode 100644 neonContext/ObjectTree/ObjectTree.aod create mode 100644 neonView/ObjectTree_view/ObjectTree_view.aod diff --git a/entity/ObjectTree_entity/ObjectTree_entity.aod b/entity/ObjectTree_entity/ObjectTree_entity.aod new file mode 100644 index 0000000000..dffdd4a141 --- /dev/null +++ b/entity/ObjectTree_entity/ObjectTree_entity.aod @@ -0,0 +1,60 @@ +<?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> diff --git a/entity/ObjectTree_entity/entityfields/description/valueProcess.js b/entity/ObjectTree_entity/entityfields/description/valueProcess.js new file mode 100644 index 0000000000..552c76f974 --- /dev/null +++ b/entity/ObjectTree_entity/entityfields/description/valueProcess.js @@ -0,0 +1 @@ +import("system.result"); diff --git a/entity/ObjectTree_entity/entityfields/icon/valueProcess.js b/entity/ObjectTree_entity/entityfields/icon/valueProcess.js new file mode 100644 index 0000000000..38e1eeb090 --- /dev/null +++ b/entity/ObjectTree_entity/entityfields/icon/valueProcess.js @@ -0,0 +1,2 @@ +import("system.result"); +result.string("VAADIN:TASKS"); \ No newline at end of file diff --git a/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js new file mode 100644 index 0000000000..4ec7d6d6bd --- /dev/null +++ b/entity/ObjectTree_entity/recordcontainers/jdito/contentProcess.js @@ -0,0 +1,111 @@ +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 diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod index 8546885e0c..cd5180fe05 100644 --- a/entity/Organisation_entity/Organisation_entity.aod +++ b/entity/Organisation_entity/Organisation_entity.aod @@ -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> diff --git a/entity/Organisation_entity/entityfields/objecttrees/children/objectid_param/valueProcess.js b/entity/Organisation_entity/entityfields/objecttrees/children/objectid_param/valueProcess.js new file mode 100644 index 0000000000..70a89edc2c --- /dev/null +++ b/entity/Organisation_entity/entityfields/objecttrees/children/objectid_param/valueProcess.js @@ -0,0 +1,4 @@ +import("system.result"); +import("system.vars"); + +result.string(vars.get("$field.ORGANISATION_ID")); \ No newline at end of file diff --git a/neonContext/ObjectTree/ObjectTree.aod b/neonContext/ObjectTree/ObjectTree.aod new file mode 100644 index 0000000000..5baa37bf33 --- /dev/null +++ b/neonContext/ObjectTree/ObjectTree.aod @@ -0,0 +1,12 @@ +<?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> diff --git a/neonView/ObjectTree_view/ObjectTree_view.aod b/neonView/ObjectTree_view/ObjectTree_view.aod new file mode 100644 index 0000000000..f619dc246d --- /dev/null +++ b/neonView/ObjectTree_view/ObjectTree_view.aod @@ -0,0 +1,21 @@ +<?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> diff --git a/neonView/OrganisationMain_view/OrganisationMain_view.aod b/neonView/OrganisationMain_view/OrganisationMain_view.aod index b708d1e0bf..810948868a 100644 --- a/neonView/OrganisationMain_view/OrganisationMain_view.aod +++ b/neonView/OrganisationMain_view/OrganisationMain_view.aod @@ -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> -- GitLab