فهرست منبع

AMBARI-10237. 'Reload Page' popup issues: multiple instances, broken reload link, displaying popup after connection is established (onechiporenko)

Oleg Nechiporenko 10 سال پیش
والد
کامیت
9b2291bfa3

+ 1 - 0
ambari-web/app/assets/test/tests.js

@@ -138,6 +138,7 @@ var files = ['test/init_model_test',
   'test/mixins/common/configs/enhanced_configs_test',
   'test/mixins/common/chart/storm_linear_time_test',
   'test/mixins/common/localStorage_test',
+  'test/mixins/common/reload_popup_test',
   'test/mixins/common/serverValidator_test',
   'test/mixins/common/table_server_view_mixin_test',
   'test/mixins/main/host/details/host_components/decommissionable_test',

+ 19 - 13
ambari-web/app/controllers/wizard/step3_controller.js

@@ -20,7 +20,7 @@ var App = require('app');
 var lazyloading = require('utils/lazy_loading');
 var numberUtils = require('utils/number_utils');
 
-App.WizardStep3Controller = Em.Controller.extend({
+App.WizardStep3Controller = Em.Controller.extend(App.ReloadPopupMixin, {
 
   name: 'wizardStep3Controller',
 
@@ -477,6 +477,7 @@ App.WizardStep3Controller = Em.Controller.extend({
    * @return {$.ajax|null}
    */
   doBootstrap: function () {
+    var self = this;
     if (this.get('stopBootstrap')) {
       return null;
     }
@@ -496,12 +497,14 @@ App.WizardStep3Controller = Em.Controller.extend({
         timeout: App.timeout
       }).
       then(
-      null,
-      function () {
-        App.showReloadPopup();
-        console.log('Bootstrap failed');
-      }
-    );
+        function () {
+          self.closeReloadPopup();
+        },
+        function () {
+          self.showReloadPopup();
+          console.log('Bootstrap failed');
+        }
+      );
   },
 
   /**
@@ -578,6 +581,7 @@ App.WizardStep3Controller = Em.Controller.extend({
     if (this.get('stopBootstrap')) {
       return null;
     }
+    var self = this;
     return App.ajax.send({
       name: 'wizard.step3.is_hosts_registered',
       sender: this,
@@ -588,12 +592,14 @@ App.WizardStep3Controller = Em.Controller.extend({
         timeout: App.timeout
       }).
       then(
-      null,
-      function () {
-        App.showReloadPopup();
-        console.log('Error: Getting registered host information from the server');
-      }
-    );
+        function () {
+          self.closeReloadPopup();
+        },
+        function () {
+          self.showReloadPopup();
+          console.log('Error: Getting registered host information from the server');
+        }
+      );
   },
 
   /**

+ 7 - 3
ambari-web/app/controllers/wizard/step9_controller.js

@@ -18,7 +18,7 @@
 var App = require('app');
 var stringUtils = require('utils/string_utils');
 
-App.WizardStep9Controller = Em.Controller.extend({
+App.WizardStep9Controller = Em.Controller.extend(App.ReloadPopupMixin, {
 
   name: 'wizardStep9Controller',
 
@@ -1023,6 +1023,7 @@ App.WizardStep9Controller = Em.Controller.extend({
    * @return {$.ajax|null}
    */
   getLogsByRequest: function (polling, requestId) {
+    var self = this;
     return App.ajax.send({
       name: 'wizard.step9.load_log',
       sender: this,
@@ -1034,9 +1035,12 @@ App.WizardStep9Controller = Em.Controller.extend({
       },
       success: 'getLogsByRequestSuccessCallback',
       error: 'getLogsByRequestErrorCallback'
-    }).retry({times: App.maxRetries, timeout: 3000}).then(null,
+    }).retry({times: App.maxRetries, timeout: 3000}).then(
+      function () {
+        self.closeReloadPopup();
+      },
       function () {
-        App.showReloadPopup();
+        self.showReloadPopup();
         console.log('Install services all retries failed');
       }
     );

+ 1 - 0
ambari-web/app/mixins.js

@@ -22,6 +22,7 @@
 require('mixins/common/blueprint');
 require('mixins/common/localStorage');
 require('mixins/common/userPref');
+require('mixins/common/reload_popup');
 require('mixins/common/serverValidator');
 require('mixins/common/table_server_view_mixin');
 require('mixins/common/table_server_mixin');

+ 52 - 0
ambari-web/app/mixins/common/reload_popup.js

@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+App.ReloadPopupMixin = Em.Mixin.create({
+
+  reloadPopup: null,
+
+  showReloadPopup: function () {
+    var self = this;
+    if (!this.get('reloadPopup')) {
+      this.set('reloadPopup', App.ModalPopup.show({
+        primary: null,
+        secondary: null,
+        showFooter: false,
+        header: this.t('app.reloadPopup.header'),
+        body: "<div id='reload_popup' class='alert alert-info'><div class='spinner'><span>" +
+          this.t('app.reloadPopup.text') + "</span></div></div><div><a href='javascript:void(null)' onclick='location.reload();'>" +
+          this.t('app.reloadPopup.link') + "</a></div>",
+        encodeBody: false,
+        onClose: function () {
+          self.set('reloadPopup', null);
+          this._super();
+        }
+      }));
+    }
+  },
+
+  closeReloadPopup: function () {
+    var reloadPopup = this.get('reloadPopup');
+    if (reloadPopup) {
+      reloadPopup.onClose();
+    }
+  }
+
+});

+ 11 - 5
ambari-web/app/utils/polling.js

@@ -17,7 +17,7 @@
  */
 
 var App = require('app');
-App.Poll = Em.Object.extend({
+App.Poll = Em.Object.extend(App.ReloadPopupMixin, {
   name: '',
   stage: '',
   label: '',
@@ -151,6 +151,7 @@ App.Poll = Em.Object.extend({
    */
   startPolling: function () {
     if (!this.get('requestId')) return false;
+    var self = this;
 
     this.pollTaskLog();
     App.ajax.send({
@@ -163,10 +164,15 @@ App.Poll = Em.Object.extend({
       error: 'startPollingErrorCallback'
     })
       .retry({times: App.maxRetries, timeout: App.timeout})
-      .then(null, function () {
-        App.showReloadPopup();
-        console.log('Install services all retries failed');
-      });
+      .then(
+        function () {
+          self.closeReloadPopup();
+        },
+        function () {
+          self.showReloadPopup();
+          console.log('Install services all retries failed');
+        }
+      );
     return true;
   },
 

+ 0 - 1
ambari-web/app/views.js

@@ -30,7 +30,6 @@ require('views/common/modal_popups/alert_popup');
 require('views/common/modal_popups/confirmation_feedback_popup');
 require('views/common/modal_popups/confirmation_popup');
 require('views/common/modal_popups/prompt_popup');
-require('views/common/modal_popups/reload_popup');
 require('views/common/modal_popups/cluster_check_popup');
 require('views/common/modal_popups/invalid_KDC_popup');
 require('views/common/modal_popups/dependent_configs_list_popup');

+ 40 - 9
ambari-web/app/views/common/modal_popups/reload_popup.js → ambari-web/test/mixins/common/reload_popup_test.js

@@ -18,13 +18,44 @@
 
 var App = require('app');
 
-App.showReloadPopup = function () {
-  return App.ModalPopup.show({
-    primary: null,
-    secondary: null,
-    showFooter: false,
-    header: this.t('app.reloadPopup.header'),
-    body: "<div id='reload_popup' class='alert alert-info'><div class='spinner'><span>" + this.t('app.reloadPopup.text') + "</span></div></div><div><a href='#' onclick='location.reload();'>" + this.t('app.reloadPopup.link') + "</a></div>",
-    encodeBody: false
+require('mixins/common/reload_popup');
+
+describe('App.ReloadPopupMixin', function () {
+
+  var obj;
+
+  beforeEach(function () {
+    obj = Em.Object.create(App.ReloadPopupMixin);
+  });
+
+  describe('#showReloadPopup', function () {
+
+    var mockObj = {
+      key: 'value'
+    };
+
+    beforeEach(function () {
+      sinon.stub(App.ModalPopup, 'show').returns(mockObj);
+    });
+
+    afterEach(function () {
+      App.ModalPopup.show.restore();
+    });
+
+    it('should show modal popup', function () {
+      obj.showReloadPopup();
+      expect(obj.get('reloadPopup')).to.eql(mockObj);
+    });
   });
-};
+
+  describe('#closeReloadPopup', function () {
+
+    it('should hide modal popup', function () {
+      obj.showReloadPopup();
+      obj.closeReloadPopup();
+      expect(obj.get('reloadPopup')).to.be.null;
+    });
+
+  });
+
+});