Jelajahi Sumber

AMBARI-6025 Convert UI code of Move Master Wizard to lazily load host and host component info. (atkach)

atkach 11 tahun lalu
induk
melakukan
735e008fa6

+ 3 - 16
ambari-web/app/controllers/main/service/reassign_controller.js

@@ -139,23 +139,10 @@ App.ReassignMasterController = App.WizardController.extend({
    */
   loadConfirmedHosts: function () {
     var hosts = App.db.getHosts();
-    if (!hosts || !hosts.length) {
-      var hosts = {};
-
-      App.Host.find().forEach(function (item) {
-        hosts[item.get('id')] = {
-          name: item.get('id'),
-          cpu: item.get('cpu'),
-          memory: item.get('memory'),
-          disk_info: item.get('diskInfo'),
-          bootStatus: "REGISTERED",
-          isInstalled: true
-        };
-      });
-      App.db.setHosts(hosts);
-    }
 
-    this.set('content.hosts', hosts);
+    if (hosts) {
+      this.set('content.hosts', hosts);
+    }
     console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts);
   },
   /**

+ 7 - 3
ambari-web/app/templates/main/service/reassign.hbs

@@ -36,9 +36,13 @@
             </ul>
           </div>
         </div>
-        <div class="wizard-content well span9">
-          {{outlet}}
-        </div>
+          <div class="wizard-content well span9">
+            {{#if view.isLoaded}}
+              {{outlet}}
+            {{else}}
+                <div class="spinner"></div>
+            {{/if}}
+          </div>
       </div>
     </div>
   </div>

+ 42 - 0
ambari-web/app/views/main/service/reassign_view.js

@@ -49,6 +49,48 @@ App.ReassignMasterView = Em.View.extend({
 
   isStepDisabled: function (index) {
     return this.get('controller.isStepDisabled').findProperty('step', index).get('value');
+  },
+
+  isLoaded: false,
+
+  willInsertElement: function() {
+    this.set('isLoaded', false);
+    this.loadHosts();
+  },
+
+  /**
+   * load hosts from server
+   */
+  loadHosts: function () {
+    App.ajax.send({
+      name: 'hosts.high_availability.wizard',
+      data: {},
+      sender: this,
+      success: 'loadHostsSuccessCallback',
+      error: 'loadHostsErrorCallback'
+    });
+  },
+
+  loadHostsSuccessCallback: function (data, opt, params) {
+    var hosts = {};
+
+    data.items.forEach(function (item) {
+      hosts[item.Hosts.host_name] = {
+        name: item.Hosts.host_name,
+        cpu: item.Hosts.cpu_count,
+        memory: item.Hosts.total_mem,
+        disk_info: item.Hosts.disk_info,
+        bootStatus: "REGISTERED",
+        isInstalled: true
+      };
+    });
+    App.db.setHosts(hosts);
+    this.set('controller.content.hosts', hosts);
+    this.set('isLoaded', true);
+  },
+
+  loadHostsErrorCallback: function(){
+    this.set('isLoaded', true);
   }
 
 });