rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / performance / src / main / webapp / performance / js / curAlarmsController.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 refreshByCond;
17 var lang = 'en-US';
18
19 avalon.config({
20         interpolate: ["<!--", "-->"]
21 })
22
23 refreshByCond = function(){
24         vm.$initTable();
25 };
26
27 var vm = avalon.define({
28         $id: "curAlarmsController",
29         logType: 'secLog',
30         severity: '',
31         ackState: '',
32         filterState: '',
33         ruleType: 1,
34         curalarmsType: 'curalarms',
35         moreCondBtn: false,
36         showClear: true,
37         dataRangeLocationDisabled:true,
38         dataRangeTypeDisabled:true,
39         dataRangeCodeDisabled:true,
40         alCodeTree_affirm:false,
41         alLocationTree_affirm:false,
42         alarmCodeSelectedCount: 0,
43         alarmLocationSelectedCount: 0,
44         alarmTypeSelectedCount: 0,
45         tempHide:false,
46         treeIcons: [
47                 "ict-arrowRight",
48                 "ict-arrowLeft",
49                 "ict-selectLeft"
50         ],
51
52         severityTypes: [
53                 {id: '1', name: $.i18n.prop("ngict_fm_iui_curalarm_critical"), value: true, type: "severityTypes", class: "alarm-serious"},
54                 {id: '2', name: $.i18n.prop("ngict_fm_iui_curalarm_major"), value: true, type: "severityTypes", class: "alarm-important"},
55                 {id: '3', name: $.i18n.prop("ngict_fm_iui_curalarm_minor"), value: true, type: "severityTypes", class: "alarm-secondary"},
56                 {id: '4', name: $.i18n.prop("ngict_fm_iui_curalarm_warning"), value: true, type: "severityTypes", class: "alarm-slightly"}
57         ],
58
59         ackStateTypes: [
60                 {id: '1', name: $.i18n.prop("ngict_fm_iui_curalarm_ackAlarm"), value: false, type: "ackStateTypes"},
61                 {id: '2', name: $.i18n.prop("ngict_fm_iui_curalarm_unackAlarm"), value: true, type: "ackStateTypes"}
62         ],
63
64         filterStateTypes: [
65                 {id: '1', name: $.i18n.prop("ngict_fm_iui_curalarm_visible"), value: true, type: "filterStateTypes"},
66                 {id: '0', name: $.i18n.prop("ngict_fm_iui_curalarm_invisible"), value: false, type: "filterStateTypes"}
67         ],
68
69         alTypes:[
70                 "Communications Alarm",
71                 "Processing Error Alarm",
72                 "Quality of Service Alarm",
73                 "Equipment Alarm",
74                 "Environmental Alarm",
75                 "OMC Alarm",
76                 "Integrity Violation",
77                 "Operational Violation",
78                 "Physical Violation",
79                 "Security Violation",
80                 "Time Domain Violation"
81         ],
82
83         $alarmsTableFields: {
84                 curalarms: [
85                         {"mData": null,name: "<input id='dataTableCheckBox' type='checkBox'/>","sClass": 'details-check',"sWidth": '5%',"fnRender": alarmsUtil.checkBox},
86                         {"mData": "order", name: $.i18n.prop("ngict_fm_iui_curalarm_order"),"sClass": 'details-control', "sWidth": '6%'},
87                         {"mData": "id", sWidth : "10%",name: $.i18n.prop("ngict_fm_iui_curalarm_id"),"bVisible": true},
88                         {"mData": "position1DisplayName", sWidth : "10%",name:$.i18n.prop("ngict_fm_iui_curalarm_ne")},
89                         {"mData": "mocName",sWidth : "14%", name: $.i18n.prop("ngict_fm_iui_curalarm_moc")},
90                         {"mData": "probableCauseCodeNameAndCode",       sWidth : "14%",name: $.i18n.prop("ngict_fm_iui_curalarm_probableCauseCode")},
91                         {"mData": "alarmRaisedTime", sWidth : "15%",name: $.i18n.prop("ngict_fm_iui_curalarm_alarmRaisedTime"),"fnRender": alarmsUtil.timeRender},
92                         {"mData": "perceivedSeverity",sWidth : "10%", name: $.i18n.prop("ngict_fm_iui_curalarm_perceivedSeverity"),fnRender:alarmsUtil.Severity},
93                         {"mData": "alarmType",sWidth : "10%", name: $.i18n.prop("ngict_fm_iui_curalarm_alarmType"),"bVisible": false},
94                         {"mData": "ackState",sClass:"ackState",sWidth : "10%", name: $.i18n.prop("ngict_fm_iui_curalarm_ackState"),"fnRender":alarmsUtil.ackState},
95                         {"mData": "ackTime", sWidth : "13%",name: $.i18n.prop("ngict_fm_iui_curalarm_ackTime"),"fnRender": alarmsUtil.timeRender,"bVisible": false},
96                         {"mData": "position1", name: $.i18n.prop("ngict_fm_iui_curalarm_position1"),"bVisible": false},
97                         {"mData": "alarmChangedTime", name: $.i18n.prop("ngict_fm_iui_curalarm_alarmChangedTime"),"bVisible": false,"fnRender": alarmsUtil.timeRender},
98                         {"mData": "ackUserId", name: $.i18n.prop("ngict_fm_iui_curalarm_ackUserId"),"bVisible": false},
99                         {"mData": "ackSystemId", name: $.i18n.prop("ngict_fm_iui_curalarm_ackSystemId"),"bVisible": false},
100                         {"mData": "alarmClearedTime", name: $.i18n.prop("ngict_fm_iui_curalarm_alarmClearedTime"),"bVisible": false,"fnRender": alarmsUtil.timeRender},
101                         {"mData": "additionalText", name: $.i18n.prop("ngict_fm_iui_curalarm_additionalText"),"bVisible": false},
102                         {"mData": "ackSystemId", name: $.i18n.prop("ngict_fm_iui_curalarm_ackSystem"),"bVisible": false},
103                         {"mData": "clearUserId", name: $.i18n.prop("ngict_fm_iui_curalarm_clearUserId"),"bVisible": false},
104                         {"mData": "clearSystemId", name: $.i18n.prop("ngict_fm_iui_curalarm_clearSystemId"),"bVisible": false},
105                         {"mData": "clearType", name: $.i18n.prop("ngict_fm_iui_curalarm_clearType"),"bVisible": false},
106                         {"mData": "probableCauseCode", name: $.i18n.prop("ngict_fm_iui_curalarm_probableCauseCode"),"bVisible": false},
107                         {"mData": "specificProblem", name: $.i18n.prop("ngict_fm_iui_curalarm_specificProblem"),"bVisible": false},
108                         {"mData": "neIp", name: $.i18n.prop("ngict_fm_iui_curalarm_neIp"),"bVisible": false},
109                         {"mData": "pathIds", name: $.i18n.prop("ngict_fm_iui_curalarm_pathIds"),"bVisible": false},
110                         {"mData": "pathName", name: $.i18n.prop("ngict_fm_iui_curalarm_pathName"),"bVisible": false}
111                 ],
112         },
113
114         $language: {
115                 "sProcessing": "<img src='../common/thirdparty/data-tables/images/loading-spinner-grey.gif'/><span>&nbsp;&nbsp;处理中...</span>",
116                 "sLengthMenu": $.i18n.prop("ngict-fm-iui-table-sLengthMenu"),
117                 "sZeroRecords": $.i18n.prop("ngict-fm-iui-table-sZeroRecords"),
118                 "sInfo": "<span class='seperator'></span>" + $.i18n.prop("ngict-fm-iui-table-sInfo"),
119                 "sInfoEmpty": $.i18n.prop("ngict-fm-iui-table-sInfoEmpty"),
120                 "sGroupActions": $.i18n.prop("ngict-fm-iui-table-sGroupActions"),
121                 "sAjaxRequestGeneralError": $.i18n.prop("ngict-fm-iui-table-sAjaxRequestGeneralError"),
122                 "sEmptyTable": $.i18n.prop("ngict-fm-iui-table-sEmptyTable"),
123                 "oPaginate": {
124                         "sPrevious": $.i18n.prop("ngict-fm-iui-table-sPrevious"),
125                         "sNext": $.i18n.prop("ngict-fm-iui-table-sNext"),
126                         "sPage": $.i18n.prop("ngict-fm-iui-table-sPage"),
127                         "sPageOf": $.i18n.prop("ngict-fm-iui-table-sPageOf")
128                 }
129         },
130
131         $queryAlarmsInfoUrl: '/openoapi/umc/v1/fm/curalarms',
132         $saveCondUrl: '/web/rest/web/fm/rules?isc_dataFormat=json',
133         fmConds: {},
134         $sunburstSetting: {width: 450, height: 400},
135
136         $getLogCond: function(){
137                 var cond = {};
138                 var severitys = [];
139                 var ackState = [];
140                 var filterState = [];
141                 for (var i = 0; i < vm.severityTypes.length; i++) {
142                         vm.severityTypes[i].value ? severitys.push(vm.severityTypes[i].id) : null;
143                 };
144                 for (var i = 0; i < vm.ackStateTypes.length; i++) {
145                         vm.ackStateTypes[i].value ? cond.ackState = ackState.push(vm.ackStateTypes[i].id) : null;
146                 };
147                 for (var i = 0; i < vm.filterStateTypes.length; i++) {
148                         vm.filterStateTypes[i].value ? cond.filterState = filterState.push(vm.filterStateTypes[i].id) : null;
149                 };
150                 cond.severity = severitys;
151                 cond.ackState = ackState;
152                 cond.filterState = filterState;
153                 cond.location=vm.fmConds.location;
154                 cond.ackTimeStarTime = vm.fmConds.ackTimeStarTime;
155                 cond.ackTimeEndTime = vm.fmConds.ackTimeEndTime;
156                 cond.ackRelativeTime = vm.fmConds.ackRelativeTime;
157                 cond.ackTimeMode = vm.fmConds.ackTimeMode;
158                 cond.alarmRaisedStartTime = vm.fmConds.alarmRaisedStartTime;
159                 cond.alarmRaisedEndTime = vm.fmConds.alarmRaisedEndTime;
160                 cond.alarmRaisedRelativeTime = vm.fmConds.alarmRaisedRelativeTime;
161                 cond.alarmRaisedTimeMode = vm.fmConds.alarmRaisedTimeMode;
162                 cond.clearedTimeStarTime = vm.fmConds.clearedTimeStarTime;
163                 cond.clearedTimeEndTime = vm.fmConds.clearedTimeEndTime;
164                 cond.clearedTimeMode = vm.fmConds.clearedTimeMode;
165                 cond.probableCause = vm.fmConds.probableCause;
166                 cond.alarmType = vm.fmConds.alarmType;
167                 cond.ruleType = vm.ruleType;
168                 return cond;
169         },
170
171         $initRegister: function(){
172                 $('#alCode .condSelect').click(function(){
173                         $('#alCodeTree').modal('show');
174                 });
175
176                 $('#alCodeTree').on('hide.bs.modal', function(){
177                         $table = $("#selectedProbableCausesTreeTable");
178                         if(vm.alCodeTree_affirm===false){
179                                 $('#selectedProbableCausesTreeTable tbody').children().remove();
180                                 for(i=0;i<alarmTemp.length;i++){
181                                         $table.append(alarmTemp[i]);
182                                 }
183                         }
184                         vm.alCodeTree_affirm=false;
185                 });
186
187                 $('#alCodeTree').on('show.bs.modal', function(){
188                         vm.alCodeTree_affirm=false;
189                         alarmTemp=[];
190                         var $trs=$("#selectedProbableCausesTreeTable tr");
191                         if($trs.length!=0){
192                                 for(var i=0;i<$trs.length;i++){
193                                         alarmTemp.push($trs.eq(i)[0].outerHTML);
194                                 }
195                                 $('#selectedProbableCausesTreeTable td').on("click", function(){
196                                         var $tds = $('#selectedProbableCausesTreeTable td');
197                                         for (var i = 0; i < $tds.length; i++) {
198                                                 $tds.eq(i).removeClass('tallCellSelected');
199                                                 $tds.eq(i).parent().removeClass('checked');
200                                         }
201                                         $(this).addClass('tallCellSelected');
202                                         $(this).parent().addClass("checked");
203                                 });
204                         }       
205                 })
206
207                 $('#alType .condSelect').click(function(){
208                         $('#alTypeTree').modal('show');
209                 });
210
211                 //告警位置初始化
212                 $('#alLocation .condSelect').click(function(){
213                         $('#alLocationTree').modal('show');
214                 });
215
216                 $('#alLocationTree').on('hide.bs.modal', function(){
217                         $table = $("#selectedDeptTreeTable");
218                         if(vm.alLocationTree_affirm===false){
219                                 $('#selectedDeptTreeTable tbody').children().remove();
220                                 for(i=0;i<alarmTemp.length;i++){
221                                         $table.append(alarmTemp[i]);
222                                 }
223                         }
224                         vm.alLocationTree_affirm=false;
225                 });
226
227                 $('#alLocationTree').on('show.bs.modal', function(){
228                         vm.alLocationTree_affirm=false;
229                         alarmTemp=[];
230                         var $trs=$("#selectedDeptTreeTable tr");
231                         if($trs.length!=0){
232                                 for(var i=0;i<$trs.length;i++){
233                                         alarmTemp.push($trs.eq(i)[0].outerHTML);
234                                 }
235                         }
236                         $('#selectedDeptTreeTable td').on("click", function(){
237                                 var $tds = $('#selectedDeptTreeTable td');
238                                 for (var i = 0; i < $tds.length; i++) {
239                                         $tds.eq(i).removeClass('tallCellSelected');
240                                         $tds.eq(i).parent().removeClass('checked');
241                                 }
242                                 $(this).addClass('tallCellSelected');
243                                 $(this).parent().addClass("checked");
244                         });
245                 })
246
247                 $(document).on("click", function(e){ 
248                         var target = $(e.target);
249                         if(target.closest("#alLocationTree").length == 0 && target.closest("#alLocation .condSelect").length==0){
250                                 $("#alLocationTree").fadeOut();
251                         }
252                         if(target.closest("#alCodeTree").length == 0 && target.closest("#alCode .condSelect").length==0){
253                                 $('#alCodeTree').fadeOut();
254                         }
255                         if(target.closest("#alTypeTree").length == 0 && target.closest("#alType .condSelect").length==0){
256                                 $('#alTypeTree').fadeOut();
257                         }
258                 });
259
260                  //主表格确认
261                 $('#affirm').hover(function(){
262                         $('#affirmTrip').show();
263                 },function(){
264                         $('#affirmTrip').hide();
265                 });
266
267                 //主表格反确认
268                 $('#unAffirm').hover(function(){
269                         $('#unAffirmTrip').show();
270                 },function(){
271                         $('#unAffirmTrip').hide();
272                 });
273
274                  //初始化 checkBox
275                  $('.confirmTime input[type="radio"]').iCheck({
276                         radioClass: 'iradio_square-aero',
277                         increaseArea: '20%'
278                  });
279  
280                 //告警类型树的选项被选中时
281                 $('#selectedAlTypeTable input[type="checkBox"]').on("ifChecked", function(){
282                         $(this).parent().parent().addClass('tallCellSelected');
283                 });
284
285                 //告警类型未被选中时
286                  $('#selectedAlTypeTable input[type="checkBox"]').on("ifUnchecked", function(){
287                         $(this).parent().parent().removeClass('tallCellSelected');
288                 });
289         },
290
291         $initTable: function(){
292                 var setting = {};
293                 setting.language = vm.$language;
294                 setting.columns = vm.$alarmsTableFields[vm.curalarmsType];
295                 setting.restUrl = vm.$queryAlarmsInfoUrl;
296                 setting.tableId = "ict_alarms_table";
297                 serverPageTable.initDataTable(setting, vm.$getLogCond(), 'ict_alarms_table_div');
298         },
299
300         condChange: function(){
301                 refreshByCond();
302         },
303
304         moreCondClicked: function(){
305                 $('#moreCond').fadeToggle();
306                 var icon = $(this).children('span').eq(0);
307                 if ($(this).hasClass('blueactive')) {
308                         vm.moreCondBtn = false;
309                         icon.removeClass('borderBottom');
310                         icon.addClass('borderBotTop');
311                         $("div.fliterline").show();
312                 } else {
313                         vm.moreCondBtn = true;
314                         icon.removeClass('borderTop');
315                         icon.addClass('borderBottom');
316                         $("div.fliterline").hide();
317                 }
318         },
319
320         alarmsCondSave: function(){
321                 if ($('#saveCondId').val() != null && $.trim($('#saveCondId').val()) != '') {
322                         var name = $('#saveCondId').val();
323                         alarmsUtil.condSave(vm.$getLogCond(), vm.$saveCondUrl, name);
324                 }
325         },
326
327         saveModal: function(){
328                 $('#myModal').modal('show');
329         },
330
331         searchModal: function(){
332                 refreshByCond();
333         },
334
335         tabClicked: function(modelItem, item){
336                 if (!modelItem.value) {
337                         modelItem.value = true;
338                 } else {
339                         modelItem.value = false;
340                 }
341                 refreshByCond();
342         },
343
344         moveTreeNode: function(item){
345                  alarmsUtil.moveNode(item);
346         },
347
348         //告警位置——确认
349         deptTreeAffirm: function(){
350                 var selectName="";
351                 var locationObj=[];
352                 var $tds= $("#selectedDeptTreeTable td");
353                 for (var i = 0; i < $tds.length; i++) {
354                         var obj={};
355                         obj.id=$tds.eq(i).attr('nodeid');
356                         obj.oid=$tds.eq(i).attr('oid');
357                         locationObj.push(obj);
358                         if(i==0){
359                                 selectName+=$tds.eq(i).text();
360                         }else{
361                                 selectName+=","+$tds.eq(i).text();
362                         }
363                 };
364                 vm.fmConds.location=locationObj;
365                 vm.alarmLocationSelectedCount=locationObj.length;
366                 vm.alLocationTree_affirm=true;
367                 $('#alLocationTree').modal('hide')
368         },
369
370         //告警码树 确认
371         probableCausesTreeAffirm: function(){
372                 var selectName="";
373                 var probableCause=[];
374                 var $tds= $("#selectedProbableCausesTreeTable td");
375                 var systemType=[];
376                 for (var i = 0; i < $tds.length; i++) {
377                         var obj={};
378                         obj.codeid=$tds.eq(i).attr('codeid');
379                         obj.parentid=$tds.eq(i).attr('parentid');
380                         obj.type=$tds.eq(i).attr('type');
381                         probableCause.push(obj);
382                 };
383                 vm.fmConds.probableCause=probableCause;
384                 vm.alarmCodeSelectedCount = probableCause.length;
385                 vm.alCodeTree_affirm=true;
386                 $('#alCodeTree').modal('hide');
387         },
388
389         //告警类型 确认
390         alTypeTreeAffirm: function(){
391                 var selectName="";
392                 var alType=[];
393                 var $tds=$("#selectedAlTypeTable td.tallCellSelected");
394                 for (var i = 0; i < $tds.length; i++) {
395                         var obj={};
396                         alType.push(obj);
397                         if(i==0){
398                                 selectName+=$tds.eq(i).text();
399                         }else{
400                                 selectName+=","+$tds.eq(i).text();
401                         }
402                 };
403                 vm.fmConds.alType=alType;
404                 if(selectName!=""){
405                         $('#alType .condSelect :selected').text(selectName);
406                 }else{
407                         $('#alType .condSelect :selected').text("请选择告警类型");
408                 }
409                 vm.alarmTypeSelectedCount = alType.length;
410                 //$('#alTypeTree').fadeOut();
411                 $('#alTypeTree').modal('hide')
412         }
413 });
414
415 //初始化 告警类型
416 initAlTypeTable = function(){
417         var html = "";
418         for (var i = 0; i < vm.alTypes.length; i++) {
419                 html += "<tr><td><input type='checkbox'>" + vm.alTypes[i] + "</td></tr>";
420         };
421         $('#selectedAlTypeTable').append(html);
422 }
423
424 initPage = function(){
425         bootbox.setDefaults({
426                 locale: lang.replace("-", "_")
427         });
428         //自定义确认时间组件
429         alarmsUtil.setDateRange("daterangeConfirm", vm);
430         alarmsUtil.dateRangeEnableDisable("customAckTime");
431         //自定义发生时间组件
432         alarmsUtil.setDateRange("daterangeOccur", vm);
433         alarmsUtil.dateRangeEnableDisable("customRaisedTime");
434         //高级菜单界面中,对告警发生时间、确认时间、清除时间初始化
435         alarmsUtil.dateRangeCustom(vm);
436         //告警码树初始化
437         alarmsUtil.initTree();
438         //告警类型初始化
439         initAlTypeTable();
440         vm.$initRegister();
441         refreshByCond();
442         localStorage.setItem("curRuleDataId",0);
443 }
444
445 initPage();