ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject git commit: AMBARI-7711 Admin View: UX for setting users/groups/perms is vague and should prompt unsaved. (Levgen Gorbachev via ababiichuk)
Date Fri, 10 Oct 2014 13:52:32 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 caf42aaa2 -> 47e5d20ca


AMBARI-7711 Admin View: UX for setting users/groups/perms is vague and should prompt unsaved.
(Levgen Gorbachev via ababiichuk)


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

Branch: refs/heads/branch-1.7.0
Commit: 47e5d20cae0d4b06ce5b0dd8477046d2e990dbad
Parents: caf42aa
Author: aBabiichuk <ababiichuk@cybervisiontech.com>
Authored: Fri Oct 10 16:52:28 2014 +0300
Committer: aBabiichuk <ababiichuk@cybervisiontech.com>
Committed: Fri Oct 10 16:52:28 2014 +0300

----------------------------------------------------------------------
 .../scripts/controllers/users/UsersShowCtrl.js  |  3 +-
 .../app/scripts/directives/editableList.js      | 46 +++++++++-
 .../ui/admin-web/app/scripts/routes.js          |  9 +-
 .../ui/admin-web/app/views/leftNavbar.html      |  2 +-
 .../main/resources/ui/admin-web/package.json    | 22 ++---
 .../resources/ui/admin-web/test/karma.conf.js   | 16 +++-
 .../test/unit/directives/editablelist_test.js   | 90 ++++++++++++++++++++
 7 files changed, 167 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
index 6451387..5fb2fc2 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersShowCtrl.js
@@ -44,7 +44,6 @@ angular.module('ambariAdminConsole')
   }, function(newValue) {
     if(newValue){
       if( !angular.equals(newValue, $scope.user.groups) ){
-        console.log('Update!');
         $scope.updateGroups();
       }
         
@@ -189,4 +188,4 @@ angular.module('ambariAdminConsole')
     });
   }
   loadPrivileges();  
