Add capability for multi-role support
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / PolicyRolesController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 app.controller('policyRolesController', function ($scope, PolicyAppService, modalService, $modal, Notification){
21     $( "#dialog" ).hide();
22
23     $scope.isDisabled = true;
24
25     PolicyAppService.getData('get_LockDownData').then(function(data) {
26         var j = data;
27         $scope.data = JSON.parse(j.data);
28         $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
29         if ($scope.lockdowndata[0].lockdown == true) {
30             $scope.isDisabled = true;
31         } else {
32             $scope.isDisabled = false;
33         }
34         console.log($scope.data);
35     }, function(error) {
36         console.log("failed");
37     });
38     
39     $scope.scopeDatas = [];
40     PolicyAppService.getData('get_RolesData').then(function (data) {
41         var j = data;
42         $scope.data = JSON.parse(j.data);
43         console.log($scope.data);
44         $scope.rolesDatas = JSON.parse($scope.data.rolesDatas);
45         console.log($scope.rolesDatas);
46     }, function (error) {
47         console.log("failed");
48     });
49
50     $scope.rolesTableGrid = {
51         data : 'rolesDatas',
52         enableFiltering: true,
53         columnDefs: [{
54             field: 'id', enableFiltering: false, headerCellTemplate: '' +
55             '<button id=\'New\' ng-click="grid.appScope.editRolesWindow(null)" class="btn btn-success">' + 'Create</button>',
56             cellTemplate:
57             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editRolesWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button>' ,  width: '4%'
58         },
59         { field: 'loginId.userName', displayName : 'Name', sort: { direction: 'asc', priority: 0 }},
60         { field: 'scope', displayName : 'Scope' },
61         { field: 'role', displayName : 'Role' }
62         ]
63     };
64
65
66     $scope.editRoleName = null;
67
68     $scope.editRolesWindow = function(editRoleData) {
69         if ($scope.lockdowndata[0].lockdown == true) {
70             Notification.error("Policy Application has been Locked")
71         } else {
72             $scope.editRoleName = editRoleData;
73             var modalInstance = $modal.open({
74                 backdrop: 'static', keyboard: false,
75                 templateUrl : 'edit_Role_popup.html',
76                 controller: 'editRoleController',
77                 resolve: {
78                     message: function () {
79                         var message = {
80                             editRoleData: $scope.editRoleName
81                         };
82                         return message;
83                     }
84                 }
85             });
86             modalInstance.result.then(function(response) {
87                 console.log('response', response);
88                 $scope.rolesDatas = response.rolesDatas;
89             });
90         }
91     };
92
93 });