Просмотр исходного кода

AMBARI-3054. User Preference to show 'Background Operations'. (xiwang)

Xi Wang 11 лет назад
Родитель
Сommit
895fd88eca

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

@@ -44,6 +44,7 @@ require('controllers/main/admin/rollbackHA/step2_controller');
 require('controllers/main/admin/rollbackHA/step3_controller');
 require('controllers/main/admin/rollbackHA/rollback_wizard_controller');
 require('controllers/main/admin/cluster');
+require('controllers/main/admin/user_settings');
 require('controllers/main/admin/stack_upgrade_controller');
 require('controllers/main/admin/user');
 require('controllers/main/admin/misc_controller');

+ 3 - 1
ambari-web/app/controllers/global/background_operations_controller.js

@@ -224,7 +224,9 @@ App.BackgroundOperationsController = Em.Controller.extend({
    */
   showPopup: function(){
     App.updater.immediateRun('requestMostRecent');
-    if(this.get('popupView') && App.HostPopup.get('isBackgroundOperations')){
+
+    if(this.get('popupView') && App.HostPopup.get('isBackgroundOperations') && App.HostPopup.get('showServices')){
+      this.set ('popupView.isNotShowBgChecked', !App.router.get('mainAdminUserSettingsController').loadShowBgChecked());
       this.set('popupView.isOpen', true);
       $(this.get('popupView.element')).appendTo('#wrapper');
     } else {

+ 95 - 0
ambari-web/app/controllers/main/admin/user_settings.js

@@ -0,0 +1,95 @@
+/**
+ * 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.MainAdminUserSettingsController = Em.Controller.extend({
+  name:'mainAdminUserSettingsController',
+  loadShowBgChecked: function () {
+    if (App.testMode) {
+      return true;
+    } else {
+      this.getUserPref(this.persistKey());
+      var currentPrefObject = this.get('currentPrefObject');
+      if (currentPrefObject != null) {
+        return currentPrefObject;
+      } else {
+        // post persist
+        this.postUserPref(this.persistKey(), true);
+        return true;
+      }
+    }
+  },
+
+  persistKey: function () {
+    var loginName = App.router.get('loginName');
+    return 'admin-settings-show-bg-' + loginName;
+  },
+  currentPrefObject: null,
+
+  /**
+   * get persist value from server with persistKey
+   */
+  getUserPref: function (key) {
+    var self = this;
+    var url = App.apiPrefix + '/persist/' + key;
+    jQuery.ajax(
+      {
+        url: url,
+        context: this,
+        async: false,
+        success: function (response) {
+          if (response) {
+            var value = jQuery.parseJSON(response);
+            console.log('Got persist value from server with key: ' + key + '. Value is: ' + response);
+            self.set('currentPrefObject', value);
+            return value;
+          }
+        },
+        error: function (xhr) {
+          // this user is first time login
+          if (xhr.status == 404) {
+            console.log('Persist did NOT find the key: '+ key);
+            self.set('currentPrefObject', null);
+            return null;
+          }
+        },
+        statusCode: require('data/statusCodes')
+      }
+    );
+  },
+  /**
+   * post persist key/value to server, value is object
+   */
+  postUserPref: function (key, value) {
+    var url = App.apiPrefix + '/persist/';
+    var keyValuePair = {};
+    keyValuePair[key] = JSON.stringify(value);
+
+    jQuery.ajax({
+      async: false,
+      context: this,
+      type: "POST",
+      url: url,
+      data: JSON.stringify(keyValuePair),
+      beforeSend: function () {
+        console.log('BeforeSend to persist: persistKeyValues', keyValuePair);
+      }
+    });
+  }
+});

+ 21 - 8
ambari-web/app/controllers/main/host/details.js

@@ -239,7 +239,7 @@ App.MainHostDetailsController = Em.Controller.extend({
         deleted = {xhr: xhr, url: url, method: 'DELETE'};
       },
       statusCode: require('data/statusCodes')
-    });
+      });
     return deleted;
   },
 
@@ -278,7 +278,9 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            App.router.get('backgroundOperationsController').showPopup();
+            if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+              App.router.get('backgroundOperationsController').showPopup();
+            }
 
           });
     });
@@ -349,10 +351,14 @@ App.MainHostDetailsController = Em.Controller.extend({
             component.set('workStatus', App.HostComponentStatus.stopped);
           },App.testModeDelayForActions);
         }
+
       } else {
         App.router.get('clusterController').loadUpdatedStatusDelayed(500);
       }
