ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject git commit: AMBARI-7786 Admin View: Show confirmation dialog when navigate from User/Group edit page. (Levgen Gorbachevi via ababiichuk)
Date Wed, 15 Oct 2014 13:12:15 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 435c1cc62 -> 862d038f6


AMBARI-7786 Admin View: Show confirmation dialog when navigate from User/Group edit page.
(Levgen Gorbachevi via ababiichuk)


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

Branch: refs/heads/branch-1.7.0
Commit: 862d038f6a786045a52803c6c7c8b95a03bf41a7
Parents: 435c1cc
Author: aBabiichuk <ababiichuk@cybervisiontech.com>
Authored: Wed Oct 15 15:17:07 2014 +0300
Committer: aBabiichuk <ababiichuk@cybervisiontech.com>
Committed: Wed Oct 15 16:11:25 2014 +0300

----------------------------------------------------------------------
 .../main/resources/ui/admin-web/app/index.html  |  1 +
 .../ambariViews/CreateViewInstanceCtrl.js       | 37 ++++++++++++-
 .../controllers/ambariViews/ViewsEditCtrl.js    | 56 ++++++++++++++++----
 .../controllers/groups/GroupsCreateCtrl.js      | 32 ++++++++++-
 .../controllers/users/UsersCreateCtrl.js        | 35 ++++++++++--
 .../app/scripts/services/UnsavedDialog.js       | 41 ++++++++++++++
 .../admin-web/app/views/ambariViews/create.html |  2 +-
 .../ui/admin-web/app/views/groups/create.html   |  4 +-
 .../ui/admin-web/app/views/users/create.html    |  4 +-
 .../test/unit/services/UnsavedDialog__test.js   | 41 ++++++++++++++
 10 files changed, 232 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/index.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/index.html b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
index f0f3f18..8564c2a 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/index.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
@@ -150,6 +150,7 @@
     <script src="scripts/services/ConfirmationModal.js"></script>
     <script src="scripts/services/Auth.js"></script>
     <script src="scripts/services/GetDifference.js"></script>
