var dtLang = {
"sProcessing" : "处理中...",
"lengthMenu" : '显示 ' + '5 '
+ '20 '
+ '100 '
+ '全部 ' + ' 项结果',
"sZeroRecords" : "没有匹配结果",
"sInfo" : "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
"sInfoEmpty" : "显示第 0 至 0 项结果,共 0 项",
"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
"sInfoPostFix" : "",
"sSearch" : "搜索:",
"sUrl" : "",
"sEmptyTable" : "表中数据为空",
"sLoadingRecords" : "载入中...",
"sInfoThousands" : ",",
"oPaginate" : {
"sFirst" : "首页",
"sPrevious" : "上页",
"sNext" : "下页",
"sLast" : "末页"
},
"oAria" : {
"sSortAscending" : ": 以升序排列此列",
"sSortDescending" : ": 以降序排列此列"
}
};
var fillAuthRoleData = function(data) {
var tableHead = "
序号 公钥 注册时间 角色种类 管理 ";
var tableTail = "
";
console.log("fillAuthRoleData111");
var html = tableHead;
global.authorizedUsers = data;
console.log(data);
var lines = (data);
for (var i = 0; i < lines.kv.length; i++) {
if (lines.kv[i].key == "__NodeManager__") {
continue;
} else {
html += "";
html += (i + 1);
html += (" ");
html += (lines.kv[i].key);
html += (" ");
html += (lines.time[i].value);
html += (" ");
var roles = lines.kv[i].value.split(",");
global.rolesList = lines.kv[i].value.split(",").length;
var len = global.rolesList;
html += "";
for (var j = 0; j < global.rolesList; j++) {
html += "" + roles[j]
" ";
}
html += (" ");
html += (" ");
// html += (" ");
html += " ";
}
}
html += tableTail;
$("#authorizedRole").html(html);
$("#authorizedRole").off("click", ":button")
.on(
"click",
":button",
function(event) {
var deleteInfo = {};
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
var chosenDelete = ($(this).closest("tr").find(
"select option:selected").val());
// console.log("chosenDelete" + chosenDelete);
deleteInfo.role = chosenDelete;
deleteInfo.pubKey = global.authorizedUsers.kv[pos].key;
deleteInfo.action = "deleteRole";
global.wssocket.send(JSON.stringify(deleteInfo));
// console.log(data);
});
$("#authorizedRoleTab").DataTable(
{
"language" : dtLang,
"rowCallback" : function(row, data, displayNum, displayIndex,
dataIndex) {
},
"headerCallback" : function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
},
scrollCollapse : false,
paging : true,
pageLength : 5,
order : [ [ 2, 'desc' ] ],
"columnDefs" : [
{
"targets" : 2,
"render" : function(data, type, row, meta) {
return new Date(data / 1).toLocaleString();
}
},
{
"targets" : 1,
"render" : function(data, type, row, meta) {
if (data.length > 15)
return ""
+ data.substring(0, 15)
+ " ... ";
else
return data;
}
},
]
});
};
var fillUnAuthRoleData = function(data) {
console.log("fillUnAuthRoleData222");
var applyTableHead = "序号 公钥 申请时间 申请角色 是否授权 ";
var applyTableTail = "
";
var html = applyTableHead;
var lines = data;
global.authList = lines;
for (var i = 0; i < lines.kv.length; i++) {
html += "";
html += (i + 1);
html += (" ");
html += (lines.kv[i].key);
html += (" ");
html += (lines.time[i].value);
html += (" ");
var roles = lines.kv[i].value.split(",");
global.applyRolesList = lines.kv[i].value.split(",").length;
var len = global.applyRolesList;
html += "";
for (var j = 0; j < global.applyRolesList; j++) {
html += "" + roles[j]
" ";
}
// html += (lines.kv[i].value);
html += (" ");
html += (" ");
html += (" ");
html += " ";
}
html += applyTableTail;
$("#unAuthorizedRole").html(html);
$("#unAuthorizedRole").off("click", ":button")
.on(
"click",
":button",
function(event) {
var authInfo = {};
authInfo.action = "authNodeRole";
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
authInfo.pubKey = global.authList.kv[pos].key;
authInfo.isAccept = "" + event.target.value == '授权';
global.wssocket.send(JSON.stringify(authInfo));
// console.log(data);
});
$("#unAuthorizedRoleTab").DataTable(
{
"language" : dtLang,
"rowCallback" : function(row, data, displayNum, displayIndex,
dataIndex) {
},
"headerCallback" : function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
},
scrollCollapse : false,
paging : true,
pageLength : 5,
order : [ [ 2, 'desc' ] ],
"columnDefs" : [
{
"targets" : 2,
"render" : function(data, type, row, meta) {
return new Date(data / 1).toLocaleString();
}
},
{
"targets" : 1,
"render" : function(data, type, row, meta) {
if (data.length > 15)
return ""
+ data.substring(0, 15)
+ " ... ";
else
return data;
}
},
// {
// "targets" : 3,
// "render" : function(data, type, row, meta) {
// if (data.length > 15)
// return ""
// + data.substring(0, 15)
// + " ... ";
// else
// return data;
// }
// }
]
});
};
// TODO
// 在WSHandler的onUserList之类的方法里使用。
// -----------------------------------------------
var loadUserMan = function() {
setTimeout(function() {
console.log("loadUserManTrigged!");
var loginAllUser = {};
loginAllUser.action = "listAllAuthRole";
global.wssocket.send(JSON.stringify(loginAllUser));
var loginApplyList = {};
loginApplyList.action = "listUnAuthRole";
global.wssocket.send(JSON.stringify(loginApplyList));
var getUserActivities = {};
getUserActivities.action = "countNodeLogGroupByCategory";
getUserActivities.start = getDateDaysBefore(30);
getUserActivities.category = "login,applyNodeRole,authNodeRole";
getUserActivities.interval = 24*3600*1000;
global.wssocket.send(JSON.stringify(getUserActivities));
var countList = {};
countList.action = "countRole";
global.wssocket.send(JSON.stringify(countList));
}, 200);
};
// -----------------------------------------------
var setUserTypeDistribution = function(data) {
$("#RolePie")
.html(
"
");
var myChart = echarts.init($("#RolePieCanv")[0], 'walden');
var count = data.data;
var option222 = {
tooltip : {
trigger : 'item',
formatter : '{a} {b}: {c} ({d}%)'
},
legend : {
orient : 'vertical',
left : 10,
data : [ '节点管理员', '合约管理员', '合约提供者', '合约使用者' ]
},
series : [ {
name : '访问来源',
type : 'pie',
radius : [ '50%', '70%' ],
avoidLabelOverlap : false,
label : {
normal : {
show : false,
position : 'center'
},
emphasis : {
show : true,
textStyle : {
fontSize : '15',
fontWeight : 'bold'
}
}
},
labelLine : {
normal : {
show : false
}
},
data : [ {
value : data.NodeManager,
name : '节点管理员'
}, {
value : data.ContractInstanceManager,
name : '合约管理员'
}, {
value : data.ContractProvider,
name : '合约提供者'
}, {
value : data.ContractUser,
name : '合约使用者'
} ]
} ]
};
myChart.setOption(option222);
};
var drawUserActivityGraph = function(data) {
global.lastData = data;
console.log(data);
console.log("drawUserActivityGraph");
$("#nodeUserActivityDiv")
.html(
"
");
var xAxisData = [];
var loginData = data.data.login;
var applyData = data.data.applyNodeRole;
var authData = data.data.authNodeRole;
var startTime = data.start;
var interval = data.interval;
for (var i=0;i