This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1208 from itelo/users-styleguide
feat(users): Modify users module to implement style guidelines.
- Loading branch information
Showing
36 changed files
with
763 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
'use strict'; | ||
(function () { | ||
'use strict'; | ||
|
||
// Configuring the Users module | ||
angular.module('users.admin').run(['Menus', | ||
function (Menus) { | ||
angular | ||
.module('users.admin') | ||
.run(menuConfig); | ||
|
||
menuConfig.$inject = ['Menus']; | ||
|
||
// Configuring the Users module | ||
function menuConfig(Menus) { | ||
Menus.addSubMenuItem('topbar', 'admin', { | ||
title: 'Manage Users', | ||
state: 'admin.users' | ||
}); | ||
} | ||
]); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 35 additions & 24 deletions
59
modules/users/client/controllers/admin/list-users.client.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
'use strict'; | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('users.admin').controller('UserListController', ['$scope', '$filter', 'Admin', | ||
function ($scope, $filter, Admin) { | ||
Admin.query(function (data) { | ||
$scope.users = data; | ||
$scope.buildPager(); | ||
angular | ||
.module('users.admin') | ||
.controller('UserListController', UserListController); | ||
|
||
UserListController.$inject = ['$scope', '$filter', 'AdminService']; | ||
|
||
function UserListController($scope, $filter, AdminService) { | ||
var vm = this; | ||
vm.buildPager = buildPager; | ||
vm.figureOutItemsToDisplay = figureOutItemsToDisplay; | ||
vm.pageChanged = pageChanged; | ||
|
||
AdminService.query(function (data) { | ||
vm.users = data; | ||
vm.buildPager(); | ||
}); | ||
|
||
$scope.buildPager = function () { | ||
$scope.pagedItems = []; | ||
$scope.itemsPerPage = 15; | ||
$scope.currentPage = 1; | ||
$scope.figureOutItemsToDisplay(); | ||
}; | ||
function buildPager() { | ||
vm.pagedItems = []; | ||
vm.itemsPerPage = 15; | ||
vm.currentPage = 1; | ||
vm.figureOutItemsToDisplay(); | ||
} | ||
|
||
$scope.figureOutItemsToDisplay = function () { | ||
$scope.filteredItems = $filter('filter')($scope.users, { | ||
$: $scope.search | ||
function figureOutItemsToDisplay() { | ||
vm.filteredItems = $filter('filter')(vm.users, { | ||
$: vm.search | ||
}); | ||
$scope.filterLength = $scope.filteredItems.length; | ||
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage); | ||
var end = begin + $scope.itemsPerPage; | ||
$scope.pagedItems = $scope.filteredItems.slice(begin, end); | ||
}; | ||
vm.filterLength = vm.filteredItems.length; | ||
var begin = ((vm.currentPage - 1) * vm.itemsPerPage); | ||
var end = begin + vm.itemsPerPage; | ||
vm.pagedItems = vm.filteredItems.slice(begin, end); | ||
} | ||
|
||
$scope.pageChanged = function () { | ||
$scope.figureOutItemsToDisplay(); | ||
}; | ||
function pageChanged() { | ||
vm.figureOutItemsToDisplay(); | ||
} | ||
} | ||
]); | ||
})(); |
40 changes: 25 additions & 15 deletions
40
modules/users/client/controllers/admin/user.client.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,50 @@ | ||
'use strict'; | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('users.admin').controller('UserController', ['$scope', '$state', 'Authentication', 'userResolve', | ||
function ($scope, $state, Authentication, userResolve) { | ||
$scope.authentication = Authentication; | ||
$scope.user = userResolve; | ||
angular | ||
.module('users.admin') | ||
.controller('UserController', UserController); | ||
|
||
$scope.remove = function (user) { | ||
UserController.$inject = ['$scope', '$state', 'Authentication', 'userResolve']; | ||
|
||
function UserController($scope, $state, Authentication, user) { | ||
var vm = this; | ||
|
||
vm.authentication = Authentication; | ||
vm.user = user; | ||
vm.remove = remove; | ||
vm.update = update; | ||
|
||
function remove(user) { | ||
if (confirm('Are you sure you want to delete this user?')) { | ||
if (user) { | ||
user.$remove(); | ||
|
||
$scope.users.splice($scope.users.indexOf(user), 1); | ||
vm.users.splice(vm.users.indexOf(user), 1); | ||
} else { | ||
$scope.user.$remove(function () { | ||
vm.user.$remove(function () { | ||
$state.go('admin.users'); | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
$scope.update = function (isValid) { | ||
function update(isValid) { | ||
if (!isValid) { | ||
$scope.$broadcast('show-errors-check-validity', 'userForm'); | ||
$scope.$broadcast('show-errors-check-validity', 'vm.userForm'); | ||
|
||
return false; | ||
} | ||
|
||
var user = $scope.user; | ||
var user = vm.user; | ||
|
||
user.$update(function () { | ||
$state.go('admin.user', { | ||
userId: user._id | ||
}); | ||
}, function (errorResponse) { | ||
$scope.error = errorResponse.data.message; | ||
vm.error = errorResponse.data.message; | ||
}); | ||
}; | ||
} | ||
} | ||
]); | ||
})(); |
Oops, something went wrong.