Skip to content

Commit e36c0d0

Browse files
author
Yoshifumi Kohata
committed
Merge pull request #9 from appirio-tech/kohata-COR503-activation-link
Copy activation link feature in Admin tool [COR-503]
2 parents 0adbf6d + 61e3f40 commit e36c0d0

File tree

8 files changed

+349
-253
lines changed

8 files changed

+349
-253
lines changed

bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
"angular-jwt": "~0.0.9",
2525
"angular-footable": "~1.0.3",
2626
"appirio-tech-ng-auth": "3.x.x",
27-
"appirio-tech-ng-api-services": "0.x.x"
27+
"appirio-tech-ng-api-services": "0.x.x",
28+
"angular-clipboard": "~1.2.1"
2829
},
2930
"overrides": {
3031
"bootstrap": {
3132
"main": [
3233
"less/bootstrap.less",
34+
"dist/css/bootstrap.css",
3335
"dist/js/bootstrap.js",
3436
"dist/fonts/glyphicons-halflings-regular.eot",
3537
"dist/fonts/glyphicons-halflings-regular.svg",
3638
"dist/fonts/glyphicons-halflings-regular.ttf",
3739
"dist/fonts/glyphicons-halflings-regular.woff",
38-
"dist/fonts/glyphicons-halflings-regular.woff2",
39-
"css/bootstrap.css"
40+
"dist/fonts/glyphicons-halflings-regular.woff2"
4041
]
4142
},
4243
"footable": {

src/app/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ angular.module('supportAdminApp', [
1414
'app.constants',
1515
'appirio-tech-ng-api-services',
1616
'appirio-tech-ng-auth',
17-
'ui.footable'])
17+
'ui.footable',
18+
'angular-clipboard'])
1819
// In the run phase of your Angular application
1920
.run(function($rootScope, $location, AuthService, $state, UserV3Service) {
2021
// Listen to '$locationChangeSuccess', not '$stateChangeStart'

src/app/login/login.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ angular.module('supportAdminApp')
3232
$userService.findById(token.userId).then(
3333
function(currentUser) {
3434
$rootScope.currentUser = currentUser;
35-
$state.go('index.main');
35+
$state.go('index.users');
3636
},
3737
function(err) {
3838
$log.error('Failed to get user data.');
3939
$log.error(err);
40-
$state.go('index.main');
40+
$state.go('index.users');
4141
}
4242
);
4343
};

src/app/users/constants.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
var module = angular.module('supportAdminApp');
4+
5+
module.constant('users.Constants', {
6+
7+
MSG_CLIPBORD_TOOLTIP: "Copy to clipboard",
8+
9+
MSG_CLIPBOARD_COPIED: "Copied",
10+
11+
DICT_USER_STATUS: {
12+
'A': 'Active',
13+
'U': 'Unverified',
14+
'4': 'Deactivated(User request)',
15+
'5': 'Deactivated(Duplicate account)',
16+
'6': 'Deactivated(Cheating account)'
17+
}
18+
});

src/app/users/user.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
var module = angular.module('supportAdminApp');
4+
5+
module.factory('User', ['$log', 'users.Constants', 'API_URL',
6+
function($log, $const, API_URL) {
7+
8+
var User = function() {};
9+
10+
11+
User.prototype.statusDesc = function() {
12+
return $const.DICT_USER_STATUS[this.status];
13+
};
14+
15+
User.prototype.createdAtLabel = function() {
16+
return this.formatDate(this.createdAt);
17+
};
18+
19+
User.prototype.modifiedAtLabel = function() {
20+
return this.formatDate(this.modifiedAt);
21+
};
22+
23+
User.prototype.formatDate = function(isoDateText) {
24+
return isoDateText && isoDateText.replace("T"," ").replace(".000Z","");
25+
};
26+
27+
/**
28+
* create an activation link from an activation code.
29+
*/
30+
User.prototype.getActivationLink = function() {
31+
if(!this.credential || !this.credential.activationCode)
32+
return '';
33+
return API_URL + '/pub/activation.html?code=' + this.credential.activationCode + '&retUrl=https%3A%2F%2Fwww.topcoder.com%2Fskill-picker%2F';
34+
};
35+
36+
return User;
37+
}
38+
]);
39+
40+

src/app/users/users.controller.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
var module = angular.module('supportAdminApp');
44

55
module.controller('users.UserSearchController', [
6-
'$log', '$scope', '$rootScope', '$timeout', '$state', '$modal', 'AuthService','UserService', 'Alert',
7-
function ($log, $scope, $rootScope, $timeout, $state, $modal, $authService, $userService, $alert) {
6+
'$log', '$scope', '$rootScope', '$timeout', '$state', '$modal', 'AuthService', 'UserService', 'Alert', 'users.Constants', 'API_URL',
7+
function ($log, $scope, $rootScope, $timeout, $state, $modal, $authService, $userService, $alert, $const, API_URL) {
88

99
// footable
1010
angular.element(document).ready(function () {
@@ -72,31 +72,31 @@ module.controller('users.UserSearchController', [
7272
$scope.formSearch.setLoading(false);
7373
$timeout(function(){
7474
$('.footable').trigger('footable_redraw');
75-
}, 100);
75+
}, 100);
7676
},
7777
function(error) {
7878
$alert.error(error.error, $scope);
7979
$scope.formSearch.setLoading(false);
8080
}
8181
);
8282
};
83-
83+
8484
// list
8585
$scope.users = [];
8686

87-
$scope.format = function(isoDateText) {
88-
return isoDateText && isoDateText.replace("T"," ").replace(".000Z","");
89-
};
87+
// tooltip for activation link copy
88+
$scope.tooltip = {
89+
message : $const.MSG_CLIPBORD_TOOLTIP,
9090

91-
var statusLabels = {
92-
'A': 'Active',
93-
'U': 'Unverified',
94-
'4': 'Deactivated(User request)',
95-
'5': 'Deactivated(Duplicate account)',
96-
'6': 'Deactivated(Cheating account)'
97-
};
98-
$scope.statusLabel = function(status) {
99-
return statusLabels[status] || 'Unknown';
91+
success : function() {
92+
this.message = $const.MSG_CLIPBOARD_COPIED;
93+
},
94+
fail : function(err) {
95+
$log.debug(err);
96+
},
97+
reset : function() {
98+
$timeout(function(){ $scope.tooltip.message = $const.MSG_CLIPBORD_TOOLTIP; }, 250);
99+
}
100100
};
101101

102102
$scope.activate = function(index) {
@@ -123,9 +123,6 @@ module.controller('users.UserSearchController', [
123123
};
124124

125125
$scope.openDeactivateDialog = function(index) {
126-
var user = $scope.users[index];
127-
128-
//if(window.confirm('Are you sure you want to deactivate user \'' + user.handle + '\'?')) {
129126
var modalInstance = $modal.open({
130127
size: 'sm',
131128
templateUrl: 'app/users/status-update-dialog.html',
@@ -234,8 +231,8 @@ module.controller('users.UserEditDialogController', [
234231
]);
235232

236233
module.controller('users.StatusUpdateDialogController', [
237-
'$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'Alert', 'user',
238-
function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, $alert, user) {
234+
'$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'users.Constants', 'Alert', 'user',
235+
function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, $const, $alert, user) {
239236

240237
$scope.form = {
241238
status : user.status,

src/app/users/users.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script src="../bower_components/footable/js/footable.paginate.js"></script>
1010
<script src="../bower_components/footable/js/footable.sort.js"></script>
1111
-->
12-
12+
1313
<div class="row wrapper border-bottom white-bg page-heading">
1414
<div class="col-lg-10">
1515
<h2>Members</h2>
@@ -88,10 +88,23 @@ <h2>Members</h2>
8888
<td>{{user.handle}}</td>
8989
<td>{{user.email}}</td>
9090
<td>{{user.firstName}} {{user.lastName}}</td>
91-
<td>{{statusLabel(user.status)}}</td>
92-
<td>{{format(user.createdAt)}}</td>
93-
<td>{{format(user.modifiedAt)}}</td>
94-
<td>{{user.credential.activationCode}}</td>
91+
<td>{{user.statusDesc()}}</td>
92+
<td>{{user.createdAtLabel()}}</td>
93+
<td>{{user.modifiedAtLabel()}}</td>
94+
<td>
95+
{{user.credential.activationCode}}
96+
<div class="input-group" style="width: 400px;">
97+
<input type="text" value="{{user.getActivationLink()}}" class="form-control" readonly="readonly">
98+
99+
<span class="input-group-btn" data-tooltip="{{tooltip.message}}" placement="right" title="Copy to clipboard">
100+
<button clipboard text="user.getActivationLink()" type="button" class="btn btn-default"
101+
on-copied="tooltip.success()" on-error="tooltip.fail(err)" ng-mouseleave="tooltip.reset()">
102+
<i class="fa fa-clipboard text-primary"></i>
103+
</button>
104+
</span>
105+
</span>
106+
</div>
107+
</td>
95108
<td data-value="{{user.active}}">
96109
<a href="#" ng-show="user.active"><i class="fa fa-check text-navy"></i></a>
97110
</td>

0 commit comments

Comments
 (0)