/* * @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 _fieldName_ = "", _tableName_=""; function checkboxFormatter(value, row, index) { var checkboxStr = ''; } function inputPwdFormatter(value, row, index) { return ''; } function inputDataSourceFormatter(value, row, index) { if(row.type == "system") { return ''; } return ''; } function dsCommandsFormatter(value, row, index) { return ''; } function ssCommandsFormatter(value, row, index) { return ''; } function dbTest(index) { var tableData = $("#" + baseMap.get("flowDataSourceModalId") + "_flowDataSourceTable").bootstrapTable('getData'); var row = tableData[index]; common.ajax({ url : "/flow/testConnect", type : "POST", data : JSON.stringify(row), contentType : "application/json" }, function(data) { if(data.statusCode == 1) { Messenger().post({ message: "【" + row.name + "】连接数据库成功!", type: "success", hideAfter: 5, showCloseButton: true }); } else { Messenger().post({ message: "【" + row.name + "】连接数据库失败!", type: "error", hideAfter: 5, showCloseButton: true }); } }); } function serverTest(index) { var tableData = $("#" + baseMap.get("flowDataSourceModalId") + "_flowServerSourceTable").bootstrapTable('getData'); var row = tableData[index]; common.ajax({ url : "/global/testServerConnect", type : "POST", data : JSON.stringify(row), contentType : "application/json" }, function(data) { if(data.statusCode == 1) { Messenger().post({ message: row.name +"【" + row.ip + ":" + row.port + "】连接成功!", type: "success", hideAfter: 5, showCloseButton: true }); } else { Messenger().post({ message: row.name +"【" + row.ip + ":" + row.port + "】连接失败!", type: "error", hideAfter: 5, showCloseButton: true }); } }); } function inputFocus(obj) { $(obj).click(); } function inputBlur(obj, index) { $("#" + _tableName_).bootstrapTable("updateCell", {"index":index, "field":_fieldName_, "value":$(obj).val(), "reinit":false }); } function getSelectData(cellValue, index, url, param) { var result = ""; common.ajax({ url : url, type : "GET", data : param, async : false, contentType : "application/json" }, function(data) { var selectStr = ''; result = selectStr; }); return result; } function dbTypeSelectFormatter(value, row, index) { var selectStr = getSelectData(value, index, "/common/getDatabaseTypes", null); return selectStr; } function serverTypeSelectFormatter(value, row, index) { var selectStr = getSelectData(value, index, "/common/getServerTypes", null); return selectStr; } function selectChange(obj, index) { var rowData = '{"'+ _fieldName_ + '":"' + $(obj).val() + '"}'; $("#" + _tableName_).bootstrapTable('updateRow', {"index":index, "row":JSON.parse(rowData) }); } function getElementDataById(id, func) { common.ajax({ url : "/common/getMcgProductById", type : "POST", data : "flowId=" + $("#flowSelect").attr("flowId") + "&id="+id }, func); } function initFlowDataSourceModal(modalId) { common.ajax({ url : "/global/getMcgGlobal", type : "POST", data : null }, function(data){ var flowVarRows = []; for(var i=0; i 0) { for(var i=0; i 0) { var rows = []; for(var i=0; i 0) { var rows = []; for(var i=0; i 0) { var rows = []; for(var i=0; i 0) { var rows = []; for(var i=0; i请选择')); for(var i=0; i' + result[i].tableName + '')); } $("#" + id + "_tableNameSelect").selectpicker('refresh'); $("#" + id + "_tableNameSelect").selectpicker('val', data.dataField.tableName); }); } } else { $("#" + id + "_flowDataTable").bootstrapTable(); } }); } function initJsonModal(id, editor) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.jsonProperty != undefined) { $("#" + id +"_key").val(data.jsonProperty.key); $("#" + id +"_name").val(data.jsonProperty.name); $("#" + id +"_jsonDesc").val(data.jsonProperty.jsonDesc); } if(data != "" && data != undefined && data.jsonCore != null) { editor.setValue(data.jsonCore.source); } else { editor.setValue(""); } }); } function initSqlQueryModal(id, editor) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.sqlQueryProperty != undefined) { $("#" + id +"_key").val(data.sqlQueryProperty.key); $("#" + id +"_name").val(data.sqlQueryProperty.name); $("#" + id +"_desc").val(data.sqlQueryProperty.desc); } if(data != "" && data != undefined && data.sqlQueryCore != null) { $("#" + id + "_dataSourceId").selectpicker('val', data.sqlQueryCore.dataSourceId); editor.setValue(data.sqlQueryCore.source); } else { editor.setValue(""); } }); } function initSqlExecuteModal(id, editor) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.sqlExecuteProperty != undefined) { $("#" + id +"_key").val(data.sqlExecuteProperty.key); $("#" + id +"_name").val(data.sqlExecuteProperty.name); $("#" + id +"_desc").val(data.sqlExecuteProperty.desc); } if(data != "" && data != undefined && data.sqlExecuteCore != null) { $("#" + id + "_dataSourceId").selectpicker('val', data.sqlExecuteCore.dataSourceId); editor.setValue(data.sqlExecuteCore.source); } else { editor.setValue(""); } }); } function initScriptModal(id, editor) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.scriptProperty != undefined) { $("#" + id + "_key").val(data.scriptProperty.key); $("#" + id + "_scriptName").val(data.scriptProperty.scriptName); $("#" + id + "_scriptDesc").val(data.scriptProperty.scriptDesc); } if(data != "" && data != undefined && data.scriptCore != null) { editor.setValue(data.scriptCore.source); } else { editor.setValue("var Console = Java.type('com.mcg.plugin.assist.Console');\r\nvar console = new Console();\r\n\r\nfunction main(param) {\r\n var result = {};\r\n console.success({'name':'mcg-helper', 'desc':'欢迎使用mcg-helper研发助手'});\r\n \r\n return result;\r\n}"); } }); } function initJavaModal(id, editor) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.javaProperty != undefined) { $("#" + id + "_key").val(data.javaProperty.key); $("#" + id + "_name").val(data.javaProperty.name); $("#" + id + "_javaDesc").val(data.javaProperty.javaDesc); } if(data != "" && data != undefined && data.javaCore != null) { editor.setValue(data.javaCore.source); } else { editor.setValue("import com.alibaba.fastjson.JSON;\r\nimport com.alibaba.fastjson.JSONArray;\r\nimport com.alibaba.fastjson.JSONObject;\r\nimport com.mcg.plugin.assist.Console;\r\n\r\npublic class Controller {\r\n private Console console = new Console();\r\n\r\n public JSON execute(JSON param) {\r\n console.info(\"-----欢迎使用---------\");\r\n\r\n JSONObject result = new JSONObject();\r\n return result;\r\n }\r\n}\r\n"); } }); } function initPythonModal(id, editor) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.pythonProperty != undefined) { $("#" + id + "_key").val(data.pythonProperty.key); $("#" + id + "_name").val(data.pythonProperty.name); $("#" + id + "_pythonDesc").val(data.pythonProperty.pythonDesc); } if(data != "" && data != undefined && data.pythonCore != null) { editor.setValue(data.pythonCore.source); } else { editor.setValue("#param为Dictionary类型\r\ndef main(param):\r\n\r\n result = {}\r\n\r\n\r\n return result"); } }); } function initLinuxModal(id, editor) { getElementDataById(id, function(data) { if(data != "" && data != undefined) { common.formUtils.setValues(id + "_linuxForm", data); $("#" + id + "_connMode").selectpicker('refresh'); $("#" + id + "_connMode").selectpicker('val', data.linuxCore.connMode); $("#" + id + "_serverSourceId").selectpicker('refresh'); $("#" + id + "_serverSourceId").selectpicker('val', data.linuxCore.serverSourceId); if(data.linuxCore != null) { if(data.linuxCore.connMode == "dependency") { $("#" + id + "_serverSourceId").prop("disabled", false); $("#" + id + "_serverSourceId").selectpicker('refresh'); $("#" + id + "_ip_port").css("display", "none"); $("#" + id + "_user_pwd").css("display", "none"); } else if(data.linuxCore.connMode == "assign") { $("#" + id + "_serverSourceId").prop("disabled", true); $("#" + id + "_serverSourceId").selectpicker('refresh'); $("#" + id + "_ip_port").css("display", "block"); $("#" + id + "_user_pwd").css("display", "block"); } } editor.setValue(data.linuxCore.source); } else { editor.setValue(""); } }); } function initWontonModal(id) { getElementDataById(id, function(data) { if(data != null && data != "") { common.formUtils.setValues(id + "_wontonForm", data); if(data.wontonNetRule.TargetIp != null) { $("#" + id + "_targetIps").val(data.wontonNetRule.TargetIps.join(",")); } if(data.wontonNetRule.TargetPorts != null) { $("#" + id + "_targetPorts").val(data.wontonNetRule.TargetPorts.join(",")); } if(data.wontonNetRule.TargetProtos != null) { $("#" + id + "_targetProtos").val(data.wontonNetRule.TargetProtos.join(",")); } } }); } function initProcessModal(id, treeObj) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.processProperty != undefined) { common.formUtils.setValues(id + "_processForm", data); if(data.processProperty.flowId != null || data.processProperty.flowId != "") { var rootNode = treeObj.getNodeByParam("id", data.processProperty.flowId, null); if(rootNode != null) { $("#" + id + "_flowName").html(rootNode.name+" "); treeObj.selectNode(rootNode); } } } }); } function initLoopModal(id) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.loopProperty != undefined) { common.formUtils.setValues(id + "_loopForm", data); } }); } function initGitModal(id) { getElementDataById(id, function(data) { if(data != null && data != "" && data != undefined && data.gitProperty != undefined) { common.formUtils.setValues(id + "_gitForm", data); } }); } function initSftpModal(id, editor) { getElementDataById(id, function(data) { if(data != "" && data != undefined) { common.formUtils.setValues(id + "_sftpForm", data); $("#" + id + "_connMode").selectpicker('refresh'); $("#" + id + "_connMode").selectpicker('val', data.sftpProperty.connMode); $("#" + id + "_serverSourceId").selectpicker('refresh'); $("#" + id + "_serverSourceId").selectpicker('val', data.sftpProperty.serverSourceId); if(data.sftpProperty != null) { if(data.sftpProperty.connMode == "dependency") { $("#" + id + "_serverSourceId").prop("disabled", false); $("#" + id + "_serverSourceId").selectpicker('refresh'); $("#" + id + "_ip_port").css("display", "none"); $("#" + id + "_user_pwd").css("display", "none"); } else if(data.sftpProperty.connMode == "assign") { $("#" + id + "_serverSourceId").prop("disabled", true); $("#" + id + "_serverSourceId").selectpicker('refresh'); $("#" + id + "_ip_port").css("display", "block"); $("#" + id + "_user_pwd").css("display", "block"); } } } if(data != null && data != undefined && data.sftpUpload != null && data.sftpUpload.sftpUploadRecords != null && data.sftpUpload.sftpUploadRecords.length > 0) { var rows = []; for(var i=0; i