You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/PlexRequests.UI/Content/app/userManagement/userManagementController.js

106 lines
3.2 KiB

9 years ago
(function () {
var controller = function ($scope, userManagementService) {
$scope.user = {}; // The local user
9 years ago
$scope.users = []; // list of users
9 years ago
$scope.claims = []; // List of claims
9 years ago
9 years ago
$scope.selectedUser = {}; // User on the right side
$scope.selectedClaims = {};
9 years ago
9 years ago
9 years ago
$scope.sortType = "username";
9 years ago
$scope.sortReverse = false;
9 years ago
$scope.searchTerm = "";
9 years ago
$scope.error = {
error: false,
errorMessage: ""
};
9 years ago
// Select a user to populate on the right side
$scope.selectUser = function (id) {
var user = $scope.users.filter(function (item) {
return item.id === id;
});
$scope.selectedUser = user[0];
9 years ago
}
9 years ago
9 years ago
// Get all users in the system
9 years ago
$scope.getUsers = function () {
$scope.users = userManagementService.getUsers()
9 years ago
.then(function (data) {
$scope.users = data.data;
});
9 years ago
};
9 years ago
// Get the claims and populate the create dropdown
$scope.getClaims = function () {
userManagementService.getClaims()
9 years ago
.then(function (data) {
$scope.claims = data.data;
});
9 years ago
}
9 years ago
// Create a user, do some validation too
9 years ago
$scope.addUser = function () {
9 years ago
9 years ago
if (!$scope.user.username || !$scope.user.password) {
$scope.error.error = true;
$scope.error.errorMessage = "Please provide a correct username and password";
generateNotify($scope.error.errorMessage, 'warning');
return;
}
9 years ago
9 years ago
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 = {};
}
});
9 years ago
};
9 years ago
$scope.hasClaim = function(claim) {
var claims = $scope.selectedUser.claimsArray;
var result = claims.some(function (item) {
return item === claim.name;
});
return result;
};
9 years ago
$scope.$watch('claims|filter:{selected:true}',
function (nv) {
$scope.selectedClaims = nv.map(function (claim) {
return claim.name;
});
},
true);
$scope.updateUser = function () {
userManagementService.updateUser($scope.selectedUser.id, $scope.selectedUser.claimsItem);
9 years ago
}
function getBaseUrl() {
return $('#baseUrl').val();
}
9 years ago
// On page load
$scope.init = function () {
$scope.getUsers();
$scope.getClaims();
return;
}
9 years ago
}
angular.module('PlexRequests').controller('userManagementController', ["$scope", "userManagementService", controller]);
}());