/* * @Copyright (c) 2018 缪聪(mcg-helper@qq.com) * * 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 screenMaxHeight = $(window).height(); //最大可视宽度 var screenMaxWidth = $(window).width(); //ace编辑器的属性性,目前用于全屏功能记录其改变的高宽值 var acePropertyMap = new Map(); /* * 消息类,用于前端展示流程日志和通知消息 * */ var Message = function(param){ this.continer = ""; this.msg = param.msg; } /* 前端展示日志和通知 * 流程日志输出方法 * 通知展示 * */ Message.prototype.output = function() { var self = this; var log = { "info" : { html:"暂无内容", value:"暂无内容", execute:function(){ this.value = self.msg.body.content; this.html = self.build(); } }, "success" : { html:"暂无内容", value:"暂无内容", execute:function(){ this.value = self.msg.body.content; this.html = self.build(); } }, "error" : { html:"暂无内容", value:"暂无内容", execute:function(){ this.value = self.msg.body.content; this.html = self.build(); Messenger().post({ message: "发生异常", type: "error", hideAfter: 5, showCloseButton: true }); } } }; var textEditor = { "make" : { "options" : { }, execute:function(container, param) { $("#" + container).html('
' + param + '
');
}
}
};
var linuxEditor = {
"make" : {
"options" : {
},
execute:function(container, param) {
var length = param.split("\n").length;
var screenRows = 25;
if(length < 24) {
screenRows = length + 1;
}
var term = new Terminal({
cols: 120,
rows: screenRows
});
term.open(document.getElementById(container));
term.write(param);
}
}
};
var jsonEditor = {
"make" : {
"options" : {
mode: 'view',
modes: ['view','code']
},
execute:function(container, param) {
if(param != null || !"" == param) {
var result = {};
try {
result = JSON.parse(param);
var editor = new JSONEditor(document.getElementById(container), this.options, result);
// editor.setMode("code");
} catch (e) {
$("#" + container).html('' + param + '
');
/*
Messenger().post({
message: "控制台接收到非JSON数据,异常:" + e,
type: "error",
hideAfter: 5,
showCloseButton: true
});
*/
}
}
}
}
};
var notify = {
execute:function(){
Messenger().post({
message: self.msg.body.content,
type: self.msg.body.type,
hideAfter: 5,
showCloseButton: true
});
}
};
var wonton = {
};
if(self.msg.header.mesType == "FLOW") {
/*
* 将子流程中的控件日志过滤,不在当流程图中显示次序号
* 每个控件第一次输出日志时,因为第一次才会有次序号orderNum
* */
if(!self.msg.body.subFlag && self.msg.body.orderNum != undefined && self.msg.body.orderNum > 0) {
if(baseMap.get("runnerFlowElementId") == null) {
baseMap.put("runnerFlowElementId", self.msg.body.eleId);
} else {
$("#name_" + baseMap.get("runnerFlowElementId")).removeClass("run_flicker");
baseMap.put("runnerFlowElementId", self.msg.body.eleId);
}
var elementName = elementMap.get(self.msg.body.eleId).getName();
var nameHtml = $("#name_" + self.msg.body.eleId).html();
var orderNumLength = $("#name_" + self.msg.body.eleId).children("span").length; //当前控件上显示次序号的个数
// 当由于循环功能,一个控件上的次序号显示超出5个后,就显示“...”,不再追加次序号
if(orderNumLength < 5) {
var appendHtml = '' + self.msg.body.orderNum + '';
$("#name_" + self.msg.body.eleId).html(nameHtml.substring(0, nameHtml.length - elementName.length) + appendHtml + elementName);
} else if(orderNumLength == 5){
var appendHtml = '...';
$("#name_" + self.msg.body.eleId).html(nameHtml.substring(0, nameHtml.length - elementName.length) + appendHtml + elementName);
}
$("#name_" + self.msg.body.eleId).addClass("run_flicker");
}
log[self.msg.body.logType].execute();
var html = '';
html = log[self.msg.body.logType].html;
$(self.continer).append(html);
//控制台日志输出
if(this.msg.body.eleType != "finish") {
console.log(self.msg.body.eleType + "--" + self.msg.body.logOutType);
if(self.msg.body.eleType == "linux" && self.msg.body.logOutType == "ssh") {
linuxEditor["make"].execute(self.msg.id, log[self.msg.body.logType].value);
} else if(self.msg.body.eleType == "text" && self.msg.body.logOutType == "text") {
textEditor["make"].execute(self.msg.id, log[self.msg.body.logType].value);
} else {
jsonEditor["make"].execute(self.msg.id, log[self.msg.body.logType].value);
}
}
if(self.msg.body.logType == "error") {
baseMap.put("selector", self.msg.body.eleId);
baseMap.put("highlight", "highlight" + self.msg.body.eleId); //把当前被高亮标记div的id放入缓存
$("#highlight" + baseMap.get("selector")).addClass("highlight");
$("#flowStopBtn span").removeClass("text-danger"); //控制台执行状态去掉红色,变为默认灰色
var pos = $("#log" + baseMap.get("selector")).offset().top;
$("#mcg_flow").animate({scrollTop: pos - 10}, 100);
}
} else if(self.msg.header.mesType == "NOTIFY") {
notify.execute();
} else if(self.msg.header.mesType == "WONTON") {
for(var i=0;i