You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2016/02/02 18:14:37 UTC

ambari git commit: AMBARI-14880. Add popup that will show desired messages upon login (alexantonenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 9cc01b45e -> aab6d8898


AMBARI-14880. Add popup that will show desired messages upon login (alexantonenko)


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

Branch: refs/heads/trunk
Commit: aab6d889895ddf2c02fd6fa2c79ec9901fb9e768
Parents: 9cc01b4
Author: Alex Antonenko <hi...@gmail.com>
Authored: Tue Feb 2 19:14:21 2016 +0200
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Tue Feb 2 19:14:33 2016 +0200

----------------------------------------------------------------------
 .../loginActivities/LoginMessageMainCtrl.js     | 53 +++++++++++---
 .../ui/admin-web/app/scripts/i18n.config.js     |  6 +-
 .../resources/ui/admin-web/app/styles/main.css  |  8 ++-
 .../app/views/loginActivities/loginMessage.html | 74 +++++++++++++-------
 ambari-web/app/assets/data/clusters/info.json   | 11 ---
 ambari-web/app/assets/data/settings/motd.json   | 10 +++
 ambari-web/app/messages.js                      |  1 +
 ambari-web/app/router.js                        | 41 +++++++++++
 ambari-web/app/utils/ajax/ajax.js               |  4 ++
 9 files changed, 158 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/LoginMessageMainCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/LoginMessageMainCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/LoginMessageMainCtrl.js
index 11fcea5..88c4d27 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/LoginMessageMainCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/loginActivities/LoginMessageMainCtrl.js
@@ -18,17 +18,21 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-  .controller('LoginMessageMainCtrl',['$scope', 'Alert', '$timeout', '$http', '$translate', function($scope, Alert, $timeout, $http, $translate) {
-    var $t = $translate.instant;
+  .controller('LoginMessageMainCtrl',['$scope', 'Alert', '$timeout', '$location', '$http', '$translate', 'UnsavedDialog', function($scope, Alert, $timeout, $location, $http, $translate, UnsavedDialog) {
+    var $t = $translate.instant,
+      targetUrl = '/loginActivities';
+
     $scope.status = false;
     $scope.motdExists = false;
     $scope.text = "";
+    $scope.buttonText = "Ok";
     $scope.submitDisabled = true;
 
     $http.get('/api/v1/admin-settings/motd').then(function (res) {
-      var respons = JSON.parse(res.data.AdminSettings.content);
-      $scope.text = respons.text ? respons.text : "";
-      $scope.status = respons.status && respons.status == "true" ? true : false;
+      var response = JSON.parse(res.data.AdminSettings.content);
+      $scope.text = response.text ? response.text : "";
+      $scope.buttonText = response.button ? response.button : "";
+      $scope.status = response.status && response.status == "true" ? true : false;
       $scope.motdExists = true;
     });
 
@@ -40,28 +44,57 @@ angular.module('ambariAdminConsole')
       $scope.submitDisabled = false;
     };
 
-    $scope.saveLoginMsg = function(form) {
+    $scope.$watch(function(scope) {
+      return scope.submitDisabled;
+    }, function(submitDisabled) {
+      $scope.form.$dirty = !submitDisabled
+    });
+
+    $scope.saveLoginMsg = function(targetUrl) {
       var method = $scope.motdExists ? 'PUT' : 'POST';
       var data = {
         'AdminSettings' : {
-          'content' : '{"text":"' + $scope.text + '", "status":"' + $scope.status + '"}',
+          'content' : '{"text":"' + $scope.text + '", "button":"' + $scope.buttonText + '", "status":"' + $scope.status + '"}',
           'name' : 'motd',
           'setting_type' : 'ambari-server'
         }
       };
-      form.submitted = true;
-      if (form.$valid){
+      $scope.form.submitted = true;
+      if ($scope.form.$valid){
         $scope.submitDisabled = true;
-        $http({
+        return $http({
           method: method,
           url: '/api/v1/admin-settings/' + ($scope.motdExists ? 'motd' : ''),
           data: data
         }).then(function successCallback() {
           $scope.motdExists = true;
+          targetUrl ? $location.path(targetUrl) : "";
         }, function errorCallback(data) {
           $scope.submitDisabled = false;
           Alert.error($t('common.loginActivities.saveError'), data.data.message);
         });
       }
     };
+
+    $scope.$on('$locationChangeStart', function(event, __targetUrl) {
+      if( $scope.form.$dirty ){
+        UnsavedDialog().then(function(action) {
+          targetUrl = __targetUrl.split('#').pop();
+          switch(action){
+            case 'save':
+              $scope.saveLoginMsg(targetUrl);
+              break;
+            case 'discard':
+              $scope.form.$setPristine();
+              $location.path(targetUrl);
+              break;
+            case 'cancel':
+              targetUrl = '/loginActivities';
+              break;
+          }
+        });
+        event.preventDefault();
+      }
+    });
+
   }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
index c83d627..c1b9d88 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
@@ -85,9 +85,13 @@ angular.module('ambariAdminConsole')
         'loginActivities':'Login Activities',
         'loginMessage': 'Login Message',
         'loginMessage.placeholder': 'Please enter login message',
+        'buttonText.placeholder': 'Please enter text for the "ok" button',
         'homeDirectory': 'Home Directory',
         'onlySimpleChars': 'Must contain only simple characters.',
-        'saveError': 'Save error'
+        'saveError': 'Save error',
+        'message': 'Message',
+        'buttonText': 'Button text',
+        'switch': 'On/Off'
       },
 
       'controls': {

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css b/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
index f54d87c..0474e9c 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css
@@ -682,11 +682,13 @@ table.no-border tr td{
   min-height: 63px;
 }
 
-.login-message-pane .active, .inactive {font-size:30px;cursor:pointer;float: left;margin-left: 17px;}
+.login-message-pane .active, .inactive {font-size:30px;cursor:pointer;float: left;}
 .login-message-pane i.active {color: #5cb85c;margin-top: 3px;}
 .login-message-pane i.inactive {color: #d9534f;margin-top: 2px;}
-.login-message-pane .well {height: 74px;}
-.login-message-pane input {margin-left: 3px;}
+.login-message-pane .on-off-switch-wrap {height:32px;}
+
+/*.login-message-pane .well {height: 74px;}
+.login-message-pane input {margin-left: 3px;}*/
 
 .views-permissions-panel .panel-body{
   padding-bottom: 0;

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/loginMessage.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/loginMessage.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/loginMessage.html
index 8fb7870..37b6165 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/loginMessage.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/loginActivities/loginMessage.html
@@ -18,44 +18,68 @@
 
 <br/>
 <div class="login-message-pane" ng-controller="LoginMessageMainCtrl">
-
   <form class="form-horizontal" novalidate name="form" autocomplete="off">
     <div class="well">
-      <div class="form-group" ng-class="{'has-error' : (form.login_text.$error.pattern) && form.submitted}">
-        <i class="fa fa-toggle-on active"
-           ng-if="status == true"
-           ng-click="changeStatus();">
-        </i>
-        <i class="fa fa-toggle-on fa-rotate-180 inactive"
-           ng-if="status == false"
-           ng-click="changeStatus();">
-        </i>
-        <div class="col-sm-11">
-          <input type="text"
-                 ng-disabled="!status"
+      <fieldset>
+        <div class="form-group" ng-class="{'has-error' : (form.login_text.$error.pattern) && form.submitted}">
+          <label class="col-sm-2 control-label">{{'common.loginActivities.switch' | translate}}</label>
+          <div class="on-off-switch-wrap col-sm-10">
+            <i class="fa fa-toggle-on active"
+               ng-if="status == true"
+               ng-click="changeStatus();">
+            </i>
+            <i class="fa fa-toggle-on fa-rotate-180 inactive"
+               ng-if="status == false"
+               ng-click="changeStatus();">
+            </i>
+            <input type="checkbox" name="status" class="hidden" ng-model="status">
+          </div>
+        </div>
+        <div class="form-group" ng-class="{'has-error' : (form.login_text.$error.pattern) && form.submitted}">
+          <label class="col-sm-2 control-label">{{'common.loginActivities.message' | translate}}</label>
+          <div class="col-sm-10">
+            <input type="text"
                  class="form-control"
                  name="login_text"
                  placeholder="{{'common.loginActivities.loginMessage.placeholder' | translate}}"
                  ng-model="text"
                  ng-change="inputChangeEvent()"
                  ng-pattern="/^([a-zA-Z0-9._\s]+)$/"
+                 ng-disabled="!status"
                  autocomplete="off">
 
-          <div class="alert alert-danger top-margin" ng-show="form.login_text.$error.pattern && form.submitted">
-            {{'common.loginActivities.onlySimpleChars' | translate}}
+            <div class="alert alert-danger top-margin" ng-show="form.login_text.$error.pattern && form.submitted">
+             {{'common.loginActivities.onlySimpleChars' | translate}}
+            </div>
           </div>
         </div>
+        <div class="form-group" ng-class="{'has-error' : (form.login_text.$error.pattern) && form.submitted}">
+          <label class="col-sm-2 control-label">{{'common.loginActivities.buttonText' | translate}}</label>
+          <div class="col-sm-5">
+            <input type="text"
+                   class="form-control"
+                   name="button_text"
+                   placeholder="{{'common.loginActivities.buttonText.placeholder' | translate}}"
+                   ng-model="buttonText"
+                   ng-change="inputChangeEvent()"
+                   ng-disabled="!status"
+                   ng-pattern="/^([a-zA-Z0-9._\s]+)$/"
+                   autocomplete="off">
+
+            <div class="alert alert-danger top-margin" ng-show="form.button_text.$error.pattern && form.submitted">
+              {{'common.loginActivities.onlySimpleChars' | translate}}
+            </div>
+          </div>
+        </div>
+        <div class="col-sm-offset-2 col-sm-10">
+          <button
+            class="btn btn-primary groupcreate-btn pull-right left-margin"
+            ng-disabled="submitDisabled"
+            ng-click="saveLoginMsg()">
+            {{'common.controls.save' | translate}}
+          </button>
       </div>
-    </div>
-    <div class="form-group">
-      <div class="col-sm-offset-2 col-sm-10">
-        <button
-          class="btn btn-primary groupcreate-btn pull-right left-margin"
-          ng-disabled="submitDisabled"
-          ng-click="saveLoginMsg(form)">
-          {{'common.controls.save' | translate}}
-        </button>
-      </div>
+      </fieldset>
     </div>
   </form>
 </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-web/app/assets/data/clusters/info.json
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/data/clusters/info.json b/ambari-web/app/assets/data/clusters/info.json
deleted file mode 100644
index 072af2f..0000000
--- a/ambari-web/app/assets/data/clusters/info.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-  "items" : [
-    {
-      "Clusters" : {
-        "cluster_name" : "tdk",
-        "provisioning_state" : "INSTALLED",
-        "version" : "HDP-2.0.1"
-      }
-    }
-  ]
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-web/app/assets/data/settings/motd.json
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/data/settings/motd.json b/ambari-web/app/assets/data/settings/motd.json
new file mode 100644
index 0000000..c051a90
--- /dev/null
+++ b/ambari-web/app/assets/data/settings/motd.json
@@ -0,0 +1,10 @@
+{
+  "href" : "/api/v1/admin-settings/motd",
+  "AdminSettings" : {
+    "content" : "{\"text\":\"You are using test mode\", \"button\":\"\", \"status\":\"true\"}",
+    "name" : "motd",
+    "setting_type" : "ambari-server",
+    "update_timestamp" : 1454428666251,
+    "updated_by" : "admin"
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 2de2f2b..8861b2a 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -424,6 +424,7 @@ Em.I18n.translations = {
   'popup.jdkValidation.body': 'The {0} Stack requires JDK {1} but Ambari is configured for JDK {2}. This could result in error or problems with running your cluster.',
 
   'login.header':'Sign in',
+  'login.message.title':'Login Message',
   'login.username':'Username',
   'login.loginButton':'Sign in',
   'login.error.bad.credentials':'Unable to sign in. Invalid username/password combination.',

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index 3c6a07c..08df9c5 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -317,6 +317,13 @@ App.Router = Em.Router.extend({
       loginData: data
     };
     App.router.get('clusterController').loadAuthorizations().complete(function() {
+      App.ajax.send({
+        name: 'router.login.message',
+        sender: self,
+        success: 'showLoginMessage'
+
+    });
+
       // no need to load cluster data if it's already loaded
       if (self.get('clusterData')) {
         self.loginGetClustersSuccessCallback(self.get('clusterData'), {}, requestData);
@@ -352,6 +359,40 @@ App.Router = Em.Router.extend({
   },
 
   /**
+   * success callback of router.login.message
+   * @param {object} data
+   */
+  showLoginMessage: function (data){
+    var response = JSON.parse(data.AdminSettings.content),
+      text = response.text ? response.text : "",
+      buttonText = response.button ? response.button : Em.I18n.t('ok'),
+      status = response.status && response.status == "true" ? true : false;
+
+    if(text && status){
+      return App.ModalPopup.show({
+        classNames: ['sixty-percent-width-modal'],
+        header: Em.I18n.t('login.message.title'),
+        bodyClass: Ember.View.extend({
+          template: Ember.Handlebars.compile(text)
+        }),
+        primary: buttonText,
+        secondary: null,
+
+        onPrimary: function () {
+          this.hide();
+        },
+        onClose: function () {
+          this.hide();
+        },
+        didInsertElement: function () {
+          this.fitHeight();
+        }
+      });
+    }
+  },
+
+
+  /**
    * success callback of login request
    * @param {object} clustersData
    * @param {object} opt

http://git-wip-us.apache.org/repos/asf/ambari/blob/aab6d889/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index 4872f50..9cd54d2 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -2088,6 +2088,10 @@ var urls = {
     'real': '/clusters?fields=Clusters/provisioning_state',
     'mock': '/data/clusters/info.json'
   },
+  'router.login.message': {
+    'real': '/admin-settings/motd',
+    'mock': '/data/settings/motd.json'
+  },
   'router.logoff': {
     'real': '/logout',
     'mock': '',