Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2917 Added Point locator test fields validation in Modbus IP #2919

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e063ca3
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 8, 2024
46e07bd
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 12, 2024
790358f
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 12, 2024
77ae878
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 12, 2024
5184d5f
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 14, 2024
05d7982
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 19, 2024
d8bcbd7
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 20, 2024
86b9e80
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 20, 2024
363b9c0
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 20, 2024
cbf1a8e
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 21, 2024
fa49be3
#2845 Fixed message validation in event search
Patrykb0802 Jun 21, 2024
7fd2396
Merge branch 'release/2.7.8' into feature/#2917_Added_Point_locator_t…
Limraj Jun 21, 2024
ab16263
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jun 27, 2024
e8865e7
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jul 1, 2024
6805506
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jul 2, 2024
d2ee637
#2917 Added Point locator test fields validation in Modbus IP
Patrykb0802 Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#2917 Added Point locator test fields validation in Modbus IP
- Added Modbus IP properties fields validation for integers
- Changed validation mechanism
  • Loading branch information
Patrykb0802 committed Jun 20, 2024
commit d8bcbd70b6b1b1c809f64d3c2d935a16fc37de12
94 changes: 72 additions & 22 deletions WebContent/WEB-INF/jsp/dataSourceEdit/editModbus.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,87 @@
setDisabled("scanBtn", scanning);
setDisabled("scanCancelBtn", !scanning);
}

