From 90c36849a34a54410ce6daaf6899438817a2716f Mon Sep 17 00:00:00 2001 From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local> Date: Wed, 26 Jun 2019 09:35:02 +0200 Subject: [PATCH] AttributeRelation edit empty attributes --- .../AttributeRelation_entity.aod | 19 ----- .../alter/children/edit/onActionProcess.js | 18 ----- .../alter/children/edit/stateProcess.js | 13 ---- .../recordcontainers/jdito/contentProcess.js | 73 +++++++++---------- .../recordcontainers/jdito/onUpdate.js | 6 +- .../AttributeRelationTree_view.aod | 57 +++++++-------- 6 files changed, 67 insertions(+), 119 deletions(-) delete mode 100644 entity/AttributeRelation_entity/entityfields/alter/children/edit/onActionProcess.js delete mode 100644 entity/AttributeRelation_entity/entityfields/alter/children/edit/stateProcess.js diff --git a/entity/AttributeRelation_entity/AttributeRelation_entity.aod b/entity/AttributeRelation_entity/AttributeRelation_entity.aod index 294f3f2322..745b6f08a5 100644 --- a/entity/AttributeRelation_entity/AttributeRelation_entity.aod +++ b/entity/AttributeRelation_entity/AttributeRelation_entity.aod @@ -144,17 +144,6 @@ </entityParameter> </children> </entityConsumer> - <entityActionGroup> - <name>alter</name> - <children> - <entityActionField> - <name>edit</name> - <onActionProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/alter/children/edit/onActionProcess.js</onActionProcess> - <iconId>NEON:PENCIL</iconId> - <stateProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/alter/children/edit/stateProcess.js</stateProcess> - </entityActionField> - </children> - </entityActionGroup> <entityParameter> <name>GetTree_param</name> <expose v="true" /> @@ -272,14 +261,6 @@ <expose v="true" /> <documentation>%aditoprj%/entity/AttributeRelation_entity/entityfields/showempty_param/documentation.adoc</documentation> </entityParameter> - <entityParameter> - <name>AttributeId_param</name> - <expose v="true" /> - </entityParameter> - <entityParameter> - <name>IsNew_param</name> - <expose v="true" /> - </entityParameter> </entityFields> <recordContainers> <jDitoRecordContainer> diff --git a/entity/AttributeRelation_entity/entityfields/alter/children/edit/onActionProcess.js b/entity/AttributeRelation_entity/entityfields/alter/children/edit/onActionProcess.js deleted file mode 100644 index aa6e8903ba..0000000000 --- a/entity/AttributeRelation_entity/entityfields/alter/children/edit/onActionProcess.js +++ /dev/null @@ -1,18 +0,0 @@ -import("ObjectRelation_lib"); -import("system.neon"); -import("system.vars"); - -if (vars.exists("$sys.selectionRows") && vars.get("$sys.selectionRows").length > 0) -{ - var row = vars.get("$sys.selectionRows")[0]; - var params = { - "ObjectType_param" : vars.get("$param.ObjectType_param"), - "ObjectRowId_param" : vars.get("$param.ObjectRowId_param"), - "AttributeId_param" : row.AB_ATTRIBUTE_ID, - "DisplaySimpleName_param" : vars.get("$param.DisplaySimpleName_param"), - "FilteredAttributeIds_param" : vars.get("$param.FilteredAttributeIds_param"), - "IsNew_param" : row.UID[0] == "," // if first char is "," it is a newly generated UUID - }; - var operatingState = row.VALUE ? neon.OPERATINGSTATE_EDIT : neon.OPERATINGSTATE_NEW; // V--- remove "," if it exists - neon.openContext("AttributeRelation", "AttributeRelationTreeEdit_view", [row.UID[0] == "," ? row.UID.substr(1) : row.UID], operatingState, params); -} \ No newline at end of file diff --git a/entity/AttributeRelation_entity/entityfields/alter/children/edit/stateProcess.js b/entity/AttributeRelation_entity/entityfields/alter/children/edit/stateProcess.js deleted file mode 100644 index b8964feb97..0000000000 --- a/entity/AttributeRelation_entity/entityfields/alter/children/edit/stateProcess.js +++ /dev/null @@ -1,13 +0,0 @@ -import("system.result"); -import("system.vars"); -import("system.neon"); -import("Attribute_lib"); - -var state = neon.COMPONENTSTATE_DISABLED; -if (vars.exists("$sys.selectionRows") && vars.get("$sys.selectionRows").length > 0) -{ - var row = vars.get("$sys.selectionRows")[0]; - if (row.AB_ATTRIBUTE_ID) - state = neon.COMPONENTSTATE_EDITABLE; -} -result.string(state); \ No newline at end of file diff --git a/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js b/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js index 337c80c855..1022a93cb3 100644 --- a/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/AttributeRelation_entity/recordcontainers/jdito/contentProcess.js @@ -17,46 +17,33 @@ var getTree = vars.exists("$param.GetTree_param") && vars.getString("$param.GetT var showEmpty = vars.exists("$param.ShowEmpty_param") && vars.getString("$param.ShowEmpty_param") == "true"; var displaySimpleName = vars.exists("$param.DisplaySimpleName_param") && vars.get("$param.DisplaySimpleName_param"); -var sqlSelect = "select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, '', '', '', ATTRIBUTE_NAME from AB_ATTRIBUTE"; -var attributeRelationJoin = "join AB_ATTRIBUTERELATION on AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID"; var sqlCondition = new SqlCondition(); var subCondition = new SqlCondition(); if (vars.exists("$local.idvalues") && vars.get("$local.idvalues")) { let idVals = vars.get("$local.idvalues"); - let idCond = new SqlCondition(); - idVals.forEach(function (id) + let attrId = idVals.length === 1 && idVals[0].split(",")[1]; + if (!attrId) + showEmpty = false; + + if (showEmpty) + sqlCondition.andPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attrId); + else { - this.orPrepare("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", id); - }, subCondition); - sqlCondition.andSqlCondition(subCondition); + sqlCondition.andIn("AB_ATTRIBUTERELATION.AB_ATTRIBUTERELATIONID", idVals); + rowId = null; + } getTree = false; } else if (showEmpty || rowId) { + if (showEmpty) { - let idCond = new SqlCondition(); let possibleAttributes = AttributeUtil.getPossibleAttributes(objectType); - possibleAttributes.forEach(function (attributeId) - { - this.orPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", attributeId); - }, idCond); - sqlCondition.andSqlCondition(idCond); - - attributeRelationJoin = "left " + attributeRelationJoin; - } - if (rowId) - { - subCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", rowId); - if (objectType != null) - subCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType); - if (subCondition.isSet()) - attributeRelationJoin += " and " + db.translateCondition(subCondition.build("1=1")); - // add condition to match all returned by joins (override default 1=2 of build) - sqlCondition.and("1=1"); + sqlCondition.andIn("AB_ATTRIBUTE.AB_ATTRIBUTEID", possibleAttributes); } if (vars.exists("$param.FilteredAttributeIds_param") && vars.getString("$param.FilteredAttributeIds_param")) { @@ -72,8 +59,18 @@ else if (showEmpty || rowId) sqlCondition.andSqlCondition(subCondition, "1=2"); } } +var joinCondition = ""; +if (rowId) +{ + subCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", rowId); + if (objectType != null) + subCondition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType); + if (subCondition.isSet()) + joinCondition = " and " + db.translateCondition(subCondition.build("1=1")); + // add condition to match all returned by joins (override default 1=2 of build) + sqlCondition.and("1=1"); +} -//these fields are always required var defaultFields = [ "AB_ATTRIBUTERELATIONID", "AB_ATTRIBUTE.AB_ATTRIBUTEID", @@ -87,30 +84,31 @@ var defaultFields = [ var valueFields = AttributeTypeUtil.getAllDatabaseFields(); var attributeSql = sqlCondition.buildSql("select " + defaultFields.join(", ") + ", " + valueFields.join(", ") + " from AB_ATTRIBUTE " - + attributeRelationJoin + + (showEmpty ? "left " : "") + "join AB_ATTRIBUTERELATION on AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID " + joinCondition + " left join AB_ATTRIBUTE COMBOVAL on " + $AttributeTypes.COMBO.databaseField + " = COMBOVAL.AB_ATTRIBUTEID" //for the view value of combobox attributes , "1=2" ); var attributeValues = db.table(attributeSql).map(function (row) { - let attributeId = row[1]; - let attributeName = translate.text(row[4]); + var attributeId = row[1]; + var attributeName = translate.text(row[4]); + var type = row[3].trim(); if (!getTree && !displaySimpleName && row[2]) { let parentName = AttributeUtil.getFullAttributeName(row[2]); attributeName = (parentName ? parentName + " / " : "") + attributeName; } - let value = row[AttributeTypeUtil.getTypeColumnIndex(row[3]) + defaultFields.length]; - let viewValue; - if (row[3].trim() == $AttributeTypes.COMBO) + var value = row[AttributeTypeUtil.getTypeColumnIndex(row[3]) + defaultFields.length]; + var viewValue; + if (type == $AttributeTypes.COMBO) viewValue = translate.text(row[6]); else - viewValue = AttributeTypeUtil.getAttributeViewValue(row[3].trim(), value, row[5]); + viewValue = AttributeTypeUtil.getAttributeViewValue(type, value, row[5]); //TODO: what should be the uid if showEmpty is true? // V-- set "," to mark this as new generated UUID - return [row[0] || "," + util.getNewUUID(), row[2], value, viewValue, attributeId, attributeName]; + return [row[0] || util.getNewUUID() + "," + attributeId, row[2], value, viewValue, attributeId, attributeName]; }); @@ -135,7 +133,7 @@ function _fetchAttributes (pAttributeIds) if (!(id in this)) sqlCondition.orPrepare("AB_ATTRIBUTE.AB_ATTRIBUTEID", id); }, attributeObj); - db.table(sqlCondition.buildSql(sqlSelect, "1=2")) + db.table(sqlCondition.buildSql("select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME from AB_ATTRIBUTE", "1=2")) .forEach(function (row) { this[row[0]] = true; //make entry in attributeObj to avoid duplicates @@ -143,9 +141,10 @@ function _fetchAttributes (pAttributeIds) nextIds.push(row[1]); else row[1] = null; - row[5] = translate.text(row[5]); //translate attribute name - parentAttributes.push(row); + row[2] = translate.text(row[2]); //translate attribute name + parentAttributes.push([row[0], row[1], "", "", "", row[2]]); }, attributeObj); + if (nextIds.length) _fetchAttributes(nextIds); } diff --git a/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js b/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js index ff99179b2c..b42dfc4e2e 100644 --- a/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/AttributeRelation_entity/recordcontainers/jdito/onUpdate.js @@ -6,9 +6,10 @@ import("Attribute_lib"); var type = AttributeUtil.getAttributeType(vars.get("$field.AB_ATTRIBUTE_ID")); var columns, values; +var uid = vars.get("$local.uid").split(","); // if first char is "," it is a newly generated UUID -if (vars.get("$local.uid")[0] != "," && !(vars.exists("$param.IsNew_param") && vars.getString("$param.IsNew_param") == "true")) +if (uid.length === 1) { columns = [ "AB_ATTRIBUTE_ID", @@ -43,9 +44,8 @@ else "USER_NEW" ]; - var uid = vars.get("$local.uid"); values = [ - uid[0] == "," ? uid.substr(1) : uid, // if first char is "," it is a newly generated UUID + uid[0], // if first char is "," it is a newly generated UUID vars.get("$field.AB_ATTRIBUTE_ID"), vars.get("$param.ObjectRowId_param"), vars.get("$param.ObjectType_param"), diff --git a/neonView/AttributeRelationTree_view/AttributeRelationTree_view.aod b/neonView/AttributeRelationTree_view/AttributeRelationTree_view.aod index 5ce8d66397..1eee2f28de 100644 --- a/neonView/AttributeRelationTree_view/AttributeRelationTree_view.aod +++ b/neonView/AttributeRelationTree_view/AttributeRelationTree_view.aod @@ -1,29 +1,28 @@ -<?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.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.1"> - <name>AttributeRelationTree_view</name> - <majorModelMode>DISTRIBUTED</majorModelMode> - <layout> - <boxLayout> - <name>layout</name> - </boxLayout> - </layout> - <children> - <treeTableViewTemplate> - <name>TreeTable</name> - <parentField>PARENT_ID</parentField> - <favoriteActionGroup1>alter</favoriteActionGroup1> - <showChildrenCount v="false" /> - <entityField>#ENTITY</entityField> - <columns> - <neonTableColumn> - <name>840551af-5a99-4965-a96a-ed134efb28a9</name> - <entityField>AB_ATTRIBUTE_ID</entityField> - </neonTableColumn> - <neonTableColumn> - <name>7844082c-fd31-4878-9e57-024cb2b2b627</name> - <entityField>VALUE</entityField> - </neonTableColumn> - </columns> - </treeTableViewTemplate> - </children> -</neonView> +<?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.1.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonView/1.1.1"> + <name>AttributeRelationTree_view</name> + <majorModelMode>DISTRIBUTED</majorModelMode> + <layout> + <boxLayout> + <name>layout</name> + </boxLayout> + </layout> + <children> + <treeTableViewTemplate> + <name>TreeTable</name> + <parentField>PARENT_ID</parentField> + <showChildrenCount v="false" /> + <entityField>#ENTITY</entityField> + <columns> + <neonTableColumn> + <name>840551af-5a99-4965-a96a-ed134efb28a9</name> + <entityField>AB_ATTRIBUTE_ID</entityField> + </neonTableColumn> + <neonTableColumn> + <name>7844082c-fd31-4878-9e57-024cb2b2b627</name> + <entityField>VALUE</entityField> + </neonTableColumn> + </columns> + </treeTableViewTemplate> + </children> +</neonView> -- GitLab