123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- module.controller('GroupListCtrl', function($scope, $route, $q, realm, Groups, GroupsCount, Group, GroupChildren, Notifications, $location, Dialog, ComponentUtils, $translate) {
- $scope.realm = realm;
- $scope.groupList = [
- {
- "id" : "realm",
- "name": $translate.instant('groups'),
- "subGroups" : []
- }
- ];
- $scope.searchCriteria = '';
- $scope.currentPage = 1;
- $scope.currentPageInput = $scope.currentPage;
- $scope.pageSize = 20;
- $scope.numberOfPages = 1;
- $scope.tree = [];
- var refreshGroups = function (search) {
- console.log('refreshGroups');
- $scope.currentPageInput = $scope.currentPage;
- var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
- console.log('first:' + first);
- var queryParams = {
- realm : realm.realm,
- first : first,
- max : $scope.pageSize
- };
- var countParams = {
- realm : realm.realm,
- top : 'true'
- };
- if(angular.isDefined(search) && search !== '') {
- queryParams.search = search;
- countParams.search = search;
- }
- var promiseGetGroups = $q.defer();
- Groups.query(queryParams, function(entry) {
- promiseGetGroups.resolve(entry);
- }, function() {
- promiseGetGroups.reject($translate.instant('group.fetch.fail', {params: queryParams}));
- });
- promiseGetGroups.promise.then(function(groups) {
- $scope.groupList = [
- {
- "id" : "realm",
- "name": $translate.instant('groups'),
- "subGroups": ComponentUtils.sortGroups('name', groups)
- }
- ];
- if (angular.isDefined(search) && search !== '') {
- // Add highlight for concrete text match
- setTimeout(function () {
- document.querySelectorAll('span').forEach(function (element) {
- if (element.textContent.indexOf(search) != -1) {
- angular.element(element).addClass('highlight');
- }
- });
- }, 500);
- }
- }, function (failed) {
- Notifications.error(failed);
- });
- var promiseCount = $q.defer();
- console.log('countParams: realm[' + countParams.realm);
- GroupsCount.query(countParams, function(entry) {
- promiseCount.resolve(entry);
- }, function() {
- promiseCount.reject($translate.instant('group.fetch.fail', {params: countParams}));
- });
- promiseCount.promise.then(function(entry) {
- if(angular.isDefined(entry.count) && entry.count > $scope.pageSize) {
- $scope.numberOfPages = Math.ceil(entry.count/$scope.pageSize);
- } else {
- $scope.numberOfPages = 1;
- }
- }, function (failed) {
- Notifications.error(failed);
- });
- };
- refreshGroups();
- $scope.$watch('currentPage', function(newValue, oldValue) {
- if(parseInt(newValue, 10) !== oldValue) {
- refreshGroups($scope.searchCriteria);
- }
- });
- $scope.clearSearch = function() {
- $scope.searchCriteria = '';
- if (parseInt($scope.currentPage, 10) === 1) {
- refreshGroups();
- } else {
- $scope.currentPage = 1;
- }
- };
- $scope.searchGroup = function() {
- if (parseInt($scope.currentPage, 10) === 1) {
- refreshGroups($scope.searchCriteria);
- } else {
- $scope.currentPage = 1;
- }
- };
- $scope.edit = function(selected) {
- if (selected.id === 'realm') return;
- $location.url("/realms/" + realm.realm + "/groups/" + selected.id);
- };
- $scope.cut = function(selected) {
- $scope.cutNode = selected;
- };
- $scope.isDisabled = function() {
- if (!$scope.tree.currentNode) return true;
- return $scope.tree.currentNode.id === 'realm';
- };
- $scope.paste = function(selected) {
- if (selected === null) return;
- if ($scope.cutNode === null) return;
- if (selected.id === $scope.cutNode.id) return;
- if (selected.id === 'realm') {
- Groups.save({realm: realm.realm}, {id:$scope.cutNode.id, name: $scope.cutNode.name}, function() {
- $route.reload();
- Notifications.success($translate.instant('group.move.success'));
- });
- } else {
- GroupChildren.save({realm: realm.realm, groupId: selected.id}, {id:$scope.cutNode.id, name: $scope.cutNode.name}, function() {
- $route.reload();
- Notifications.success($translate.instant('group.move.success'));
- });
- }
- };
- $scope.remove = function(selected) {
- if (selected === null) return;
- Dialog.confirmWithButtonText(
- $translate.instant('group.remove.confirm.title', {name: selected.name}),
- $translate.instant('group.remove.confirm.message', {name: selected.name}),
- $translate.instant('dialogs.delete.confirm'),
- function() {
- Group.remove({ realm: realm.realm, groupId : selected.id }, function() {
- $route.reload();
- Notifications.success($translate.instant('group.remove.success'));
- });
- }
- );
- };
- $scope.createGroup = function(selected) {
- var parent = 'realm';
- if (selected) {
- parent = selected.id;
- }
- $location.url("/create/group/" + realm.realm + '/parent/' + parent);
- };
- var isLeaf = function(node) {
- return node.id !== "realm" && (!node.subGroups || node.subGroups.length === 0);
- };
- $scope.getGroupClass = function(node) {
- if (node.id === "realm") {
- return 'pficon pficon-users';
- }
- if (isLeaf(node)) {
- return 'normal';
- }
- if (node.subGroups.length && node.collapsed) return 'collapsed';
- if (node.subGroups.length && !node.collapsed) return 'expanded';
- return 'collapsed';
- };
- $scope.getSelectedClass = function(node) {
- if (node.selected) {
- return 'selected';
- } else if ($scope.cutNode && $scope.cutNode.id === node.id) {
- return 'cut';
- }
- return undefined;
- }
- });
- module.controller('GroupCreateCtrl', function($scope, $route, realm, parentId, Groups, Group, GroupChildren, Notifications, $location, $translate) {
- $scope.realm = realm;
- $scope.group = {};
- $scope.save = function() {
- console.log('save!!!');
- if (parentId === 'realm') {
- console.log('realm');
- Groups.save({realm: realm.realm}, $scope.group, function(data, headers) {
- var l = headers().location;
- var id = l.substring(l.lastIndexOf("/") + 1);
- $location.url("/realms/" + realm.realm + "/groups/" + id);
- Notifications.success($translate.instant('group.create.success'));
- })
- } else {
- GroupChildren.save({realm: realm.realm, groupId: parentId}, $scope.group, function(data, headers) {
- var l = headers().location;
- var id = l.substring(l.lastIndexOf("/") + 1);
- $location.url("/realms/" + realm.realm + "/groups/" + id);
- Notifications.success($translate.instant('group.create.success'));
- })
- }
- };
- $scope.cancel = function() {
- $location.url("/realms/" + realm.realm + "/groups");
- };
- });
- module.controller('GroupTabCtrl', function(Dialog, $scope, Current, Group, Notifications, $location, $translate) {
- $scope.removeGroup = function() {
- Dialog.confirmWithButtonText(
- $translate.instant('group.remove.confirm.title', {name: $scope.group.name}),
- $translate.instant('group.remove.confirm.message', {name: $scope.group.name}),
- $translate.instant('dialogs.delete.confirm'),
- function() {
- Group.remove({
- realm : Current.realm.realm,
- groupId : $scope.group.id
- }, function() {
- $location.url("/realms/" + Current.realm.realm + "/groups");
- Notifications.success($translate.instant('group.remove.success'));
- });
- }
- );
- };
- });
- module.controller('GroupDetailCtrl', function(Dialog, $scope, realm, group, Group, Notifications, $location, $translate) {
- $scope.realm = realm;
- if (!group.attributes) {
- group.attributes = {}
- }
- convertAttributeValuesToString(group);
- $scope.group = angular.copy(group);
- $scope.changed = false; // $scope.create;
- $scope.$watch('group', function() {
- if (!angular.equals($scope.group, group)) {
- $scope.changed = true;
- }
- }, true);
- $scope.save = function() {
- convertAttributeValuesToLists();
- Group.update({
- realm: realm.realm,
- groupId: $scope.group.id
- }, $scope.group, function () {
- $scope.changed = false;
- convertAttributeValuesToString($scope.group);
- group = angular.copy($scope.group);
- Notifications.success($translate.instant('group.edit.success'));
- });
- };
- function convertAttributeValuesToLists() {
- var attrs = $scope.group.attributes;
- for (var attribute in attrs) {
- if (typeof attrs[attribute] === "string") {
- attrs[attribute] = attrs[attribute].split("##");
- }
- }
- }
- function convertAttributeValuesToString(group) {
- var attrs = group.attributes;
- for (var attribute in attrs) {
- if (typeof attrs[attribute] === "object") {
- attrs[attribute] = attrs[attribute].join("##");
- }
- }
- }
- $scope.reset = function() {
- $scope.group = angular.copy(group);
- $scope.changed = false;
- };
- $scope.cancel = function() {
- $location.url("/realms/" + realm.realm + "/groups");
- };
- $scope.addAttribute = function() {
- $scope.group.attributes[$scope.newAttribute.key] = $scope.newAttribute.value;
- delete $scope.newAttribute;
- }
- $scope.removeAttribute = function(key) {
- delete $scope.group.attributes[key];
- }
- });
- module.controller('GroupRoleMappingCtrl', function($scope, $http, $route, realm, group, clients, client, Client, Notifications, GroupRealmRoleMapping,
- GroupClientRoleMapping, GroupAvailableRealmRoleMapping, GroupAvailableClientRoleMapping,
- GroupCompositeRealmRoleMapping, GroupCompositeClientRoleMapping, $translate) {
- $scope.realm = realm;
- $scope.group = group;
- $scope.selectedRealmRoles = [];
- $scope.selectedRealmMappings = [];
- $scope.realmMappings = [];
- $scope.clients = clients;
- $scope.client = client;
- $scope.clientRoles = [];
- $scope.clientComposite = [];
- $scope.selectedClientRoles = [];
- $scope.selectedClientMappings = [];
- $scope.clientMappings = [];
- $scope.dummymodel = [];
- $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.addRealmRole = function() {
- $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']');
- $scope.selectedRealmRoles = [];
- $http.post(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/realm',
- $scope.selectedRealmRolesToAdd).then(function() {
- $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.selectedRealmMappings = [];
- $scope.selectRealmRoles = [];
- if ($scope.selectedClient) {
- console.log('load available');
- $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.selectedClientRoles = [];
- $scope.selectedClientMappings = [];
- }
- $scope.selectedRealmRolesToAdd = [];
- Notifications.success($translate.instant('group.roles.add.success'));
- });
- };
- $scope.deleteRealmRole = function() {
- $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']');
- $http.delete(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/realm',
- {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() {
- $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.selectedRealmMappings = [];
- $scope.selectRealmRoles = [];
- if ($scope.selectedClient) {
- console.log('load available');
- $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.selectedClientRoles = [];
- $scope.selectedClientMappings = [];
- }
- $scope.selectedRealmMappingsToRemove = [];
- Notifications.success($translate.instant('group.roles.remove.success'));
- });
- };
- $scope.addClientRole = function() {
- $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']');
- $http.post(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/clients/' + $scope.selectedClient.id,
- $scope.selectedClientRolesToAdd).then(function() {
- $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.selectedClientRoles = [];
- $scope.selectedClientMappings = [];
- $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.selectedClientRolesToAdd = [];
- Notifications.success($translate.instant('group.roles.add.success'));
- });
- };
- $scope.deleteClientRole = function() {
- $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']');
- $http.delete(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/clients/' + $scope.selectedClient.id,
- {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() {
- $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.selectedClientRoles = [];
- $scope.selectedClientMappings = [];
- $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
- $scope.selectedClientMappingsToRemove = [];
- Notifications.success($translate.instant('group.roles.remove.success'));
- });
- };
- $scope.changeClient = function(client) {
- $scope.selectedClient = client;
- if (!client || !client.id) {
- $scope.selectedClient = null;
- $scope.clientRoles = null;
- $scope.clientMappings = null;
- $scope.clientComposite = null;
- return;
- }
- if ($scope.selectedClient) {
- $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
- }
- $scope.selectedClientRoles = [];
- $scope.selectedClientMappings = [];
- };
- clientSelectControl($scope, $route.current.params.realm, Client);
- });
- module.controller('GroupMembersCtrl', function($scope, realm, group, GroupMembership) {
- $scope.realm = realm;
- $scope.page = 0;
- $scope.group = group;
- $scope.query = {
- realm: realm.realm,
- groupId: group.id,
- max : 5,
- first : 0
- };
- $scope.firstPage = function() {
- $scope.query.first = 0;
- $scope.searchQuery();
- };
- $scope.previousPage = function() {
- $scope.query.first -= parseInt($scope.query.max);
- if ($scope.query.first < 0) {
- $scope.query.first = 0;
- }
- $scope.searchQuery();
- };
- $scope.nextPage = function() {
- $scope.query.first += parseInt($scope.query.max);
- $scope.searchQuery();
- };
- $scope.searchQuery = function() {
- console.log("query.search: " + $scope.query.search);
- $scope.searchLoaded = false;
- $scope.users = GroupMembership.query($scope.query, function() {
- console.log('search loaded');
- $scope.searchLoaded = true;
- $scope.lastSearch = $scope.query.search;
- });
- };
- $scope.searchQuery();
- });
- module.controller('DefaultGroupsCtrl', function($scope, $q, realm, Groups, GroupsCount, DefaultGroups, Notifications, $translate) {
- $scope.realm = realm;
- $scope.groupList = [];
- $scope.selectedGroup = null;
- $scope.tree = [];
- $scope.searchCriteria = '';
- $scope.currentPage = 1;
- $scope.currentPageInput = $scope.currentPage;
- $scope.pageSize = 20;
- $scope.numberOfPages = 1;
- var refreshDefaultGroups = function () {
- DefaultGroups.query({realm: realm.realm}, function(data) {
- $scope.defaultGroups = data;
- });
- }
- var refreshAvailableGroups = function (search) {
- var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
- $scope.currentPageInput = $scope.currentPage;
- var queryParams = {
- realm : realm.realm,
- first : first,
- max : $scope.pageSize
- };
- var countParams = {
- realm : realm.realm,
- top : 'true'
- };
- if(angular.isDefined(search) && search !== '') {
- queryParams.search = search;
- countParams.search = search;
- }
- var promiseGetGroups = $q.defer();
- Groups.query(queryParams, function(entry) {
- promiseGetGroups.resolve(entry);
- }, function() {
- promiseGetGroups.reject($translate.instant('group.fetch.fail', {params: queryParams}));
- });
- promiseGetGroups.promise.then(function(groups) {
- $scope.groupList = groups;
- }, function (failed) {
- Notifications.success(failed);
- });
- var promiseCount = $q.defer();
- GroupsCount.query(countParams, function(entry) {
- promiseCount.resolve(entry);
- }, function() {
- promiseCount.reject($translate.instant('group.fetch.fail', {params: countParams}));
- });
- promiseCount.promise.then(function(entry) {
- if(angular.isDefined(entry.count) && entry.count > $scope.pageSize) {
- $scope.numberOfPages = Math.ceil(entry.count/$scope.pageSize);
- }
- }, function (failed) {
- Notifications.success(failed);
- });
- };
- refreshAvailableGroups();
- $scope.$watch('currentPage', function(newValue, oldValue) {
- if(parseInt(newValue, 10) !== parseInt(oldValue, 10)) {
- refreshAvailableGroups($scope.searchCriteria);
- }
- });
- $scope.clearSearch = function() {
- $scope.searchCriteria = '';
- if (parseInt($scope.currentPage, 10) === 1) {
- refreshAvailableGroups();
- } else {
- $scope.currentPage = 1;
- }
- };
- $scope.searchGroup = function() {
- if (parseInt($scope.currentPage, 10) === 1) {
- refreshAvailableGroups($scope.searchCriteria);
- } else {
- $scope.currentPage = 1;
- }
- };
- refreshDefaultGroups();
- $scope.addDefaultGroup = function() {
- if (!$scope.tree.currentNode) {
- Notifications.error($translate.instant('group.default.add.error'));
- return;
- }
- DefaultGroups.update({realm: realm.realm, groupId: $scope.tree.currentNode.id}, function() {
- refreshDefaultGroups();
- Notifications.success($translate.instant('group.default.add.success'));
- });
- };
- $scope.removeDefaultGroup = function() {
- DefaultGroups.remove({realm: realm.realm, groupId: $scope.selectedGroup.id}, function() {
- refreshDefaultGroups();
- Notifications.success($translate.instant('group.default.remove.success'));
- });
- };
- var isLeaf = function(node) {
- return node.id !== "realm" && (!node.subGroups || node.subGroups.length === 0);
- };
- $scope.getGroupClass = function(node) {
- if (node.id === "realm") {
- return 'pficon pficon-users';
- }
- if (isLeaf(node)) {
- return 'normal';
- }
- if (node.subGroups.length && node.collapsed) return 'collapsed';
- if (node.subGroups.length && !node.collapsed) return 'expanded';
- return 'collapsed';
- };
- $scope.getSelectedClass = function(node) {
- if (node.selected) {
- return 'selected';
- } else if ($scope.cutNode && $scope.cutNode.id === node.id) {
- return 'cut';
- }
- return undefined;
- }
- });
|