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

Commit

Permalink
Merge pull request #676 from Gym/admin-feature
Browse files Browse the repository at this point in the history
Admin module
  • Loading branch information
lirantal committed Jul 25, 2015
2 parents d7f9622 + 6066020 commit e1ca1aa
Show file tree
Hide file tree
Showing 18 changed files with 424 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/articles/client/config/articles.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module('articles').config(['$stateProvider',
url: '/articles',
template: '<ui-view/>',
data: {
roles: ['user']
roles: ['user', 'admin']
}
}).
state('articles.list', {
Expand Down
2 changes: 1 addition & 1 deletion modules/chat/client/config/chat.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('chat').config(['$stateProvider',
url: '/chat',
templateUrl: 'modules/chat/views/chat.client.view.html',
data: {
roles: ['user']
roles: ['user', 'admin']
}
});
}
Expand Down
12 changes: 12 additions & 0 deletions modules/core/client/config/core-admin.client.menus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

angular.module('core.admin').run(['Menus',
function (Menus) {
Menus.addMenuItem('topbar', {
title: 'Admin',
state: 'admin',
type: 'dropdown',
roles: ['admin']
});
}
]);
16 changes: 16 additions & 0 deletions modules/core/client/config/core-admin.client.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

// Setting up route
angular.module('core.admin.routes').config(['$stateProvider',
function ($stateProvider) {
$stateProvider
.state('admin', {
abstract: true,
url: '/admin',
template: '<ui-view/>',
data: {
roles: ['admin']
}
});
}
]);
2 changes: 2 additions & 0 deletions modules/core/client/core.client.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

// Use Applicaion configuration module to register a new module
ApplicationConfiguration.registerModule('core');
ApplicationConfiguration.registerModule('core.admin', ['core']);
ApplicationConfiguration.registerModule('core.admin.routes', ['ui.router']);
11 changes: 11 additions & 0 deletions modules/users/client/config/users-admin.client.menus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

// Configuring the Articles module
angular.module('users.admin').run(['Menus',
function (Menus) {
Menus.addSubMenuItem('topbar', 'admin', {
title: 'Manage Users',
state: 'admin.users'
});
}
]);
37 changes: 37 additions & 0 deletions modules/users/client/config/users-admin.client.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

// Setting up route
angular.module('users.admin.routes').config(['$stateProvider',
function ($stateProvider) {
$stateProvider
.state('admin.users', {
url: '/users',
templateUrl: 'modules/users/views/admin/user-list.client.view.html',
controller: 'UserListController'
})
.state('admin.user', {
url: '/users/:userId',
templateUrl: 'modules/users/views/admin/user.client.view.html',
controller: 'UserController',
resolve: {
userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) {
return Admin.get({
userId: $stateParams.userId
});
}]
}
})
.state('admin.user-edit', {
url: '/users/:userId/edit',
templateUrl: 'modules/users/views/admin/user-edit.client.view.html',
controller: 'UserController',
resolve: {
userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) {
return Admin.get({
userId: $stateParams.userId
});
}]
}
});
}
]);
2 changes: 1 addition & 1 deletion modules/users/client/config/users.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module('users').config(['$stateProvider',
url: '/settings',
templateUrl: 'modules/users/views/settings/settings.client.view.html',
data: {
roles: ['user']
roles: ['user', 'admin']
}
}).
state('settings.profile', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

angular.module('users.admin').controller('UserListController', ['$scope', '$filter', 'Admin',
function ($scope, $filter, Admin) {
Admin.query(function (data) {
$scope.users = data;
$scope.buildPager();
});

$scope.buildPager = function () {
$scope.pagedItems = [];
$scope.itemsPerPage = 15;
$scope.currentPage = 1;
$scope.figureOutItemsToDisplay();
};

$scope.figureOutItemsToDisplay = function () {
$scope.filteredItems = $filter('filter')($scope.users, {
$: $scope.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);
};

$scope.pageChanged = function () {
$scope.figureOutItemsToDisplay();
};
}
]);
34 changes: 34 additions & 0 deletions modules/users/client/controllers/admin/user.client.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

angular.module('users.admin').controller('UserController', ['$scope', '$state', 'Authentication', 'userResolve',
function ($scope, $state, Authentication, userResolve) {
$scope.authentication = Authentication;
$scope.user = userResolve;

$scope.remove = function (user) {
if (confirm('Are you sure you want to delete this user?')) {
if (user) {
user.$remove();

$scope.users.splice($scope.users.indexOf(user), 1);
} else {
$scope.user.$remove(function () {
$state.go('admin.users');
});
}
}
};

$scope.update = function () {
var user = $scope.user;

user.$update(function () {
$state.go('admin.user', {
userId: user._id
});
}, function (errorResponse) {
$scope.error = errorResponse.data.message;
});
};
}
]);
16 changes: 15 additions & 1 deletion modules/users/client/services/users.client.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

// Users service used for communicating with the users REST endpoint
angular.module('users').factory('Users', ['$resource',
function($resource) {
function ($resource) {
return $resource('api/users', {}, {
update: {
method: 'PUT'
}
});
}
]);


//TODO this should be Users service
angular.module('users.admin').factory('Admin', ['$resource',
function ($resource) {
return $resource('api/users/:userId', {
userId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
]);
4 changes: 3 additions & 1 deletion modules/users/client/users.client.module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';

// Use Applicaion configuration module to register a new module
ApplicationConfiguration.registerModule('users');
ApplicationConfiguration.registerModule('users', ['core']);
ApplicationConfiguration.registerModule('users.admin', ['core.admin']);
ApplicationConfiguration.registerModule('users.admin.routes', ['core.admin.routes']);
35 changes: 35 additions & 0 deletions modules/users/client/views/admin/user-edit.client.view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<section>
<div class="page-header">
<h1>User <span data-ng-bind="user.username"</span</h1>
</div>
<div class="col-md-12">
<form name="userForm" class="form-horizontal" data-ng-submit="update()" novalidate>
<fieldset>
<div class="form-group">
<label class="control-label" for="firstName">First Name</label>
<div class="controls">
<input name="firstName" type="text" data-ng-model="user.firstName" id="firstName" class="form-control" placeholder="First Name" required>
</div>
</div>
<div class="form-group">
<label class="control-label" for="lastName">Last Name</label>
<div class="controls">
<input type="text" name="lastName" data-ng-model="user.lastName" id="lastName" class="form-control" placeholder="Last Name" />
</div>
</div>
<div class="form-group">
<label class="control-label" for="roles">Roles</label>
<div class="controls">
<input class="form-control" type="text" name="roles" data-ng-model="user.roles" id="roles" ng-list />
</div>
</div>
<div class="form-group">
<input type="submit" value="Update" class="btn btn-default">
</div>
<div data-ng-show="error" class="text-danger">
<strong data-ng-bind="error"></strong>
</div>
</fieldset>
</form>
</div>
</section>
20 changes: 20 additions & 0 deletions modules/users/client/views/admin/user-list.client.view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<section>
<div class="page-header">
<div class="row">
<div class="col-md-4">
<h1>Users</h1>
</div>
<div class="col-md-4" style="margin-top: 2em">
<input class="form-control col-md-4" type="text" data-ng-model="search" placeholder="Search" ng-change="figureOutItemsToDisplay()" />
</div>
</div>
</div>
<div class="list-group">
<a data-ng-repeat="user in pagedItems" data-ui-sref="admin.user({userId: user._id})" class="list-group-item">
<h4 class="list-group-item-heading" data-ng-bind="user.username"></h4>
<p class="list-group-item-text" data-ng-bind="article.content"></p>
</a>
</div>

<pagination boundary-links="true" max-size="8" items-per-page="itemsPerPage" total-items="filterLength" ng-model="currentPage" ng-change="pageChanged()"></pagination>
</section>
51 changes: 51 additions & 0 deletions modules/users/client/views/admin/user.client.view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<section>
<div class="page-header">
<div class="row">
<div class="col-md-6">
<h1 data-ng-bind="user.username"></h1>
</div>
<div class="col-md-4">
<a class="btn btn-primary" data-ui-sref="admin.user-edit({userId: user._id})">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-primary" data-ng-click="remove();" ng-if="user._id !== authentication.user._id">
<i class="glyphicon glyphicon-trash"></i>
</a>
</div>
</div>
</div>

<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-3"><strong>First Name</strong></div>
<div class="col-md-6" data-ng-bind="user.firstName"></div>
</div>
<hr/>
<div class="row">
<div class="col-md-3"><strong>Last Name</strong></div>
<div class="col-md-6" data-ng-bind="user.lastName"></div>
</div>
<hr/>
<div class="row">
<div class="col-md-3"><strong>Email</strong></div>
<div class="col-md-6" data-ng-bind="user.email"></div>
</div>
<hr/>
<div class="row">
<div class="col-md-3"><strong>Provider</strong></div>
<div class="col-md-6" data-ng-bind="user.provider"></div>
</div>
<hr/>
<div class="row">
<div class="col-md-3"><strong>Created</strong></div>
<div class="col-md-6" data-ng-bind="user.created"></div>
</div>
<hr/>
<div class="row">
<div class="col-md-3"><strong>Roles</strong></div>
<div class="col-md-6" data-ng-bind="user.roles"></div>
</div>
</div>
</div>
</section>
Loading

0 comments on commit e1ca1aa

Please sign in to comment.