Prechádzať zdrojové kódy

AMBARI-3730. Create user 'Settings' option on user dropdown menu.(xiwang)

Xi Wang 11 rokov pred
rodič
commit
e308a772fc

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

@@ -44,7 +44,6 @@ 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');

+ 101 - 0
ambari-web/app/controllers/application.js

@@ -39,5 +39,106 @@ App.ApplicationController = Em.Controller.extend({
 
   init: function(){
     this._super();
+  },
+
+  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);
+      }
+    });
+  },
+  showSettingsPopup: function() {
+    var self = this;
+    var initValue = this.loadShowBgChecked();
+    var curValue = null;
+    App.ModalPopup.show({
+      header: Em.I18n.t('common.userSettings'),
+      bodyClass: Em.View.extend({
+        templateName: require('templates/common/settings'),
+        isShowBgChecked: initValue,
+        updateValue: function () {
+          curValue = this.get('isShowBgChecked');
+        }.observes('isShowBgChecked')
+      }),
+      primary: Em.I18n.t('common.save'),
+      onPrimary: function() {
+        if (curValue == null) {
+          curValue = initValue;
+        }
+        var key = self.persistKey();
+        if (!App.testMode) {
+          self.postUserPref(key, curValue);
+        }
+        this.hide();
+      },
+      onSecondary: function() {
+        this.hide();
+      }
+    })
   }
+
+
 });

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

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

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

@@ -1,95 +0,0 @@
-/**
- * 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);
-      }
-    });
-  }
-});

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

@@ -156,7 +156,7 @@ App.MainHostDetailsController = Em.Controller.extend({
       } else {
         App.router.get('clusterController').loadUpdatedStatusDelayed(500);
       }
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     });
@@ -278,7 +278,7 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+            if (App.router.get('applicationController').loadShowBgChecked()) {
               App.router.get('backgroundOperationsController').showPopup();
             }
 
@@ -356,7 +356,7 @@ App.MainHostDetailsController = Em.Controller.extend({
         App.router.get('clusterController').loadUpdatedStatusDelayed(500);
       }
 
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     });
@@ -471,7 +471,7 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked() && showPopup) {
+            if (App.router.get('applicationController').loadShowBgChecked() && showPopup) {
               App.router.get('backgroundOperationsController').showPopup();
             }
           });
@@ -527,7 +527,7 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+            if (App.router.get('applicationController').loadShowBgChecked()) {
               App.router.get('backgroundOperationsController').showPopup();
             }
 
@@ -557,7 +557,7 @@ App.MainHostDetailsController = Em.Controller.extend({
         }
         self.doDatanodeDecommission(decommissionHostNames, true);
       }
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     });
@@ -662,7 +662,7 @@ App.MainHostDetailsController = Em.Controller.extend({
         decommissionHostNames.splice(index, 1);
         self.doDatanodeDecommission(decommissionHostNames, false);
       }
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     });

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

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

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

@@ -76,7 +76,7 @@ App.MainServiceItemController = Em.Controller.extend({
     else {
       App.router.get('clusterController').loadUpdatedStatusDelayed(500);// @todo check working without param 500
     }
-    if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+    if (App.router.get('applicationController').loadShowBgChecked()) {
       App.router.get('backgroundOperationsController').showPopup();
     }
   },
@@ -142,7 +142,7 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     App.showConfirmationPopup(function() {
       self.content.set('runRebalancer', true);
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     });
@@ -156,7 +156,7 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     App.showConfirmationPopup(function() {
       self.content.set('runCompaction', true);
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     });
@@ -192,7 +192,7 @@ App.MainServiceItemController = Em.Controller.extend({
 
   runSmokeTestSuccessCallBack: function(data) {
     if (data.Requests.id) {
-      if (App.router.get('mainAdminUserSettingsController').loadShowBgChecked()) {
+      if (App.router.get('applicationController').loadShowBgChecked()) {
         App.router.get('backgroundOperationsController').showPopup();
       }
     }

+ 3 - 3
ambari-web/app/messages.js

@@ -25,6 +25,9 @@ Em.I18n.translations = {
 
   'app.loadingPlaceholder': 'Loading...',
   'app.signout':'Sign out',
+  'app.settings':'Settings',
+  'app.settings.showBgOperations': 'Show background operations dialog when an operation is started',
+  'app.settings.notShowBgOperations': 'Do not show this dialog again when starting a background operation',
 
   'apply':'apply',
   'and':'and',
@@ -882,9 +885,6 @@ Em.I18n.translations = {
   'admin.cluster.repositories.os':'OS',
   'admin.cluster.repositories.baseUrl':'Base URL',
 
-  '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',
 

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

@@ -793,13 +793,6 @@ 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) {

+ 1 - 0
ambari-web/app/templates/application.hbs

@@ -46,6 +46,7 @@
               </button>
               <ul class="dropdown-menu">
                 <li><a href="" {{action logoff}}>{{t app.signout}}</a></li>
+                <li><a href="" {{action showSettingsPopup target="controller"}}>{{t app.settings}}</a></li>
               </ul>
             </div>
           {{/if}}

+ 2 - 5
ambari-web/app/templates/main/admin/userSettings.hbs → ambari-web/app/templates/common/settings.hbs

@@ -17,13 +17,10 @@
 }}
 
 <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}}
+      {{view Ember.Checkbox checkedBinding="view.isShowBgChecked" class="checkbox"}}
+      {{t app.settings.showBgOperations}}
     </label>
   </div>
 </div>

+ 3 - 3
ambari-web/app/utils/host_progress_popup.js

@@ -473,7 +473,7 @@ App.HostPopup = Em.Object.create({
       isOpen: false,
       didInsertElement: function(){
         this.set('isOpen', true);
-        this.set ('isNotShowBgChecked', !App.router.get('mainAdminUserSettingsController').loadShowBgChecked());
+        this.set ('isNotShowBgChecked', !App.router.get('applicationController').loadShowBgChecked());
       },
       headerClass: Ember.View.extend({
         controller: this,
@@ -485,9 +485,9 @@ App.HostPopup = Em.Object.create({
       isNotShowBgChecked : null,
       updateNotShowBgChecked: function () {
         var curVal = !this.get('isNotShowBgChecked');
-        var key = App.router.get('mainAdminUserSettingsController').persistKey();
+        var key = App.router.get('applicationController').persistKey();
         if (!App.testMode) {
-          App.router.get('mainAdminUserSettingsController').postUserPref(key, curVal);
+          App.router.get('applicationController').postUserPref(key, curVal);
         }
       }.observes('isNotShowBgChecked'),
 

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

@@ -72,7 +72,6 @@ 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');

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

@@ -21,9 +21,7 @@ var App = require('app');
 App.ModalPopup = Ember.View.extend({
 
   viewName: 'modalPopup',
-
   templateName: require('templates/common/modal_popup'),
-
   header: '&nbsp;',
   body: '&nbsp;',
   encodeBody: true,

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

@@ -46,11 +46,6 @@ 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',

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

@@ -1,34 +0,0 @@
-/**
- * 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')
-});