[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / FWTermListDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP 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('termListDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22                 
23     PolicyAppService.getData('getDictionary/get_TermListData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas);
28         console.log($scope.termListDictionaryDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32
33     PolicyAppService.getData('getDictionary/get_TagListData').then(function (data) {
34         var j = data;
35         $scope.data = JSON.parse(j.data);
36         console.log($scope.data);
37         $scope.fwTagDictionaryDatasByName = JSON.parse($scope.data.fwTagDictionaryDatas);
38         console.log($scope.fwTagDictionaryDatasByName);
39     }, function (error) {
40         console.log("failed");
41     });
42
43     PolicyAppService.getData('get_LockDownData').then(function(data){
44         var j = data;
45         $scope.data = JSON.parse(j.data);
46         $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
47         if($scope.lockdowndata[0].lockdown == true){
48                 $scope.termListDictionaryGrid.columnDefs[0].visible = false;
49                 $scope.gridApi.grid.refresh();
50         }else{
51                 $scope.termListDictionaryGrid.columnDefs[0].visible = true;
52                 $scope.gridApi.grid.refresh();
53         }
54     },function(error){
55         console.log("failed");
56     });
57         
58     $scope.termListDictionaryGrid = {
59         data : 'termListDictionaryDatas',
60         enableFiltering: true,
61         exporterCsvFilename: 'TermList.csv',
62         enableGridMenu: true,
63         enableSelectAll: true,
64         columnDefs: [{
65             field: 'id', enableFiltering: false, headerCellTemplate: '' +
66             '<button id=\'New\' ng-click="grid.appScope.createNewFWTermListWindow()" class="btn btn-success">' + 'Create</button>',
67             cellTemplate:
68             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editFWTermListWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
69             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteFWTermList(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
70         },{ field: 'termName', displayName : 'Term-Name', sort: { direction: 'asc', priority: 0 }},
71             { field: 'termDescription', displayName : 'Term-Description' },
72             { field: 'fromZone', displayName : 'From Zone' },
73             {field: 'toZone', displayName : 'To Zone' },
74             {field: 'srcIPList', displayName : 'Source-IP-List'},
75             {field: 'destIPList',displayName : 'Destination-IP-List' },
76             {field: 'srcPortList',displayName : 'Source-Port-List' },
77             {field: 'destPortList',displayName : 'Destination-Port-List' },
78             {field: 'action',displayName : 'Action List' },
79             {field: 'userCreatedBy.userName',displayName : 'Created By'  },
80             {field: 'userModifiedBy.userName',displayName : 'Modified By'},
81             {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''  },
82             {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''  }
83         ],
84         exporterMenuPdf: false,
85         exporterPdfDefaultStyle: {fontSize: 9},
86         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
87         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
88         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
89         exporterPdfFooter: function ( currentPage, pageCount ) {
90          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
91         },
92         exporterPdfCustomFormatter: function ( docDefinition ) {
93          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
94          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
95          return docDefinition;
96         },
97         exporterFieldCallback: function(grid, row, col, input) {
98                         if( col.name == 'createdDate' || col.name == 'modifiedDate') {
99                                 var date = new Date(input);
100                                 return date.toString("yyyy-MM-dd HH:MM:ss a");
101                         } else {
102                                 return input;
103                         }
104                 },
105         exporterPdfOrientation: 'portrait',
106         exporterPdfPageSize: 'LETTER',
107         exporterPdfMaxGridWidth: 500,
108         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
109         onRegisterApi: function(gridApi){
110                 $scope.gridApi = gridApi;
111         }
112     };
113
114     $scope.editTermList = null;
115     $scope.createNewFWTermListWindow = function(){
116         $scope.editTermList = null;
117         var modalInstance = $modal.open({
118                 backdrop: 'static', keyboard: false,
119             templateUrl : 'add_fwTermList_popup.html',
120             controller: 'editFWTermListController',
121             resolve: {
122                 message: function () {
123                     var message = {
124                         termListDictionaryDatas: $scope.editTermList
125                     };
126                     return message;
127                 }
128             }
129         });
130         modalInstance.result.then(function(response){
131             console.log('response', response);
132             $scope.termListDictionaryDatas=response.termListDictionaryDatas;
133         });
134     };
135
136     $scope.editFWTermListWindow = function(termListDictionaryData) {
137         $scope.editTermList = termListDictionaryData;
138         var modalInstance = $modal.open({
139                 backdrop: 'static', keyboard: false,
140             templateUrl : 'add_fwTermList_popup.html',
141             controller: 'editFWTermListController',
142             resolve: {
143                 message: function () {
144                     var message = {
145                         termListDictionaryData: $scope.editTermList
146                     };
147                     return message;
148                 }
149             }
150         });
151         modalInstance.result.then(function(response){
152             console.log('response', response);
153             $scope.termListDictionaryDatas = response.termListDictionaryDatas;
154         });
155     };
156
157     $scope.deleteFWTermList = function(data) {
158         modalService.popupConfirmWin("Confirm","You are about to delete the TermList  "+data.termName+". Do you want to continue?",
159             function(){
160                 var uuu = "deleteDictionary/fw_dictionary/remove_termList";
161                 var postData={data: data};
162                 $.ajax({
163                     type : 'POST',
164                     url : uuu,
165                     dataType: 'json',
166                     contentType: 'application/json',
167                     data: JSON.stringify(postData),
168                     success : function(data){
169                         $scope.$apply(function(){$scope.termListDictionaryDatas=data.termListDictionaryDatas;});
170                     },
171                     error : function(data){
172                         console.log(data);
173                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
174                     }
175                 });
176
177             })
178     };
179
180
181 });