You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2013/12/06 18:08:30 UTC

git commit: AMBARI-3992. After making config changes w/o saving, prompt user if they try to navigate away. (onechiporenko)

Updated Branches:
  refs/heads/trunk 56f7f8744 -> 66a5dbe60


AMBARI-3992. After making config changes w/o saving, prompt user if they try to navigate away. (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 66a5dbe6038e6f3d2a25b195759237d5702ec855
Parents: 56f7f87
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Fri Dec 6 19:03:15 2013 +0200
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Fri Dec 6 19:08:24 2013 +0200

----------------------------------------------------------------------
 .../controllers/main/service/info/configs.js    | 79 +++++++++++++++++++-
 ambari-web/app/messages.js                      |  1 +
 ambari-web/app/routes/main.js                   |  6 ++
 3 files changed, 83 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/66a5dbe6/ambari-web/app/controllers/main/service/info/configs.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/info/configs.js b/ambari-web/app/controllers/main/service/info/configs.js
index bbccd0c..1c11baa 100644
--- a/ambari-web/app/controllers/main/service/info/configs.js
+++ b/ambari-web/app/controllers/main/service/info/configs.js
@@ -146,6 +146,8 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
    * clear and set properties to default value
    */
   clearStep: function () {
+    this.set('isInit', true);
+    this.set('hash', null);
     this.set('dataIsLoaded', false);
     this.set('filter', '');
     this.get('filterColumns').setEach('selected', false);
@@ -166,6 +168,17 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   }.property('content'),
 
   /**
+   * "Finger-print" of the <code>stepConfigs</code>. Filled after first configGroup selecting
+   * Used to determine if some changes were made (when user navigates away from this page)
+   * {String}
+   */
+  hash: null,
+  /**
+   * Is this initial config group changing
+   * {Boolean}
+   */
+  isInit: true,
+  /**
    * On load function
    */
   loadStep: function () {
@@ -174,6 +187,20 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
     this.loadServiceConfigs();
   },
 
+  getHash: function() {
+    var hash = {};
+    this.get('stepConfigs')[0].configs.forEach(function(config) {
+      hash[config.get('name')] = {value: config.get('value'), overrides: []};
+      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);
+  },
+
   /**
    * Loads the actual configuration of all host components.
    * This helps in determining which services need a restart, and also
@@ -394,6 +421,10 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
     this.set('selectedService', this.get('stepConfigs').objectAt(0));
     this.checkForSecureConfig(this.get('selectedService'));
     this.set('dataIsLoaded', true);
+
+    this.set('hash', this.getHash());
+    this.set('isInit', false);
+
   }.observes('selectedConfigGroup'),
 
   loadServiceConfigHostsOverrides: function (allConfigs, loadedGroupToOverrideSiteToTagMap, configGroups) {
@@ -1752,7 +1783,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
       if (!this.get('content.hostComponents').filterProperty('staleConfigs').findProperty('workStatus', 'INSTALLED')) {
         return;
       }
-    };
+    }
     var content = this;
     return App.ModalPopup.show({
       primary: Em.I18n.t('ok'),
@@ -1790,7 +1821,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
               state: state
             }
           });
-        })
+        });
         this.hide();
         // load data (if we need to show this background operations popup) from persist
         App.router.get('applicationController').dataLoading().done(function (initValue) {
@@ -1980,6 +2011,48 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   },
 
   selectConfigGroup: function (event) {
+    if (!this.get('isInit')) {
+      if (this.hasUnsavedChanges()) {
+        this.showSavePopup(event);
+        return;
+      }
+    }
     this.set('selectedConfigGroup', event.context);
+  },
+
+  /**
+   * Are some unsaved changes available
+   * @returns {boolean}
+   */
+  hasUnsavedChanges: function() {
+    return this.get('hash') != this.getHash();
+  },
+
+  /**
+   * If some configs are changed and user navigates away or select another config-group, show this popup with propose to save changes
+   * @param {object} event - triggered event for seleting another config-group
+   */
+  showSavePopup: function(event) {
+    if (!event) event = null;
+    var _this = this;
+    App.ModalPopup.show({
+      header: Em.I18n.t('common.warning'),
+      body: Em.I18n.t('services.service.config.exitPopup.body'),
+      primary: Em.I18n.t('common.save'),
+      secondary: Em.I18n.t('common.cancel'),
+      onPrimary: function() {
+        _this.restartServicePopup();
+        this._super();
+      },
+      onSecondary: function() {
+        if (event) {
+          // Prevent multiple popups
+          _this.set('hash', _this.getHash());
+
+          _this.selectConfigGroup(event);
+        }
+        this._super();
+      }
+    });
   }
-});
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/66a5dbe6/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 2e61af6..f31dc0b 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -1121,6 +1121,7 @@ Em.I18n.translations = {
   'services.service.config.confirmDirectoryChange':'You are about to make changes to service directories that are core to {0}. Before you proceed, be absolutely certain of the implications and that you have taken necessary manual steps, if any, for the changes. Are you sure you want to proceed?',
   '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.add.header':'Add Service Wizard',
   'services.reassign.header':'Move Master Wizard',

http://git-wip-us.apache.org/repos/asf/ambari/blob/66a5dbe6/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index f35c3ff..0a2d711 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -868,6 +868,12 @@ module.exports = Em.Route.extend({
         connectOutlets: function (router, context) {
           var item = router.get('mainServiceItemController.content');
           router.get('mainServiceItemController').connectOutlet('mainServiceInfoConfigs', item);
+        },
+        exit: function(router, context) {
+          var controller = router.get('mainServiceInfoConfigsController');
+          if (controller.hasUnsavedChanges()) {
+            controller.showSavePopup();
+          }
         }
       }),
       audit: Em.Route.extend({