From dc6ff32c77369ec31f0f16701cb8af9c87c4c52b Mon Sep 17 00:00:00 2001 From: Benjamin Ulrich <b.ulrich@adito.de> Date: Tue, 15 Sep 2020 07:19:09 +0000 Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.: 1058900][Ausweisung der Klassifizierung in Firma (FilterView und PreviewView)] --- .../classificationtypeid/valueProcess.js | 4 +- .../recordcontainers/jdito/onUpdate.js | 48 ++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/entity/ClassificationAdmin_entity/entityfields/classificationtypeid/valueProcess.js b/entity/ClassificationAdmin_entity/entityfields/classificationtypeid/valueProcess.js index 97abbd1464..7c575abe67 100644 --- a/entity/ClassificationAdmin_entity/entityfields/classificationtypeid/valueProcess.js +++ b/entity/ClassificationAdmin_entity/entityfields/classificationtypeid/valueProcess.js @@ -6,5 +6,5 @@ import("Classification_lib"); if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW && !vars.get("$this.value")) result.string(util.getNewUUID()); -else if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT && !vars.get("$this.value")) - result.string($ClassificationPlaceholder.TOPSECRETPLACEHOLDER()); \ No newline at end of file +else if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_EDIT && !vars.get("$this.value")) // this means we are editing one of the classificationgroups + result.string($ClassificationPlaceholder.TOPSECRETPLACEHOLDER()); //this placeholder is set for the onUpdateProcess further explanation in there \ No newline at end of file diff --git a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js b/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js index b5eae575a4..43a6304543 100644 --- a/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/ClassificationAdmin_entity/recordcontainers/jdito/onUpdate.js @@ -1,12 +1,12 @@ +import("Classification_lib"); +import("Sql_lib"); +import("system.db"); +import("system.eMath"); import("system.entities"); -import("system.util"); -import("system.text"); import("system.neon"); -import("system.db"); -import("Sql_lib"); +import("system.text"); +import("system.util"); import("system.vars"); -import("Classification_lib"); -import("system.eMath"); try { @@ -45,11 +45,12 @@ function _update() var i; var isGroupDataSet = false; - if(rowdata["CLASSIFICATIONTYPEID.value"] == $ClassificationPlaceholder.TOPSECRETPLACEHOLDER()) +// the classificationtypeId.value has the placeholder set when editing a classificationgroup dataset to allow us +// to handle the updating differently depending on whether its an classifcation group dataset or an classification type dataset +// since you want changes to the name of groups to effect only the group name and changes to the group of an classificationtype to change it's group + if(rowdata["CLASSIFICATIONTYPEID.value"] == $ClassificationPlaceholder.TOPSECRETPLACEHOLDER()) isGroupDataSet = true; - - vars.get("$local.changed").forEach(function (field, i) { var dbField = dbFields[field]; @@ -63,14 +64,14 @@ function _update() if(!isGroupDataSet) //-> update the classification type dataset { - var groupIds = ClassificationUtils.getAllGroups(vars.get("$field.OBJECT_TYPE")); + var groupIds = ClassificationUtils.getAllGroups(vars.get("$field.OBJECT_TYPE")); //gets all existing groups of the object_type var newGroupId; var newGroupName; var insertGroup = false; var groupchange = true; var newId; for (i = 0; i < columns.length; i++) { - if(columns[i] == "CLASSIFICATIONGROUP_ID") + if(columns[i] == "CLASSIFICATIONGROUP_ID")//if the classificationgroup_Id changed: determine whether or not a new group has to be inserted { if(!groupIds.toString().includes(values[i])) { @@ -101,23 +102,27 @@ function _update() } } - if(groupchange == true) { var gradeColumn, gradeTable, multiplicand, update, gradingTable; var oldGroup = ClassificationUtils.getClassificationGroup(text.decodeMS(uid)[1]); var newMax = ClassificationUtils.getMaxScoreExcludeType(oldGroup, text.decodeMS(uid)[1]); gradingTable = ClassificationUtils.getGradingTableByGroupId(oldGroup); - var lostScore = parseInt(newSelect("max(SCORE)").from("CLASSIFICATIONSCORE").where("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", text.decodeMS(uid)[1]).cell()); - if(insertGroup) + + var lostScore = parseInt(newSelect("max(SCORE)") + .from("CLASSIFICATIONSCORE") + .where("CLASSIFICATIONSCORE.CLASSIFICATIONTYPE_ID", text.decodeMS(uid)[1]) + .cell()); //the greatest score of the "moved" classificationtype affects the classificationGradings + + if(insertGroup) //new group has to be inserted { var maxSorting = newSelect("distinct CLASSIFICATIONGROUP.CLASSIFICATIONGROUPID, CLASSIFICATIONGROUP.SORTING") .from("CLASSIFICATIONGROUP") .join("CLASSIFICATIONTYPE", "CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID = CLASSIFICATIONGROUP.CLASSIFICATIONGROUPID") .where("CLASSIFICATIONTYPE.OBJECT_TYPE", vars.get("$field.OBJECT_TYPE")) .orderBy("CLASSIFICATIONGROUP.SORTING desc") - .table()[0][1]; - db.insertData("CLASSIFICATIONGROUP", ["CLASSIFICATIONGROUPID", "TITLE", "SORTING"], null, [newGroupId, newGroupName, eMath.addInt(maxSorting, 1)]) //insert the new group + .table()[0][1]; //gets the greatest sorting value of the object_type + db.insertData("CLASSIFICATIONGROUP", ["CLASSIFICATIONGROUPID", "TITLE", "SORTING"], null, [newGroupId, newGroupName, eMath.addInt(maxSorting, 1)]) //insert the new group (sorting is greater than the greatest one var gradingColumns = [ "CLASSIFICATIONGRADINGID", @@ -133,13 +138,13 @@ function _update() newGroupId ]; - db.insertData("CLASSIFICATIONGRADING", gradingColumns, null, gradingValues); // insert a "dummy" classificationGradingValue + db.insertData("CLASSIFICATIONGRADING", gradingColumns, null, gradingValues); // insert a "dummy" classificationGradingValue, since not having one results in problems } - else + else // classificationtype has to be moved to another classificatingroup { - newId = vars.get("$field.CLASSIFICATIONGROUP"); - newGradingTable = ClassificationUtils.getGradingTableByGroupId(newId); - newNewMax = eMath.addInt(newMax, lostScore) + newId = vars.get("$field.CLASSIFICATIONGROUP"); //we know that the field has the classificationgroupId of the new group set + newGradingTable = ClassificationUtils.getGradingTableByGroupId(newId); //we use this id to get the gradingtable of the new group + newNewMax = eMath.addInt(newGradingTable[0][1], lostScore) //maxvalue of the gradingtable with the added lostScore = the new maxValue if(newGradingTable[0][1] != newNewMax) //update existing classificationGrading if the maxValue has changed { gradeColumn = ["MAXGRADEFORSCORE"]; @@ -173,7 +178,6 @@ function _update() } } - cond = newWhereIfSet("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID = '" + text.decodeMS(uid)[1] + "'"); columns.push("SCORETYPE"); values.push(vars.get("$field.CLASSIFICATIONTYPEIDDISPLAYVALUE")); -- GitLab