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/23 18:17:45 UTC

ambari git commit: AMBARI-15134. Issues with Login Message dialog Round #2 (alexantonenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 2b42559f5 -> df0b18ca5


AMBARI-15134. Issues with Login Message dialog Round #2 (alexantonenko)


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

Branch: refs/heads/trunk
Commit: df0b18ca5da59d9ed6bc4340ac09eb51db9963a4
Parents: 2b42559
Author: Alex Antonenko <hi...@gmail.com>
Authored: Tue Feb 23 18:29:33 2016 +0200
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Tue Feb 23 19:17:41 2016 +0200

----------------------------------------------------------------------
 .../loginActivities/LoginMessageMainCtrl.js     | 51 ++++++++++++++------
 .../ui/admin-web/app/scripts/i18n.config.js     |  4 +-
 .../app/views/loginActivities/loginMessage.html | 14 +++---
 ambari-web/app/router.js                        | 11 ++++-
 4 files changed, 55 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/df0b18ca/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 763bd59..911bb0b 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
@@ -22,19 +22,27 @@ angular.module('ambariAdminConsole')
     var $t = $translate.instant,
       targetUrl = '/loginActivities';
 
-    $scope.status = false;
-    $scope.motdExists = false;
-    $scope.text = "";
-    $scope.buttonText = "OK";
-    $scope.submitDisabled = true;
+    $scope.getMOTD = function() {
+      $http.get('/api/v1/settings/motd').then(function (res) {
+        $scope.motdExists = true;
+        var
+          response = JSON.parse(res.data.Settings.content.replace(/\n/g, "\\n")),
+          lt = /&lt;/g,
+          gt = /&gt;/g,
+          ap = /&#39;/g,
+          ic = /&#34;/g;
 
-    $http.get('/api/v1/settings/motd').then(function (res) {
-      $scope.motdExists = true;
-      var response = JSON.parse(res.data.Settings.content.replace(/\n/g, "\\n"));
-      $scope.text = response.text ? response.text : "";
-      $scope.buttonText = response.button ? response.button : "";
-      $scope.status = response.status && response.status == "true" ? true : false;
-    });
+        $scope.text = response.text ? response.text.toString().replace(lt, "<").replace(gt, ">").replace(ap, "'").replace(ic, '"') : "";
+        $scope.buttonText = response.button ? response.button.toString().replace(lt, "<").replace(gt, ">").replace(ap, "'").replace(ic, '"') : "OK";
+        $scope.status = response.status && response.status == "true" ? true : false;
+      }, function(response) {
+        $scope.status = false;
+        $scope.motdExists = false;
+        $scope.text = "";
+        $scope.buttonText = "OK";
+      });
+      $scope.submitDisabled = true;
+    };
 
     $scope.inputChangeEvent = function(){
       $scope.submitDisabled = false;
@@ -43,6 +51,10 @@ angular.module('ambariAdminConsole')
       $scope.submitDisabled = false;
     };
 
