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