From ffdb45d5a5170d79b32f2a3d3bde1cdc739ba924 Mon Sep 17 00:00:00 2001 From: Alija Sabic Date: Mon, 11 Mar 2019 15:49:44 +0100 Subject: [PATCH 1/2] Add getRuntimeComponentPropertyList() to ARE REST wrapper --- lib/rest_library/areCommunicator.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/rest_library/areCommunicator.js b/lib/rest_library/areCommunicator.js index f5417e4..ca16e63 100644 --- a/lib/rest_library/areCommunicator.js +++ b/lib/rest_library/areCommunicator.js @@ -269,6 +269,26 @@ function getRuntimeComponentProperty(successCallback, errorCallback, componentId }); } +function getRuntimeComponentPropertyList(successCallback, errorCallback, componentId, componentKey) { + + if ( (compoentId == "") || (componentKey == "")) return; + + $.ajax({ + type: "GET", + url: _baseURI + "runtime/model/components/"+encodeParam(componentId)+"/properties/"+encodeParam(componentKey), + datatype: "application/json", + crossDomain: true, + success: + function (data, textStatus, jqXHR) { + successCallback(jqXHR.responseText, textStatus); + }, + error: + function (jqXHR, textStatus, errorThrown) { + errorCallback(errorThrown, jqXHR.responseText); + } + }); +} + function setRuntimeComponentProperties(successCallback, errorCallback, propertyMap) { From f16261fed498ef1c5ff7b4c3371e1f21427af540 Mon Sep 17 00:00:00 2001 From: Alija Sabic Date: Tue, 12 Mar 2019 13:31:11 +0100 Subject: [PATCH 2/2] Load dynamic properties, display empty input if no data available (propertyEditor) --- view/propertyEditor.js | 166 +++++++++++++++++++++++++---------------- 1 file changed, 103 insertions(+), 63 deletions(-) diff --git a/view/propertyEditor.js b/view/propertyEditor.js index 06fabb4..0df37a3 100644 --- a/view/propertyEditor.js +++ b/view/propertyEditor.js @@ -132,8 +132,6 @@ ACS.propertyEditor = function (modelList, // ACS.modelList } } } - - //Part for component if (selectedElementType === "component") { @@ -211,7 +209,7 @@ ACS.propertyEditor = function (modelList, // ACS.modelList //var tempString=actModel.componentList[selectedElement].getId(); //Properties for (var h = 0; h < actModel.componentList[selectedElement].propertyList.length; h++) { - var property = actModel.componentList[selectedElement].propertyList[h]; + var property = actModel.componentList[selectedElement].propertyList[h]; var propName = property.getKey(); row[h + 1] = bodyT.insertRow(-1); cell = row[h + 1].insertCell(0); @@ -219,6 +217,7 @@ ACS.propertyEditor = function (modelList, // ACS.modelList var comboValues = property.combobox; var valtemp = property.value; var typetemp = property.getType(); + var isDynProp = property.getStringList; cell.innerHTML = propName; //generat dropdown list in case that combox includes values @@ -245,77 +244,118 @@ ACS.propertyEditor = function (modelList, // ACS.modelList cell.appendChild(dropdownList); } - //generate checkbox field for boolean - if (comboValues === '' && typetemp === ACS.dataType.BOOLEAN) { + if (isDynProp) { + + log.debug('downloading (dynamic) properties list'); + setBaseURI(ACS.areBaseURI + '/rest/'); + cell = row[h + 1].insertCell(1); - boolInput = null; - boolInput = document.createElement("INPUT"); - boolInput.setAttribute("type", "checkbox"); - boolInput.setAttribute("value", valtemp); - if ((valtemp === "true") || (valtemp === "True")) { - boolInput.setAttribute("checked", true); + var id = propertyEdPanelCaptions.innerHTML; + var key = propName; + var currentValue = valtemp || ""; + var elementId = h + "/1/" + valtemp; + + fetchDynProperties(cell, elementId, currentValue, id, key); + function fetchDynProperties(cellToAdd, elementId, currentValue, id, key) { + getRuntimeComponentPropertyList(function(data, httpStatus) { + var entries = data ? JSON.parse(data) : null; + entries.unshift(""); + if(entries && entries.length === 0) { + console.warn('empty dynamic property list'); + var inputElement = document.createElement('input'); + inputElement.setAttribute("id", elementId); + cellToAdd.appendChild(inputElement); + } else { + var dropdownList = document.createElement('select'); + for (var l = 0; l < entries.length; l++) { + var option = new Option(entries[l], entries[l]); + option.selected = (entries[l] == currentValue); + dropdownList.appendChild(option); + } + dropdownList.setAttribute("id", elementId); + dropdownList.addEventListener("change", writeProperty); + cellToAdd.appendChild(dropdownList); + } + }, function(HTTPstatus, AREerrorMessage) { + console.error('check if ARE is running'); + console.error('error: ' + AREerrorMessage); + var inputElement = document.createElement('input'); + inputElement.setAttribute("id", elementId); + cellToAdd.appendChild(inputElement); + }, id, key); + }; + + } else { + //generate checkbox field for boolean + if (comboValues === '' && typetemp === ACS.dataType.BOOLEAN) { + cell = row[h + 1].insertCell(1); + boolInput = null; + boolInput = document.createElement("INPUT"); + boolInput.setAttribute("type", "checkbox"); + boolInput.setAttribute("value", valtemp); + if ((valtemp === "true") || (valtemp === "True")) { + boolInput.setAttribute("checked", true); + } + boolInput.setAttribute("id", h + "/1/" + valtemp); + boolInput.addEventListener("change", writeProperty); + cell.appendChild(boolInput); + } + //generate intage field + if (comboValues === '' && typetemp === ACS.dataType.INTEGER) { + cell = row[h + 1].insertCell(1); + numberInput = null; + numberInput = document.createElement("INPUT"); + numberInput.setAttribute("type", "number"); + numberInput.setAttribute("value", valtemp); + numberInput.setAttribute("id", h + "/1/" + valtemp); + numberInput.addEventListener("focus", setPreviousNumber); + numberInput.addEventListener("change", writeProperty); + numberInput.addEventListener("input", writePropertyChangLocal); //workaround when blur is not fired + cell.appendChild(numberInput); } - boolInput.setAttribute("id", h + "/1/" + valtemp); - boolInput.addEventListener("change", writeProperty); - cell.appendChild(boolInput); - } - //generate intage field - if (comboValues === '' && typetemp === ACS.dataType.INTEGER) { - cell = row[h + 1].insertCell(1); - numberInput = null; - numberInput = document.createElement("INPUT"); - numberInput.setAttribute("type", "number"); - numberInput.setAttribute("value", valtemp); - numberInput.setAttribute("id", h + "/1/" + valtemp); - numberInput.addEventListener("focus", setPreviousNumber); - numberInput.addEventListener("change", writeProperty); - numberInput.addEventListener("input", writePropertyChangLocal); //workaround when blur is not fired - cell.appendChild(numberInput); - } - if (comboValues === '' && typetemp === ACS.dataType.DOUBLE) { - cell = row[h + 1].insertCell(1); - numberInput = null; - numberInput = document.createElement("INPUT"); - numberInput.setAttribute("type", "text"); - //numberInput.setAttribute("step","0.0000000001"); - numberInput.setAttribute("value", valtemp); - numberInput.setAttribute("pattern", "^[-]?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?"); - numberInput.setAttribute("id", h + "/1/" + valtemp); - numberInput.addEventListener("change", writeProperty); - numberInput.addEventListener("input", writePropertyChangLocal); //workaround when blur is not fired - cell.appendChild(numberInput); - } + if (comboValues === '' && typetemp === ACS.dataType.DOUBLE) { + cell = row[h + 1].insertCell(1); + numberInput = null; + numberInput = document.createElement("INPUT"); + numberInput.setAttribute("type", "text"); + //numberInput.setAttribute("step","0.0000000001"); + numberInput.setAttribute("value", valtemp); + numberInput.setAttribute("pattern", "^[-]?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?"); + numberInput.setAttribute("id", h + "/1/" + valtemp); + numberInput.addEventListener("change", writeProperty); + numberInput.addEventListener("input", writePropertyChangLocal); //workaround when blur is not fired + cell.appendChild(numberInput); + } - if (comboValues === '' && typetemp === ACS.dataType.STRING) { - cell = row[h + 1].insertCell(1); - textInput = null; - textInput = document.createElement("INPUT"); - textInput.setAttribute("type", "text"); - textInput.setAttribute("name", propName); - textInput.setAttribute("value", ACS.utils.decodeForXml(valtemp)); - textInput.setAttribute("id", h + "/1/" + valtemp); - textInput.addEventListener("blur", writeProperty); - textInput.addEventListener("input", writePropertyChangLocal); //workaround when blur is not fired - cell.appendChild(textInput); + if (comboValues === '' && typetemp === ACS.dataType.STRING) { + cell = row[h + 1].insertCell(1); + textInput = null; + textInput = document.createElement("INPUT"); + textInput.setAttribute("type", "text"); + textInput.setAttribute("name", propName); + textInput.setAttribute("value", ACS.utils.decodeForXml(valtemp)); + textInput.setAttribute("id", h + "/1/" + valtemp); + textInput.addEventListener("blur", writeProperty); + textInput.addEventListener("input", writePropertyChangLocal); //workaround when blur is not fired + cell.appendChild(textInput); + } } - //element.setAttribute("type", "button"); - //element.setAttribute("value", tempString); } //internal Properties internalPropertyTable.setAttribute("class", "propertyEditorT"); - var headerInternalProoperty = internalPropertyTable.createTHead(); - headerInternalProoperty.setAttribute("class", "propertyEditorTh"); - row[0] = headerInternalProoperty.insertRow(0); - var headerInternalProopertyCell1 = document.createElement("TH"); - headerInternalProopertyCell1.innerHTML = "Internal Property"; - row[0].appendChild(headerInternalProopertyCell1); - var headerInternalProopertyCell2 = document.createElement("TH"); - headerInternalProopertyCell2.innerHTML = "Value"; - row[0].appendChild(headerInternalProopertyCell2); + var headerInternalProperty = internalPropertyTable.createTHead(); + headerInternalProperty.setAttribute("class", "propertyEditorTh"); + row[0] = headerInternalProperty.insertRow(0); + var headerInternalPropertyCell1 = document.createElement("TH"); + headerInternalPropertyCell1.innerHTML = "Internal Property"; + row[0].appendChild(headerInternalPropertyCell1); + var headerInternalPropertyCell2 = document.createElement("TH"); + headerInternalPropertyCell2.innerHTML = "Value"; + row[0].appendChild(headerInternalPropertyCell2); var bodyT2 = internalPropertyTable.createTBody(); bodyT2.setAttribute("class", "propertyEditorTb");