Policy TestSuite Enabled
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / attributeDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 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('attributeDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21         $( "#dialog" ).hide();
22
23         PolicyAppService.getData('getDictionary/get_AttributeData').then(function (data) {
24                 var j = data;
25                 $scope.data = JSON.parse(j.data);
26                 console.log($scope.data);
27                 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
28                 console.log($scope.attributeDictionaryDatas);
29         }, function (error) {
30                 console.log("failed");
31         });
32
33
34         $scope.exportData = function () {
35                 var blob = new Blob([document.getElementById('attributeTable').innerHTML], {
36                         type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
37                 });
38                 saveAs(blob, "Attribute.xls");
39         };
40
41         PolicyAppService.getData('get_LockDownData').then(function(data){
42                 var j = data;
43                 $scope.data = JSON.parse(j.data);
44                 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
45                 if($scope.lockdowndata[0].lockdown == true){
46                         $scope.attributeDictionaryGrid.columnDefs[0].visible = false;
47                         $scope.gridApi.grid.refresh();
48                 }else{
49                         $scope.attributeDictionaryGrid.columnDefs[0].visible = true;
50                         $scope.gridApi.grid.refresh();
51                 }
52         },function(error){
53                 console.log("failed");
54         });
55
56         $scope.attributeDictionaryGrid = {
57                         data : 'attributeDictionaryDatas',
58                         enableFiltering: true,
59                         exporterCsvFilename: 'Attribute.csv',
60                         enableGridMenu: true,
61                         enableSelectAll: true,
62                         columnDefs: [{
63                                 field: 'id' , enableFiltering: false, headerCellTemplate: '' +
64                                 '<button id=\'New\' ng-click="grid.appScope.createNewAttributeWindow()" class="btn btn-success">' + 'Create</button>',
65                                 cellTemplate:
66                                         '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editAttributeWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
67                                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteAttribute(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
68                         },{ field: 'xacmlId', displayName : 'Attribute ID', sort: { direction: 'asc', priority: 0 }},
69                         { field: 'datatypeBean.shortName', displayName : 'Data Type' },
70                         { field: 'attributeValue'},
71                         { field: 'description' },
72                         { field: 'priority' , displayName : 'Priority'},
73                         {field: 'userCreatedBy.userName', displayName : 'Created By' },
74                         {field: 'userModifiedBy.userName', displayName : 'Modified By'},
75                         {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''  },
76                         {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''  }
77                         ],
78                         exporterMenuPdf: false,
79                         exporterPdfDefaultStyle: {fontSize: 9},
80                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
81                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
82                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
83                         exporterPdfFooter: function ( currentPage, pageCount ) {
84                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
85                         },
86                         exporterPdfCustomFormatter: function ( docDefinition ) {
87                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
88                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
89                                 return docDefinition;
90                         },
91                         exporterPdfOrientation: 'portrait',
92                         exporterPdfPageSize: 'LETTER',
93                         exporterPdfMaxGridWidth: 500,
94                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
95                         onRegisterApi: function(gridApi){
96                                 $scope.gridApi = gridApi;
97                         }
98         };
99
100
101         $scope.editAttributeName = null;
102         $scope.createNewAttributeWindow = function(){
103                 $scope.editAttributeName = null;
104                 var modalInstance = $modal.open({
105                         backdrop: 'static', keyboard: false,
106                         templateUrl : 'add_Attribute_popup.html',
107                         controller: 'editAttributeController',
108                         resolve: {
109                                 message: function () {
110                                         var message = {
111                                                         attributeDictionaryDatas: $scope.editAttributeName
112                                         };
113                                         return message;
114                                 }
115                         }
116                 });
117                 modalInstance.result.then(function(response){
118                         console.log('response', response);
119                         $scope.attributeDictionaryDatas=response.attributeDictionaryDatas;
120                 });
121         };
122
123         $scope.editAttributeWindow = function(attributeDictionaryData) {
124                 $scope.editAttributeName = attributeDictionaryData;
125                 var modalInstance = $modal.open({
126                         backdrop: 'static', keyboard: false,
127                         templateUrl : 'add_Attribute_popup.html',
128                         controller: 'editAttributeController',
129                         resolve: {
130                                 message: function () {
131                                         var message = {
132                                                         attributeDictionaryData: $scope.editAttributeName
133                                         };
134                                         return message;
135                                 }
136                         }
137                 });
138                 modalInstance.result.then(function(response){
139                         console.log('response', response);
140                         $scope.attributeDictionaryDatas = response.attributeDictionaryDatas;
141                 });
142         };
143
144         $scope.deleteAttribute = function(data) {
145                 var uuu = "searchDictionary";
146                 var postData={data: data, type: "attribute"};
147                 var searchString = "\n";
148                 $.ajax({
149                         type : 'POST',
150                         url : uuu,
151                         dataType: 'json',
152                         contentType: 'application/json',
153                         data: JSON.stringify(postData),
154                         success : function(resultList){
155                                 $scope.$apply(function(){
156                                         $scope.list =resultList.result;});
157                                 $scope.searchData = JSON.stringify(resultList.result);
158                                 $scope.searchDatas = JSON.parse($scope.searchData);        
159                                 $scope.success = true;
160                                 var i;
161                                 if($scope.searchDatas.length > 0){
162                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
163                                                 searchString += $scope.searchDatas[i] + "\n";
164                                         }       
165                                 }else{
166                                         searchString += "No Policies is Using this Value"
167                                 }
168
169                                 console.log($scope.list);
170                                 if($scope.success){
171                                         modalService.popupConfirmWin("Confirm","You are about to delete the Attribute Dictionary :  "+data.xacmlId+". \n "+searchString+" \n Do you want to continue?",
172                                                         function(){
173                                                 var uuu = "deleteDictionary/attribute_dictionary/remove_attribute";
174                                                 var postData={data: data};
175                                                 $.ajax({
176                                                         type : 'POST',
177                                                         url : uuu,
178                                                         dataType: 'json',
179                                                         contentType: 'application/json',
180                                                         data: JSON.stringify(postData),
181                                                         success : function(data){
182                                                                 $scope.$apply(function(){$scope.attributeDictionaryDatas=data.attributeDictionaryDatas;});
183                                                         },
184                                                         error : function(data){
185                                                                 console.log(data);
186                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
187                                                         }
188                                                 });
189
190                                         })}
191                         },
192                         error : function(data){
193                                 alert("Error while Searching.");
194                         }
195                 });
196         };
197
198
199 });