From 4d60ee139e50666253f7b0ccb469e28ba8c6fcaf Mon Sep 17 00:00:00 2001 From: ykohata Date: Fri, 27 Nov 2015 18:32:22 +0900 Subject: [PATCH] - Deactivate account [COR-455] - Change user account status [COR-444] --- src/app/users/status-update-dialog.html | 35 ++++++++ src/app/users/users.controller.js | 110 ++++++++++++++++++----- src/app/users/users.html | 16 ++-- src/app/users/users.service.js | 43 ++++++++- src/components/alert/alert.controller.js | 10 ++- 5 files changed, 182 insertions(+), 32 deletions(-) create mode 100644 src/app/users/status-update-dialog.html diff --git a/src/app/users/status-update-dialog.html b/src/app/users/status-update-dialog.html new file mode 100644 index 0000000..f2ae500 --- /dev/null +++ b/src/app/users/status-update-dialog.html @@ -0,0 +1,35 @@ +
+ + + +
+ +
+
diff --git a/src/app/users/users.controller.js b/src/app/users/users.controller.js index e845055..6ffc839 100644 --- a/src/app/users/users.controller.js +++ b/src/app/users/users.controller.js @@ -6,6 +6,13 @@ module.controller('users.UserSearchController', [ '$scope', '$rootScope', '$timeout', '$state', '$modal', 'AuthService','UserService', function ($scope, $rootScope, $timeout, $state, $modal, $authService, $userService) { + // footable + angular.element(document).ready(function () { + $('.footable').footable({ + addRowToggle: true + }); + }); + // auth $scope.authorized = function() { return $authService.isLoggedIn(); @@ -29,6 +36,8 @@ module.controller('users.UserSearchController', [ $scope.search = function() { + $scope.$broadcast('alert.ClearAll', {}); + var handle = $scope.formSearch.handle, email = $scope.formSearch.email, active = $scope.formSearch.getActive(), @@ -61,9 +70,12 @@ module.controller('users.UserSearchController', [ function(users) { $scope.users = users; $scope.formSearch.setLoading(false); + $timeout(function(){ + $('.footable').trigger('footable_redraw'); + }, 100); }, function(error) { - $scope.$broadcast('AlertIssued', {type:'danger', message:error.error}); + $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); $scope.formSearch.setLoading(false); } ); @@ -76,10 +88,22 @@ module.controller('users.UserSearchController', [ return isoDateText && isoDateText.replace("T"," ").replace(".000Z",""); }; + var statusLabels = { + 'A': 'Active', + 'U': 'Unverified', + '4': 'Deactivated(User request)', + '5': 'Deactivated(Duplicate account)', + '6': 'Deactivated(Cheating account)' + }; + $scope.statusLabel = function(status) { + return statusLabels[status] || 'Unknown'; + }; + $scope.activate = function(index) { + $scope.$broadcast('alert.ClearAll', {}); var user = $scope.users[index]; if(!user.credential || !user.credential.activationCode) { - $scope.$broadcast('AlertIssued', + $scope.$broadcast('alert.AlertIssued', {type:'danger', message:'The user \'' + user.handle + '\' is invalid. Unable to activate it.'}); return; }; @@ -88,34 +112,40 @@ module.controller('users.UserSearchController', [ $userService.activate(user.credential.activationCode).then( function(responseUser) { user.active = responseUser.active; + user.status = responseUser.status; $scope.formSearch.setLoading(false); }, function(error) { - $scope.$broadcast('AlertIssued', {type:'danger', message:error.error}); + $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); $scope.formSearch.setLoading(false); } ); } }; - $scope.deactivate = function(index) { + $scope.openDeactivateDialog = function(index) { var user = $scope.users[index]; - if(window.confirm('Are you sure you want to deactivate user \'' + user.handle + '\'?')) { - // dummy - user.active = false; - } + //if(window.confirm('Are you sure you want to deactivate user \'' + user.handle + '\'?')) { + var modalInstance = $modal.open({ + size: 'sm', + templateUrl: 'app/users/status-update-dialog.html', + controller: 'users.StatusUpdateDialogController', + resolve: { + user: function(){ return $scope.users[index]; } + } + }); }; - $scope.openDialog = function(index) { - var modalInstance = $modal.open({ - size: 'sm', - templateUrl: 'app/users/user-edit-dialog.html', - controller: 'users.UserEditDialogController', - resolve: { - user: function(){ return $scope.users[index]; } - } - }); + $scope.openEditDialog = function(index) { + var modalInstance = $modal.open({ + size: 'sm', + templateUrl: 'app/users/user-edit-dialog.html', + controller: 'users.UserEditDialogController', + resolve: { + user: function(){ return $scope.users[index]; } + } + }); }; } ]); @@ -142,6 +172,7 @@ module.controller('users.UserEditDialogController', [ }; $scope.save = function() { + $scope.$broadcast('alert.ClearAll', {}); if(window.confirm('Are you sure you want to save changes?')) { $scope.form.setLoading(true); // dummy @@ -155,11 +186,48 @@ module.controller('users.UserEditDialogController', [ }, 1200); } } + } +]); - $scope.addAlert = function(index) { - //$scope.alerts.push({message: 'Another alert!'}); - $scope.$broadcast('AlertIssued', {type:'danger', message:'TEST!!!'}); - } +module.controller('users.StatusUpdateDialogController', [ + '$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'user', + function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, user) { + + $scope.form = { + status : user.status, + comment : null, + isLoading : false, + setLoading: function(loading) { + this.isLoading = loading; + } + }; + $scope.cancel = function() { + $modalInstance.close(); + }; + + $scope.save = function() { + $scope.$broadcast('alert.ClearAll', {}); + if(user.status === $scope.form.status) { + $scope.$broadcast('alert.AlertIssued', {type:'danger', message:'Status not changed.'}); + return; + } + if(window.confirm('Are you sure you want to save changes?')) { + $scope.form.setLoading(true); + $userService.updateStatus(user.id, $scope.form.status, $scope.form.comment).then( + function(responseUser) { + user.active = responseUser.active; + user.status = responseUser.status; + $scope.form.setLoading(false); + $modalInstance.close(); + }, + function(error) { + $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); + $scope.form.setLoading(false); + } + ); + + } + } } ]); diff --git a/src/app/users/users.html b/src/app/users/users.html index 96f4997..6a5febd 100644 --- a/src/app/users/users.html +++ b/src/app/users/users.html @@ -69,11 +69,14 @@

Members

- + - - + + + + + @@ -84,19 +87,22 @@

Members

+ + + diff --git a/src/app/users/users.service.js b/src/app/users/users.service.js index 66ecabe..bccbf54 100644 --- a/src/app/users/users.service.js +++ b/src/app/users/users.service.js @@ -4,7 +4,7 @@ angular.module('supportAdminApp') .factory('UserService', ['$q','$http', 'API_URL', function ($q, $http, API_URL) { // local dev - //API_URL = 'http://local.topcoder-dev.com:8080'; + //var API_URL = 'http://local.topcoder-dev.com:8080'; return ({ /** find users */ @@ -12,7 +12,7 @@ angular.module('supportAdminApp') var opts = options || {}; var query = ""; angular.forEach({ - "fields": opts.fields || "id,handle,email,active,credential,firstName,lastName,createdAt,modifiedAt", + "fields": opts.fields || "id,handle,email,active,status,credential,firstName,lastName,createdAt,modifiedAt", "filter": opts.filter //"limit" : null, //"offset": null, @@ -88,6 +88,43 @@ angular.module('supportAdminApp') return $q.reject(err); } ); - } // activate() + }, // activate() + + updateStatus: function(userId, status, comment) { + + var param = comment ? '?comment=' + encodeURIComponent(comment) : ''; + var request = $http({ + method: 'PATCH', + url: API_URL + '/v3/users/'+userId+'/status/'+status+param, + headers: { + "Content-Type":"application/json" + }, + data: {} + }); + + return request.then( + function(response) { + console.log(response); + return response.data.result.content; + }, + function(error) { + console.log(error); + var err; + if(error && error.data && error.data.result) { + err = { + status: error.status, + error : error.data.result.content + }; + } + if(!err) { + err = { + status: error.status, + error : error.statusText + }; + } + return $q.reject(err); + } + ); + } // updateStatus() }); }]); diff --git a/src/components/alert/alert.controller.js b/src/components/alert/alert.controller.js index 57a0e55..7a4a5d6 100644 --- a/src/components/alert/alert.controller.js +++ b/src/components/alert/alert.controller.js @@ -7,14 +7,18 @@ module.controller('AlertController', ['$scope', '$rootScope', $scope.closeAlert = function(index) { $scope.alerts.splice(index, 1); - } + }; $scope.addAlert = function(alert) { $scope.alerts.push(alert); - } + }; - $scope.$on('AlertIssued', function(event, alert){ + $scope.$on('alert.AlertIssued', function(event, alert){ $scope.addAlert(alert); }); + + $scope.$on('alert.ClearAll', function(event, alert){ + $scope.alerts.length = 0; + }); } ]);
User IDUser ID Handle EmailRegistred atActivation CodeNameStatusCreated atModified atActivation Code Active Action
{{user.id}} {{user.handle}} {{user.email}}{{user.firstName}} {{user.lastName}}{{statusLabel(user.status)}} {{format(user.createdAt)}}{{format(user.modifiedAt)}} {{user.credential.activationCode}} - + EDIT Activate - + Deactivate