feat: update param filters in listContractProcess

refactor
style
This commit is contained in:
Frank.R.Wu
2021-06-30 10:39:00 +08:00
parent 10841c1b03
commit 59d54cb2b5
12 changed files with 1449 additions and 1457 deletions

View File

@@ -1,57 +1,70 @@
var loadContractInstances = function (event) {
console.log("loadContractInstances" + event);
listContractProcess();
const CONSENSUS_TABLE = {
0: '无',
1: 'PBFT',
2: 'RAFT',
3: 'Single'
};
var listContractProcess = function (event) {
const RESPONSE_TYPE_TABLE = {
0: 'ALL',
1: 'MOST',
2: 'FIRST'
};
function loadContractInstances(event) {
console.log("loadContractInstances" + event);
listContractProcess();
}
function listContractProcess(event) {
console.log("listContractProcess" + event);
setTimeout(function () {
var param = {};
param.action = "listContractProcess";
global.wssocket.send(JSON.stringify({
action: 'listContractProcess',
// data: event,
// 1 << 0: INIT, 1 << 1: RUNNING, 1 << 2: HANGED, 1 << 3: KILLED, 0: ALL
filters: global.myRole && global.myRole.indexOf('NodeManager') > -1 ? 0 : 7
}));
// param.data = event;
param.fromNodePortal = true;
global.wssocket.send(JSON.stringify(param));
var request2 = {};
request2.action = "listLeakContractProcess";
global.wssocket.send(JSON.stringify(request2));
global.wssocket.send(JSON.stringify({
action: 'listLeakContractProcess'
}));
}, 300);
};
}
var onListContractProcess1 = function (obj) {
console.log("+++++++++=" + obj.data);
var table = JSON.parse(obj.data);
function onListContractProcess1(obj) {
console.log("+++++++++=" + obj.data.length);
const table = JSON.parse(obj.data);
global.contractList = table;
drawContractInstanceStatusPie(table);
// drawContractInstanceTimesPie(table);
drawContractInstanceTypeTimesPie(table);
drawciTable(table);
drawConInfoTable(table);
console.log(table);
$("#selectContractInstance").html("");
var x = document.getElementById("selectContractInstance");
const x = document.getElementById("selectContractInstance");
x.options.length = 0;
x.add(new Option("选择...", " "));
global.permissionNameMap = {};
for (var i = 0; i < table.length; i++) {
if (table[i].contractStatus == "KILLED") {
for (let i = 0; i < table.length; i++) {
if (table[i]['contractStatus'] !== 'RUNNING') {
continue;
}
var option = document.createElement("option");
let option = document.createElement("option");
option.text = table[i].name;
console.log(table[i].name);
global.permissionNameMap[table[i].id] = table[i].contractPermission;
global.permissionNameMap[table[i].id] = table[i]['contractPermission'];
// option.value=table[i].id;
option.value = table[i].id;
x.add(option, null);
}
};
}
var drawciTable = function (table) {
if ($("#ciTabDiv").css("height") == "0px") {
console.log("drawciTabDiv: ignore");
function drawConInfoTable(table) {
const ciTabDiv = $("#ciTabDiv");
if (ciTabDiv.css("height") === "0px") {
console.log("drawConInfoTabDiv: ignore");
return;
}
var dtLang = {
@@ -81,78 +94,51 @@ var drawciTable = function (table) {
"sSortDescending": ": 以降序排列此列"
}
};
var tableHead = "<table id='ciTabDivTab' class='table display row-border' style='word-break:normal; word-break:keep-all'><thead><tr><th>序号</th><th>ID</th><th>名称</th><th>状态</th><th>端口</th><th>类型</th><th>通讯</th><th>共识</th><th>统计</th><th>次数</th><th>流量</th><th>内存</th><th>管理</th></tr></thead><tbody>";
var tableTail = "</tbody></table>";
const tableHead = `<table id='ciTabDivTab' class='table display row-border' style='word-break:keep-all;'>
<thead><tr>
<th>序号</th>
<th>ID</th>
<th>名称</th>
<th>状态</th>
<th>端口</th>
<th>类型</th>
<th>通讯</th>
<th>共识</th>
<!--<th>返回方式</th>-->
<th>次数</th>
<th>流量</th>
<th>内存</th>
<th>管理</th>
</tr>
</thead><tbody>`;
const tableTail = "</tbody></table>";
console.log("drawciTable");
var html = tableHead;
for (var i = 0; i < table.length; i++) {
if (table[i].contractStatus=="KILLED") continue;
html += "<tr><td>";
html += (i + 1);
html += "</td> <td>";
html += table[i].id;
html += "</td> <td>";
html += "<a href='/client/bdwareclient.html?self=true&contract="
+ table[i].id + "' target='_blank'>" + table[i].name + "</>";
html += "</td> <td>";
html += table[i].contractStatus;
html += "</td> <td>";
html += table[i].port;
html += "</td><td>";
html += table[i].type;
html += "</td> <td>";
html += table[i].networkType == 0 ? "TCP" : "P2P";
html += "</td><td>";
var consensusType;
switch (table[i].consensusType) {
case 0:
consensusType = "无";
break;
case 1:
consensusType = "PBFT";
break;
case 2:
consensusType = "RAFT";
break;
case 3:
consensusType = "Single";
break;
}
html += consensusType;
html += "</td><td>";
var responseType;
switch (table[i].responseType) {
case 0:
responseType = "ALL";
break;
case 1:
responseType = "MOST";
break;
case 2:
responseType = "FIRST";
break;
}
html += responseType;
html += "</td><td>";
html += table[i].times;
table[i].port;
html += "</td> <td>";
html += table[i].traffic;
html += "</td> <td>";
html += table[i].storage;
html += "</td> <td style='padding:2px 12px 2px 12px'>";
html += "<button onclick='stopContractByID(\"" + table[i].id + "\")' class='btn btn-secondary'>" + "停止</button>"
//table[i].resultCheck;
// html += "</td> <td>";
// html += "<button class='btn btn-outline-secondary' type='button'
// onclick='viewContractInstance("+ table[i].contractID +
// ")'>更多</button>";
html += "</td> </tr>";
console.log("drawConInfoTable");
let html = tableHead;
for (let i = 0; i < table.length; i++) {
html += `<tr>
<td>${i + 1}</td>
<td>${table[i].id}</td>
<td><a href='/client/bdwareclient.html?self=true&contract=${table[i].id}' target='_blank'>
${table[i].name}
</a></td>
<td>${table[i]['contractStatus']}</td>
<td>${table[i].port || '-'}</td>
<td>${table[i].type}</td>
<td>${table[i]['networkType'] ? "P2P" : "TCP"}</td>
<td>${table[i]['consensusType'] ? CONSENSUS_TABLE[table[i]['consensusType']] : '无'}</td>
<!--<td>${table[i].responseType ? RESPONSE_TYPE_TABLE[table[i].responseType] : '-'}</td>-->
<td>${table[i].times}</td>
<td>${table[i]['traffic'] || '-'}</td>
<td>${table[i].storage || '-'}</td>
<td style='padding:2px 12px 2px 12px'>
<button onclick="stopContractByID('${table[i].id}')" class="btn btn-secondary">停止</button>
</td>
</tr>`
}
html += tableTail;
html = "<h5 class='card-title'>合约实例列表</h5>" + html;
$("#ciTabDiv").html(html);
ciTabDiv.html(html);
$("#ciTabDivTab").DataTable(
{
@@ -161,7 +147,7 @@ var drawciTable = function (table) {
dataIndex) {
},
"headerCallback": function (thead, data, start, end, display) {
"headerCallback": function (thead/*, data, start, end, display*/) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
@@ -174,7 +160,7 @@ var drawciTable = function (table) {
"columnDefs": [
{
"targets": 1,
"render": function (data, type, row, meta) {
"render": function (data/*, type, row, meta*/) {
if (data.length > 8)
return "<span title='" + data + "'>"
+ data.substring(0, 8)
@@ -185,46 +171,48 @@ var drawciTable = function (table) {
},]
});
};
var stopContractByID = function (contractID) {
$("#dialogBodyDiv").html("是否停止合约ContractID:" + contractID);
}
function stopContractByID(contractID) {
$("#dialogBodyDiv").html("是否停止合约ContractID" + contractID);
showDialog("请确认", function () {
var request = {};
request.action = "killContractProcess";
request.requestID = new Date().getTime() + "";
request.id = contractID;
global.wssocket.send(JSON.stringify(request));
global.wssocket.send(JSON.stringify({
action: 'killContractProcess',
requestID: new Date().getTime().toString(),
id: contractID
}));
});
};
var drawContractInstanceStatusPie = function (table) {
if ($("#ciStatusPieDiv").css("height") == "0px") {
}
function drawContractInstanceStatusPie(table) {
const ciStatusPieDiv = $("#ciStatusPieDiv")
if (ciStatusPieDiv.css("height") === "0px") {
console.log("drawContractInstanceStatusPie: ignore");
return;
}
$("#ciStatusPieDiv")
.html(
"<div class='col-12' id='ciStatusPieDivCanv' style='width:100%; min-height: 150px; padding: 0px'></div>");
var result = {};
for (var i = 0; i < table.length; i++) {
var obj = table[i];
if (result[obj.contractStatus] == undefined) {
result[obj.contractStatus] = 1;
$(ciStatusPieDiv).html(
"<div class='col-12' id='ciStatusPieDivCanv' style='width:100%; min-height: 150px; padding: 0;'></div>");
const result = {};
for (let i = 0; i < table.length; i++) {
const obj = table[i];
if (!result[obj['contractStatus']]) {
result[obj['contractStatus']] = 1;
} else
result[obj.contractStatus]++;
result[obj['contractStatus']]++;
}
global.result = result;
var dataList = [];
var valDataList = [];
for (var key in result) {
const dataList = [];
const valDataList = [];
for (const key in result) {
dataList.push(key);
var l = {};
l.name = key
l.value = result[key];
valDataList.push(l);
valDataList.push({
name: key,
value: result[key]
});
}
var myChart = echarts.init($("#ciStatusPieDivCanv")[0], 'walden');
var option222 = {
const myChart = echarts.init($("#ciStatusPieDivCanv")[0], 'walden');
const option222 = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
@@ -261,35 +249,35 @@ var drawContractInstanceStatusPie = function (table) {
}]
};
myChart.setOption(option222);
};
}
var drawContractInstanceTimesPie = function (table) {
if ($("#ciTimesPieDiv").css("height") == "0px") {
function drawContractInstanceTimesPie(table) {
const ciTimesPieDiv = $("#ciTimesPieDiv");
if (ciTimesPieDiv.css("height") === "0px") {
console.log("drawContractInstanceTimesPie: ignore");
return;
}
$("#ciTimesPieDiv")
.html(
"<div class='col-12' id='ciTimesPieDivCanv' style='width:100%; min-height: 150px; padding: 0px'></div>");
var result = {};
for (var i = 0; i < table.length; i++) {
var obj = table[i];
ciTimesPieDiv.html(
"<div class='col-12' id='ciTimesPieDivCanv' style='width:100%; min-height: 150px; padding: 0;'></div>");
const result = {};
for (let i = 0; i < table.length; i++) {
const obj = table[i];
result[obj.name] = obj.times;
}
global.result = result;
var dataList = [];
var valDataList = [];
for (var key in result) {
const dataList = [];
const valDataList = [];
for (const key in result) {
dataList.push(key);
var l = {};
l.name = key
l.value = result[key];
valDataList.push(l);
valDataList.push({
name: key,
value: result[key]
});
}
var myChart = echarts.init($("#ciTimesPieDivCanv")[0], 'walden');
const myChart = echarts.init($("#ciTimesPieDivCanv")[0], 'walden');
var option222 = {
const option222 = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
@@ -326,18 +314,19 @@ var drawContractInstanceTimesPie = function (table) {
}]
};
myChart.setOption(option222);
};
}
var changeContractInstance = function (obj) {
function changeContractInstance(obj) {
let i;
console.log(obj);
global.contractInstance = obj;
console.log(typeof (obj));
showPermissionList(global.contractInstance);
var contract;
for (var i = 0; i < global.contractList.length; i++) {
if (global.contractList[i].id == obj) {
let contract;
for (i = 0; i < global.contractList.length; i++) {
if (global.contractList[i].id === obj) {
contract = global.contractList[i];
global.instance = contract;
global.instanceName = contract.name;
@@ -350,79 +339,82 @@ var changeContractInstance = function (obj) {
}
$("#selectContractFunction").html("");
var x = document.getElementById("selectContractFunction");
const x = document.getElementById("selectContractFunction");
x.options.length = 0;
x.add(new Option("选择方法...", " "));
console.log("contract ", contract);
for (var i = 0; i < contract.exportedFunctions.length; i++) {
var option = document.createElement("option");
option.text = contract.exportedFunctions[i].functionName;
option.value = contract.exportedFunctions[i].functionName;
for (i = 0; i < contract['exportedFunctions'].length; i++) {
const option = document.createElement("option");
option.text = contract['exportedFunctions'][i].functionName;
option.value = contract['exportedFunctions'][i].functionName;
x.add(option, null);
}
};
}
var changeMemeryFiles = function (obj) {
function changeMemoryFiles(obj) {
console.log(obj);
global.memoryFile = obj;
};
}
var executeContractWithDynamicResult = function () {
function executeContractWithDynamicResult() {
const argDiv = $("#arg")[0]
console.log("executeContractWithDynamicResult");
var request = {};
const request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "";
request.contractName = global.contractInstance;
request.sequencing = global.instanceSequencing;
request.useP2P = global.useP2P;
request.isDebug = executeContractAsDebug.checked;
var operation = $("#selectContractFunction")[0].value;
if (operation == " " && operation == undefined) {
const operation = $("#selectContractFunction")[0].value;
if (operation === " " && !operation) {
myToast("执行合约", "请选择合约方法!");
return;
}
request.arg = "{\"action\":\"" + operation + "\",\"arg\":\""
+ $("#arg")[0].value + "\"}";
request.arg = `{"action":"${operation}","arg":"${argDiv.value}"}`;
request.pubkey = global.sm2Key.publicKey;
request.withDyanmicAnalysis = true;
request.signature = sm2.doSignature(request.contractID + "|" + operation
+ "|" + $("#arg")[0].value + "|" + global.sm2Key.publicKey,
global.sm2Key.privateKey, {hash: true, der: true});
request.signature = sm2.doSignature(
`${request.contractID}|${operation}|${argDiv.value}|${global.sm2Key.publicKey}`,
global.sm2Key.privateKey,
{hash: true, der: true});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
};
}
var executeContract = function () {
var request = {};
function executeContract() {
const argDiv = $('#arg')[0];
const request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "";
request.contractID = global.contractInstance;
var operation = $("#selectContractFunction")[0].value;
if (operation == " " && operation == undefined) {
const operation = $("#selectContractFunction")[0].value;
if (operation === " " && !operation) {
myToast("执行合约", "请选择合约方法!");
return;
}
request.operation = operation;
request.arg = $("#arg")[0].value;
request.arg = argDiv.value;
request.pubkey = global.sm2Key.publicKey;
request.isDebug = executeContractAsDebug.checked;
console.log(request.arg);
request.signature = sm2.doSignature(request.contractID + "|" + operation
+ "|" + $("#arg")[0].value + "|" + global.sm2Key.publicKey,
global.sm2Key.privateKey, {hash: true, der: true});
request.signature = sm2.doSignature(
`${request.contractID}|${operation}|${argDiv.value}|${global.sm2Key.publicKey}`,
global.sm2Key.privateKey,
{hash: true, der: true});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
};
}
var onExecuteResult = function (obj) {
function onExecuteResult(obj) {
console.log("onExecuteResult obj.data", obj.data);
try {
var result = obj;
var styleTail = "<br>字符串格式";
const result = obj;
let styleTail = "<br>字符串格式";
$("#responseStatus").html("执行状态:" + result.status);
if (result.analysis != undefined) {
if (result['analysis']) {
$("#responseArea")[0].value = "执行结果:" + result.result + "\n动态分析结果:"
+ result.analysis;
+ result['analysis'];
} else {
if (result.result instanceof Object) {
$("#responseArea")[0].value = JSON.stringify(result.result);
@@ -430,27 +422,25 @@ var onExecuteResult = function (obj) {
} else
$("#responseArea")[0].value = result.result;
}
$("#responseID").html("请求ID:" + obj.responseID);
$("#responseTime").html("响应时间:" + obj.executeTime + ("ms") + styleTail);
$("#responseID").html(`请求ID:${obj['responseID']}`);
$("#responseTime").html(`响应时间:${obj['executeTime']}ms${styleTail}`);
} catch (e) {
$("#responseStatus").html("执行状态:Fail");
$("#responseStatus").html("执行状态Failed");
$("#responseArea")[0].value = obj.data;
$("#responseID").html("请求ID:" + obj.responseID);
$("#responseTime").html("响应时间:" + obj.executeTime + ("ms"));
$("#responseID").html(`请求ID${obj['responseID']}`);
$("#responseTime").html(`响应时间:${obj['executeTime']}ms`);
}
};
}
var onHashResult = function (obj) {
function onHashResult(obj) {
$("#hashResult").html("数链指纹:" + obj.data);
};
}
var drawCPTable = function (table) {
function drawCPTable(table) {
console.log("drawCPTable");
global.contractprocess = table.data;
if ($("#ciTabDiv").css("height") == "0px") {
console.log("drawciTabDiv: ignore");
if ($("#ciTabDiv").css("height") === "0px") {
console.log("drawCPTableDiv: ignore");
return;
}
var dtLang = {
@@ -480,39 +470,39 @@ var drawCPTable = function (table) {
"sSortDescending": ": 以降序排列此列"
}
};
var tableHead = "<table id='cpTabDivTab' class='table display row-border'><thead><tr><th>序号</th><th>PID</th><th>是否泄漏</th><th>启动时间</th><th>CPUUser</th><th>CPUSyss</th><th>resident</th><th>memory</th><th>管理</th></tr></thead><tbody>";
var tableTail = "</tbody></table>";
const tableHead = `<table id='cpTabDivTab' class='table display row-border'>
<thead><tr>
<th>序号</th>
<th>PID</th>
<th>是否泄漏</th>
<th>启动时间</th>
<th>CPUUser</th>
<th>CPUSyss</th>
<th>resident</th>
<th>memory</th>
<th>管理</th>
</tr></thead><tbody>`;
const tableTail = "</tbody></table>";
table = table.data;
console.log("drawciTable");
var html = tableHead;
for (var i = 0; i < table.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td> <td>";
html += table[i].pid;
html += "</td> <td>";
html += table[i].isLeak;
html += "</td> <td>";
html += new Date(table[i].cpuStart).toLocaleString();
html += "</td> <td>";
html += table[i].cpuTotal;
html += "</td> <td>";
html += table[i].cpuSys;
html += "</td> <td>";
html += ((table[i].resident) / (1024 * 1024)).toFixed(2) + "MB";
html += "</td><td>";
html += ((table[i].memsize) / (1024 * 1024)).toFixed(2) + "MB";
html += "</td> <td style='padding:2px 12px 2px 12px'>";
html += "<button onclick='stopContractByPID(\"" + table[i].pid + "\")' class='btn btn-secondary'>" + "停止</button>"
//table[i].resultCheck;
// html += "</td> <td>";
// html += "<button class='btn btn-outline-secondary' type='button'
// onclick='viewContractInstance("+ table[i].contractID +
// ")'>更多</button>";
html += "</td> </tr>";
console.log("drawConInfoTable");
let html = tableHead;
for (let i = 0; i < table.length; i++) {
html += `<tr>
<td>${i + 1}</td>
<td>${table[i].pid}</td>
<td>${table[i]['isLeak']}</td>
<td>${new Date(table[i]['cpuStart']).toLocaleString()}/td>
<td>${table[i]['cpuTotal']}</td>
<td>${table[i]['cpuSys']}</td>
<td>${(table[i]['resident'] / (1024 * 1024)).toFixed(2)}MB</td>
<td>${(table[i]['memsize'] / (1024 * 1024)).toFixed(2)}MB</td>
<td style='padding:2px 12px 2px 12px'>
<button onclick="stopContractByPID('${table[i].pid}')" class='btn btn-secondary'>停止</button>
</td>
</tr>`
}
html += tableTail;
html = "<h5 class='card-title'>合约进程列表</h5>" + html;
html = `<h5 class='card-title'>合约进程列表</h5>${html}`;
$("#cpTabDiv").html(html);
$("#cpTabDivTab").DataTable(
@@ -522,7 +512,7 @@ var drawCPTable = function (table) {
dataIndex) {
},
"headerCallback": function (thead, data, start, end, display) {
"headerCallback": function (thead/*, data, start, end, display*/) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
@@ -535,7 +525,7 @@ var drawCPTable = function (table) {
"columnDefs": [
{
"targets": 1,
"render": function (data, type, row, meta) {
"render": function (data/*, type, row, meta*/) {
if (data.length > 10)
// return "<span title='" + data + "'>"
// + data.substring(0, 10)
@@ -547,16 +537,17 @@ var drawCPTable = function (table) {
},]
});
};
var stopContractByPID = function (pid) {
}
function stopContractByPID(pid) {
$("#dialogBodyDiv").html("是否停止PID:" + pid);
showDialog("请确认", function () {
var request = {};
request.action = "killProcessByPID";
request.pid = pid;
global.wssocket.send(JSON.stringify(request));
var request2 = {};
request2.action = "listLeakContractProcess";
global.wssocket.send(JSON.stringify(request2));
global.wssocket.send(JSON.stringify({
action: 'killProcessByPID',
pid: pid
}));
global.wssocket.send(JSON.stringify({
action: 'listLeakContractProcess'
}));
});
};
}