rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / monitor / src / main / webapp / monitor / js / monitorSettingController.js
1 /*
2  * Copyright 2016-2017, CMCC Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 var vm = avalon
17                 .define({
18                         $id : "monitorController",
19                         server_rtn:{
20                                 info_block:false,
21                                 warning_block:false,
22                                 rtn_info:""
23                         },
24             resource:{
25                 monitorList:[]
26             },
27             ifPROXYIPChange:"",
28             monitorUrl:"",
29             oldmonitorInfo:{
30                 ipAddress:"",
31                 label:"",
32                 customPara:{
33
34                }     
35             },
36             monitorInfo:{
37                 oid:"",
38                 origin:"",
39                 neTypeId:"",
40                 label:"",
41                 ipAddress:"",
42                                 extendPara:"",
43                 customPara:{
44
45                }     
46             },
47             dataTableLanguage: {
48                 "sProcessing": "<img src='/openoui/common/thirdparty/data-tables/images/loading-spinner-grey.gif'/><span>&nbsp;&nbsp;Loadding...</span>",   
49                 "sLengthMenu": $.i18n.prop("openo-umc-monitor-iui-table-sLengthMenu"),
50                 "sZeroRecords": $.i18n.prop("openo-umc-monitor-iui-table-sZeroRecords"),
51                 "sInfo": "<span class='seperator'></span>" + $.i18n.prop("openo-umc-monitor-iui-table-sInfo"),
52                 "sInfoEmpty": $.i18n.prop("openo-umc-monitor-iui-table-sInfoEmpty"),
53                 "sGroupActions": $.i18n.prop("openo-umc-monitor-iui-table-sGroupActions"),
54                 "sAjaxRequestGeneralError": $.i18n.prop("openo-umc-monitor-iui-table-sAjaxRequestGeneralError"),
55                 "sEmptyTable": $.i18n.prop("openo-umc-monitor-iui-table-sEmptyTable"),
56                 "oPaginate": {
57                     "sPrevious": $.i18n.prop("openo-umc-monitor-iui-table-sPrevious"),
58                     "sNext": $.i18n.prop("openo-umc-monitor-iui-table-sNext"),
59                     "sPage": $.i18n.prop("openo-umc-monitor-iui-table-sPage"),
60                     "sPageOf": $.i18n.prop("openo-umc-monitor-iui-table-sPageOf")
61                 }
62             },
63
64                         $monitorListRestUrl :'/openoapi/umc/v1/monitor/monitorinfos',
65             $monitorInstanceRestUrl :'/openoapi/umc/v1/monitor/monitorinfo/',
66             $queryDacsRestUrl : '/openoapi/umc/v1/monitor/dacs',
67             $updateMonitorTaskRestUrl : '/openoapi/umc/v1/monitor/monitortask/',
68
69                         $loginProtocol:  {
70                selectItems : [
71                 {
72                     cond_value : 'SSH',
73                     name :"SSH"
74                 },                
75                 {
76                     cond_value : 'TELNET',
77                     name : "TELNET"
78                 }
79                 
80             ]
81         },
82         dac:  {
83                selectItems : []
84         },
85                 
86                 monitorSettingDlgInfo:{
87                 titleName:"",
88                 saveType:""
89         }, 
90                 queryMonitorList : function() {
91
92               $.ajax({
93                 "type": 'get',
94                 "url": vm.$monitorListRestUrl,   
95                 "dataType": "json",
96                 "success": function (resp) {
97                                         for(index in resp)
98                                         {
99                                                 var monitorInfo=resp[index]
100                                                 var customPara={};
101                                                 if(monitorInfo.customPara!=""){
102                                                         customPara=JSON.parse(monitorInfo.customPara);
103                                                         if(typeof(customPara.PROXYIP) == "undefined")
104                                                         {
105                                                                 customPara.PROXYIP="127.0.0.1";
106                                                         }
107                                                  }
108                                                  else{
109                                                          customPara={PROXYIP:"127.0.0.1"};
110                                                  }
111                                                  monitorInfo.customPara=customPara;
112                                         }
113
114                      vm.resource.monitorList = resp;
115
116                      $('#monitorManagerTable').DataTable({                    
117                       "oLanguage": vm.dataTableLanguage,
118                       "sDom": '<"top"rt><"bottom"lip>',
119                       "sPaginationType": "bootstrap_extended", 
120                       "bSort": false
121                     });
122
123                 },
124                  error: function(XMLHttpRequest, textStatus, errorThrown) {
125                        monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_query_list_errInfo')+errorThrown,"danger");
126                  }
127               
128               });
129                                   
130
131                 },
132         queryMonitorInstance : function(oid){
133
134             vm.monitorInfo.oid=oid;
135              vm.monitorUrl=vm.$monitorInstanceRestUrl+oid;
136
137              $.ajax({
138                 "type": 'GET',
139                 "url": vm.monitorUrl,   
140                 "dataType": "json",
141                 "success": function (resp) {
142
143                     var monitorInfo=resp;
144                                         var customPara={};
145                     if(monitorInfo.customPara!=""){
146                         customPara=JSON.parse(monitorInfo.customPara);
147                                                 if(typeof(customPara.PROXYIP) == "undefined")
148                                                 {
149                                                         customPara.PROXYIP="127.0.0.1";
150                                                 }
151                      }
152                                          else{
153                                                  customPara={PROXYIP:"127.0.0.1"};
154                                          }
155                                          monitorInfo.customPara=customPara;
156                      vm.monitorInfo=monitorInfo;
157                                          
158                      vm.oldmonitorInfo.ipAddress=monitorInfo.ipAddress;
159                      vm.oldmonitorInfo.label=monitorInfo.label;
160                      vm.oldmonitorInfo.customPara=customPara;
161
162                      
163
164                 },
165                  error: function(XMLHttpRequest, textStatus, errorThrown) {
166                        monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_query_monitor_errInfo')+errorThrown,"danger");
167                  }
168
169               
170               });
171
172         },
173                 
174                 deleteMonitorInfo : function(oid){
175             vm.monitorInfo.oid=oid;
176             vm.monitorUrl=vm.$monitorInstanceRestUrl+oid;
177
178              $.ajax({
179                 "type": 'DELETE',
180                 "url": vm.monitorUrl,   
181                 "dataType": "json",
182                 "success": function (resp) {
183                      vm.gotoMonitorListPage();
184                 },
185                  error: function(XMLHttpRequest, textStatus, errorThrown) {
186                        monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_query_monitor_errInfo')+errorThrown,"danger");
187                  }
188
189               
190               });
191
192         },
193                 updateMonitorSet:function(){
194
195
196                 vm.monitorSettingDlgInfo.titleName=$.i18n.prop('com_zte_openo_umc_monitor_btn_monitorset');
197                 vm.server_rtn.warning_block=false;
198                 vm.server_rtn.info_block=false;
199
200                 $(".form-group").each(function () {
201                         $(this).removeClass('has-success');
202                         $(this).removeClass('has-error');
203                         $(this).find(".help-block[id]").remove();
204                 });
205
206                 if(vm.monitorInfo.customPara.PROXYIP=="" && vm.dac.selectItems.length>0){
207                     vm.monitorInfo.customPara.PROXYIP=vm.dac.selectItems[0].ipAddress;
208                 }
209
210                 if(vm.monitorInfo.customPara.PROTOCOL==""){
211                     vm.monitorInfo.customPara.PROTOCOL="SSH";
212                     vm.monitorInfo.customPara.PORT="22";
213                 }
214
215                 $("#monitorSettingDlg").modal("show");
216         },
217         testMonitorSet:function(){
218            vm.server_rtn.warning_block=false;
219            vm.server_rtn.info_block=true;
220            vm.server_rtn.rtn_info="Monitor Set Access Test Pass";
221         },
222         saveMonitorSet : function() {
223             success.hide();
224             error.hide();
225             if (form.valid() == false) {
226                     return false;
227              }
228                         var propertyNames=vm.monitorInfo.customPara.$propertyNames.split("&shy;");
229                         var isPropertyUnEqual=false;
230                         for(index in propertyNames)
231                         {
232                                 var name=propertyNames[index]
233                                 if(vm.oldmonitorInfo.customPara[name]!=vm.monitorInfo.customPara[name])
234                                 {
235                                         isPropertyUnEqual=true;
236                                         break;
237                                 }
238                         }
239              // judge monitorInfo whether change
240              if( vm.oldmonitorInfo.ipAddress!=vm.monitorInfo.ipAddress ||
241             isPropertyUnEqual){
242
243              vm.server_rtn.warning_block=false;
244              vm.server_rtn.info_block=true;
245              vm.server_rtn.rtn_info=$.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_checkInfo');
246                         var customPara=JSON.stringify(vm.monitorInfo.customPara.$model);
247                     $.ajax({
248                     "type": 'POST',
249                     "url": vm.monitorUrl,
250                     "data": JSON.stringify({
251                              "ipAddress": vm.monitorInfo.ipAddress,
252                              "oid": vm.monitorInfo.oid,
253                                                          "neTypeId": vm.monitorInfo.neTypeId,
254                                                          "label": vm.monitorInfo.label,
255                                                          "origin": vm.monitorInfo.origin,
256                                                          "extendPara": vm.monitorInfo.extendPara,
257                              "customPara": customPara
258                         }),
259                     "dataType": "json",
260                     "contentType" : "application/json",
261                     success: function (resp) {  
262                          // judge PROXYIP whether change
263                          
264                          if(vm.oldmonitorInfo.customPara.PROXYIP!=vm.monitorInfo.customPara.PROXYIP){
265                                vm.ifPROXYIPChange=1;     
266                          }
267                          else{
268                                vm.ifPROXYIPChange=0;  
269                          }
270
271                          vm.updateMonitorTask();
272
273                         vm.oldmonitorInfo.ipAddress=vm.monitorInfo.ipAddress;
274                         vm.oldmonitorInfo.label=vm.monitorInfo.label;
275                                                 var customPara=vm.monitorInfo.customPara.$model;
276                         vm.oldmonitorInfo.customPara=customPara;
277
278
279                     },
280                      error: function(XMLHttpRequest, textStatus, errorThrown) {
281                         
282                            vm.server_rtn.warning_block=true;
283                            vm.server_rtn.info_block=false; 
284                            vm.server_rtn.rtn_info= $.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_save_failInfo')+errorThrown;                
285                      }
286              });
287
288              }
289              else if(vm.oldmonitorInfo.label!=vm.monitorInfo.label){
290                 //only change label label
291                 
292                 //save new monitorInfo
293           
294              vm.server_rtn.warning_block=false;
295              vm.server_rtn.info_block=true;
296              vm.server_rtn.rtn_info=$.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_checkInfo');
297                         var customPara=JSON.stringify(vm.monitorInfo.customPara.$model);
298
299                     $.ajax({
300                     "type": 'POST',
301                     "url": vm.monitorUrl,
302                     "data": JSON.stringify({
303                              "ipAddress": vm.monitorInfo.ipAddress,
304                              "oid": vm.monitorInfo.oid,
305                                                          "neTypeId": vm.monitorInfo.neTypeId,
306                                                          "label": vm.monitorInfo.label,
307                                                          "origin": vm.monitorInfo.origin,
308                                                          "extendPara": vm.monitorInfo.extendPara,
309                              "customPara": customPara
310                         }),
311                     "dataType": "json",
312                     "contentType" : "application/json",
313                     success: function (resp) {  
314                     if(resp.result=="SUCCESS"){
315
316                         vm.oldmonitorInfo.label=vm.monitorInfo.label;
317                         $('#monitorSettingDlg').modal('hide');                            
318                          monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_save_successInfo'),"success"); 
319
320                        
321                     }
322                     else{
323                            vm.server_rtn.warning_block=true;
324                            vm.server_rtn.info_block=false; 
325                            vm.server_rtn.rtn_info= $.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_save_failInfo'); 
326                         }
327
328                     },
329                      error: function(XMLHttpRequest, textStatus, errorThrown) {
330                         
331                            vm.server_rtn.warning_block=true;
332                            vm.server_rtn.info_block=false; 
333                            vm.server_rtn.rtn_info= $.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_save_failInfo')+errorThrown;                
334                      }
335                 });
336                 
337              }
338              else{
339                 //no change
340                  $('#monitorSettingDlg').modal('hide');                            
341                  monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_save_successInfo'),"success"); 
342              }
343              
344
345
346             
347
348         },
349         cancelMonitorSet: function() {
350
351             vm.monitorInfo.ipAddress=vm.oldmonitorInfo.ipAddress;
352             vm.monitorInfo.name=vm.oldmonitorInfo.name;
353             vm.monitorInfo.customPara=vm.oldmonitorInfo.customPara;
354              $('#monitorSettingDlg').modal('hide');   
355
356         },
357         queryDACs:function(){
358            
359
360             $.ajax({
361                     "type": 'get',
362                     "url":  vm.$queryDacsRestUrl,
363                     "dataType": "json",
364                     success: function (resp) {  
365                          vm.dac.selectItems = (resp==null)?[]:resp;  
366                          // vm.proxy.selectItems.sort(function(a,b){return a.ipAddress>b.ipAddress?1:-1});                 
367                     },
368                      error: function(XMLHttpRequest, textStatus, errorThrown) { 
369                            monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_dac_query_failInfo')+errorThrown,"danger");                    
370                      }                  
371                 });
372         },
373         updateMonitorTask:function(){
374             vm.server_rtn.warning_block=false;
375              vm.server_rtn.info_block=true;
376              vm.server_rtn.rtn_info=$.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_task_checkInfo');
377
378
379                      var data= JSON.stringify({
380                                 oid:vm.monitorInfo.oid,
381                                 moc:vm.monitorInfo.neTypeId,
382                                 proxyIp:vm.monitorInfo.customPara.PROXYIP
383                             });
384
385                    $.ajax({
386                     "type": 'PUT',
387                     "url": vm.$updateMonitorTaskRestUrl+vm.ifPROXYIPChange,
388                      "data" :data,
389                     "dataType": "json",
390                     "contentType":"application/json",
391                     success: function (resp) {  
392                         if(resp.result=="SUCCESS"){
393                          
394                         $('#monitorSettingDlg').modal('hide');                            
395                          monitorUtil.growl($.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_save_successInfo'),"success"); 
396
397                         }
398                         else
399                         {
400                                vm.server_rtn.warning_block=true;
401                                vm.server_rtn.info_block=false; 
402                                vm.server_rtn.rtn_info= $.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_task_failInfo')+resp.info;     
403                         }
404
405                     },
406                      error: function(XMLHttpRequest, textStatus, errorThrown) {
407                         
408                            vm.server_rtn.warning_block=true;
409                            vm.server_rtn.info_block=false; 
410                            vm.server_rtn.rtn_info= $.i18n.prop('com_zte_openo_umc_monitor_monitorsetting_monitor_task_failInfo')+errorThrown;                
411                           
412                      }
413                 });
414                
415         },
416                 gotoDACPage:function(){
417                         window.location.href="dacList.html";
418                 },      
419                 gotoMonitorSettingPage:function(oid){
420                         window.location.href="monitorSetting.html?"+oid;
421                 },         
422                 gotoMonitorListPage:function(){
423                         window.location.href="monitorSettingList.html";
424                 }          
425         });
426
427 avalon.scan();
428
429