RANGER-632 : Added validation error msg on Ranger UI in service/policy create 
page and also added pause option in bootstrap-notify plugin.

Signed-off-by: Velmurugan Periasamy <[email protected]>


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

Branch: refs/heads/HDP-2.3.2-groupid
Commit: aaf6c4be13f190beb4d1cbe7dc080eb4bf665ec9
Parents: c1304f9
Author: Gautam Borad <[email protected]>
Authored: Wed Sep 16 13:53:50 2015 +0530
Committer: Velmurugan Periasamy <[email protected]>
Committed: Fri Sep 18 01:03:25 2015 -0400

----------------------------------------------------------------------
 .../bootstrap-notify/js/bootstrap-notify.js     | 44 ++++++++++++++++----
 .../src/main/webapp/scripts/utils/XAUtils.js    | 26 +++++++++++-
 .../views/policies/RangerPolicyCreate.js        | 12 ++++--
 .../scripts/views/service/ServiceCreate.js      | 23 +++-------
 security-admin/src/main/webapp/styles/xa.css    |  5 +++
 5 files changed, 80 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/aaf6c4be/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
 
b/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
index e58c6c5..ba309e2 100644
--- 
a/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
+++ 
b/security-admin/src/main/webapp/libs/bower/bootstrap-notify/js/bootstrap-notify.js
@@ -47,13 +47,21 @@
           this.$note.text(this.options.message.text);
       } else
         this.$note.html(this.options.message);
-
+    
+    var style = this.options.type == 'error' ? 'color:#a94442' : 
'color:#3c763d';  
+    
     if(this.options.closable) {
-      var link = $('<a class="close pull-right" href="#">&times;</a>');
+      var link = $('<a class="close pull-right" style="'+style+';" 
href="#">&times;</a>');
       $(link).on('click', $.proxy(onClose, this));
       this.$note.prepend(link);
     }
 
+    if(this.options.pausable) {
+       var pauseLink = $('<a class="pause pull-right pause-play-close" 
style="'+style+';" href="#"><i class="icon-pause"></i></a><a class="play 
pull-right pause-play-close" href="#" style="'+style+';display:none;"><i 
class="icon-play"></i></a>');
+       $(pauseLink).on('click', $.proxy(onPause, this));
+       this.$note.prepend(pauseLink);
+       
+    }
     return this;
   };
 
@@ -64,10 +72,31 @@
     return false;
   };
 
+  var onPause = function() {
+         if(this.$note.find('.pause').is(':visible')){
+                 clearInterval(this.clearNotifyInterval)
+                 this.$note.find('.pause').hide()
+                 this.$note.find('.play').show()
+         }else{
+                 setFadeOut(this)
+                 this.$note.find('.pause').show()
+                 this.$note.find('.play').hide()
+         }
+         return false;
+  };
+  var setFadeOut = function(self){
+         var that = self;
+         self.clearNotifyInterval = setTimeout(function() {
+                 that.$note.fadeOut('slow', $.proxy(that.onClose, that));    
+         }, self.options.fadeOut.delay || 7000);
+  };
+         
   Notification.prototype.show = function () {
-    if(this.options.fadeOut.enabled)
-      this.$note.delay(this.options.fadeOut.delay || 3000).fadeOut('slow', 
$.proxy(onClose, this));
-
+       var that = this;  
+    if(this.options.fadeOut.enabled){
+       setFadeOut(this)
+    }
+//  this.$note.delay(this.options.fadeOut.delay || 3000).fadeOut('slow', 
$.proxy(onClose, this));
     this.$element.append(this.$note);
     this.$note.alert();
   };
@@ -88,10 +117,11 @@
     transition: 'fade',
     fadeOut: {
       enabled: true,
-      delay: 3000
+      delay: 7000
     },
     message: null,
     onClose: function () {},
-    onClosed: function () {}
+    onClosed: function () {},
+    pausable: false
   }
 })(window.jQuery);

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/aaf6c4be/security-admin/src/main/webapp/scripts/utils/XAUtils.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/utils/XAUtils.js 
b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
index 6d84d1c..b8a061f 100644
--- a/security-admin/src/main/webapp/scripts/utils/XAUtils.js
+++ b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
@@ -194,7 +194,8 @@ define(function(require) {
                                        html : html,
                                        text : text
                                },
-                               type : 'info'
+                               type : 'info',
+                               pausable: true
                        };
                }
                $('.top-right').notify(options).show();
@@ -220,7 +221,8 @@ define(function(require) {
                                        html : html,
                                        text : text
                                },
-                               type : 'error'
+                               type : 'error',
+                               pausable: true
                        };
                }
                $('.top-right').notify(options).show();
@@ -246,6 +248,7 @@ define(function(require) {
                                        html : html
                                },
                                type : 'success',
+                               pausable: true
                        };
                }
                $('.top-right').notify(options).show();
@@ -1096,5 +1099,24 @@ define(function(require) {
                })
                return {'userRoleList' : userRoleList };
        };
