Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 6066020

Browse files
committed
Admin module base & user admin implementation.
update displayName implements #700 (client-side role security) on angular routes.
1 parent c8880ea commit 6066020

18 files changed

+424
-5
lines changed

modules/articles/client/config/articles.client.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ angular.module('articles').config(['$stateProvider',
1010
url: '/articles',
1111
template: '<ui-view/>',
1212
data: {
13-
roles: ['user']
13+
roles: ['user', 'admin']
1414
}
1515
}).
1616
state('articles.list', {

modules/chat/client/config/chat.client.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ angular.module('chat').config(['$stateProvider',
88
url: '/chat',
99
templateUrl: 'modules/chat/views/chat.client.view.html',
1010
data: {
11-
roles: ['user']
11+
roles: ['user', 'admin']
1212
}
1313
});
1414
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
angular.module('core.admin').run(['Menus',
4+
function (Menus) {
5+
Menus.addMenuItem('topbar', {
6+
title: 'Admin',
7+
state: 'admin',
8+
type: 'dropdown',
9+
roles: ['admin']
10+
});
11+
}
12+
]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
// Setting up route
4+
angular.module('core.admin.routes').config(['$stateProvider',
5+
function ($stateProvider) {
6+
$stateProvider
7+
.state('admin', {
8+
abstract: true,
9+
url: '/admin',
10+
template: '<ui-view/>',
11+
data: {
12+
roles: ['admin']
13+
}
14+
});
15+
}
16+
]);

modules/core/client/core.client.module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
// Use Applicaion configuration module to register a new module
44
ApplicationConfiguration.registerModule('core');
5+
ApplicationConfiguration.registerModule('core.admin', ['core']);
6+
ApplicationConfiguration.registerModule('core.admin.routes', ['ui.router']);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
// Configuring the Articles module
4+
angular.module('users.admin').run(['Menus',
5+
function (Menus) {
6+
Menus.addSubMenuItem('topbar', 'admin', {
7+
title: 'Manage Users',
8+
state: 'admin.users'
9+
});
10+
}
11+
]);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
// Setting up route
4+
angular.module('users.admin.routes').config(['$stateProvider',
5+
function ($stateProvider) {
6+
$stateProvider
7+
.state('admin.users', {
8+
url: '/users',
9+
templateUrl: 'modules/users/views/admin/user-list.client.view.html',
10+
controller: 'UserListController'
11+
})
12+
.state('admin.user', {
13+
url: '/users/:userId',
14+
templateUrl: 'modules/users/views/admin/user.client.view.html',
15+
controller: 'UserController',
16+
resolve: {
17+
userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) {
18+
return Admin.get({
19+
userId: $stateParams.userId
20+
});
21+
}]
22+
}
23+
})
24+
.state('admin.user-edit', {
25+
url: '/users/:userId/edit',
26+
templateUrl: 'modules/users/views/admin/user-edit.client.view.html',
27+
controller: 'UserController',
28+
resolve: {
29+
userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) {
30+
return Admin.get({
31+
userId: $stateParams.userId
32+
});
33+
}]
34+
}
35+
});
36+
}
37+
]);

modules/users/client/config/users.client.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ angular.module('users').config(['$stateProvider',
1010
url: '/settings',
1111
templateUrl: 'modules/users/views/settings/settings.client.view.html',
1212
data: {
13-
roles: ['user']
13+
roles: ['user', 'admin']
1414
}
1515
}).
1616
state('settings.profile', {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
angular.module('users.admin').controller('UserListController', ['$scope', '$filter', 'Admin',
4+
function ($scope, $filter, Admin) {
5+
Admin.query(function (data) {
6+
$scope.users = data;
7+
$scope.buildPager();
8+
});
9+
10+
$scope.buildPager = function () {
11+
$scope.pagedItems = [];
12+
$scope.itemsPerPage = 15;
13+
$scope.currentPage = 1;
14+
$scope.figureOutItemsToDisplay();
15+
};
16+
17+
$scope.figureOutItemsToDisplay = function () {
18+
$scope.filteredItems = $filter('filter')($scope.users, {
19+
$: $scope.search
20+
});
21+
$scope.filterLength = $scope.filteredItems.length;
22+
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage);
23+
var end = begin + $scope.itemsPerPage;
24+
$scope.pagedItems = $scope.filteredItems.slice(begin, end);
25+
};
26+
27+
$scope.pageChanged = function () {
28+
$scope.figureOutItemsToDisplay();
29+
};
30+
}
31+
]);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
angular.module('users.admin').controller('UserController', ['$scope', '$state', 'Authentication', 'userResolve',
4+
function ($scope, $state, Authentication, userResolve) {
5+
$scope.authentication = Authentication;
6+
$scope.user = userResolve;
7+
8+
$scope.remove = function (user) {
9+
if (confirm('Are you sure you want to delete this user?')) {
10+
if (user) {
11+
user.$remove();
12+
13+
$scope.users.splice($scope.users.indexOf(user), 1);
14+
} else {
15+
$scope.user.$remove(function () {
16+
$state.go('admin.users');
17+
});
18+
}
19+
}
20+
};
21+
22+
$scope.update = function () {
23+
var user = $scope.user;
24+
25+
user.$update(function () {
26+
$state.go('admin.user', {
27+
userId: user._id
28+
});
29+
}, function (errorResponse) {
30+
$scope.error = errorResponse.data.message;
31+
});
32+
};
33+
}
34+
]);

0 commit comments

Comments
 (0)