Skip to content

Commit

Permalink
Merge pull request meanjs#1208 from itelo/users-styleguide
Browse files Browse the repository at this point in the history
feat(users): Modify users module to implement style guidelines.
  • Loading branch information
mleanos committed Mar 14, 2016
2 parents d5c6c8e + 173b702 commit 4c89ce7
Show file tree
Hide file tree
Showing 36 changed files with 763 additions and 555 deletions.
16 changes: 11 additions & 5 deletions modules/users/client/config/users-admin.client.menus.js
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'
});
}
]);
})();
39 changes: 24 additions & 15 deletions modules/users/client/config/users-admin.client.routes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
'use strict';
(function () {
'use strict';

// Setting up route
angular.module('users.admin.routes').config(['$stateProvider',
function ($stateProvider) {
// Setting up route
angular
.module('users.admin.routes')
.config(routeConfig);

routeConfig.$inject = ['$stateProvider'];

function routeConfig($stateProvider) {
$stateProvider
.state('admin.users', {
url: '/users',
templateUrl: 'modules/users/client/views/admin/list-users.client.view.html',
controller: 'UserListController',
controllerAs: 'vm',
data: {
pageTitle: 'Users List'
}
Expand All @@ -16,12 +23,9 @@ angular.module('users.admin.routes').config(['$stateProvider',
url: '/users/:userId',
templateUrl: 'modules/users/client/views/admin/view-user.client.view.html',
controller: 'UserController',
controllerAs: 'vm',
resolve: {
userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) {
return Admin.get({
userId: $stateParams.userId
});
}]
userResolve: getUser
},
data: {
pageTitle: 'Edit {{ userResolve.displayName }}'
Expand All @@ -31,16 +35,21 @@ angular.module('users.admin.routes').config(['$stateProvider',
url: '/users/:userId/edit',
templateUrl: 'modules/users/client/views/admin/edit-user.client.view.html',
controller: 'UserController',
controllerAs: 'vm',
resolve: {
userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) {
return Admin.get({
userId: $stateParams.userId
});
}]
userResolve: getUser
},
data: {
pageTitle: 'Edit User {{ userResolve.displayName }}'
}
});

getUser.$inject = ['$stateParams', 'AdminService'];

function getUser($stateParams, AdminService) {
return AdminService.get({
userId: $stateParams.userId
}).$promise;
}
}
]);
})();
38 changes: 32 additions & 6 deletions modules/users/client/config/users.client.routes.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,83 @@
'use strict';
(function () {
'use strict';

// Setting up route
angular.module('users').config(['$stateProvider',
function ($stateProvider) {
// Setting up route
angular
.module('users.routes')
.config(routeConfig);

routeConfig.$inject = ['$stateProvider'];

function routeConfig($stateProvider) {
// Users state routing
$stateProvider
.state('settings', {
abstract: true,
url: '/settings',
templateUrl: 'modules/users/client/views/settings/settings.client.view.html',
controller: 'SettingsController',
controllerAs: 'vm',
data: {
roles: ['user', 'admin']
}
})
.state('settings.profile', {
url: '/profile',
templateUrl: 'modules/users/client/views/settings/edit-profile.client.view.html',
controller: 'EditProfileController',
controllerAs: 'vm',
data: {
pageTitle: 'Settings'
}
})
.state('settings.password', {
url: '/password',
templateUrl: 'modules/users/client/views/settings/change-password.client.view.html',
controller: 'ChangePasswordController',
controllerAs: 'vm',
data: {
pageTitle: 'Settings password'
}
})
.state('settings.accounts', {
url: '/accounts',
templateUrl: 'modules/users/client/views/settings/manage-social-accounts.client.view.html',
controller: 'SocialAccountsController',
controllerAs: 'vm',
data: {
pageTitle: 'Settings accounts'
}
})
.state('settings.picture', {
url: '/picture',
templateUrl: 'modules/users/client/views/settings/change-profile-picture.client.view.html',
controller: 'ChangeProfilePictureController',
controllerAs: 'vm',
data: {
pageTitle: 'Settings picture'
}
})
.state('authentication', {
abstract: true,
url: '/authentication',
templateUrl: 'modules/users/client/views/authentication/authentication.client.view.html'
templateUrl: 'modules/users/client/views/authentication/authentication.client.view.html',
controller: 'AuthenticationController',
controllerAs: 'vm'
})
.state('authentication.signup', {
url: '/signup',
templateUrl: 'modules/users/client/views/authentication/signup.client.view.html',
controller: 'AuthenticationController',
controllerAs: 'vm',
data: {
pageTitle: 'Signup'
}
})
.state('authentication.signin', {
url: '/signin?err',
templateUrl: 'modules/users/client/views/authentication/signin.client.view.html',
controller: 'AuthenticationController',
controllerAs: 'vm',
data: {
pageTitle: 'Signin'
}
Expand All @@ -68,6 +90,8 @@ angular.module('users').config(['$stateProvider',
.state('password.forgot', {
url: '/forgot',
templateUrl: 'modules/users/client/views/password/forgot-password.client.view.html',
controller: 'PasswordController',
controllerAs: 'vm',
data: {
pageTitle: 'Password forgot'
}
Expand All @@ -94,9 +118,11 @@ angular.module('users').config(['$stateProvider',
.state('password.reset.form', {
url: '/:token',
templateUrl: 'modules/users/client/views/password/reset-password.client.view.html',
controller: 'PasswordController',
controllerAs: 'vm',
data: {
pageTitle: 'Password reset form'
}
});
}
]);
})();
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 modules/users/client/controllers/admin/user.client.controller.js
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;
});
};
}
}
]);
})();
Loading

0 comments on commit 4c89ce7

Please sign in to comment.