فهرست منبع

AMBARI-11492. Need to enter configs again, no notification, regarding that your changes will be discarded on going back (alexantonenko)

Alex Antonenko 10 سال پیش
والد
کامیت
2cb335c47b
3فایلهای تغییر یافته به همراه67 افزوده شده و 3 حذف شده
  1. 55 2
      ambari-web/app/controllers/wizard/step7_controller.js
  2. 1 0
      ambari-web/app/messages.js
  3. 11 1
      ambari-web/app/routes/installer.js

+ 55 - 2
ambari-web/app/controllers/wizard/step7_controller.js

@@ -37,6 +37,8 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
    */
   stepConfigs: [],
 
+  hash: null,
+
   selectedService: null,
 
   slaveHostToGroup: null,
@@ -278,6 +280,38 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
     this.get('filterColumns').setEach('selected', false);
   },
 
+  /**
+   * Generate "finger-print" for current <code>stepConfigs[0]</code>
+   * Used to determine, if user has some unsaved changes (comparing with <code>hash</code>)
+   * @returns {string|null}
+   * @method getHash
+   */
+  getHash: function () {
+    if (!this.get('stepConfigs')[0]) {
+      return null;
+    }
+    var hash = {};
+    this.get('stepConfigs').forEach(function(stepConfig){
+      stepConfig.configs.forEach(function (config) {
+        hash[config.get('name')] = {value: config.get('value'), overrides: [], isFinal: config.get('isFinal')};
+        if (!config.get('overrides')) return;
+        if (!config.get('overrides.length')) return;
+
+        config.get('overrides').forEach(function (override) {
+          hash[config.get('name')].overrides.push(override.get('value'));
+        });
+      });
+    });
+    return JSON.stringify(hash);
+  },
+
+   /**
+   * Are some changes available
+   */
+  hasChanges: function () {
+    return this.get('hash') != this.getHash();
+  },
+
   /**
    * Load config groups for installed services
    * One ajax-request for each service
@@ -657,6 +691,7 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
       if (self.get('content.skipConfigStep')) {
         App.router.send('next');
       }
+      self.set('hash', self.getHash());
     });
   },
 
@@ -772,7 +807,6 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
         miscService.configs = c;
       }
     }
-
     this.set('stepConfigs', serviceConfigs);
   },
 
@@ -1310,6 +1344,25 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
     return deferred;
   },
 
+  showChangesWarningPopup: function(goToNextStep) {
+    var self = this;
+    return App.ModalPopup.show({
+      header: Em.I18n.t('common.warning'),
+      body: Em.I18n.t('services.service.config.exitChangesPopup.body'),
+      secondary: Em.I18n.t('common.cancel'),
+      primary: Em.I18n.t('yes'),
+      onPrimary: function () {
+        if (goToNextStep) {
+          goToNextStep();
+          this.hide(); 
+        }
+      },
+      onSecondary: function () {
+        this.hide();
+      }
+    });
+  },
+
   showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
     var self = this;
     return App.ModalPopup.show({
@@ -1326,7 +1379,7 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
         deferred.reject();
         this._super();
       }
-    })
+    });
   },
   /**
    * Proceed to the next step

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

@@ -1758,6 +1758,7 @@ Em.I18n.translations = {
   'services.service.config.configOverride.head':'Config Override',
   'services.service.config.configOverride.body':'Cannot override a config that has not been saved yet.',
   'services.service.config.exitPopup.body':'You have unsaved changes. Save changes or discard?',
+  'services.service.config.exitChangesPopup.body':'You will be brought back to the \"Assign Slaves and Clients\" step and will lose all your current customizations. Are you sure?',
   'services.service.config.propertyFilterPopover.title':'Properties filter',
   'services.service.config.propertyFilterPopover.content':'Enter keywords to filter properties by property name, value, or description.',
   'services.service.config.hive.oozie.postgresql': 'Existing PostgreSQL Database',

+ 11 - 1
ambari-web/app/routes/installer.js

@@ -309,7 +309,17 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
     },
     back: function (router) {
       var step = router.get('installerController.content.skipSlavesStep') ? 'step5' : 'step6';
-      router.transitionTo(step);
+      var wizardStep7Controller = router.get('wizardStep7Controller');
+
+      var goToNextStep = function() {
+        router.transitionTo(step);
+      };
+
+      if (wizardStep7Controller.hasChanges()) {
+        wizardStep7Controller.showChangesWarningPopup(goToNextStep);
+      } else {
+        goToNextStep();
+      }
     },
     next: function (router) {
       var controller = router.get('installerController');