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 #676 from Gym/admin-feature
Admin module
- Loading branch information
Showing
18 changed files
with
424 additions
and
5 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
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
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'] | ||
}); | ||
} | ||
]); |
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 |
---|---|---|
@@ -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'] | ||
} | ||
}); | ||
} | ||
]); |
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
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' | ||
}); | ||
} | ||
]); |
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 |
---|---|---|
@@ -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 | ||
}); | ||
}] | ||
} | ||
}); | ||
} | ||
]); |
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
31 changes: 31 additions & 0 deletions
31
modules/users/client/controllers/admin/user-list.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 |
---|---|---|
@@ -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
34
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 |
---|---|---|
@@ -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; | ||
}); | ||
}; | ||
} | ||
]); |
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
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
35
modules/users/client/views/admin/user-edit.client.view.html
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 |
---|---|---|
@@ -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
20
modules/users/client/views/admin/user-list.client.view.html
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 |
---|---|---|
@@ -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> |
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 |
---|---|---|
@@ -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> |
Oops, something went wrong.