Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / FWTermListDictController.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 var editFWTermListController =  function ($scope, $modalInstance, message, FWDictionaryService, PapUrlService, UserInfoService, Notification){
24          $scope.fromZonechoices = [];
25      $scope.toZonechoices = [];
26      $scope.sourceListchoices = [];
27      $scope.destinationListchoices = [];
28      $scope.sourceServicechoices = [];
29      $scope.destinationServicechoices = [];
30      $scope.actionListchoices = [];
31     if(message.termListDictionaryData==null){
32         $scope.label='Add Term List Name'
33     }else{
34         $scope.label='Edit Term List Name'
35         $scope.disableCd=true; 
36         var fromZoneheaders = message.termListDictionaryData.fromZone;
37         var splitFromZone = ',';
38         if(fromZoneheaders != null){
39                 if (fromZoneheaders.indexOf(splitFromZone) >= 0) {
40                         var splitFromZoneValue = fromZoneheaders.split(splitFromZone);
41                         for(i = 0; i < splitFromZoneValue.length; i++){
42                                 var key  = splitFromZoneValue[i];
43                                 $scope.fromZonechoices.push({'id':'choice'+i+1, 'option': key});
44                         }
45                 }else{
46                  var key  = fromZoneheaders;
47                  $scope.fromZonechoices.push({'id':'choice'+1, 'option': key});
48             }
49         }
50         
51         var toZoneheaders = message.termListDictionaryData.toZone;
52         var splitToZone = ',';
53         if(toZoneheaders != null){
54                 if (toZoneheaders.indexOf(splitToZone) >= 0) {
55                         var splitToZoneValue = toZoneheaders.split(splitToZone);
56                         for(i = 0; i < splitToZoneValue.length; i++){
57                                 var key  = splitToZoneValue[i];
58                                 $scope.toZonechoices.push({'id':'choice'+i+1, 'option': key});
59                         }
60                 }else{
61                  var key  = toZoneheaders;
62                  $scope.toZonechoices.push({'id':'choice'+1, 'option': key});
63             }
64         }
65         
66         var srcIPheaders = message.termListDictionaryData.srcIPList;
67         var splitSrcIP = ',';
68         if(srcIPheaders != null){
69                 if (srcIPheaders.indexOf(splitSrcIP) >= 0) {
70                         var splitSrcIPValue = srcIPheaders.split(splitSrcIP);
71                         for(i = 0; i < splitSrcIPValue.length; i++){
72                                 var key  = splitSrcIPValue[i];
73                                 $scope.sourceListchoices.push({'id':'choice'+i+1, 'option': key});
74                         }
75                 }else{
76                  var key  = srcIPheaders;
77                  $scope.sourceListchoices.push({'id':'choice'+1, 'option': key});
78             }
79         }
80         
81         var desIPheaders = message.termListDictionaryData.destIPList;
82         var splitDesIP = ',';
83         if(desIPheaders != null){
84                 if (desIPheaders.indexOf(splitDesIP) >= 0) {
85                         var splitDestIPValue = desIPheaders.split(splitDesIP);
86                         for(i = 0; i < splitDestIPValue.length; i++){
87                                 var key  = splitDestIPValue[i];
88                                 $scope.destinationListchoices.push({'id':'choice'+i+1, 'option': key});
89                         }
90                 }else{
91                  var key  = desIPheaders;
92                  $scope.destinationListchoices.push({'id':'choice'+1, 'option': key});
93             }
94         }
95         
96         var srcServheaders = message.termListDictionaryData.srcPortList;
97         var splitSrcServ = ',';
98         if(srcServheaders != null){
99                 if (srcServheaders.indexOf(splitSrcServ) >= 0) {
100                         var splitSrcServValue = srcServheaders.split(splitSrcServ);
101                         for(i = 0; i < splitSrcServValue.length; i++){
102                                 var key  = splitSrcServValue[i];
103                                 $scope.sourceServicechoices.push({'id':'choice'+i+1, 'option': key});
104                         }
105                 }else{
106                  var key  = srcServheaders;
107                  $scope.sourceServicechoices.push({'id':'choice'+1, 'option': key});
108             }
109         }
110         
111         var desServheaders = message.termListDictionaryData.destPortList;
112         var splitdesSer = ',';
113         if(desServheaders != null){
114                 if (desServheaders.indexOf(splitdesSer) >= 0) {
115                         var splitDesSerValue = desServheaders.split(splitdesSer);
116                         for(i = 0; i < splitDesSerValue.length; i++){
117                                 var key  = splitDesSerValue[i];
118                                 $scope.destinationServicechoices.push({'id':'choice'+i+1, 'option': key});
119                         }
120                 }else{
121                  var key  = desServheaders;
122                  $scope.destinationServicechoices.push({'id':'choice'+1, 'option': key});
123             }
124         }
125         
126         var actionheaders = message.termListDictionaryData.action;
127         var splitAction = ',';
128         if(actionheaders != null){
129                 if (actionheaders.indexOf(splitAction) >= 0) {
130                         var splitActionValue = actionheaders.split(splitAction);
131                         for(i = 0; i < splitActionValue.length; i++){
132                                 var key  = splitActionValue[i];
133                                 $scope.actionListchoices.push({'id':'choice'+i+1, 'option': key});
134                         }
135                 }else{
136                  var key  = actionheaders;
137                  $scope.actionListchoices.push({'id':'choice'+1, 'option': key});
138             }
139         }
140     }
141         
142         var papUrl;
143         PapUrlService.getPapUrl().then(function(data) {
144                 var config = data;
145                 papUrl = config.PAP_URL;
146                 console.log(papUrl);
147                 
148                 FWDictionaryService.getPrefixListDictionaryDataByName(papUrl).then(function (data) {
149                 var j = data;
150                 $scope.data = JSON.parse(j.data);
151                 console.log($scope.data);
152                 $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas);
153                 console.log($scope.prefixListDictionaryDatas);
154             }, function (error) {
155                 console.log("failed");
156             });
157             
158             FWDictionaryService.getZoneDictionaryDataByName(papUrl).then(function (data) {
159                 var j = data;
160                 $scope.data = JSON.parse(j.data);
161                 console.log($scope.data);
162                 $scope.zoneDictionaryDatas = JSON.parse($scope.data.zoneDictionaryDatas);
163                 console.log($scope.zoneDictionaryDatas);
164             }, function (error) {
165                 console.log("failed");
166             });
167             
168             FWDictionaryService.getAddressGroupDictionaryDataByName(papUrl).then(function (data) {
169                 var j = data;
170                 $scope.data = JSON.parse(j.data);
171                 console.log($scope.data);
172                 $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas);
173                 console.log($scope.addressGroupDictionaryDatas);
174             }, function (error) {
175                 console.log("failed");
176             });
177             
178             FWDictionaryService.getServiceListDictionaryDataByName(papUrl).then(function (data) {
179                 var j = data;
180                 $scope.data = JSON.parse(j.data);
181                 console.log($scope.data);
182                 $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
183                 console.log($scope.serviceListDictionaryDatas);
184             }, function (error) {
185                 console.log("failed");
186             });
187             
188             FWDictionaryService.getServiceGroupDictionaryDataByName(papUrl).then(function (data) {
189                 var j = data;
190                 $scope.data = JSON.parse(j.data);
191                 console.log($scope.data);
192                 $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas);
193                 console.log($scope.serviceGroupDictionaryDatas);
194             }, function (error) {
195                 console.log("failed");
196             });
197             
198             FWDictionaryService.getActionListDictionaryDataByName(papUrl).then(function (data) {
199                 var j = data;
200                 $scope.data = JSON.parse(j.data);
201                 console.log($scope.data);
202                 $scope.actionListDictionaryDatas = JSON.parse($scope.data.actionListDictionaryDatas);
203                 console.log($scope.actionListDictionaryDatas);
204             }, function (error) {
205                 console.log("failed");
206             });
207         });
208         
209         /*getting user info from session*/
210         var loginId = null;
211         UserInfoService.getFunctionalMenuStaticDetailSession()
212                 .then(function (response) {                     
213                         loginId = response.userid;              
214          });
215         
216     $scope.editTermList = message.termListDictionaryData;
217
218     $scope.saveTermName = function(termListDictionaryData) {
219         var mergeFromZoneData = extend(termListDictionaryData, $scope.fromZoneDatas[0]);
220         var mergeToData = extend(mergeFromZoneData, $scope.toZoneDatas[0]);
221         var mergeSourceListData = extend(mergeToData, $scope.sourceListDatas[0]);
222         var mergeDListData = extend(mergeSourceListData, $scope.destinationListDatas[0]);
223         var mergeSServicesData = extend(mergeDListData, $scope.sourceServicesDatas[0]);
224         var mergeDServicesData = extend(mergeSServicesData, $scope.destinationServicesDatas[0]);
225         var finalData = extend(mergeDServicesData, $scope.actionListDatas[0]);
226         var uuu = papUrl + "/ecomp/fw_dictionary/save_termList.htm";
227         var postData={termListDictionaryData: finalData, loginId: loginId};
228         $.ajax({
229             type : 'POST',
230             url : uuu,
231             dataType: 'json',
232             contentType: 'application/json',
233             data: JSON.stringify(postData),
234             success : function(data){
235                 $scope.$apply(function(){
236                     $scope.termListDictionaryDatas=data.termListDictionaryDatas;});
237                 if($scope.termListDictionaryDatas == "Duplicate"){
238                         Notification.error("FW TermList Dictionary exists with Same Term Name.")
239                 }else{      
240                         console.log($scope.termListDictionaryDatas);
241                     $modalInstance.close({termListDictionaryDatas:$scope.termListDictionaryDatas});
242                 }
243             },
244             error : function(data){
245                 alert("Error while saving.");
246             }
247         });
248     };
249
250     $scope.close = function() {
251         $modalInstance.close();
252     };
253     
254     
255     function extend(obj, src) {
256         for (var key in src) {
257             if (src.hasOwnProperty(key)) obj[key] = src[key];
258         }
259         return obj;
260     }
261     
262     $scope.fromZoneDatas = [{"fromZoneDatas" : $scope.fromZonechoices}];
263     $scope.addFromZoneNewChoice = function() {
264         var newItemNo = $scope.fromZonechoices.length+1;
265         $scope.fromZonechoices.push({'id':'choice'+newItemNo});
266     };
267     $scope.removeFromZoneChoice = function() {
268         var lastItem = $scope.fromZonechoices.length-1;
269         $scope.fromZonechoices.splice(lastItem);
270     };
271     
272     $scope.toZoneDatas = [{"toZoneDatas" : $scope.toZonechoices}];
273     $scope.addToZoneNewChoice = function() {
274         var newItemNo = $scope.toZonechoices.length+1;
275         $scope.toZonechoices.push({'id':'choice'+newItemNo});
276     };
277     $scope.removeToZoneChoice = function() {
278         var lastItem = $scope.toZonechoices.length-1;
279         $scope.toZonechoices.splice(lastItem);
280     };
281     
282     $scope.sourceListDatas = [{"sourceListDatas" : $scope.sourceListchoices}];
283     $scope.addSourceListNewChoice = function() {
284         var newItemNo = $scope.sourceListchoices.length+1;
285         $scope.sourceListchoices.push({'id':'choice'+newItemNo});
286     };
287     $scope.removeSourceListChoice = function() {
288         var lastItem = $scope.sourceListchoices.length-1;
289         $scope.sourceListchoices.splice(lastItem);
290     };
291     
292     $scope.destinationListDatas = [{"destinationListDatas" : $scope.destinationListchoices}];
293     $scope.addDListNewChoice = function() {
294         var newItemNo = $scope.destinationListchoices.length+1;
295         $scope.destinationListchoices.push({'id':'choice'+newItemNo});
296     };
297     $scope.removeDlistChoice = function() {
298         var lastItem = $scope.destinationListchoices.length-1;
299         $scope.destinationListchoices.splice(lastItem);
300     };
301     
302     $scope.sourceServicesDatas = [{"sourceServiceDatas" : $scope.sourceServicechoices}];
303     $scope.addSourceServiceNewChoice = function() {
304         var newItemNo = $scope.sourceServicechoices.length+1;
305         $scope.sourceServicechoices.push({'id':'choice'+newItemNo});
306     };
307     $scope.removeSourceServiceChoice = function() {
308         var lastItem = $scope.sourceServicechoices.length-1;
309         $scope.sourceServicechoices.splice(lastItem);
310     };
311     
312     $scope.destinationServicesDatas = [{"destinationServiceDatas" : $scope.destinationServicechoices}];
313     $scope.addDServicesNewChoice = function() {
314         var newItemNo = $scope.destinationServicechoices.length+1;
315         $scope.destinationServicechoices.push({'id':'choice'+newItemNo});
316     };
317     $scope.removeDServicesChoice = function() {
318         var lastItem = $scope.destinationServicechoices.length-1;
319         $scope.destinationServicechoices.splice(lastItem);
320     };
321     
322     $scope.actionListDatas = [{"actionListDatas" : $scope.actionListchoices}];
323     $scope.addActionListNewChoice = function() {
324         var newItemNo = $scope.actionListchoices.length+1;
325         $scope.actionListchoices.push({'id':'choice'+newItemNo});
326     };
327     $scope.removeActionListChoice = function() {
328         var lastItem = $scope.actionListchoices.length-1;
329         $scope.actionListchoices.splice(lastItem);
330     };
331 }