Blame SOURCES/bz1664057-01-gui-issues-in-create-new-cluster-form.patch

50c00a
From 52b6ec5ac3ffc03d42217f85cda4fdff0f441735 Mon Sep 17 00:00:00 2001
50c00a
From: Ivan Devat <idevat@redhat.com>
50c00a
Date: Fri, 11 Jan 2019 15:13:09 +0100
50c00a
Subject: [PATCH] squash bz1664057 [GUI] Issues in 'create new clust
50c00a
50c00a
2dfc71c34bd5 refresh changed node addresses in link details
50c00a
50c00a
17241fa845f6 omit empty node addresses in api call
50c00a
50c00a
90558e69fb9f remove old err messages after successfull setup
50c00a
50c00a
b073db339cf2 omit "addrs" in webui api call on empty addresses
50c00a
---
50c00a
 pcsd/public/js/api.js                     | 10 ++--
50c00a
 pcsd/public/js/cluster-setup.js           | 60 ++++++++++++++++++-----
50c00a
 pcsd/public/js/dev/tests-cluster-setup.js | 25 ++++++++--
50c00a
 pcsd/views/manage.erb                     |  2 +-
50c00a
 4 files changed, 75 insertions(+), 22 deletions(-)
50c00a
50c00a
diff --git a/pcsd/public/js/api.js b/pcsd/public/js/api.js
50c00a
index c6eb20d6..6c433b54 100644
50c00a
--- a/pcsd/public/js/api.js
50c00a
+++ b/pcsd/public/js/api.js
50c00a
@@ -212,10 +212,12 @@ api.clusterSetup = function(submitData, processOptions){
50c00a
   var data = {
50c00a
     cluster_name: setupData.clusterName,
50c00a
     nodes: setupData.nodeList.map(function(node){
50c00a
-      return {
50c00a
-        name: node.name,
50c00a
-        addrs: node.addrs,
50c00a
-      };
50c00a
+      apiNode = { name: node.name };
50c00a
+      var addrs = node.addrs.filter(function(addr){return addr.length > 0});
50c00a
+      if (addrs.length > 0) {
50c00a
+        apiNode["addrs"] = addrs;
50c00a
+      }
50c00a
+      return apiNode;
50c00a
     }),
50c00a
     transport_type: setupData.transportType,
50c00a
     transport_options: setupData.transportType == "knet"
50c00a
diff --git a/pcsd/public/js/cluster-setup.js b/pcsd/public/js/cluster-setup.js
50c00a
index e14b314d..2b7b0a4e 100644
50c00a
--- a/pcsd/public/js/cluster-setup.js
50c00a
+++ b/pcsd/public/js/cluster-setup.js
50c00a
@@ -50,12 +50,7 @@ clusterSetup.link.detail.create = function(transportType, nodesNames){
50c00a
   var addrList = detail.find(".transport-addresses");
50c00a
 
50c00a
   $(nodesNames).each(function(j, nodeName){
50c00a
-    var address = tools.snippet.take("transport-addr").find("tr");
50c00a
-    $(".node-name", address).text(nodeName+":");
50c00a
-    $(".address", address)
50c00a
-      .attr("name", clusterSetup.link.detail.addressName(nodeName))
50c00a
-    ;
50c00a
-    $(addrList).append(address);
50c00a
+    $(addrList).append(clusterSetup.link.detail.createAddress(nodeName));
50c00a
   });
50c00a
 
50c00a
   detail.find(".options").append(
50c00a
@@ -67,6 +62,34 @@ clusterSetup.link.detail.create = function(transportType, nodesNames){
50c00a
   return detail;
50c00a
 };
50c00a
 
50c00a
+clusterSetup.link.detail.createAddress = function(nodeName){
50c00a
+  var address = tools.snippet.take("transport-addr").find("tr");
50c00a
+  address.attr("data-transport-addr-host", nodeName)
50c00a
+  $(".node-name", address).text(nodeName+":");
50c00a
+  $(".address", address)
50c00a
+    .attr("name", clusterSetup.link.detail.addressName(nodeName))
50c00a
+  ;
50c00a
+  return address;
50c00a
+};
50c00a
+
50c00a
+clusterSetup.link.detail.refreshNodesNames = function(linkDetail, nodesNames){
50c00a
+  // Is fast enough. No cache required.
50c00a
+  var previousNodesNames = $.makeArray(
50c00a
+    linkDetail
50c00a
+      .find(".transport-addresses [data-transport-addr-host]")
50c00a
+      .map(function(){return $(this).attr("data-transport-addr-host")})
50c00a
+  );
50c00a
+
50c00a
+  var newAddresses = nodesNames.map(function(nodeName){
50c00a
+    return previousNodesNames.contains(nodeName)
50c00a
+      ? linkDetail.find("[data-transport-addr-host="+nodeName+"]")
50c00a
+      : clusterSetup.link.detail.createAddress(nodeName)
50c00a
+    ;
50c00a
+  });
50c00a
+
50c00a
+  linkDetail.find(".transport-addresses").empty().append(newAddresses);
50c00a
+};
50c00a
+
50c00a
 //------------------------------------------------------------------------------
50c00a
 clusterSetup.netmap.updateAddLinkAbility = function(transportType, linkList){
50c00a
   var addLinkButton = $("#csetup-transport-netmaps .add-link");
50c00a
@@ -108,10 +131,16 @@ clusterSetup.netmap.current.get = function(){
50c00a
   return $(clusterSetup.netmap.current.selector());
50c00a
 };
50c00a
 
50c00a
-clusterSetup.netmap.current.detailList = function(){
50c00a
+clusterSetup.netmap.current.detailsContainer = function(){
50c00a
   return $(clusterSetup.netmap.current.selector() +" .link-detail-list");
50c00a
 };
50c00a
 
50c00a
+clusterSetup.netmap.current.detailList = function(){
50c00a
+  return $(
50c00a
+    clusterSetup.netmap.current.selector() +" .link-detail-list .detail"
50c00a
+  );
50c00a
+};
50c00a
+
50c00a
 clusterSetup.netmap.current.linksContainer = function(){
50c00a
   return $(clusterSetup.netmap.current.selector() +" .link-container");
50c00a
 };
50c00a
@@ -143,7 +172,7 @@ clusterSetup.netmap.current.createLink = function(id, nodesNames){
50c00a
       .attr(clusterSetup.link.pairAttr, id)
50c00a
   );
50c00a
 
50c00a
-  clusterSetup.netmap.current.detailList().append(
50c00a
+  clusterSetup.netmap.current.detailsContainer().append(
50c00a
     clusterSetup.link.detail
50c00a
       .create(clusterSetup.transportType.current(), nodesNames)
50c00a
       .attr(clusterSetup.link.pairAttr, id)
50c00a
@@ -171,8 +200,8 @@ clusterSetup.netmap.current.setCurrentLink = function(id){
50c00a
   linkList.children().each(function(){ $(this).removeClass("current") });
50c00a
   linkList.children(pairSelector).addClass("current");
50c00a
 
50c00a
-  clusterSetup.netmap.current.detailList().find(".detail").hide();
50c00a
-  clusterSetup.netmap.current.detailList().find(pairSelector).show()
50c00a
+  clusterSetup.netmap.current.detailList().hide();
50c00a
+  clusterSetup.netmap.current.detailsContainer().find(pairSelector).show()
50c00a
   ;
50c00a
 };
50c00a
 
50c00a
@@ -320,7 +349,7 @@ clusterSetup.data.settings = function(clusterName, nodesNames){
50c00a
     {
50c00a
       clusterName: clusterName,
50c00a
       nodeList: clusterSetup.data.nodes(nodesNames, function(nodeName){
50c00a
-        return clusterSetup.netmap.current.detailList()
50c00a
+        return clusterSetup.netmap.current.detailsContainer()
50c00a
           .find("[name='"+clusterSetup.link.detail.addressName(nodeName)+"']")
50c00a
           .map(function(){ return $(this).val().trim() })
50c00a
           .toArray()
50c00a
@@ -371,7 +400,7 @@ clusterSetup.data.settings = function(clusterName, nodesNames){
50c00a
     clusterSetup.transportType.current() === "knet"
50c00a
 
50c00a
     ? {
50c00a
-      linkList: clusterSetup.netmap.current.detailList().find(".detail")
50c00a
+      linkList: clusterSetup.netmap.current.detailList()
50c00a
         .map(function(linknumber, form){
50c00a
           return $.extend({linknumber: linknumber}, fromForm(form, [
50c00a
             "ip_version",
50c00a
@@ -414,7 +443,7 @@ clusterSetup.data.settings = function(clusterName, nodesNames){
50c00a
       ),
50c00a
       compression: {},
50c00a
       crypto: {},
50c00a
-      linkList: clusterSetup.netmap.current.detailList().find(".detail")
50c00a
+      linkList: clusterSetup.netmap.current.detailList()
50c00a
         .map(function(linknumber, form){
50c00a
           return fromForm(
50c00a
             form,
50c00a
@@ -481,6 +510,10 @@ clusterSetup.step.clusterSettings = function(clusterName, nodesNames, actions){
50c00a
 
50c00a
   $("#csetup .cluster-settings").tabs();
50c00a
 
50c00a
+  clusterSetup.netmap.current.detailList().each(function(){
50c00a
+    clusterSetup.link.detail.refreshNodesNames($(this), nodesNames);
50c00a
+  });
50c00a
+
50c00a
   $("#csetup-transport-netmaps .add-link").unbind("click").click(function(){
50c00a
     clusterSetup.netmap.current.createLink(
50c00a
       clusterSetup.generateUid(),
50c00a
@@ -688,6 +721,7 @@ clusterSetup.submit.run = function(useAdvancedOptions){
50c00a
     );
50c00a
 
50c00a
   }).then(function(){
50c00a
+    clusterSetup.dialog.resetMessages([]);
50c00a
     return api.rememberCluster(formData.clusterName, formData.nodesNames);
50c00a
 
50c00a
   }).then(function(){
50c00a
diff --git a/pcsd/public/js/dev/tests-cluster-setup.js b/pcsd/public/js/dev/tests-cluster-setup.js
50c00a
index 54b7fbdd..b3b9f5c8 100644
50c00a
--- a/pcsd/public/js/dev/tests-cluster-setup.js
50c00a
+++ b/pcsd/public/js/dev/tests-cluster-setup.js
50c00a
@@ -16,15 +16,16 @@ dev.utils.clusterSetupDialog.prefill = function(url, nodesNames){
50c00a
     clusterSetup.submit.run(true);
50c00a
 
50c00a
     setTimeout(function(){
50c00a
-      // dev.utils.clusterSetupDialog.prefillKnet();
50c00a
+      dev.utils.clusterSetupDialog.prefillKnet();
50c00a
+      dev.utils.clusterSetupDialog.prefillTransportOptionsKnet();
50c00a
       dev.utils.clusterSetupDialog.prefillCompression();
50c00a
       dev.utils.clusterSetupDialog.prefillCrypto();
50c00a
       dev.utils.clusterSetupDialog.prefillTotem();
50c00a
       dev.utils.clusterSetupDialog.prefillQuorum();
50c00a
-      dev.utils.clusterSetupDialog.prefillTransportOptionsUdp("udp");
50c00a
-      $("[href='#csetup-transport-options']").trigger("click");
50c00a
+      // dev.utils.clusterSetupDialog.prefillTransportOptionsUdp("udp");
50c00a
+      // $("[href='#csetup-transport-options']").trigger("click");
50c00a
       // $("[href='#csetup-quorum']").trigger("click");
50c00a
-      dev.utils.clusterSetupDialog.prefillUdp("udpu");
50c00a
+      // dev.utils.clusterSetupDialog.prefillUdp("udpu");
50c00a
       $(".ui-dialog:has('#csetup') button:contains('Create cluster')")
50c00a
         // .trigger("click")
50c00a
       ;
50c00a
@@ -390,6 +391,21 @@ testClusterSetup.clusterSetupUnforcible = function(url, data, success, fail){
50c00a
   }
50c00a
 };
50c00a
 
50c00a
+testClusterSetup.clusterSetupUnforcibleFirstTime =
50c00a
+function(url, data, success, fail){
50c00a
+  switch(url){
50c00a
+    case "/manage/cluster-setup":
50c00a
+      if (dev.flags.cluster_setup_test_setup_first_time_was_run === undefined) {
50c00a
+        dev.flags.cluster_setup_test_setup_first_time_was_run = true;
50c00a
+        return success(
50c00a
+          JSON.stringify(dev.fixture.libErrorUnforcibleLarge)
50c00a
+        );
50c00a
+      }
50c00a
+    default:
50c00a
+      return testClusterSetup.successPath(url, data, success, fail);
50c00a
+  }
50c00a
+};
50c00a
+
50c00a
 testClusterSetup.clusterSetupException = function(url, data, success, fail){
50c00a
   switch(url){
50c00a
     case "/manage/cluster-setup":
50c00a
@@ -467,6 +483,7 @@ dev.runScenario(
50c00a
   // testClusterSetup.clusterSetup403
50c00a
   // testClusterSetup.clusterSetup500
50c00a
   // testClusterSetup.clusterSetupUnforcible
50c00a
+  // testClusterSetup.clusterSetupUnforcibleFirstTime
50c00a
   // testClusterSetup.clusterSetupException
50c00a
   // testClusterSetup.clusterSetupForceFail
50c00a
   // testClusterSetup.clusterSetupForceFailForcible
50c00a
diff --git a/pcsd/views/manage.erb b/pcsd/views/manage.erb
50c00a
index 7b0c9daa..c0569d40 100644
50c00a
--- a/pcsd/views/manage.erb
50c00a
+++ b/pcsd/views/manage.erb
50c00a
@@ -1075,7 +1075,7 @@ It is very useful when combined with Last Man Standing.
50c00a
 
50c00a
   
50c00a
     
50c00a
-    <input type="text" class="address"/>
50c00a
+    <input type="text" class="address"/>
50c00a
   
50c00a
 
50c00a
 
50c00a
-- 
50c00a
2.17.0
50c00a