[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / FWServiceListDictGridController.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('serviceListDictGridController', function ($scope, PolicyAppService, modalService, $modal){
21     $( "#dialog" ).hide();
22     
23     PolicyAppService.getData('getDictionary/get_ServiceListData').then(function (data) {
24         var j = data;
25         $scope.data = JSON.parse(j.data);
26         console.log($scope.data);
27         $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
28         console.log($scope.serviceListDictionaryDatas);
29     }, function (error) {
30         console.log("failed");
31     });
32
33     PolicyAppService.getData('getDictionary/get_ProtocolListData').then(function (data) {
34         var j = data;
35         $scope.data = JSON.parse(j.data);
36         console.log($scope.data);
37         $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas);
38         console.log($scope.protocolListDictionaryDatas);
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.serviceListDictionaryGrid.columnDefs[0].visible = false;
49                 $scope.gridApi.grid.refresh();
50         }else{
51                 $scope.serviceListDictionaryGrid.columnDefs[0].visible = true;
52                 $scope.gridApi.grid.refresh();
53         }
54     },function(error){
55         console.log("failed");
56     });
57
58     $scope.serviceListDictionaryGrid = {
59         data : 'serviceListDictionaryDatas',
60         enableFiltering: true,
61         exporterCsvFilename: 'ServiceList.csv',
62         enableGridMenu: true,
63         enableSelectAll: true,
64         columnDefs: [{
65             field: 'id', enableFiltering: false, headerCellTemplate: '' +
66             '<button id=\'New\' ng-click="grid.appScope.createNewFWServiceListWindow()" class="btn btn-success">' + 'Create</button>',
67             cellTemplate:
68             '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editFWServiceListWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
69             '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteFWServiceList(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
70         },{ field: 'serviceName', displayName : 'Service Name', sort: { direction: 'asc', priority: 0 }},
71             { field: 'serviceDescription' , displayName : 'Description'},
72             {field: 'serviceType', displayName : 'Service Type' },
73             {field: 'serviceTransProtocol', displayName : 'Transport Protocol'},
74             {field: 'serviceAppProtocol',displayName : 'APP Protocol'  },
75             {field: 'servicePorts',displayName : 'Ports'  }
76         ],
77         exporterMenuPdf: false,
78         exporterPdfDefaultStyle: {fontSize: 9},
79         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
80         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
81         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
82         exporterPdfFooter: function ( currentPage, pageCount ) {
83          return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
84         },
85         exporterPdfCustomFormatter: function ( docDefinition ) {
86          docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
87          docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
88          return docDefinition;
89         },
90         exporterPdfOrientation: 'portrait',
91         exporterPdfPageSize: 'LETTER',
92         exporterPdfMaxGridWidth: 500,
93         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
94         onRegisterApi: function(gridApi){
95                 $scope.gridApi = gridApi;
96         }
97     };
98
99     $scope.editServiceList = null;
100     $scope.createNewFWServiceListWindow = function(){
101         $scope.editServiceList = null;
102         var modalInstance = $modal.open({
103                 backdrop: 'static', keyboard: false,
104             templateUrl : 'add_FWServiceList_popup.html',
105             controller: 'editFWServiceListController',
106             resolve: {
107                 message: function () {
108                     var message = {
109                         serviceListDictionaryDatas: $scope.editServiceList
110                     };
111                     return message;
112                 }
113             }
114         });
115         modalInstance.result.then(function(response){
116             console.log('response', response);
117             $scope.serviceListDictionaryDatas=response.serviceListDictionaryDatas;
118         });
119     };
120
121     $scope.editFWServiceListWindow = function(serviceListDictionaryData) {
122         $scope.editServiceList = serviceListDictionaryData;
123         var modalInstance = $modal.open({
124                 backdrop: 'static', keyboard: false,
125             templateUrl : 'add_FWServiceList_popup.html',
126             controller: 'editFWServiceListController',
127             resolve: {
128                 message: function () {
129                     var message = {
130                         serviceListDictionaryData: $scope.editServiceList
131                     };
132                     return message;
133                 }
134             }
135         });
136         modalInstance.result.then(function(response){
137             console.log('response', response);
138             $scope.serviceListDictionaryDatas = response.serviceListDictionaryDatas;
139         });
140     };
141
142     $scope.deleteFWServiceList = function(data) {
143         modalService.popupConfirmWin("Confirm","You are about to delete the Service List  "+data.serviceName+". Do you want to continue?",
144             function(){
145                 var uuu =  "deleteDictionary/fw_dictionary/remove_serviceList";
146                 var postData={data: data};
147                 $.ajax({
148                     type : 'POST',
149                     url : uuu,
150                     dataType: 'json',
151                     contentType: 'application/json',
152                     data: JSON.stringify(postData),
153                     success : function(data){
154                         $scope.$apply(function(){$scope.serviceListDictionaryDatas=data.serviceListDictionaryDatas;});
155                     },
156                     error : function(data){
157                         console.log(data);
158                         modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
159                     }
160                 });
161
162             })
163     };
164
165 });