-      App.router.get('backgroundOperationsController').showPopup();
+
+      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
     });
   },
 
@@ -465,8 +471,9 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            App.router.get('backgroundOperationsController').showPopup();
-
+            if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+              App.router.get('backgroundOperationsController').showPopup();
+            }
           });
       });
   },
@@ -520,7 +527,9 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            App.router.get('backgroundOperationsController').showPopup();
+            if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+              App.router.get('backgroundOperationsController').showPopup();
+            }
 
           });
       }
@@ -548,7 +557,9 @@ App.MainHostDetailsController = Em.Controller.extend({
         }
         self.doDatanodeDecommission(decommissionHostNames, true);
       }
-      App.router.get('backgroundOperationsController').showPopup();
+      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
     });
   },
 
@@ -650,7 +661,9 @@ App.MainHostDetailsController = Em.Controller.extend({
         decommissionHostNames.splice(index, 1);
         self.doDatanodeDecommission(decommissionHostNames, false);
       }
-      App.router.get('backgroundOperationsController').showPopup();
+      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
     });
   },
   

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

@@ -109,7 +109,9 @@ App.MainServiceController = Em.ArrayController.extend({
     var requestId = data.Requests.id;
     console.log('requestId is: ' + requestId);
 
-    App.router.get('backgroundOperationsController').showPopup();
+    if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      App.router.get('backgroundOperationsController').showPopup();
+    }
   },
   allServicesCallErrorCallback: function() {
     console.log("ERROR");

+ 12 - 4
ambari-web/app/controllers/main/service/item.js

@@ -76,7 +76,9 @@ App.MainServiceItemController = Em.Controller.extend({
     else {
       App.router.get('clusterController').loadUpdatedStatusDelayed(500);// @todo check working without param 500
     }
-    App.router.get('backgroundOperationsController').showPopup();
+    if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      App.router.get('backgroundOperationsController').showPopup();
+    }
   },
   /**
    * Confirmation popup for start/stop services
@@ -140,7 +142,9 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     App.showConfirmationPopup(function() {
       self.content.set('runRebalancer', true);
-      App.router.get('backgroundOperationsController').showPopup();
+      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
     });
   },
 
@@ -152,7 +156,9 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     App.showConfirmationPopup(function() {
       self.content.set('runCompaction', true);
-      App.router.get('backgroundOperationsController').showPopup();
+      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
     });
   },
 
@@ -186,7 +192,9 @@ App.MainServiceItemController = Em.Controller.extend({
 
   runSmokeTestSuccessCallBack: function(data) {
     if (data.Requests.id) {
-      App.router.get('backgroundOperationsController').showPopup();
+      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
     }
     else {
       console.warn('error during runSmokeTestSuccessCallBack');

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

@@ -133,6 +133,7 @@ Em.I18n.translations = {
   'common.stats':'Stats',
   'common.abort': 'Abort',
   'common.misc': 'Misc',
+  'common.userSettings': 'User Settings',
   'common.operations': 'Operations',
   'common.reinstall': 'Re-Install',
   'common.errorPopup.header': 'An error has been encountered',
@@ -872,6 +873,9 @@ Em.I18n.translations = {
   'admin.cluster.upgradeAvailable':'Upgrade available',
   'admin.cluster.upgradeUnavailable':'Upgrade unavailable',
 
+  'admin.userSettings.header': 'Customize User Settings',
+  'admin.userSettings.showBgOperations': 'Show background operations dialog when an operation is started',
+  'admin.userSettings.notShowBgOperations': 'Do not show this dialog again when starting a background operation',
   'admin.misc.header': 'Service Users and Groups',
   'admin.misc.nothingToShow': 'No user accounts to display',
 

+ 7 - 1
ambari-web/app/routes/main.js

@@ -793,7 +793,13 @@ module.exports = Em.Route.extend({
         router.get('mainAdminController').connectOutlet('mainAdminAdvanced');
       }
     }),
-
+    adminUserSettings: Em.Route.extend({
+      route: '/userSettings',
+      connectOutlets: function (router) {
+        router.set('mainAdminController.category', "userSettings");
+        router.get('mainAdminController').connectOutlet('mainAdminUserSettings');
+      }
+    }),
     adminMisc: Em.Route.extend({
       route: '/misc',
       connectOutlets: function (router) {

+ 15 - 0
ambari-web/app/styles/application.less

@@ -1053,6 +1053,16 @@ a:focus {
     overflow: auto;
     width: 100%;
   }
+  .modal-footer {
+    #footer-checkbox {
+      text-align: left;
+      padding-top: 3px;
+      margin-left: 22px;
+      .checkbox {
+        margin: 0px;
+      }
+    }
+  }
 
   .modal-body {
 
@@ -3080,6 +3090,11 @@ table.graphs {
   }
 }
 
+.admin-user-settings {
+  .checkbox {
+    margin: 0px;
+  }
+}
 /*End Admin*/
 
 /*assign masters*/

+ 29 - 0
ambari-web/app/templates/main/admin/userSettings.hbs

@@ -0,0 +1,29 @@
+{{!
+* 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.
+}}
+
+<div class="admin-user-settings">
+  <div class="header">
+    <strong>{{t admin.userSettings.header}}</strong>
+  </div>
+  <div>
+    <label>
+      {{view Ember.Checkbox checkedBinding="view.isShowBgChecked" classNames="checkbox"}}
+      {{t admin.userSettings.showBgOperations}}
+    </label>
+  </div>
+</div>

+ 11 - 0
ambari-web/app/utils/host_progress_popup.js

@@ -479,6 +479,17 @@ App.HostPopup = Em.Object.create({
         template: Ember.Handlebars.compile('{{popupHeaderName}}')
       }),
       classNames: ['sixty-percent-width-modal'],
+      // for the checkbox: do not show this dialog again
+      hasFooterCheckbox: true,
+      isNotShowBgChecked : null,
+      updateNotShowBgChecked: function () {
+        var curVal = !this.get('isNotShowBgChecked');
+        var key = App.router.get('mainAdminUserSettingsController').persistKey();
+        if (!App.testMode) {
+          App.router.get('mainAdminUserSettingsController').postUserPref(key, curVal);
+        }
+      }.observes('isNotShowBgChecked'),
+
       autoHeight: false,
       closeModelPopup: function () {
         this.set('isOpen', false);

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

@@ -72,6 +72,7 @@ require('views/main/admin/rollbackHA/step3_view');
 require('views/main/admin/rollbackHA/rollback_wizard_view');
 require('views/main/admin/cluster');
 require('views/main/admin/misc_view');
+require('views/main/admin/user_settings');
 require('views/main/admin/stack_upgrade');
 require('views/main/admin/advanced');
 require('views/main/admin/advanced/password');

+ 2 - 0
ambari-web/app/views/common/modal_popup.js

@@ -39,6 +39,8 @@ App.ModalPopup = Ember.View.extend({
     '{{#if footerClass}}{{view footerClass}}',
     '{{else}}',
     '<div class="modal-footer">',
+    '{{#if view.hasFooterCheckbox}} <label id="footer-checkbox" class="span8">  {{view Ember.Checkbox classNames="checkbox" checkedBinding="view.isNotShowBgChecked"}} &nbsp;' +
+      '{{t admin.userSettings.notShowBgOperations}}</label> {{/if}}',
     '{{#if view.secondary}}<a class="btn" {{action onSecondary target="view"}}>{{view.secondary}}</a>{{/if}}',
     '{{#if view.primary}}<a {{bindAttr class="view.enablePrimary::disabled :btn :btn-success"}} {{action onPrimary target="view"}}>{{view.primary}}</a>{{/if}}',
     '</div>',

+ 5 - 0
ambari-web/app/views/main/admin.js

@@ -46,6 +46,11 @@ App.MainAdminView = Em.View.extend({
       url: 'adminCluster',
       label: Em.I18n.t('common.cluster')
     });
+    items.push({
+      name: 'userSettings',
+      url: 'adminUserSettings',
+      label: Em.I18n.t('common.userSettings')
+    });
     items.push({
       name: 'misc',
       url: 'adminMisc',

+ 34 - 0
ambari-web/app/views/main/admin/user_settings.js

@@ -0,0 +1,34 @@
+/**
+ * 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.MainAdminUserSettingsView = Em.View.extend({
+  templateName: require('templates/main/admin/userSettings'),
+  didInsertElement: function() {
+    this.set ('isShowBgChecked', this.get('controller').loadShowBgChecked());
+  },
+  isShowBgChecked: null,
+  updateShowBgchecked: function () {
+    var curVal = this.get('isShowBgChecked');
+    var key = this.get('controller').persistKey();
+    if (!App.testMode) {
+      this.get('controller').postUserPref(key, curVal);
+    }
+  }.observes('isShowBgChecked')
+});