+    <script src="scripts/services/UnsavedDialog.js"></script>
     <!-- endbuild -->
 </body>
 </html>

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
index a9c3268..76b4a7f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
@@ -18,8 +18,9 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('CreateViewInstanceCtrl',['$scope', 'View', 'Alert', 'Auth', '$routeParams',
'$location', function($scope, View, Alert, Auth, $routeParams, $location) {
+.controller('CreateViewInstanceCtrl',['$scope', 'View', 'Alert', 'Auth', '$routeParams',
'$location', 'UnsavedDialog', function($scope, View, Alert, Auth, $routeParams, $location,
UnsavedDialog) {
   $scope.form = {};
+  var targetUrl = '';
 
   function loadMeta(){
     View.getMeta($routeParams.viewId, $scope.version).then(function(data) {
@@ -78,11 +79,43 @@ angular.module('ambariAdminConsole')
       View.createInstance($scope.instance)
         .then(function(data) {
           Alert.success('Created View Instance ' + $scope.instance.instance_name);
-          $location.path('/views/' + $scope.instance.view_name + '/versions/' + $scope.instance.version
+ '/instances/' + $scope.instance.instance_name + '/edit');
+          $scope.form.instanceCreateForm.$setPristine();
+          if( targetUrl ){
+            $location.path(targetUrl);
+          } else {
+            $location.path('/views/' + $scope.instance.view_name + '/versions/' + $scope.instance.version
+ '/instances/' + $scope.instance.instance_name + '/edit');
+          }
         })
         .catch(function(data) {
           Alert.error('Cannot create instance', data.data.message);
         });
     }
   };
+
+  $scope.cancel = function() {
+    $scope.form.instanceCreateForm.$setPristine();
+    $location.path('/views');
+  };
+
+  $scope.$on('$locationChangeStart', function(event, __targetUrl) {
+    if( $scope.form.instanceCreateForm.$dirty ){
+      UnsavedDialog().then(function(action) {
+        targetUrl = __targetUrl.split('#').pop();
+        switch(action){
+          case 'save':
+            $scope.save();
+            break;
+          case 'discard':
+            $scope.form.instanceCreateForm.$setPristine();
+            $location.path(targetUrl);
+            break;
+          case 'cancel':
+            targetUrl = '';
+            break;
+        }
+      });
+      event.preventDefault();
+    }
+  });
+
 }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js
index 1ff860a..b179a70 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/ViewsEditCtrl.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('ViewsEditCtrl', ['$scope', '$routeParams' , 'View', 'Alert', 'PermissionLoader',
'PermissionSaver', 'ConfirmationModal', '$location', function($scope, $routeParams, View,
Alert, PermissionLoader, PermissionSaver, ConfirmationModal, $location) {
+.controller('ViewsEditCtrl', ['$scope', '$routeParams' , 'View', 'Alert', 'PermissionLoader',
'PermissionSaver', 'ConfirmationModal', '$location', 'UnsavedDialog', function($scope, $routeParams,
View, Alert, PermissionLoader, PermissionSaver, ConfirmationModal, $location, UnsavedDialog)
{
   $scope.identity = angular.identity;
   $scope.isConfigurationEmpty = true;
   function reloadViewInfo(){
@@ -79,9 +79,9 @@ angular.module('ambariAdminConsole')
     $scope.editSettingsDisabled = !$scope.editSettingsDisabled;
   };
 
-  $scope.saveSettings = function() {
+  $scope.saveSettings = function(callback) {
     if( $scope.settingsForm.$valid ){
-      View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId,
{
+      return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId,
{
         'ViewInstanceInfo':{
           'visible': $scope.settings.visible,
           'label': $scope.settings.label,
@@ -89,8 +89,13 @@ angular.module('ambariAdminConsole')
         }
       })
       .success(function() {
-        reloadViewInfo();
-        $scope.editSettingsDisabled = true;
+        if( callback ){
+          callback();
+        } else {
+          reloadViewInfo();
+          $scope.editSettingsDisabled = true;
+          $scope.settingsForm.$setPristine();
+        }
       })
       .catch(function(data) {
         Alert.error('Cannot save settings', data.data.message);
@@ -104,6 +109,7 @@ angular.module('ambariAdminConsole')
       'description': $scope.instance.ViewInstanceInfo.description
     };
     $scope.editSettingsDisabled = true;
+    $scope.settingsForm.$setPristine();
   };
 
   
@@ -113,13 +119,14 @@ angular.module('ambariAdminConsole')
   }
   $scope.saveConfiguration = function() {
     if( $scope.propertiesForm.$valid ){
-      View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId,
{
+      return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId,
{
         'ViewInstanceInfo':{
           'properties': $scope.configuration
         }
       })
       .success(function() {
         $scope.editConfigurationDisabled = true;
+        $scope.propertiesForm.$setPristine();
       })
       .catch(function(data) {
         Alert.error('Cannot save properties', data.data.message);
@@ -129,6 +136,7 @@ angular.module('ambariAdminConsole')
   $scope.cancelConfiguration = function() {
     $scope.configuration = angular.copy($scope.instance.ViewInstanceInfo.properties);
     $scope.editConfigurationDisabled = true;
+    $scope.propertiesForm.$setPristine();
   };
 
   // Permissions edit
@@ -139,12 +147,13 @@ angular.module('ambariAdminConsole')
   };
 
   $scope.savePermissions = function() {
-    PermissionSaver.saveViewPermissions(
+    $scope.editPermissionDisabled = true;
+    return PermissionSaver.saveViewPermissions(
       $scope.permissionsEdit,
       {
         view_name: $routeParams.viewId,
         version: $routeParams.version,
-        instance_name: $routeParams.instanceId,
+        instance_name: $routeParams.instanceId
       }
     )
     .then(reloadViewPrivileges)
@@ -152,7 +161,6 @@ angular.module('ambariAdminConsole')
       reloadViewPrivileges();
       Alert.error('Cannot save permissions', data.data.message);
     });
-    $scope.editPermissionDisabled = true;
   };
 
   $scope.$watch(function() {
@@ -174,4 +182,34 @@ angular.module('ambariAdminConsole')
       });
     });
   };
+
+  $scope.$on('$locationChangeStart', function(event, targetUrl) {
+    if( $scope.settingsForm.$dirty || $scope.propertiesForm.$dirty){
+      UnsavedDialog().then(function(action) {
+        targetUrl = targetUrl.split('#').pop();
+        switch(action){
+          case 'save':
+            if($scope.settingsForm.$valid &&  $scope.propertiesForm.$valid ){
+              $scope.saveSettings(function() {
+                $scope.saveConfiguration().then(function() {
+                  $scope.propertiesForm.$setPristine();
+                  $scope.settingsForm.$setPristine();
+                  $location.path(targetUrl);
+                });
+              });
+            }
+            break;
+          case 'discard':
+            $scope.propertiesForm.$setPristine();
+            $scope.settingsForm.$setPristine();
+            $location.path(targetUrl);
+            break;
+          case 'cancel':
+            targetUrl = '';
+            break;
+        }
+      });
+      event.preventDefault();
+    }
+  });
 }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js
index 7ee02c0..1768bff 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/groups/GroupsCreateCtrl.js
@@ -18,19 +18,47 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('GroupsCreateCtrl',['$scope', 'Group', '$location', 'Alert', function($scope,
Group, $location, Alert) {
+.controller('GroupsCreateCtrl',['$scope', 'Group', '$location', 'Alert', 'UnsavedDialog',
function($scope, Group, $location, Alert, UnsavedDialog) {
   $scope.group = new Group();
+  var targetUrl = '/groups';
 
   $scope.createGroup = function() {
     $scope.form.submitted = true;
     if ($scope.form.$valid){
       $scope.group.save().then(function() {
         Alert.success('Created group <a href="#/groups/' + $scope.group.group_name + '/edit">'
+ $scope.group.group_name + '</a>');
-        $location.path('/groups');
+        $scope.form.$setPristine();
+        $location.path(targetUrl);
       })
       .catch(function(data) {
         Alert.error('Group creation error', data.data.message);
       });
     }
   };
+
+  $scope.cancel = function() {
+    $scope.form.$setPristine();
+    $location.path('/groups');
+  };
+
+  $scope.$on('$locationChangeStart', function(event, __targetUrl) {
+    if( $scope.form.$dirty ){
+      UnsavedDialog().then(function(action) {
+        targetUrl = __targetUrl.split('#').pop();
+        switch(action){
+          case 'save':
+            $scope.createGroup();
+            break;
+          case 'discard':
+            $scope.form.$setPristine();
+            $location.path(targetUrl);
+            break;
+          case 'cancel':
+            targetUrl = '/groups';
+            break;
+        }
+      });
+      event.preventDefault();
+    }
+  });
 }]);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersCreateCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersCreateCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersCreateCtrl.js
index e91d4b7..3fc324a 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersCreateCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/users/UsersCreateCtrl.js
@@ -18,10 +18,11 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('UsersCreateCtrl',['$scope', '$routeParams', 'User', '$location', 'Alert', function($scope,
$routeParams, User, $location, Alert) {
+.controller('UsersCreateCtrl',['$scope', '$routeParams', 'User', '$location', 'Alert', 'UnsavedDialog',
function($scope, $routeParams, User, $location, Alert, UnsavedDialog) {
   $scope.user = {
     active: true
   };
+  var targetUrl = '/users';
 
   $scope.createUser = function() {
     $scope.form.submitted = true;
@@ -33,10 +34,38 @@ angular.module('ambariAdminConsole')
         'Users/admin': !!$scope.user.admin
       }).then(function() {
         Alert.success('Created user <a href="#/users/' + $scope.user.user_name + '">'
+ $scope.user.user_name + "</a>");
-        $location.path('/users');
-      }).catch(function(data) {;
+        $scope.form.$setPristine();
+        $location.path(targetUrl);
+      }).catch(function(data) {
         Alert.error('User creation error', data.data.message);
       });
     }
   };
+
+  $scope.cancel = function() {
+    $scope.form.$setPristine();
+    $location.path('/users');
+  };
+
+  $scope.$on('$locationChangeStart', function(event, __targetUrl) {
+        
+    if( $scope.form.$dirty ){
+      UnsavedDialog().then(function(action) {
+        targetUrl = __targetUrl.split('#').pop();
+        switch(action){
+          case 'save':
+            $scope.createUser();
+            break;
+          case 'discard':
+            $scope.form.$setPristine();
+            $location.path(targetUrl);
+            break;
+          case 'cancel':
+          targetUrl = '/users';
+            break;
+        }
+      });
+      event.preventDefault();
+    }
+  });
 }]);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UnsavedDialog.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UnsavedDialog.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UnsavedDialog.js
new file mode 100644
index 0000000..63ad9b2
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/UnsavedDialog.js
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+'use strict';
+
+angular.module('ambariAdminConsole')
+.service('UnsavedDialog', ['$modal', function($modal) {
+
+	return function(){
+		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');
+        };
+      }]
+    });
+    
+    return modalInstance.result;
+	};
+}]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
index eafd7d0..411e3cc 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
@@ -116,7 +116,7 @@
   
   <div class="col-sm-12 ">
     <button class="btn btn-primary pull-right left-margin save-button" ng-click="save()"
type="submit">Save</button>
-    <a href="#/views/" class="btn btn-default pull-right cancel-button">Cancel</a>
+    <a href ng-click="cancel()" class="btn btn-default pull-right cancel-button">Cancel</a>
   </div>
     
 </form>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/views/groups/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/groups/create.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/groups/create.html
index 9e3bc47..f61aadfe 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/groups/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/groups/create.html
@@ -36,8 +36,8 @@
   <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-click="createGroup()">Save</button>
-      <a href="#/groups/" class="btn btn-default pull-right cancel-button">Cancel</a>
+      <a href ng-click="cancel()" class="btn btn-default pull-right cancel-button">Cancel</a>
     </div>
   </div>
       
-</form>
\ No newline at end of file
+</form>

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
index 912a26d..3d1cfc5 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/users/create.html
@@ -67,8 +67,8 @@
   <div class="form-group">
     <div class="col-sm-offset-2 col-sm-10">
       <button class="btn btn-primary pull-right left-margin saveuser" ng-click="createUser()">Save</button>
-      <a class="btn btn-default pull-right cancel" href="#/users">Cancel</a>
+      <a class="btn btn-default pull-right cancel" href ng-click="cancel()">Cancel</a>
     </div>
   </div>
       
-</form>
\ No newline at end of file
+</form>

http://git-wip-us.apache.org/repos/asf/ambari/blob/862d038f/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/UnsavedDialog__test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/UnsavedDialog__test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/UnsavedDialog__test.js
new file mode 100644
index 0000000..dfd777a
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/UnsavedDialog__test.js
@@ -0,0 +1,41 @@
+/**
+ * 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('UnsavedDialog Service', function () {
+  var UnsavedDialog, $modal;
+  
+  beforeEach(module('ambariAdminConsole', function($provide){
+  }));
+  
+  beforeEach(inject(function (_UnsavedDialog_, _$modal_) {
+    UnsavedDialog = _UnsavedDialog_;
+    $modal = _$modal_;
+
+    spyOn($modal, 'open').andReturn({
+      result: {
+        then: function() {
+        }
+      }
+    });
+  }));
+
+  it('should open modal window', function () {
+    UnsavedDialog();
+    expect($modal.open).toHaveBeenCalled();
+  });
+});


Mime
View raw message