This is an automated email from the ASF dual-hosted git repository. amansinha pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/drill.git
commit f6d54b480a123724f4cca7d146b0a5c3fb077652 Author: Kunal Khatua <kkha...@maprtech.com> AuthorDate: Wed Dec 5 23:34:26 2018 -0800 DRILL-6883: Force reload of options after resetting parameter If an update is initiated, the webpage loaded changes. Attempting a reset tries to reload this page, but it does not show the updated values from the back end. This patch forces the reload of updated values by redirecting to /options page Use AJAX call for Update and Reset Eliminates the need for window.location=<redirectURL> is Number check Added comments to explain extraction close apache/drill#1563 --- exec/java-exec/src/main/resources/rest/options.ftl | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/exec/java-exec/src/main/resources/rest/options.ftl b/exec/java-exec/src/main/resources/rest/options.ftl index 7ac8a2e..a8e03fa 100644 --- a/exec/java-exec/src/main/resources/rest/options.ftl +++ b/exec/java-exec/src/main/resources/rest/options.ftl @@ -22,9 +22,32 @@ <script type="text/javascript" language="javascript" src="/static/js/jquery.dataTables-1.10.16.min.js"> </script> <script type="text/javascript" language="javascript" src="/static/js/dataTables.colVis-1.1.0.min.js"></script> <script> - function resetToDefault(optionName, optionValue, optionKind) { - $.post("/option/"+optionName, {kind: optionKind, name: optionName, value: optionValue}, function (status) { location.reload(true); } ); + //Alter System Values + function alterSysOption(optionName, optionValue, optionKind) { + $.post("/option/"+optionName, {kind: optionKind, name: optionName, value: optionValue}, function () { + location.reload(true); + }); + } + + //Read Values and apply + function alterSysOptionUsingId(optionRawName) { + //Escaping '.' for id search + let optionName = optionRawName.replace(/\./gi, "\\."); + //Extracting datatype from the form + let optionKind = $("#"+optionName+" input[name='kind']").attr("value"); + //Extracting value from the form's INPUT element + let optionValue = $("#"+optionName+" input[name='value']").val(); + if (optionKind == "BOOLEAN") { + //Extracting boolean value from the form's SELECT element (since this is a dropdown input) + optionValue = $("#"+optionName+" select[name='value']").val(); + } else if (optionKind != "STRING") { //i.e. it is a number (FLOAT/DOUBLE/LONG) + if (isNaN(optionValue)) { + alert(optionValue+" is not a valid number for option: "+optionName); + return; + } } + alterSysOption(optionRawName, optionValue, optionKind); + } </script> <!-- List of Option Descriptions --> <script src="/dynamic/options.describe.js"></script> @@ -75,7 +98,7 @@ table.sortable thead .sorting_desc { background-image: url("/static/img/black-de <tr id="row-${i}"> <td style="font-family:Courier New; vertical-align:middle" id='optionName'>${option.getName()}</td> <td> - <form class="form-inline" role="form" action="/option/${option.getName()}" method="POST"> + <form class="form-inline" role="form" id="${option.getName()}"> <div class="form-group"> <input type="hidden" class="form-control" name="kind" value="${option.getKind()}"> <input type="hidden" class="form-control" name="name" value="${option.getName()}"> @@ -89,10 +112,9 @@ table.sortable thead .sorting_desc { background-image: url("/static/img/black-de <input type="text" class="form-control" placeholder="${option.getValueAsString()}" name="value" value="${option.getValueAsString()}"> </#if> <div class="input-group-btn"> - <button class="btn btn-default" type="submit">Update</button> - <button class="btn btn-default" onClick="resetToDefault('${option.getName()}','${option.getDefaultValue()}', '${option.getKind()}')" type="button" - <#if option.getDefaultValue() == option.getValueAsString()>disabled="true" style="pointer-events:none" <#else> - title="Reset to ${option.getDefaultValue()}"</#if>>Reset</button> + <button class="btn btn-default" type="button" onclick="alterSysOptionUsingId('${option.getName()}')">Update</button> + <button class="btn btn-default" type="button" onclick="alterSysOption('${option.getName()}','${option.getDefaultValue()}', '${option.getKind()}')" <#if option.getDefaultValue() == option.getValueAsString()>disabled="true" style="pointer-events:none" <#else> + title="Reset to ${option.getDefaultValue()}"</#if>>Default</button> </div> </div> </div> @@ -127,7 +149,7 @@ table.sortable thead .sorting_desc { background-image: url("/static/img/black-de //Inject Descriptions for table let size = $('#optionsTbl tbody tr').length; for (i = 1; i <= size; i++) { - let currRow = $("#row-"+i); + let currRow = $("#row-"+i); let optionName = currRow.find("#optionName").text(); let setOptDescrip = currRow.find("#description").text(getDescription(optionName)); }