This commit is contained in:
tidusjar 2016-08-28 17:10:24 +01:00
commit 0f98f12756
13 changed files with 297 additions and 101 deletions

View file

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

View file

@ -5,6 +5,21 @@
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 () {

View file

@ -8,21 +8,6 @@
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() {
$('[data-toggle="tooltip"]').tooltip();
});

View file

@ -207,6 +207,20 @@ namespace PlexRequests.UI.Helpers
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)
{
var sb = new StringBuilder();

View file

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

View file

@ -67,7 +67,8 @@ namespace PlexRequests.UI.Modules
ISonarrApi sonarrApi,
ISickRageApi sickRageApi,
ICacheProvider cache,
IAnalytics an) : base("requests", prSettings)
IAnalytics an,
INotificationEngine engine) : base("requests", prSettings)
{
Service = service;
PrSettings = prSettings;
@ -81,6 +82,7 @@ namespace PlexRequests.UI.Modules
CpApi = cpApi;
Cache = cache;
Analytics = an;
NotificationEngine = engine;
Get["/", true] = async (x, ct) => await LoadRequests();
Get["/movies", true] = async (x, ct) => await GetMovies();
@ -108,6 +110,7 @@ namespace PlexRequests.UI.Modules
private ISickRageApi SickRageApi { get; }
private ICouchPotatoApi CpApi { get; }
private ICacheProvider Cache { get; }
private INotificationEngine NotificationEngine { get; }
private async Task<Negotiator> LoadRequests()
{
@ -376,6 +379,8 @@ namespace PlexRequests.UI.Modules
originalRequest.Available = available;
var result = await Service.UpdateRequestAsync(originalRequest);
var plexService = await PlexSettings.GetSettingsAsync();
await NotificationEngine.NotifyUsers(originalRequest, plexService.PlexAuthToken);
return Response.AsJson(result
? new { Result = true, Available = available, Message = string.Empty }
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });

View file

@ -63,7 +63,8 @@ namespace PlexRequests.UI.Modules
Claims = claimsString,
Username = user.UserName,
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<INotificationService>().To<NotificationService>().InSingletonScope();
Bind<INotificationEngine>().To<NotificationEngine>();
}
}
}

View file

@ -1,8 +1,7 @@
@using PlexRequests.UI.Helpers
@inherits PlexRequests.UI.Helpers.AngularViewBase
<script src="~/Content/app/userManagement/userManagementController.js"></script>
<script src="~/Content/app/userManagement/userManagementService.js"></script>
@Html.LoadUserManagementAssets()
<div ng-controller="userManagementController" ng-init="init()">
<br />
@ -110,9 +109,27 @@
<div>
<strong>User Type: </strong><span ng-bind="selectedUser.type === 1 ? 'Local User' : 'Plex User'"></span>
</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>