+       XAUtils.showErrorMsg = function(respMsg){
+               var respArr = respMsg.split(/\([0-9]*\)/);
+               respArr.shift();
+               _.each(respArr, function(str){
+                       var validationMsg = str.split(','), erroCodeMsg = '';
+                       //get code from string 
+                       if(!_.isUndefined(validationMsg[0]) && 
validationMsg[0].indexOf("error code") != -1){
+                               var tmp = validationMsg[0].split('error code');
+                               var code = tmp[ tmp.length - 1 ];
+                               
+                               erroCodeMsg = 'Error Code : '+ 
code.match(/\d/g).join('');
+                               }
+                       var reason = str.lastIndexOf("reason") != -1 ? 
(str.substring(str.lastIndexOf("reason")+7, str.indexOf("field[")-3 ))
+                                       : str;
+                       var erroMsg = erroCodeMsg 
+"<br/>"+XAUtils.capitaliseFirstLetter(reason);
+                       return XAUtils.notifyError('Error', erroMsg);
+               });
+       };
+       
        return XAUtils;
 });

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/aaf6c4be/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js 
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
index 7370ee8..b07f9a2 100644
--- 
a/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
+++ 
b/security-admin/src/main/webapp/scripts/views/policies/RangerPolicyCreate.js
@@ -207,10 +207,14 @@ define(function(require){
                                        
App.appRouter.navigate("#!/service/"+that.rangerService.id+"/policies",{trigger:
 true});
                                        console.log("success");
                                },
-                               error: function (model, response, options) {
-                                           XAUtil.blockUI('unblock');
-                                               XAUtil.notifyError('Error', 
'Error creating Policy!');
-                                           console.log("error");
+                               error : function(model, response, options) {
+                                       XAUtil.blockUI('unblock');
+                                       var msg = that.editPolicy ? 'Error 
updating policy.': 'Error creating policy.';
+                                       if (response && response.responseJSON 
&& response.responseJSON.msgDesc) {
+                                               
XAUtil.showErrorMsg(response.responseJSON.msgDesc);
+                                       } else {
+                                               XAUtil.notifyError('Error', 
msg);
+                                       }
                                }
                        });
                },

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/aaf6c4be/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js 
b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
index 01141b6..239b61e 100644
--- a/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
+++ b/security-admin/src/main/webapp/scripts/views/service/ServiceCreate.js
@@ -164,23 +164,12 @@ define(function(require){
                                },
                                error: function (model, response, options) {
                                        XAUtil.blockUI('unblock');
-                                       if ( response && response.responseJSON 
&& response.responseJSON.msgDesc){
-                                               
if(response.responseJSON.msgDesc == "serverMsg.fsDefaultNameValidationError"){
-                                                       
that.form.fields.fsDefaultName.setError(localization.tt(response.responseJSON.msgDesc));
-                                                       
XAUtil.scrollToField(that.form.fields.fsDefaultName.$el);
-                                               }else 
if(response.responseJSON.msgDesc == "Repository Name already exists"){
-                                                       
response.responseJSON.msgDesc = "serverMsg.repositoryNameAlreadyExistsError";
-                                                       
that.form.fields.name.setError(localization.tt(response.responseJSON.msgDesc));
-                                                       
XAUtil.scrollToField(that.form.fields.name.$el);
-                                               }else 
if(response.responseJSON.msgDesc == "XUser already exists"){
-                                                       
response.responseJSON.msgDesc = "serverMsg.userAlreadyExistsError";
-                                                       
that.form.fields.userName.setError(localization.tt(response.responseJSON.msgDesc));
-                                                       
XAUtil.scrollToField(that.form.fields.userName.$el);
-                                               }else
-                                                       
XAUtil.notifyError('Error', response.responseJSON.msgDesc);
-                                       }else
-                                               XAUtil.notifyError('Error', 
'Error creating Service!');
-                                       console.log("error");
+                                       var msg = that.editService ? 'Error 
updating Service.': 'Error creating Service.';
+                                       if (response && response.responseJSON 
&& response.responseJSON.msgDesc) {
+                                               
XAUtil.showErrorMsg(response.responseJSON.msgDesc);
+                                       } else {
+                                               XAUtil.notifyError('Error', 
msg);
+                                       }
                                }
                        });
                },

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/aaf6c4be/security-admin/src/main/webapp/styles/xa.css
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/styles/xa.css 
b/security-admin/src/main/webapp/styles/xa.css
index ceb1f53..f0c7530 100644
--- a/security-admin/src/main/webapp/styles/xa.css
+++ b/security-admin/src/main/webapp/styles/xa.css
@@ -1838,4 +1838,9 @@ td.select-row-cell {
 
 #r_topNav .dropdown-menu {
        margin:0;
+}
+.pause-play-close{
+       margin-left: -5px;
+    margin-top: -2px;
+    font-size: 11px;
 }
\ No newline at end of file

Reply via email to