/*
* Copyright 2016, CMCC Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var alarmsUtil = {};
var alarmTemp=[];
alarmsUtil.timeRender = function (obj) {
if (obj.aData[obj.mDataProp] == -1 || obj.aData[obj.mDataProp] == 0) {
return "";
} else {
var date = new Date(obj.aData[obj.mDataProp]);
return commonUtil.parseDate(date, 'yyyy-MM-dd hh:mm:ss');
}
};
alarmsUtil.LinkRender = function (obj) {
return '' + obj.aData[obj.mDataProp] + '';
};
alarmsUtil.ackState = function (obj) {
var innerHtml = "";
var ackState = obj.aData.ackState;
var alarmId = obj.aData.id;
var alarmIdArr = [alarmId];
var tableId="\'" + obj.oSettings.sTableId + "\'";
var divId="\'" + obj.oSettings.nTableWrapper.parentElement.id + "\'";
if (ackState == "1" && vm.ruleType == 1) {
innerHtml = "Acknowledge";
} else if(ackState == "1" && vm.ruleType == 2){
innerHtml = "
";
}
}
return innerHtml;
};
alarmsUtil.refresh = function () {
refreshByCond();
}
/*
1.确认
2.反确认
*/
alarmsUtil.loopAffirm = function (type) {
var checkArr = $('#ict_alarms_table_div .details-check input[type="checkbox"]');
var aidArr = [];
for (var i = 0; i < checkArr.length; i++) {
if($(checkArr[i]).prop("checked")){
if ($(checkArr[i]).attr('alarmId') != 'undefined' && $(checkArr[i]).attr('alarmId') != null) {
aidArr.push($(checkArr[i]).attr('alarmId'));
}
}
}
if (type == "1" && aidArr.length > 0) {
alarmsUtil.affirm(aidArr);
} else if (type == "2" && aidArr.length > 0) {
alarmsUtil.unaffirm(aidArr);
}
}
/*
*/
alarmsUtil.loopDelAralms = function () {
var checkArr = $('#ict_alarms_table_div .details-check input[type="checkbox"]');
var aidArr = [];
for (var i = 0; i < checkArr.length; i++) {
if($(checkArr[i]).prop("checked")){
if ($(checkArr[i]).attr('alarmId') != 'undefined' && $(checkArr[i]).attr('alarmId') != null) {
aidArr.push($(checkArr[i]).attr('alarmId'));
}
}
}
if (aidArr.length > 0) {
bootbox.confirm('Are you sure to delete alarm(s)', function (result) {
if (result) {
var sSource = "/openoapi/umc/v1/fm/curalarms?request={\"ids\":["+ aidArr +"]}";
$.ajax({
type : "DELETE",
dataType : "json",
contentType : 'application/json; charset=utf-8',
url : sSource,
data : null,
async : false,
success : function (msg) {
setTimeout(function () {
refreshByCond()
}, 500);
}
});
}
});
}
}
alarmsUtil.affirm = function (alarmIdArr,tableId,divId) {
var getData = {};
var request = {};
request.ids=[];
for(i=0;i
';
return innerHtml;
}
//初始化告警码树
alarmsUtil.initProbableCausesTree = function () {
//zTree设置
var setting = {
view : {
selectedMulti : false, //设置是否可以同时选中多个借点。
showIcon : true, //不显示图标
showLine : false, //是否显示节点之间的连线
},
data : {
simpleData : {
enable : true //如果设置为 true,请务必设置 setting.data.simpleData 内的其他参数: idKey / pIdKey / rootPId,并且让数据满足父子关系。
}
},
callback : {
onExpand : zTreeOnExpand, //每次节点展开后触发的事件。
onCollapse : zTreeOnCollapse,
//onClick: zTreeOnClick
}
};
var probableCausesNodes;
//获取告警码树数据
getProbableCausesTreeNodes("");
//创建告警码树
$.fn.zTree.init($("#probableCausesTree"), setting, probableCausesNodes);
//获取所有现有的tree节点
var treeObj = $.fn.zTree.getZTreeObj("probableCausesTree");
initDataAtTree();
function initDataAtTree(){
getAllNodesWithoutTypeEqual2("")
};
function getAllNodesWithoutTypeEqual2(parentId){
var treeNodes=treeObj.getNodesByParam("parentId", parentId, null);
for(var i=0;i
" + text + "";
} else if (treeType == "probableCausesTree") {
parentId = treeNodes[i].parentId;
type = treeNodes[i].type;
htmlStr = "" + text + " |
";
}
if(treeType == "probableCausesTree"){
if(treeNodes[i].type === 2){
for(i=0;i 0) {
var severity = '{ "type": "Severity", "data": [{"severity": "' + cond.severity + '"}]}'; //级别
var severityObj = window.JSON.parse(severity)
conds.push(severityObj);
}
if (cond.ackState != null && cond.ackState != "undefined") {
var ackState = '{ "type": "AckState", "data": [{"ackState": "' + cond.ackState + '"}]}'; //级别
var ackStateObj = window.JSON.parse(ackState)
conds.push(ackStateObj);
}
if (cond.filterState != null && cond.filterState != "undefined") {
var filterState = '{ "type": "FilterState", "data": [{"filterState": "' + cond.filterState + '"}]}'; //级别
var filterStateObj = window.JSON.parse(filterState)
conds.push(filterStateObj);
}
if (cond.ackTimeStarTime != null && cond.ackTimeStarTime != "undefined") {
var ackTime = '{ "type": "AckTime", "data": [{"mode":"0","start":"' + cond.ackTimeStarTime + '","end":"' + cond.ackTimeEndTime + '" }]}'; //级别
var ackTimeObj = window.JSON.parse(ackTime)
conds.push(ackTimeObj);
}
if (cond.alarmRaisedStartTime != null && cond.alarmRaisedStartTime != "undefined") {
var alarmRaisedTime = '{ "type": "RaisedTime", "data": [{"mode":"0","start":"' + cond.alarmRaisedStartTime + '","end":"' + cond.alarmRaisedEndTime + '" }]}'; //级别
var alarmRaisedTimeObj = window.JSON.parse(alarmRaisedTime)
conds.push(alarmRaisedTimeObj);
}
if (cond.clearedTimeStarTime != null && cond.clearedTimeStarTime != "undefined") {
var clearedTime = '{ "type": "ClearedTime", "data": [{"mode":"0","start":"' + cond.clearedTimeStarTime + '","end":"' + cond.clearedTimeEndime + '" }]}'; //级别
var severityObj = window.JSON.parse(clearedTime)
conds.push(severityObj);
}
var resJsonObj = AlarmConds.parseActiveConds2JSon(conds);
resJsonObj.rule.name = name;
resJsonObj.rule.ruleType = vm.ruleType;
var resStr = window.JSON.stringify(resJsonObj);
var dataSource = "isc_AosRestDataSource_1";
var operationType = "add";
var data1 = {
dataSource : dataSource,
operationType : operationType,
data : resJsonObj,
oldValues : null
};
$.ajax({
dataType : "json",
type : "POST",
contentType : 'application/json; charset=utf-8',
url : saveUrl,
data : JSON.stringify(data1),
async : false,
success : function (msg) {
$('#saveModalCancle').trigger("click");
}
});
}
Array.prototype.contains = function (item) {
return RegExp("(^|,)" + item.toString() + "($|,)").test(this);
};
/*
@param alarmsType 1当前告警 2历史告警
@param condRuleId 查询条件的RuleId
*/
alarmsUtil.queryByParma = function (alarmsType, condRuleId) {
//1.判断是当前告警还是历史告警。
var sourceUrl;
if (alarmsType == 1) { //当前告警
sourceUrl = '/web/rest/web/fm/curqueryview?' + 'data={"ruleType":1,"ruleSort":1}&isc_flag=smartClient&_operationType=fetch&_startRow=0&_endRow=75&_textMatchStyle=exact&_componentId=condList&_dataSource=isc_RestDataSource_7&isc_metaDataPrefix=_&isc_dataFormat=json';
vm.ruleType = 1;
vm.$queryAlarmsInfoUrl = "/ngict/rest/fm/curalarms";
vm.curalarmsType = "curalarms";
vm.showClear = true; //清除按钮
} else if(alarmsType == 2){ //历史告警
sourceUrl = '/web/rest/web/fm/curqueryview?' + 'data={"ruleType":2,"ruleSort":1}&isc_flag=smartClient&_operationType=fetch&_startRow=0&_endRow=75&_textMatchStyle=exact&_componentId=condList&_dataSource=isc_RestDataSource_7&isc_metaDataPrefix=_&isc_dataFormat=json';
vm.ruleType = 2;
vm.$queryAlarmsInfoUrl = "/ngict/rest/fm/hisalarms";
vm.hisalarmsType = "hisalarms";
vm.showClear = false; //清除按钮
}else if(alarmsType == 3){ //通知
sourceUrl = '/web/rest/web/fm/curqueryview?' + 'data={"ruleType":2,"ruleSort":1}&isc_flag=smartClient&_operationType=fetch&_startRow=0&_endRow=75&_textMatchStyle=exact&_componentId=condList&_dataSource=isc_RestDataSource_7&isc_metaDataPrefix=_&isc_dataFormat=json';
vm.ruleType = 3;
vm.$queryAlarmsInfoUrl = "/ngict/rest/fm/notify";
vm.notificationType = "notification";
vm.showClear = false; //清除按钮
}
//如果没传condRuleId 直接返回
if (condRuleId == null || condRuleId == "undefined") {
return;
}
//2.取出告警规则的数据。
$.ajax({
type : "get",
data : null,
url : sourceUrl,
async : false,
success : function (msg) {
//1.遍历返回的条件数组确定是哪一个rule规则。
var ruleCondArr = msg.response.data;
var xmlData = "";
for (var i = 0; i < ruleCondArr.length; i++) {
if (ruleCondArr[i].ruleId == condRuleId) { //condRuleId
xmlData = "" + ruleCondArr[i].ruleData + "" //在jQuery裡,如果要直接将字串转成XML物件,记得前后方要加上及,才会被当成XML处理;
break;
}
};
//3.解析数据的xml联动页面的组件。
$(xmlData).find("CompoundCond").each(function () {
//1.级别
for (var i = 0; i < vm.severityTypes.length; i++) {
vm.severityTypes[i].value = false;
}
if ($(this).find("PerceivedSeverity").attr('value') != null && $(this).find("PerceivedSeverity ").attr('value') != 'undefined') {
var perceivedSeverityArr = $(this).find("PerceivedSeverity ").attr('value').split(',');
for (var i = 0; i < perceivedSeverityArr.length; i++) {
if (perceivedSeverityArr.contains(vm.severityTypes[i].id)) {
vm.severityTypes[i].value = true;
}
};
}
//2.确认状态
for (var i = 0; i < vm.ackStateTypes.length; i++) {
vm.ackStateTypes[i].value = false;
};
var ackStateV = $(this).find("AckState").attr('value');
if (ackStateV != null && ackStateV != "undefined") {
var ackStateArr = ackStateV.split(',');
for (var i = 0; i < vm.ackStateTypes.length; i++) {
if (ackStateArr.contains(vm.ackStateTypes[i].id)) {
vm.ackStateTypes[i].value = true;
}
};
}
//3.可见性
if(vm.ruleType === 1){
for (var i = 0; i < vm.filterStateTypes.length; i++) {
vm.filterStateTypes[i].value = false;
};
var filterStateV = $(this).find("FilterState").attr('value')
if (filterStateV != null && filterStateV != "undefined") {
var filterStateArr = filterStateV.split(',');
for (var i = 0; i < vm.filterStateTypes.length; i++) {
if (filterStateArr.contains(vm.filterStateTypes[i].id)) {
vm.filterStateTypes[i].value = true;
}
};
}
}
//4.确认时间
var dataRangeAck = $('input[dtitle="ackTime"]'); //日历组件
vm.fmConds.ackTimeStarTime = null;
vm.fmConds.ackTimeEndTime = null;
dataRangeAck.val('');
var ackTimeStartMs = $(this).find("AckTime").attr('start');
var ackTimeEndMs = $(this).find("AckTime").attr('end');
if (ackTimeStartMs != null && ackTimeStartMs != "undefined" && ackTimeEndMs != null && ackTimeEndMs != "undefined") {
vm.fmConds.ackTimeStarTime = ackTimeStartMs; //确认时间
vm.fmConds.ackTimeEndTime = ackTimeEndMs;
var ackTimeStarTime = new Date(parseInt(ackTimeStartMs)).format('yyyy-MM-dd');
var ackTimeEndTime = new Date(parseInt(ackTimeEndMs)).format('yyyy-MM-dd');
dataRangeAck.val(ackTimeStarTime + ' - ' + ackTimeEndTime);
}
//5.发生时间
vm.fmConds.alarmRaisedStartTime = null;
vm.fmConds.alarmRaisedEndTime = null;
var dataRangeRaised = $('input[dtitle="raisedTime"]'); //日历组件
dataRangeRaised.val('');
var raisedTimeStartMs = $(this).find("RaisedTime").attr('start');
var raisedTimeEndMs = $(this).find("RaisedTime").attr('end');
if (raisedTimeStartMs != null && raisedTimeStartMs != "undefined" && raisedTimeEndMs != null && raisedTimeEndMs != "undefined") {
vm.fmConds.alarmRaisedStartTime = raisedTimeStartMs; //发生时间
vm.fmConds.alarmRaisedEndTime = raisedTimeEndMs;
var raisedTimeStart = new Date(parseInt(raisedTimeStartMs)).format('yyyy-MM-dd');
var raisedTimeEnd = new Date(parseInt(raisedTimeEndMs)).format('yyyy-MM-dd');
dataRangeRaised.val(raisedTimeStart + ' - ' + raisedTimeEnd);
}
//6.清除时间
//7.告警码
vm.fmConds.probableCause = null;
var probableCauseArr = $(this).find("ProbableCause").attr('value');
if (probableCauseArr != null && probableCauseArr != "undefined") {
for (var i = 0; i < probableCauseArr.length; i++) {
vm.fmConds.probableCause = probableCauseArr;
// 联动
};
}
//8.告警位置
vm.fmConds.probableCause = null;
var newPositionCondArr = $(this).find("NewPositionCond").attr('value');
if (newPositionCondArr != null && newPositionCondArr != "undefined")
for (var i = 0; i < newPositionCondArr.length; i++) {
// 联动
};
//9.告警类型
vm.fmConds.alarmType = null;
var alarmTypeArr = $(this).find("AlarmType").attr('value');
if (alarmTypeArr != null && alarmTypeArr != "undefined") {
for (var i = 0; i < alarmTypeArr.length; i++) {
vm.fmConds.alarmType = alarmTypeArr;
};
}
});
}
});
}
/*
获取系统类型中的告警码数量
*/
alarmsUtil.getProbableCauseCountBySystemType=function(systemType){
//"/ngict/rest/fm/probableCause?request={"systemTypes":[6,12]}"
var getData={};
var request={};
request.systemTypes=systemType;
getData.request = JSON.stringify(request);
$.ajax({
type : "get",
data : getData,
url : "/ngict/rest/fm/probableCause",
async : true,
success : function (msg) {
vm.alarmCodeSelectedCount+=msg.length;
}});
}