most docker client parts have been moved to docker.js; this version works
This commit is contained in:
@@ -9,9 +9,7 @@
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
var socket = null;
|
||||
var focused = null;
|
||||
|
||||
var docker = new Docker();
|
||||
var docker = null;
|
||||
|
||||
function htmlenc(html) {
|
||||
return $('<div/>').text(html).html();
|
||||
@@ -97,7 +95,6 @@ function status(text, msg) {
|
||||
zoom(0);
|
||||
$("#main").show();
|
||||
$("form input:first-child").focus();
|
||||
docker.containers.contextmenu("#main");
|
||||
}
|
||||
|
||||
function emit(signal, data) {
|
||||
@@ -206,7 +203,7 @@ function previewCreate() {
|
||||
});
|
||||
$('#dosend').unbind().click(function() {
|
||||
if (Object.keys(tobecreated).length>0) {
|
||||
emit("create", docker.containers.configuration(tobecreated));
|
||||
emit("docker.container.create", docker.containers.configuration(tobecreated));
|
||||
tobecreated = {};
|
||||
showImage();
|
||||
}
|
||||
@@ -285,110 +282,6 @@ function zoom(incr = 0) {
|
||||
}
|
||||
}
|
||||
|
||||
var viz = null;
|
||||
var vizmore = null;
|
||||
var rankdir = "LR";
|
||||
function rotateviz() {
|
||||
if (!viz) return;
|
||||
if (rankdir == "LR")
|
||||
rankdir = "TB";
|
||||
else
|
||||
rankdir = "LR";
|
||||
showviz();
|
||||
previewCreate();
|
||||
}
|
||||
function showviz(vizpath, more) {
|
||||
if (!vizpath) {
|
||||
vizpath = viz;
|
||||
more = vizmore;
|
||||
} else {
|
||||
viz = vizpath;
|
||||
vizmore = more;
|
||||
}
|
||||
res = "digraph {\n"+" rankdir="+rankdir+";\n"+viz+"\n}";
|
||||
try {
|
||||
status(more?Viz(res)+more:Viz(res));
|
||||
stats();
|
||||
$('#main a > ellipse + text').attr('font-size', '12');
|
||||
$('#main a > ellipse + text + text')
|
||||
.attr('font-weight', 'bold')
|
||||
.attr('font-size', '16')
|
||||
.each(function() {$(this).attr('y', parseFloat($(this).attr('y'))+1.0)});
|
||||
$('#main a > ellipse + text + text + text, #main a > ellipse + text + text + text + text').attr('font-size', '10');
|
||||
} catch(e) {
|
||||
(res = res.split("\n")).forEach(function(v, i, a) {
|
||||
a[i] = ("000"+(i+1)).slice(-3)+": "+v;
|
||||
});
|
||||
status("<h2>Exception Caught:</h2><p>"+e+"<p><pre>"+res.join("\n")+"</pre>");
|
||||
}
|
||||
}
|
||||
|
||||
function details(name) {
|
||||
if (name) focused = name;
|
||||
else if (!focused) return overview();
|
||||
showviz(docker.containers.subgraph(focused));
|
||||
}
|
||||
|
||||
/// Convert number of bytes to readable text
|
||||
function size(num) {
|
||||
if (num>0.6*1024) {
|
||||
if (num>0.6*1024*1024) {
|
||||
if (num>0.6*1024*1024*1024) {
|
||||
if (num>0.6*1024*1024*1024*1024) {
|
||||
return Math.round(num/1024/1024/1024/1024)+"TB";
|
||||
} else {
|
||||
return Math.round(num/1024/1024/1024)+"GB";
|
||||
}
|
||||
} else {
|
||||
return Math.round(num/1024/1024)+"MB";
|
||||
}
|
||||
} else {
|
||||
return Math.round(num/1024)+"kB";
|
||||
}
|
||||
} else {
|
||||
return num+"B";
|
||||
}
|
||||
}
|
||||
|
||||
var laststats=null;
|
||||
function stats(data) {
|
||||
if (data)
|
||||
console.log("->rcv stats");
|
||||
else
|
||||
data=laststats;
|
||||
if (!data) return;
|
||||
var lines = data.split("\n");
|
||||
var head = lines.shift();
|
||||
lines.forEach(function(line) {
|
||||
if (!line) return;
|
||||
elements = line.split(/ +/);
|
||||
$('#main text + text:contains("'+elements[0]+'") + text + text')
|
||||
.html('cpu: '+elements[1]+' mem: '+elements[7]);
|
||||
$('#main text + text:contains("'+elements[0]+'") + text')
|
||||
.html('net: '+elements[8]+elements[9]+' '+elements[11]+elements[12]
|
||||
+' block: '+elements[13]+elements[14]+' '+elements[16]+elements[17]);
|
||||
});
|
||||
}
|
||||
|
||||
function images(i) {
|
||||
console.log("->rcv images");
|
||||
docker.images.set(i);
|
||||
$('#imagedata').empty().append(docker.images.tags().map(function(i) {
|
||||
var option = document.createElement('option');
|
||||
option.value = i;
|
||||
return option;
|
||||
}));
|
||||
}
|
||||
|
||||
function containers(c) {
|
||||
console.log("->rcv containers");
|
||||
docker.containers.set(c);
|
||||
if (focused && docker.containers.exists(focused))
|
||||
details(focused);
|
||||
else
|
||||
overview();
|
||||
}
|
||||
|
||||
function showLogin() {
|
||||
$("#close").hide();
|
||||
$("#console").hide();
|
||||
@@ -443,6 +336,16 @@ function showLogs() {
|
||||
$("#main").hide();
|
||||
}
|
||||
|
||||
function images(i) {
|
||||
console.log("->rcv images");
|
||||
docker.images.set(i);
|
||||
$('#imagedata').empty().append(docker.images.tags().map(function(i) {
|
||||
var option = document.createElement('option');
|
||||
option.value = i;
|
||||
return option;
|
||||
}));
|
||||
}
|
||||
|
||||
function logs(data) {
|
||||
console.log("->rcv logs("+data.name+")");
|
||||
if (data.type=='done') {
|
||||
@@ -568,11 +471,6 @@ function bash_data(data) {
|
||||
$("#screen").focus();
|
||||
}
|
||||
|
||||
function overview() {
|
||||
focused = null;
|
||||
showviz(docker.containers.graph());
|
||||
}
|
||||
|
||||
/// Initial Function: Startup
|
||||
/** To be called after login */
|
||||
function start() {
|
||||
@@ -582,8 +480,8 @@ function start() {
|
||||
$("#menu").hide();
|
||||
try {
|
||||
status("Starting up ...");
|
||||
emit("images");
|
||||
emit("containers");
|
||||
emit("docker.images");
|
||||
emit("docker.containers");
|
||||
showImage();
|
||||
} catch (m) {
|
||||
error(m);
|
||||
@@ -601,8 +499,8 @@ function initForms() {
|
||||
var obj = this;
|
||||
this.getAttribute('data-name').split(' ').forEach(function(n) {
|
||||
res += 'data-'+n+'="'+
|
||||
(obj.type!='checkbox'||obj.checked
|
||||
?obj.value:obj.getAttribute('data-false'))
|
||||
(obj.type!='checkbox'||obj.checked
|
||||
?obj.value:obj.getAttribute('data-false'))
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
+'"';
|
||||
@@ -629,6 +527,10 @@ function initForms() {
|
||||
|
||||
function init() {
|
||||
socket = io.connect();
|
||||
docker = new Docker(socket, '#main', error);
|
||||
$("#server").html($("#username").value+'@'+window.location.hostname)
|
||||
initForms();
|
||||
showLogin();
|
||||
socket
|
||||
.io
|
||||
.on("connect", connect)
|
||||
@@ -638,15 +540,9 @@ function init() {
|
||||
socket
|
||||
.on("authenticated", authenticated)
|
||||
.on("unauthorized", unauthorized)
|
||||
.on("fail", error)
|
||||
.on("containers", containers)
|
||||
.on("images", images)
|
||||
.on("stats", stats)
|
||||
.on("logs", logs)
|
||||
.on("bash-data", bash_data);
|
||||
$("#server").html($("#username").value+'@'+window.location.hostname)
|
||||
initForms();
|
||||
showLogin();
|
||||
.on("docker.images", images)
|
||||
.on("docker.container.logs", logs)
|
||||
.on("docker.container.bash.data", bash_data);
|
||||
}
|
||||
|
||||
/// On Load, Call @ref start
|
||||
|
Reference in New Issue
Block a user