+    $scope.cancel = function() {
+      $scope.getMOTD();
+    };
+
     $scope.$watch(function(scope) {
       return scope.submitDisabled;
     }, function(submitDisabled) {
@@ -50,10 +62,21 @@ angular.module('ambariAdminConsole')
     });
 
     $scope.saveLoginMsg = function(targetUrl) {
-      var method = $scope.motdExists ? 'PUT' : 'POST';
+      var
+        method = $scope.motdExists ? 'PUT' : 'POST',
+        text = "",
+        buttonText = "",
+        lt = /</g,
+        gt = />/g,
+        ap = /'/g,
+        ic = /"/g;
+
+      text = $scope.text.toString().replace(lt, "&lt;").replace(gt, "&gt;").replace(ap, "&#39;").replace(ic, "&#34;");
+      buttonText = $scope.buttonText ? $scope.buttonText.toString().replace(lt, "&lt;").replace(gt, "&gt;").replace(ap, "&#39;").replace(ic, "&#34;") : $scope.buttonText;
+
       var data = {
         'Settings' : {
-          'content' : '{"text":"' + $scope.text + '", "button":"' + $scope.buttonText + '", "status":"' + $scope.status + '"}',
+          'content' : '{"text":"' + text + '", "button":"' + buttonText + '", "status":"' + $scope.status + '"}',
           'name' : 'motd',
           'setting_type' : 'ambari-server'
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/df0b18ca/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 0c67831..2035647 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
@@ -87,9 +87,9 @@ angular.module('ambariAdminConsole')
         'loginActivities':'Login Activities',
         'loginMessage': 'Login Message',
         'loginMessage.placeholder': 'Please enter login message',
-        'buttonText.placeholder': 'Please enter text for the "ok" button',
+        'buttonText.placeholder': 'Please enter button text',
         'homeDirectory': 'Home Directory',
-        'onlySimpleChars': 'Must contain only simple characters.',
+        'notEmpty': 'These field cannot be empty',
         'saveError': 'Save error',
         'message': 'Message',
         'buttonText': 'Button',

http://git-wip-us.apache.org/repos/asf/ambari/blob/df0b18ca/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 96217f5..1374f00 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
@@ -17,7 +17,7 @@
 -->
 
 <br/>
-<div class="login-message-pane" ng-controller="LoginMessageMainCtrl">
+<div class="login-message-pane" data-ng-init="getMOTD()" ng-controller="LoginMessageMainCtrl">
   <form class="form-horizontal" novalidate name="form" autocomplete="off">
     <div class="well">
       <fieldset>
@@ -37,7 +37,6 @@
                  placeholder="{{'common.loginActivities.loginMessage.placeholder' | translate}}"
                  ng-model="text"
                  ng-change="inputChangeEvent()"
-                 ng-pattern="/^([a-zA-Z0-9._\s]+)$/"
                  ng-disabled="!status"
                  autocomplete="off">
             </textarea>
@@ -46,7 +45,7 @@
             </div>
           </div>
         </div>
-        <div class="form-group" ng-class="{'has-error' : (form.login_text.$error.pattern) && form.submitted}">
+        <div class="form-group" ng-class="{'has-error' : (form.button_text.$error.pattern) && form.submitted}">
           <label class="col-sm-2 control-label">{{'common.loginActivities.buttonText' | translate}}</label>
           <div class="col-sm-4">
             <input type="text"
@@ -56,13 +55,13 @@
                    ng-model="buttonText"
                    ng-change="inputChangeEvent()"
                    ng-disabled="!status"
-                   ng-pattern="/^([a-zA-Z0-9._\s]+)$/"
                    maxlength="25"
                    size="25"
+                   required
                    autocomplete="off">
 
-            <div class="alert alert-danger top-margin" ng-show="form.button_text.$error.pattern && form.submitted">
-              {{'common.loginActivities.onlySimpleChars' | translate}}
+            <div class="alert alert-danger top-margin" ng-show="form.button_text.$error.required && form.submitted">
+              {{'common.loginActivities.notEmpty' | translate}}
             </div>
           </div>
         </div>
@@ -73,7 +72,8 @@
             ng-click="saveLoginMsg()">
             {{'common.controls.save' | translate}}
           </button>
-      </div>
+          <a class="btn btn-default pull-right cancel" href ng-click="cancel()">{{'common.controls.cancel' | translate}}</a>
+        </div>
       </fieldset>
     </div>
   </form>

http://git-wip-us.apache.org/repos/asf/ambari/blob/df0b18ca/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index 720ac0b..1537e85 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -361,7 +361,7 @@ App.Router = Em.Router.extend({
     }
 
     var
-      text = response.text ? response.text : "",
+      text = response.text ? response.text.replace(/(\r\n|\n|\r)/gm, '<br>') : "",
       buttonText = response.button ? response.button : Em.I18n.t('ok'),
       status = response.status && response.status == "true" ? true : false,
       self = this;
@@ -373,8 +373,15 @@ App.Router = Em.Router.extend({
         bodyClass: Ember.View.extend({
           template: Ember.Handlebars.compile(text)
         }),
-        primary: buttonText,
+        primary:null,
         secondary: null,
+        footerClass: Ember.View.extend({
+          template: Ember.Handlebars.compile(
+            '<div class="modal-footer">' +
+            '<button class="btn btn-success" {{action onPrimary target="view"}}>' + buttonText + '</button>'+
+            '</div>'
+          )
+        }),
 
         onPrimary: function () {
           self.setClusterData(data, opt, params);