'), height:"auto", borderless:true},
{template:('
'), height:"auto", borderless:true},
]
}
}
});
shellWin[num].show();
configShellWin[num]=webix.ui({
id:'configShellWin'+num,
view:"window",
width:300,
height:450,
left:90, top:90,
move:true,
resize: true,
toFront:true,
head: {
view:"toolbar",
id:"myToolbarconfigWin"+num,
cols:[
{ view:"label", label:"Configuration", align:'right'},
{ view:"button", type:"icon", icon:"check-square", align:'center', width:30, click: function () {
options.ip=UI('configRemoteHostIp'+num).getValue();
options.port=UI('configRemoteHostIpPort'+num).getValue();
UI('ShellWinLabel'+num).setValue(options.ip+':'+options.port+" / Shell "+num);
shell[num].setup();
configShellWin[num].hide();
}}
]
},
body: {
rows:[
{ view:"form", scroll:true, width:300, height:400, elements: [
{ view:"label", label:"
Remote Host", height:'18px', align:'left'},
{ view:"text", id:"configRemoteHostIp"+num, label:"IP", value:options.ip},
{ view:"text", id:"configRemoteHostIpPort"+num, label:"IPPORT", value:options.port},
]}
]
}
});
shell[num].init("ShellWinInput"+num,"ShellWinOutput"+num,UI('ShellWinLog'+num));
UI('ShellWinLog'+num).scrollAuto=false;
shellWin[num].attachEvent("onViewMove", function(pos, e){
});
shellWin[num].attachEvent("onViewMoveEnd", function(pos, e){
});
UI('ShellWinLabel'+num).setValue(options.ip+':'+options.port+" / Shell "+num);
}
createShell(shellNum,{ip:'localhost',port:portRoot});
shellNum++;
/****************** MONITOR *******************/
function createMonitor(num,opts) {
var tables={},reporter;
opts.cmd = function (cmd) {
// Command interpreter for commands sent by luaos
// @cmd arg1 arg2 ...
var obj,table,
prefix=cmd.substr(0,cmd.indexOf(' ')),
args=cmd.substr(cmd.indexOf(' ')+1);
console.log(prefix);
console.log(args);
switch (prefix) {
case '@monitor:new':
obj=JSON.parse(args);
options.header=obj.header;
options.id=obj.id;
if (!reporterWin[num]) createReporter(num,options);
break;
case '@monitor:data':
if (!reporterWin[num]) return;
obj=JSON.parse(args);
table=UI(reporterWin[num]._datatable.id);
table.add(obj.row)
break;
}
}
monitor[num] = winShell(opts);
var options = monitor[num].options;
options.thread=opts.thread;
options.shell=opts.shell;
options.closed = false;
monitorWin[num]=webix.ui({
id:'MonitorWin'+num,
view:"window",
height:350,
width:600,
left:350, top:250,
move:true,
resize: true,
toFront:true,
head: {
view:"toolbar",
cols:[
{ view:"button", type:"icon", icon:"eraser", tooltip:'Clear', width:30, click:function () {
monitor[num].commands.clear()
}},
{ view:"button", type:"icon", icon:"flag", tooltip:'Scroll Auto', id:'MonitorWinLogFilmBut'+num, width:30, click:function () {
UI('MonitorWinLog'+num).scrollAuto=!UI('MonitorWinLog'+num).scrollAuto;
if (UI('MonitorWinLog'+num).scrollAuto) UI('MonitorWinLogFilmBut'+num).define('icon','flag-o')
else UI('MonitorWinLogFilmBut'+num).define('icon','flag');
UI('MonitorWinLogFilmBut'+num).refresh();
}},
{ view:"button", type:"icon", icon:"table", tooltip:'Data Monitor', width:30, click:function () {
if (!reporterWin[num]) return;
// createReporter(num,options);
reporterWin[num].show();
}},
{ view:"label", label:"Thread "+options.thread+ " / "+options.ip+':'+options.port+" / Shell "+options.shell+" / Monitor "+num, id:'MonitorWinLabel'+num, align:'right'},
{ view:"button", type:"icon", icon:"close", tooltip:'Kill', width:30, click:function () {
var self=monitorWin[num];
monitor[num].ask('kill','',function (res) {
monitor[num].ask('end','',function (res) {
});
options.closed=true;
monitorWin[num]=undefined;
monitor[num].stop();
webix.message({text:'Thread closed: #'+res});
self.close();
});
setTimeout(function () {
if (!options.closed) {
options.closed=true;
monitorWin[num]=undefined;
monitor[num].stop();
webix.message({text:'Thread closed: #'+options.thread});
self.close();
}
},1000);
}},
]
},
body:{
id : 'MonitorWinLog'+num,
view : 'scrollview',
scroll : 'y',
body : {
id:'MonitorWinLogText'+num,
rows : [
{template:('
'), height:"auto", borderless:true},
]
}
}
});
UI('MonitorWinLog'+num).scrollAuto=false;
monitorWin[num].show();
monitor[num].init(undefined,"MonitorWinOutput"+num,UI('MonitorWinLog'+num));
}
/****************** REPORTER *******************/
function createReporter(num,options) {
function makeReport(tbl) {
console.log(tbl)
var header = tbl.shift(),
columns = [],
hash =[],
data =[];
header.forEach(function (col,i) {
console.log(i,col)
columns.push({id:col,header:col,editor:'text'}); hash[i]=col;
});
tbl.forEach (function (row,i) {
var obj={id:i};
row.forEach(function (col,j) { obj[hash[j]]=col; });
data.push(obj);
});
var datatbl = {
view:"datatable",
id:'DataTable'+options.id+num,
columns:columns,
select:"cell",
multiselect:true,
blockselect:true,
clipboard:"selection",
data: data,
on:{
onBeforeBlockSelect:function(start, end, fin){
if (start.column === "rank")
end.column = "votes";
if (fin && start.column == "rank"){
var mode = this.isSelected(start) ? -1 : 1;
this.selectRange(
start.row, start.column, end.row, end.column,
mode
);
return false;
}
}
},
};
return datatbl;
}
var datatable = makeReport([options.header.map(function (col) { return Object.keys(col)[0]})]);
reporterWin[num]=webix.ui({
id:'ReporterWin'+num,
view:"window",
height:350,
width:600,
left:350, top:250,
move:true,
resize: true,
toFront:true,
head: {
view:"toolbar",
cols:[
{ view:"button", type:"icon", icon:"eraser", tooltip:'Clear', width:30, click:function () {
}},
{ view:"button", type:"icon", icon:"flag", tooltip:'Scroll Auto', id:'ReporterWinLogFilmBut'+num, width:30, click:function () {
UI('ReporterWinLog'+num).scrollAuto=!UI('ReporterWinLog'+num).scrollAuto;
if (UI('ReporterWinLog'+num).scrollAuto) UI('ReporterWinLogFilmBut'+num).define('icon','flag-o')
else UI('ReporterWinLogFilmBut'+num).define('icon','flag');
UI('ReporterWinLogFilmBut'+num).refresh();
}},
{ view:"button", type:"icon", icon:"table", tooltip:'Data Monitor', width:30, click:function () {
}},
{ view:"label", label:"Thread "+options.thread+ " / "+options.ip+':'+options.port+" / Shell "+options.shell+" / Report "+num, id:'ReporterWinLabel'+num, align:'right'},
{ view:"button", type:"icon", icon:"close", tooltip:'Kill', width:30, click:function () {
var self=reporterWin[num];
self.hide();
}},
]
},
body:datatable
});
reporterWin[num]._datatable=datatable;
return reporterWin[num]
}