2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
40 app.controller('roleFunctionListController', function ($scope, RoleService, applicationsService, $http, $state, conf, confirmBoxService, ngDialog, $modal) {
42 $scope.centralizedApps = RoleService.getManageRoleDetails().apps;
44 selectedCentralizedApp: RoleService.getManageRoleDetails().id
47 $scope.getRoleFunctions = function (id) {
48 $scope.isLoadingRoleFunctions = true;
49 RoleService.getRoleFunctionList(id).then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 $scope.availableRoleFunctions = $scope.data.availableRoleFunctions;
54 confirmBoxService.showInformation("Failed to get role functions. Please try again!");
55 console.log("failed");
56 }).finally(function(){
57 $scope.isLoadingRoleFunctions = false;
62 if($scope.apps.selectedCentralizedApp){
63 $scope.getRoleFunctions($scope.apps.selectedCentralizedApp);
65 if($scope.apps.selectedCentralizedApp == undefined){
66 $scope.getCentralizedApps(sessionStorage.userId);
71 $scope.getCentralizedApps = function(userId) {
72 RoleService.getCentralizedApps(userId).then(res=> {
74 $scope.centralizedApps = res;
75 for(var i = 0; i<res.length; i++){
76 if(res[i].appId == 1){
77 $scope.apps.selectedCentralizedApp = res[i].appId;
80 $scope.apps.selectedCentralizedApp = res[0].appId;
84 $log.error('RoleListCtrl::centralizedApps retrieval error: ', err);
86 // this.isLoadingTable = false;
93 $scope.editRoleFunction = null;
96 $scope.editRoleFunctionModalPopup = function (availableRoleFunction) {
97 $scope.editRoleFunction = availableRoleFunction;
98 $scope.availableRoleFunctionsTemp = $scope.availableRoleFunctions;
100 var modalInstance = $modal.open({
101 templateUrl: 'app/views/role/popup_modal_rolefunction.html',
102 controller: 'rolefunctionpopupController',
103 sizeClass: 'modal-small',
105 message: function message() {
107 availableRoleFunction: $scope.editRoleFunction,
108 availableRoleFunctions: $scope.availableRoleFunctionsTemp,
109 appId: $scope.apps.selectedCentralizedApp
113 isEditing: function isEditing() {
119 modalInstance.result.then(function (response) {
121 $scope.getRoleFunctions($scope.apps.selectedCentralizedApp);
124 $scope.availableRoleFunctions = $scope.availableRoleFunctionsTemp;
128 $scope.addNewRoleFunctionModalPopup = function (availableRoleFunction) {
130 $scope.editRoleFunction = null;
131 $scope.availableRoleFunctionsTemp = $scope.availableRoleFunctions;
132 var modalInstance = $modal.open({
133 templateUrl: 'app/views/role/popup_modal_rolefunction.html',
134 controller: 'rolefunctionpopupController',
135 sizeClass: 'modal-small',
137 message: function message() {
139 availableRoleFunction: $scope.editRoleFunction,
140 availableRoleFunctions: $scope.availableRoleFunctionsTemp,
141 appId: $scope.apps.selectedCentralizedApp
145 isEditing: function isEditing() {
151 modalInstance.result.then(function (response) {
153 $scope.getRoleFunctions($scope.apps.selectedCentralizedApp);
155 if (response.availableRoleFunctions != undefined)
156 $scope.availableRoleFunctions = response.availableRoleFunctions;else $scope.availableRoleFunctions = $scope.availableRoleFunctionsTemp;
160 $scope.addNewRoleFunctionPopup = function () {
161 $scope.editRoleFunction = null;
162 $("#dialog").dialog({
167 $scope.syncRoleFunctionsFromExternalAuthSystem = function(appId){
168 applicationsService.syncFunctionsFromExternalAuthSystem(appId).then(function(res){
169 if(res.status == 200){
170 confirmBoxService.showInformation('Sync operation completed successfully!').then(isConfirmed => {
171 $scope.getRoleFunctions(appId);
174 confirmBoxService.showInformation('Sync operation failed for '+app).then(isConfirmed => {});
179 $scope.saveRoleFunction = function (availableRoleFunction) {
180 var uuu = conf.api.saveRoleFuncion;
181 var postData = { availableRoleFunction: availableRoleFunction };
182 $http.post(uuu, postData).then(function (response) {
183 var data = response.data;
184 $scope.availableRoleFunctions = data.availableRoleFunctions;
185 $scope.editRoleFunction = null;
188 confirmBoxService.showInformation("Error while saving");
192 $scope.removeRole = function (availableRoleFunction) {
193 confirmBoxService.confirm("You are about to delete the role function " + availableRoleFunction.name + ". Do you want to continue?").then(function (confirmed) {
195 $scope.availableRoleFunctionsTemp = $scope.availableRoleFunctions;
196 var uuu = conf.api.removeRoleFunction.replace(':appId', $scope.apps.selectedCentralizedApp);
197 var postData = availableRoleFunction;
198 $http.post(uuu, postData).then(function (response) {
199 if(response.data.status == 'OK'){
200 confirmBoxService.showInformation(response.data.message);
201 $scope.availableRoleFunctionsTemp.splice($scope.availableRoleFunctionsTemp.indexOf(availableRoleFunction), 1);
202 $scope.availableRoleFunctions = $scope.availableRoleFunctionsTemp;
204 confirmBoxService.showInformation("Error while deleting: " + response.data.message);
207 $scope.availableRoleFunctions = $scope.availableRoleFunctionsTemp;