Repository: ambari
Updated Branches:
  refs/heads/trunk 70a59ef09 -> 2cb335c47


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


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2cb335c4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2cb335c4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2cb335c4

Branch: refs/heads/trunk
Commit: 2cb335c47b16c01457ec57c22eb826b739cf2bea
Parents: 70a59ef
Author: Alex Antonenko <hiv...@gmail.com>
Authored: Thu May 28 20:04:22 2015 +0300
Committer: Alex Antonenko <hiv...@gmail.com>
Committed: Thu May 28 20:08:18 2015 +0300

----------------------------------------------------------------------
 .../app/controllers/wizard/step7_controller.js  | 57 +++++++++++++++++++-
 ambari-web/app/messages.js                      |  1 +
 ambari-web/app/routes/installer.js              | 12 ++++-
 3 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2cb335c4/ambari-web/app/controllers/wizard/step7_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/wizard/step7_controller.js 
b/ambari-web/app/controllers/wizard/step7_controller.js
index a3297ff..1eda0a6 100644
--- a/ambari-web/app/controllers/wizard/step7_controller.js
+++ b/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,
@@ -279,6 +281,38 @@ App.WizardStep7Controller = 
Em.Controller.extend(App.ServerValidatorMixin, App.E
   },
 
   /**
+   * 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
    * @param {string[]} servicesNames
@@ -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

http://git-wip-us.apache.org/repos/asf/ambari/blob/2cb335c4/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index db05786..8548dca 100644
--- a/ambari-web/app/messages.js
+++ b/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',

http://git-wip-us.apache.org/repos/asf/ambari/blob/2cb335c4/ambari-web/app/routes/installer.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/installer.js 
b/ambari-web/app/routes/installer.js
index 5119077..849e942 100644
--- a/ambari-web/app/routes/installer.js
+++ b/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');

Reply via email to