-}]);
\ No newline at end of file
+}]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/directives/editableList.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/directives/editableList.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/directives/editableList.js
index f157d70..5f96f90 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/directives/editableList.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/directives/editableList.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.directive('editableList', ['$q', '$document', function($q, $document) {
+.directive('editableList', ['$q', '$document', '$location', function($q, $document, $location)
{
   return {
     restrict: 'E',
     templateUrl: 'views/directives/editableList.html',
@@ -84,7 +84,7 @@ angular.module('ambariAdminConsole')
         }
       });
     },
-    controller: ['$scope', '$injector', function($scope, $injector) {
+    controller: ['$scope', '$injector', '$modal', function($scope, $injector, $modal) {
       var $resource = $injector.get($scope.resourceType);
 
       $scope.identity = angular.identity; // Sorting function
@@ -160,10 +160,15 @@ angular.module('ambariAdminConsole')
         event.stopPropagation();
       };
       $scope.save = function(event) {
+        if( $scope.input ){
+          $scope.addItem($scope.input);
+        }
         $scope.itemsSource = $scope.items;
         $scope.editMode = false;
         $scope.input = '';
-        event.stopPropagation();
+        if(event){
+          event.stopPropagation();
+        }
       };
 
 
@@ -191,6 +196,41 @@ angular.module('ambariAdminConsole')
       $scope.removeFromItems = function(item) {
         $scope.items.splice( $scope.items.indexOf(item), 1);
       };
+
+      $scope.$on('$locationChangeStart', function(event, targetUrl) {
+        targetUrl = targetUrl.split('#').pop();
+        if( $scope.input ){
+          $scope.addItem($scope.input);
+        }
+        if( $scope.editMode && !angular.equals($scope.items, $scope.itemsSource)){
+          var modalInstance = $modal.open({
+            template: '<div class="modal-header"><h3 class="modal-title">Warning</h3></div><div
class="modal-body">You have unsaved changes. Save changes or discard?</div><div
class="modal-footer"><div class="btn btn-default" ng-click="cancel()">Cancel</div><div
class="btn btn-warning" ng-click="discard()">Discard</div><div class="btn btn-primary"
ng-click="save()">Save</div></div>',
+            controller: ['$scope', '$modalInstance', function($scope, $modalInstance) {
+              $scope.save = function() {
+                $modalInstance.close('save');
+              };
+              $scope.discard = function() {
+                $modalInstance.close('discard');
+              };
+              $scope.cancel = function() {
+                $modalInstance.close('cancel');
+              };
+            }]
+          });
+          modalInstance.result.then(function(action) {
+            switch(action){
+              case 'save':
+                $scope.save();
+                break;
+              case 'discard':
+                $scope.editMode = false;
+                $location.path(targetUrl);
+                break;
+            }
+          });
+          event.preventDefault();
+        }
+      });
     }]
   };
 }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
index def09b1..e47c97d 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/routes.js
@@ -86,6 +86,13 @@ angular.module('ambariAdminConsole')
       templateUrl: 'views/clusters/manageAccess.html',
       controller: 'ClustersManageAccessCtrl'
     }
+  },
+  dashboard:{
+    url: '/dashboard',
+    controller: ['$window', function($window) {
+      $window.location.href = '/#/main/dashboard';
+    }],
+    template: ''
   }
 })
 .config(['$routeProvider', '$locationProvider', 'ROUTES', function($routeProvider, $locationProvider,
ROUTES) {
@@ -101,4 +108,4 @@ angular.module('ambariAdminConsole')
 .run(['$rootScope', 'ROUTES', function($rootScope, ROUTES) {
   // Make routes available in every template and controller
   $rootScope.ROUTES = ROUTES;
-}]);
\ No newline at end of file
+}]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/app/views/leftNavbar.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/leftNavbar.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/leftNavbar.html
index e047a8d..af09f57 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/leftNavbar.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/leftNavbar.html
@@ -57,7 +57,7 @@
           <li ng-class="{active: isActive('clusters.manageAccess')}">
             <a href="#/clusters/{{cluster.Clusters.cluster_name}}/manageAccess" class="permissions">Permissions</a>
           </li>
-          <li><a href="/#/main/dashboard" class="gotodashboard">Go to Dashboard</a></li>
+          <li><a href="#/dashboard"  class="gotodashboard">Go to Dashboard</a></li>
         </ul>
         <span class="cluster-installation-progress-label" ng-show="cluster.Clusters.provisioning_state
== 'INIT'">Cluster creation in progress...</span>
       </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/package.json
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/package.json b/ambari-admin/src/main/resources/ui/admin-web/package.json
index d7de8fc..2f49d00 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/package.json
+++ b/ambari-admin/src/main/resources/ui/admin-web/package.json
@@ -1,18 +1,10 @@
 {
   "name": "adminconsole",
   "version": "0.0.0",
-  "dependencies": {
-  },
+  "dependencies": {},
   "devDependencies": {
-    "karma": "0.12.16",
-    "karma-phantomjs-launcher": "0.1",
-    "karma-chrome-launcher": "0.1.4",
-    "karma-jasmine": "0.1.5",
-    "phantomjs": "1.9.10",
-    "protractor": "1.0.0",
-    "http-server": "0.6.1",
     "bower": "1.3.8",
-    "gulp": "3.6.0",
+    "gulp": "^3.8.8",
     "gulp-autoprefixer": "0.0.7",
     "gulp-bower-files": "0.2.1",
     "gulp-cache": "0.1.1",
@@ -20,10 +12,18 @@
     "gulp-filter": "0.4.1",
     "gulp-flatten": "0.0.2",
     "gulp-load-plugins": "0.5.0",
+    "gulp-plumber": "0.6.6",
     "gulp-size": "0.3.0",
     "gulp-uglify": "0.2.1",
     "gulp-useref": "0.4.2",
-    "gulp-plumber": "0.6.6"
+    "http-server": "0.6.1",
+    "karma": "0.12.16",
+    "karma-chrome-launcher": "0.1.4",
+    "karma-jasmine": "0.1.5",
+    "karma-ng-html2js-preprocessor": "^0.1.0",
+    "karma-phantomjs-launcher": "0.1",
+    "phantomjs": "1.9.10",
+    "protractor": "1.0.0"
   },
   "scripts": {
     "prestart": "npm install",

http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js b/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
index 1b815e5..bb514cd 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/karma.conf.js
@@ -22,6 +22,7 @@ module.exports = function(config){
     basePath : '../',
 
     files : [
+      'app/bower_components/jquery/dist/jquery.js',
       'app/bower_components/angular/angular.js',
       'app/bower_components/angular-animate/angular-animate.js',
       'app/bower_components/angular-bootstrap/ui-bootstrap.js',
@@ -35,7 +36,8 @@ module.exports = function(config){
       'app/bower_components/sinon/lib/sinon.js',
       'app/bower_components/angular-mocks/angular-mocks.js',
       'app/scripts/**/*.js',
-      'test/unit/**/*.js'
+      'test/unit/**/*.js',
+      'app/views/directives/*.html'
     ],
 
     autoWatch : true,
@@ -46,13 +48,21 @@ module.exports = function(config){
 
     plugins : [
             'karma-jasmine',
-            'karma-phantomjs-launcher'
+            'karma-phantomjs-launcher',
+            'karma-ng-html2js-preprocessor'
             ],
 
     junitReporter : {
       outputFile: 'test_out/unit.xml',
       suite: 'unit'
+    },
+
+    preprocessors: {
+      'app/views/directives/*.html': ['ng-html2js']
+    },
+    ngHtml2JsPreprocessor: {
+      'stripPrefix': 'app/'
     }
 
   });
-};
\ No newline at end of file
+};

http://git-wip-us.apache.org/repos/asf/ambari/blob/47e5d20c/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/editablelist_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/editablelist_test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/editablelist_test.js
new file mode 100644
index 0000000..4b94582
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/directives/editablelist_test.js
@@ -0,0 +1,90 @@
+/**
+ * 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.
+ */
+
+describe('#Editablelist directive', function () {
+
+  describe('Editing', function () {
+    var scope, element;
+    var $location, $modal;
+
+    beforeEach(module('ambariAdminConsole'));
+    beforeEach(module('views/directives/editableList.html'));
+
+    beforeEach(inject(function($rootScope, $compile, _$location_, _$modal_) {
+      $location = _$location_;
+      $modal = _$modal_;
+
+      spyOn($modal, 'open').andReturn({
+        result:{
+          then: function() {
+          }
+        }
+      });
+
+      scope = $rootScope.$new();
+
+      element = '<editable-list items-source="permissionsEdit.TestPermission.USER" resource-type="User"
editable="true"></editable-list>';
+
+      scope.permissionsEdit = {
+         'TestPermission': {
+          'USER': ['user1', 'user2']
+         }
+      };
+
+      element = $compile(element)(scope);
+      scope.$digest();
+    }));
+
+    afterEach(function() {
+      element.remove();
+    });
+    
+
+    it('Updates permissions after save', function () {
+      var isoScope = element.isolateScope();
+      isoScope.items.push('user3');
+      
+      expect(scope.permissionsEdit.TestPermission.USER).toEqual(['user1', 'user2']);
+      
+      isoScope.save();
+      scope.$digest();
+      
+      expect(scope.permissionsEdit.TestPermission.USER).toEqual(['user1', 'user2', 'user3']);
+    });
+
+    it('Show dialog window if user trying to leave page without save', function() {
+      var isoScope = element.isolateScope();
+      isoScope.items.push('user3');
+      isoScope.editMode = true;
+      
+      expect(isoScope.editMode).toBe(true);
+      scope.$broadcast('$locationChangeStart', 'some#url');
+      expect($modal.open).toHaveBeenCalled();
+    });
+
+    it('Saves current user in editing window if user click "save"', function() {
+      var isoScope = element.isolateScope();
+      isoScope.editMode = true;
+      isoScope.input = 'user3';
+      isoScope.save();
+      scope.$digest();
+
+      expect(scope.permissionsEdit.TestPermission.USER).toEqual(['user1', 'user2', 'user3']);
+    });
+  });
+});


Mime
View raw message