function validateLocatorTest(temp){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp -> locator


let messages = [];

if (!isPositiveInt(temp.slaveId)) {
messages.push(createValidationMessage("test_slaveId", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.range)) {
messages.push(createValidationMessage("test_range", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.modbusDataType)) {
messages.push(createValidationMessage("test_modbusDataType", "<fmt:message key='badIntegerFormat'/>"));
}

if (!isPositiveInt(temp.offset)) {
messages.push(createValidationMessage("test_offset", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveByte(temp.bit)) {
messages.push(createValidationMessage("test_bit", "<fmt:message key='validate.invalidValue'/>"));
}

if(!isPositiveInt(temp.registerCount)) {
messages.push(createValidationMessage("test_registerCount", "<fmt:message key='validate.invalidValue'/>"));
}

return messages;
}

function createTempLocator(){
let slaveId = $get("test_slaveId");
let range = $get("test_range");
let modbusDataType = $get("test_modbusDataType");
let offset = $get("test_offset");
let bit = $get("test_bit");
let registerCount = $get("test_registerCount");
let charset = $get("test_charset");

let temp = {};
temp.slaveId = slaveId;
temp.range = range;
temp.modbusDataType = modbusDataType;
temp.offset = offset;
temp.bit = bit;
temp.registerCount = registerCount;
temp.charset = charset;

return temp;
}


function locatorTest() {
setDisabled("locatorTestBtn", true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove this line:


let slaveId = $get("test_slaveId");
let range = $get("test_range");
let modbusDataType = $get("test_modbusDataType");
let offset = $get("test_offset");
let bit = $get("test_bit");
let registerCount = $get("test_registerCount");
let charset = $get("test_charset");
let temp = createTempLocator();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createLocatorConfigTemp

let tempModbusData = createTempModbusData();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createModbusConfigTemp


hideGenericMessages("locatorTestGeneric");
hideContextualMessages("locatorTestDiv");
if (!isPositiveInt(slaveId)) {
createAndDisplayValidationMessage("test_slaveId", "<fmt:message key='badIntegerFormat'/>");
} else if (!isPositiveInt(offset)) {
createAndDisplayValidationMessage("test_offset", "<fmt:message key='badIntegerFormat'/>");
} else if(!isPositiveByte(bit)) {
createAndDisplayValidationMessage("test_bit", "<fmt:message key='validate.invalidValue'/>");
} else if(!isPositiveInt(registerCount)) {
createAndDisplayValidationMessage("test_registerCount", "<fmt:message key='badIntegerFormat'/>");
hideContextualMessages("dataSourceProperties");

let messagesModbus = validateModbusProperties(tempModbusData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modbusMessages, validateModbusConfig


let messagesLocator = validateLocatorTest(temp);

let messages = messagesModbus.concat(messagesLocator);

if(messages.length > 0) {
showDwrMessages(messages);
} else {
let locator = {};
locator.slaveId = parseInt(slaveId);
locator.range = parseInt(range);
locator.modbusDataType = parseInt(modbusDataType);
locator.offset = parseInt(offset);
locator.bit = parseInt(bit);
locator.registerCount = parseInt(registerCount);
locator.charset = charset;
locator.slaveId = parseInt(temp.slaveId);
locator.range = parseInt(temp.range);
locator.modbusDataType = parseInt(temp.modbusDataType);
locator.offset = parseInt(temp.offset);
locator.bit = parseInt(temp.bit);
locator.registerCount = parseInt(temp.registerCount);
locator.charset = temp.charset;

locatorTestImpl(locator);
}
Expand Down
115 changes: 110 additions & 5 deletions WebContent/WEB-INF/jsp/dataSourceEdit/editModbusIp.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,118 @@
DataSourceEditDwr.testModbusIpData($get("timeout"), $get("retries"), $get("transportType"), $get("host"),
$get("port"), $get("encapsulated"), slaveId, range, offset, length, dataTestCB);
}

function validateModbusProperties(temp){

let messages = [];

if (!isPositiveInt(temp.updatePeriods)){
messages.push(createValidationMessage("updatePeriods", "<fmt:message key='badIntegerFormat'/>"));
}

if (!isPositiveInt(temp.updatePeriodType)){
messages.push(createValidationMessage("updatePeriodType", "<fmt:message key='badIntegerFormat'/>"));
}

if (!isPositiveInt(temp.timeout)){
messages.push(createValidationMessage("timeout", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.retries)) {
messages.push(createValidationMessage("retries", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.maxReadBitCount)) {
messages.push(createValidationMessage("maxReadBitCount", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.maxReadRegisterCount)) {
messages.push(createValidationMessage("maxReadRegisterCount", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.maxWriteRegisterCount)) {
messages.push(createValidationMessage("maxWriteRegisterCount", "<fmt:message key='badIntegerFormat'/>"));
}

if(!isPositiveInt(temp.port)) {
messages.push(createValidationMessage("port", "<fmt:message key='badIntegerFormat'/>"));
}

return messages;
}

function createTempModbusData(){

let dataSourceName = $get("dataSourceName");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point in creating additional variables here, you get and immediately set them in the temp structure, you don't parse here, etc.

let dataSourceXid = $get("dataSourceXid");
let updatePeriods = $get("updatePeriods");
let updatePeriodType = $get("updatePeriodType");
let quantize = $get("quantize");
let timeout = $get("timeout");
let retries = $get("retries");
let contiguousBatches = $get("contiguousBatches");
let createSlaveMonitorPoints = $get("createSlaveMonitorPoints");
let maxReadBitCount = $get("maxReadBitCount");
let maxReadRegisterCount = $get("maxReadRegisterCount");
let maxWriteRegisterCount = $get("maxWriteRegisterCount");
let transportType = $get("transportType");
let host = $get("host");
let port = $get("port");
let encapsulated = $get("encapsulated");
let createSocketMonitorPoint = $get("createSocketMonitorPoint");

let temp = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp -> modbus

temp.dataSourceName = dataSourceName;
temp.dataSourceXid = dataSourceXid;
temp.updatePeriods = updatePeriods;
temp.updatePeriodType = updatePeriodType;
temp.quantize = quantize;
temp.timeout = timeout;
temp.retries = retries;
temp.contiguousBatches = contiguousBatches;
temp.createSlaveMonitorPoints = createSlaveMonitorPoints;
temp.maxReadBitCount = maxReadBitCount;
temp.maxReadRegisterCount = maxReadRegisterCount;
temp.maxWriteRegisterCount = maxWriteRegisterCount;
temp.transportType = transportType
temp.host = host;
temp.port = port;
temp.encapsulated = encapsulated;
temp.createSocketMonitorPoint = createSocketMonitorPoint;

return temp;
}

function saveDataSourceImpl() {
DataSourceEditDwr.saveModbusIpDataSource($get("dataSourceName"), $get("dataSourceXid"), $get("updatePeriods"),
$get("updatePeriodType"), $get("quantize"), $get("timeout"), $get("retries"), $get("contiguousBatches"),
$get("createSlaveMonitorPoints"), $get("maxReadBitCount"), $get("maxReadRegisterCount"),
$get("maxWriteRegisterCount"), $get("transportType"), $get("host"), $get("port"), $get("encapsulated"), $get("createSocketMonitorPoint"),
saveDataSourceCB);

let temp = createTempModbusData();

let messages = validateModbusProperties(temp);

if(messages.length > 0) {
showDwrMessages(messages);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting needs to be improved

} else {
let dataSourceName = temp.dataSourceName;
let dataSourceXid = temp.dataSourceXid;
let updatePeriods = parseInt(temp.updatePeriods);
let updatePeriodType = parseInt(temp.updatePeriodType);
let quantize = temp.quantize;
let timeout = parseInt(temp.timeout);
let retries = parseInt(temp.retries);
let contiguousBatches = temp.contiguousBatches;
let createSlaveMonitorPoints = temp.createSlaveMonitorPoints;
let maxReadBitCount = parseInt(temp.maxReadBitCount);
let maxReadRegisterCount = parseInt(temp.maxReadRegisterCount);
let maxWriteRegisterCount = parseInt(temp.maxWriteRegisterCount);
let transportType = temp.transportType;
let host = temp.host;
let port = parseInt(temp.port);
let encapsulated = temp.encapsulated;
let createSocketMonitorPoint = temp.createSocketMonitorPoint;
DataSourceEditDwr.saveModbusIpDataSource(dataSourceName, dataSourceXid, updatePeriods,
updatePeriodType, quantize, timeout, retries, contiguousBatches, createSlaveMonitorPoints, maxReadBitCount, maxReadRegisterCount,
maxWriteRegisterCount, transportType, host, port, encapsulated, createSocketMonitorPoint, saveDataSourceCB);
}
}
</script>

Expand Down
5 changes: 0 additions & 5 deletions WebContent/resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,6 @@ function createValidationMessage(node, message) {
return {contextKey:node, contextualMessage:message};
}

function createAndDisplayValidationMessage(node, message){
let messageToDisplay = createValidationMessage(node, message);
showDwrMessages([messageToDisplay]);
}

function updateChartComparatorComponent(idPrefix, width, height) {
var fromDate = $get(idPrefix+"_fromDate1");
var toDate = $get(idPrefix+"_toDate1");
Expand Down
Loading