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