From 4fa901db94cdd02f7dbae5764785631c1fd636f9 Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Wed, 27 Mar 2019 16:29:49 +0100 Subject: [PATCH] Parent attribute editable --- .../valueproxy/possibleItemsProcess.js | 2 +- entity/Attribute_entity/Attribute_entity.aod | 40 +++++++++++++++++-- .../attribute_parent_id/onValueChange.js | 38 ++++++++++++++++++ .../attribute_parent_id/stateProcess.js | 7 ++-- .../attrparentid_param/valueProcess.js | 4 ++ .../children/getgroups_param/valueProcess.js | 3 ++ .../children/getgroups_param/valueProcess.js | 5 --- .../recordcontainers/db/conditionProcess.js | 4 ++ .../recordcontainers/db/orderClauseProcess.js | 5 ++- 9 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 entity/Attribute_entity/entityfields/attribute_parent_id/onValueChange.js create mode 100644 entity/Attribute_entity/entityfields/attributegroup/children/attrparentid_param/valueProcess.js create mode 100644 entity/Attribute_entity/entityfields/attributegroups/children/getgroups_param/valueProcess.js delete mode 100644 entity/Attribute_entity/entityfields/attributeparent/children/getgroups_param/valueProcess.js diff --git a/entity/AttributeRelation_entity/entityfields/valueproxy/possibleItemsProcess.js b/entity/AttributeRelation_entity/entityfields/valueproxy/possibleItemsProcess.js index 48d4fad4dd..4a7f1e46ed 100644 --- a/entity/AttributeRelation_entity/entityfields/valueproxy/possibleItemsProcess.js +++ b/entity/AttributeRelation_entity/entityfields/valueproxy/possibleItemsProcess.js @@ -14,7 +14,7 @@ if (attrType == $AttributeTypes.COMBO) .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_ACTIVE", "1") .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId) .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.COMBOVALUE) - .buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_NAME from AB_ATTRIBUTE"); + .buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2", "order by ATTRIBUTE_NAME"); var valueList = db.table(valueSql); result.object(valueList); } diff --git a/entity/Attribute_entity/Attribute_entity.aod b/entity/Attribute_entity/Attribute_entity.aod index ead7f6425a..a658dcc50f 100644 --- a/entity/Attribute_entity/Attribute_entity.aod +++ b/entity/Attribute_entity/Attribute_entity.aod @@ -36,12 +36,17 @@ <entityField> <name>ATTRIBUTE_PARENT_ID</name> <title>Superordinate Attribute</title> - <consumer>AttributeChildren</consumer> + <consumer>AttributeGroup</consumer> <linkedContext>Attribute</linkedContext> <searchable v="false" /> <stateProcess>%aditoprj%/entity/Attribute_entity/entityfields/attribute_parent_id/stateProcess.js</stateProcess> <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attribute_parent_id/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attribute_parent_id/displayValueProcess.js</displayValueProcess> + <onValueChange>%aditoprj%/entity/Attribute_entity/entityfields/attribute_parent_id/onValueChange.js</onValueChange> + <onValueChangeTypes> + <element>MASK</element> + <element>PROCESS</element> + </onValueChangeTypes> </entityField> <entityConsumer> <name>AttributeChildren</name> @@ -90,8 +95,6 @@ </entityParameter> <entityParameter> <name>GetGroups_param</name> - <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributeparent/children/getgroups_param/valueProcess.js</valueProcess> - <expose v="true" /> </entityParameter> </children> </entityProvider> @@ -243,6 +246,37 @@ <title>Name</title> <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/name_with_type/valueProcess.js</valueProcess> </entityField> + <entityProvider> + <name>AttributeGroups</name> + <fieldType>DEPENDENCY_IN</fieldType> + <recordContainer>db</recordContainer> + <children> + <entityParameter> + <name>GetGroups_param</name> + <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributegroups/children/getgroups_param/valueProcess.js</valueProcess> + <expose v="true" /> + </entityParameter> + <entityParameter> + <name>AttrParentId_param</name> + <expose v="true" /> + </entityParameter> + </children> + </entityProvider> + <entityConsumer> + <name>AttributeGroup</name> + <fieldType>DEPENDENCY_OUT</fieldType> + <dependency> + <name>dependency</name> + <entityName>Attribute_entity</entityName> + <fieldName>AttributeGroups</fieldName> + </dependency> + <children> + <entityParameter> + <name>AttrParentId_param</name> + <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributegroup/children/attrparentid_param/valueProcess.js</valueProcess> + </entityParameter> + </children> + </entityConsumer> </entityFields> <recordContainers> <dbRecordContainer> diff --git a/entity/Attribute_entity/entityfields/attribute_parent_id/onValueChange.js b/entity/Attribute_entity/entityfields/attribute_parent_id/onValueChange.js new file mode 100644 index 0000000000..06db0b11a5 --- /dev/null +++ b/entity/Attribute_entity/entityfields/attribute_parent_id/onValueChange.js @@ -0,0 +1,38 @@ +import("system.db"); +import("system.neon"); +import("system.vars"); +import("Attribute_lib"); + +if (vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT) +{ + var level = 0; + if (vars.get("$field.ATTRIBUTE_PARENT_ID") != "") + { + level = db.cell(SqlCondition.begin() + .andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", vars.get("$field.ATTRIBUTE_PARENT_ID")) + .buildSql("select ATTRIBUTE_LEVEL from AB_ATTRIBUTE")); + level = parseInt(level) + 1; + } + neon.setFieldValue("$field.ATTRIBUTE_LEVEL", level); + + var table = "AB_ATTRIBUTE"; + var columns = ["ATTRIBUTE_LEVEL"]; + var types = db.getColumnTypes(table, columns); + var toUpdate = []; + + var attributes = [vars.get("$field.AB_ATTRIBUTEID")]; + while (attributes.length > 0) + { + var condition = SqlCondition.begin() + .and("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID in ('" + attributes.join("','") + "')"); + + toUpdate.push([table, columns, types, [String(++level)], condition.build()]); + + attributes = db.array(db.COLUMN, SqlCondition.begin() + .and("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID in ('" + attributes.join("','") + "')") + .buildSql("select AB_ATTRIBUTEID from AB_ATTRIBUTE") + ); + } + + db.updates(toUpdate); +} \ No newline at end of file diff --git a/entity/Attribute_entity/entityfields/attribute_parent_id/stateProcess.js b/entity/Attribute_entity/entityfields/attribute_parent_id/stateProcess.js index 11f1cb9940..cac55643fb 100644 --- a/entity/Attribute_entity/entityfields/attribute_parent_id/stateProcess.js +++ b/entity/Attribute_entity/entityfields/attribute_parent_id/stateProcess.js @@ -1,11 +1,12 @@ import("system.result"); import("system.neon"); import("system.vars"); +import("Attribute_lib"); var fieldState; -if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) - fieldState = neon.COMPONENTSTATE_AUTO; -else +if(vars.get("$field.ATTRIBUTE_TYPE").trim() == $AttributeTypes.COMBOVALUE) fieldState = neon.COMPONENTSTATE_READONLY; +else + fieldState = neon.COMPONENTSTATE_AUTO; result.string(fieldState); \ No newline at end of file diff --git a/entity/Attribute_entity/entityfields/attributegroup/children/attrparentid_param/valueProcess.js b/entity/Attribute_entity/entityfields/attributegroup/children/attrparentid_param/valueProcess.js new file mode 100644 index 0000000000..033bf9a666 --- /dev/null +++ b/entity/Attribute_entity/entityfields/attributegroup/children/attrparentid_param/valueProcess.js @@ -0,0 +1,4 @@ +import("system.vars"); +import("system.result"); + +result.string(vars.get("$field.AB_ATTRIBUTEID")); \ No newline at end of file diff --git a/entity/Attribute_entity/entityfields/attributegroups/children/getgroups_param/valueProcess.js b/entity/Attribute_entity/entityfields/attributegroups/children/getgroups_param/valueProcess.js new file mode 100644 index 0000000000..28d4124c73 --- /dev/null +++ b/entity/Attribute_entity/entityfields/attributegroups/children/getgroups_param/valueProcess.js @@ -0,0 +1,3 @@ +import("system.result"); + +result.string(true); \ No newline at end of file diff --git a/entity/Attribute_entity/entityfields/attributeparent/children/getgroups_param/valueProcess.js b/entity/Attribute_entity/entityfields/attributeparent/children/getgroups_param/valueProcess.js deleted file mode 100644 index 289c6a9357..0000000000 --- a/entity/Attribute_entity/entityfields/attributeparent/children/getgroups_param/valueProcess.js +++ /dev/null @@ -1,5 +0,0 @@ -import("system.neon"); -import("system.vars"); -import("system.result"); - -result.string(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW || ""); \ No newline at end of file diff --git a/entity/Attribute_entity/recordcontainers/db/conditionProcess.js b/entity/Attribute_entity/recordcontainers/db/conditionProcess.js index 1a30105397..ed323a5c82 100644 --- a/entity/Attribute_entity/recordcontainers/db/conditionProcess.js +++ b/entity/Attribute_entity/recordcontainers/db/conditionProcess.js @@ -10,8 +10,12 @@ var getGroups = vars.exists("$param.GetGroups_param") && vars.get("$param.GetGro var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"); if (getGroups) { + //this is for the selection of the superordinate attribute, this condition + //filters out the own id and the children to prevent loops condition = db.translateCondition(SqlCondition.begin() .andPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes.GROUP) + .andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$param.AttrParentId_param", "# != ?") + .and("AB_ATTRIBUTE.AB_ATTRIBUTEID not in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')") .build()); } else if (objectType) //if there's an objectType, it comes from the AttributeRelation entity diff --git a/entity/Attribute_entity/recordcontainers/db/orderClauseProcess.js b/entity/Attribute_entity/recordcontainers/db/orderClauseProcess.js index 4b14378884..003688a8bb 100644 --- a/entity/Attribute_entity/recordcontainers/db/orderClauseProcess.js +++ b/entity/Attribute_entity/recordcontainers/db/orderClauseProcess.js @@ -1,3 +1,6 @@ import("system.db"); import("system.result"); -result.object({"AB_ATTRIBUTE.ATTRIBUTE_LEVEL" : db.ASCENDING}); \ No newline at end of file +result.object({ + "AB_ATTRIBUTE.ATTRIBUTE_LEVEL" : db.ASCENDING, + "AB_ATTRIBUTE.ATTRIBUTE_NAME" : db.ASCENDING +}); \ No newline at end of file -- GitLab