User management

This commit is contained in:
tidusjar 2016-08-26 14:39:14 +01:00
parent e77add75a1
commit d75e309e18
8 changed files with 88 additions and 41 deletions

View file

@ -9,6 +9,7 @@
$scope.selectedUser = {}; // User on the right side $scope.selectedUser = {}; // User on the right side
$scope.selectedClaims = {}; $scope.selectedClaims = {};
$scope.sortType = "username"; $scope.sortType = "username";
$scope.sortReverse = false; $scope.sortReverse = false;
$scope.searchTerm = ""; $scope.searchTerm = "";
@ -27,20 +28,20 @@
// Get all users in the system // Get all users in the system
$scope.getUsers = function () { $scope.getUsers = function () {
$scope.users = userManagementService.getUsers() $scope.users = userManagementService.getUsers()
.then(function (data) { .then(function (data) {
$scope.users = data.data; $scope.users = data.data;
}); });
}; };
// Get the claims and populate the create dropdown // Get the claims and populate the create dropdown
$scope.getClaims = function () { $scope.getClaims = function () {
userManagementService.getClaims() userManagementService.getClaims()
.then(function (data) { .then(function (data) {
$scope.claims = data.data; $scope.claims = data.data;
}); });
} }
// Create a user, do some validation too // Create a user, do some validation too
$scope.addUser = function () { $scope.addUser = function () {
if (!$scope.user.username || !$scope.user.password) { if (!$scope.user.username || !$scope.user.password) {
@ -50,23 +51,35 @@
return; return;
} }
userManagementService.addUser($scope.user, $scope.selectedClaims).then(function (data) { userManagementService.addUser($scope.user, $scope.selectedClaims)
if (data.message) { .then(function (data) {
$scope.error.error = true; if (data.message) {
$scope.error.errorMessage = data.message; $scope.error.error = true;
} else { $scope.error.errorMessage = data.message;
$scope.users.push(data); // Push the new user into the array to update the DOM } else {
$scope.user = {}; $scope.users.push(data); // Push the new user into the array to update the DOM
$scope.selectedClaims = {}; $scope.user = {};
} $scope.selectedClaims = {};
}); }
});
}; };
$scope.$watch('claims|filter:{selected:true}', function (nv) { $scope.$watch('claims|filter:{selected:true}',
$scope.selectedClaims = nv.map(function (claim) { function (nv) {
return claim.name; $scope.selectedClaims = nv.map(function (claim) {
}); return claim.name;
}, true); });
},
true);
$scope.updateUser = function () {
}
function getBaseUrl() {
return $('#baseUrl').val();
}
// On page load // On page load

View file

@ -5,6 +5,21 @@
return opts.inverse(this); return opts.inverse(this);
}); });
Function.prototype.bind = function (parent) {
var f = this;
var args = [];
for (var a = 1; a < arguments.length; a++) {
args[args.length] = arguments[a];
}
var temp = function () {
return f.apply(parent, args);
}
return (temp);
}
$(function () { $(function () {

View file

@ -8,21 +8,6 @@
return s; return s;
} }
Function.prototype.bind = function (parent) {
var f = this;
var args = [];
for (var a = 1; a < arguments.length; a++) {
args[args.length] = arguments[a];
}
var temp = function () {
return f.apply(parent, args);
}
return (temp);
}
$(function() { $(function() {
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
}); });

View file

@ -206,6 +206,20 @@ namespace PlexRequests.UI.Helpers
return helper.Raw(asset); return helper.Raw(asset);
} }
public static IHtmlString LoadUserManagementAssets(this HtmlHelpers helper)
{
var assetLocation = GetBaseUrl();
var content = GetContentUrl(assetLocation);
var controller = $"<script src=\"{content}/Content/app/userManagement/userManagementController.js?v={Assembly}\" type=\"text/javascript\"></script>";
controller += $"<script src=\"{content}/Content/app/userManagement/userManagementService.js?v={Assembly}\" type=\"text/javascript\"></script>";
return helper.Raw(controller);
}
public static IHtmlString LoadTableAssets(this HtmlHelpers helper) public static IHtmlString LoadTableAssets(this HtmlHelpers helper)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();

View file

@ -16,6 +16,7 @@ namespace PlexRequests.UI.Models
public UserType Type { get; set; } public UserType Type { get; set; }
public string EmailAddress { get; set; } public string EmailAddress { get; set; }
public UserManagementPlexInformation PlexInfo { get; set; } public UserManagementPlexInformation PlexInfo { get; set; }
public string[] ClaimsArray { get; set; }
} }
public class UserManagementPlexInformation public class UserManagementPlexInformation

View file

@ -63,7 +63,8 @@ namespace PlexRequests.UI.Modules
Claims = claimsString, Claims = claimsString,
Username = user.UserName, Username = user.UserName,
Type = UserType.LocalUser, Type = UserType.LocalUser,
EmailAddress = userProps.EmailAddress EmailAddress = userProps.EmailAddress,
ClaimsArray = claims
}); });
} }

View file

@ -50,6 +50,7 @@ namespace PlexRequests.UI.NinjectModules
Bind<ICustomUserMapper>().To<UserMapper>(); Bind<ICustomUserMapper>().To<UserMapper>();
Bind<INotificationService>().To<NotificationService>().InSingletonScope(); Bind<INotificationService>().To<NotificationService>().InSingletonScope();
Bind<INotificationEngine>().To<NotificationEngine>();
} }
} }
} }

View file

@ -1,8 +1,7 @@
@using PlexRequests.UI.Helpers @using PlexRequests.UI.Helpers
@inherits PlexRequests.UI.Helpers.AngularViewBase @inherits PlexRequests.UI.Helpers.AngularViewBase
<script src="~/Content/app/userManagement/userManagementController.js"></script> @Html.LoadUserManagementAssets()
<script src="~/Content/app/userManagement/userManagementService.js"></script>
<div ng-controller="userManagementController" ng-init="init()"> <div ng-controller="userManagementController" ng-init="init()">
<br /> <br />
@ -110,9 +109,27 @@
<div> <div>
<strong>User Type: </strong><span ng-bind="selectedUser.type === 1 ? 'Local User' : 'Plex User'"></span> <strong>User Type: </strong><span ng-bind="selectedUser.type === 1 ? 'Local User' : 'Plex User'"></span>
</div> </div>
</div> <br/>
<br/>
<div ng-show="selectedUser.type === 1">
<!--Edit-->
<strong>Modify Roles:</strong>
<!--Load all claims-->
<div class="checkbox" ng-repeat="claim in claims">
<input id="claimCheckboxEdit_{{$id}}" class="checkbox-custom" name="selectedClaims[]" ng-checked="@*//TODO: Need to figure our how to preselect them*@" ng-model="claim.selected" type="checkbox" value="claim" />
<label for="claimCheckboxEdit_{{$id}}">{{claim.name}}</label>
</div>
<button ng-click="updateUser()" class="btn btn-primary-outline">Update</button>
</div>
</div> <!-- End of user side menu -->
</div> </div>