Add console function to sidebar
This commit is contained in:
parent
aebd9b410d
commit
4c2cf99fd2
8 changed files with 469 additions and 71 deletions
|
@ -55,27 +55,45 @@
|
|||
|
||||
}).call(this);
|
||||
|
||||
/* ---- plugins/Sidebar/media/Internals.coffee ---- */
|
||||
/* ---- plugins/Sidebar/media/Console.coffee ---- */
|
||||
|
||||
|
||||
(function() {
|
||||
var Internals,
|
||||
var Console,
|
||||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
Internals = (function(superClass) {
|
||||
extend(Internals, superClass);
|
||||
Console = (function(superClass) {
|
||||
extend(Console, superClass);
|
||||
|
||||
function Internals(sidebar) {
|
||||
function Console(sidebar) {
|
||||
var handleMessageWebsocket_original;
|
||||
this.sidebar = sidebar;
|
||||
this.stopDragY = bind(this.stopDragY, this);
|
||||
this.cleanup = bind(this.cleanup, this);
|
||||
this.onClosed = bind(this.onClosed, this);
|
||||
this.onOpened = bind(this.onOpened, this);
|
||||
this.open = bind(this.open, this);
|
||||
this.close = bind(this.close, this);
|
||||
this.loadConsoleText = bind(this.loadConsoleText, this);
|
||||
this.addLines = bind(this.addLines, this);
|
||||
this.formatLine = bind(this.formatLine, this);
|
||||
this.checkTextIsBottom = bind(this.checkTextIsBottom, this);
|
||||
this.tag = null;
|
||||
this.opened = false;
|
||||
if (window.top.location.hash === "#internals") {
|
||||
this.filter = null;
|
||||
handleMessageWebsocket_original = this.sidebar.wrapper.handleMessageWebsocket;
|
||||
this.sidebar.wrapper.handleMessageWebsocket = (function(_this) {
|
||||
return function(message) {
|
||||
if (message.cmd === "logLineAdd" && message.params.stream_id === _this.stream_id) {
|
||||
return _this.addLines(message.params.lines);
|
||||
} else {
|
||||
return handleMessageWebsocket_original(message);
|
||||
}
|
||||
};
|
||||
})(this);
|
||||
if (window.top.location.hash === "#console") {
|
||||
setTimeout(((function(_this) {
|
||||
return function() {
|
||||
return _this.open();
|
||||
|
@ -84,31 +102,153 @@
|
|||
}
|
||||
}
|
||||
|
||||
Internals.prototype.createHtmltag = function() {
|
||||
this.when_loaded = $.Deferred();
|
||||
Console.prototype.createHtmltag = function() {
|
||||
if (!this.container) {
|
||||
this.container = $("<div class=\"internals-container\">\n <div class=\"internals\"><div class=\"internals-middle\">\n <div class=\"mynode\"></div>\n <div class=\"peers\">\n <div class=\"peer\"><div class=\"line\"></div><a href=\"#\" class=\"icon\">\u25BD</div></div>\n </div>\n </div></div>\n</div>");
|
||||
this.container = $("<div class=\"console-container\">\n <div class=\"console\">\n <div class=\"console-top\">\n <div class=\"console-text\">Loading...</div>\n </div>\n <div class=\"console-middle\">\n <div class=\"mynode\"></div>\n <div class=\"peers\">\n <div class=\"peer\"><div class=\"line\"></div><a href=\"#\" class=\"icon\">\u25BD</div></div>\n </div>\n </div>\n </div>\n</div>");
|
||||
this.text = this.container.find(".console-text");
|
||||
this.text_elem = this.text[0];
|
||||
this.text.on("mousewheel", (function(_this) {
|
||||
return function(e) {
|
||||
if (e.originalEvent.deltaY < 0) {
|
||||
_this.text.stop();
|
||||
}
|
||||
return RateLimit(300, _this.checkTextIsBottom);
|
||||
};
|
||||
})(this));
|
||||
this.text.is_bottom = true;
|
||||
this.container.appendTo(document.body);
|
||||
return this.tag = this.container.find(".internals");
|
||||
this.tag = this.container.find(".console");
|
||||
this.container.on("mousedown touchend touchcancel", (function(_this) {
|
||||
return function(e) {
|
||||
if (e.target !== e.currentTarget) {
|
||||
return true;
|
||||
}
|
||||
_this.log("closing");
|
||||
if ($(document.body).hasClass("body-console")) {
|
||||
_this.close();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
return this.loadConsoleText();
|
||||
}
|
||||
};
|
||||
|
||||
Internals.prototype.open = function() {
|
||||
Console.prototype.checkTextIsBottom = function() {
|
||||
return this.text.is_bottom = Math.round(this.text_elem.scrollTop + this.text_elem.clientHeight) >= this.text_elem.scrollHeight - 15;
|
||||
};
|
||||
|
||||
Console.prototype.toColor = function(text, saturation, lightness) {
|
||||
var hash, i, j, ref;
|
||||
if (saturation == null) {
|
||||
saturation = 60;
|
||||
}
|
||||
if (lightness == null) {
|
||||
lightness = 70;
|
||||
}
|
||||
hash = 0;
|
||||
for (i = j = 0, ref = text.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
|
||||
hash += text.charCodeAt(i) * i;
|
||||
hash = hash % 1777;
|
||||
}
|
||||
return "hsl(" + (hash % 360) + ("," + saturation + "%," + lightness + "%)");
|
||||
};
|
||||
|
||||
Console.prototype.formatLine = function(line) {
|
||||
var added, level, match, module, ref, text;
|
||||
match = line.match(/(\[.*?\])[ ]+(.*?)[ ]+(.*?)[ ]+(.*)/);
|
||||
if (!match) {
|
||||
return line.replace(/\</g, "<").replace(/\>/g, ">");
|
||||
}
|
||||
ref = line.match(/(\[.*?\])[ ]+(.*?)[ ]+(.*?)[ ]+(.*)/), line = ref[0], added = ref[1], level = ref[2], module = ref[3], text = ref[4];
|
||||
added = "<span style='color: #dfd0fa'>" + added + "</span>";
|
||||
level = "<span style='color: " + (this.toColor(level, 100)) + ";'>" + level + "</span>";
|
||||
module = "<span style='color: " + (this.toColor(module, 60)) + "; font-weight: bold;'>" + module + "</span>";
|
||||
text = text.replace(/(Site:[A-Za-z0-9\.]+)/g, "<span style='color: #AAAAFF'>$1</span>");
|
||||
text = text.replace(/\</g, "<").replace(/\>/g, ">");
|
||||
return added + " " + level + " " + module + " " + text;
|
||||
};
|
||||
|
||||
Console.prototype.addLines = function(lines, animate) {
|
||||
var html_lines, j, len, line;
|
||||
if (animate == null) {
|
||||
animate = true;
|
||||
}
|
||||
html_lines = [];
|
||||
this.logStart("formatting");
|
||||
for (j = 0, len = lines.length; j < len; j++) {
|
||||
line = lines[j];
|
||||
html_lines.push(this.formatLine(line));
|
||||
}
|
||||
this.logEnd("formatting");
|
||||
this.logStart("adding");
|
||||
this.text.append(html_lines.join("<br>") + "<br>");
|
||||
this.logEnd("adding");
|
||||
if (this.text.is_bottom && animate) {
|
||||
return this.text.stop().animate({
|
||||
scrollTop: this.text_elem.scrollHeight - this.text_elem.clientHeight + 1
|
||||
}, 600, 'easeInOutCubic');
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.loadConsoleText = function() {
|
||||
this.sidebar.wrapper.ws.cmd("consoleLogRead", {
|
||||
filter: this.filter
|
||||
}, (function(_this) {
|
||||
return function(res) {
|
||||
var pos_diff, size_read, size_total;
|
||||
_this.text.html("");
|
||||
pos_diff = res["pos_end"] - res["pos_start"];
|
||||
size_read = Math.round(pos_diff / 1024);
|
||||
size_total = Math.round(res['pos_end'] / 1024);
|
||||
_this.text.append("Displaying " + res.lines.length + " of " + res.num_found + " lines found in the last " + size_read + "kB of the log file. (" + size_total + "kB total)<br>");
|
||||
_this.addLines(res.lines, false);
|
||||
return _this.text_elem.scrollTop = _this.text_elem.scrollHeight;
|
||||
};
|
||||
})(this));
|
||||
return this.sidebar.wrapper.ws.cmd("consoleLogStream", {
|
||||
filter: this.filter
|
||||
}, (function(_this) {
|
||||
return function(res) {
|
||||
return _this.stream_id = res.stream_id;
|
||||
};
|
||||
})(this));
|
||||
};
|
||||
|
||||
Console.prototype.close = function() {
|
||||
this.sidebar.move_lock = "y";
|
||||
this.sidebar.startDrag();
|
||||
return this.sidebar.stopDrag();
|
||||
};
|
||||
|
||||
Console.prototype.open = function() {
|
||||
this.createHtmltag();
|
||||
this.sidebar.fixbutton_targety = this.sidebar.page_height;
|
||||
return this.stopDragY();
|
||||
};
|
||||
|
||||
Internals.prototype.onOpened = function() {
|
||||
Console.prototype.onOpened = function() {
|
||||
this.sidebar.onClosed();
|
||||
return this.log("onOpened");
|
||||
};
|
||||
|
||||
Internals.prototype.onClosed = function() {
|
||||
return $(document.body).removeClass("body-internals");
|
||||
Console.prototype.onClosed = function() {
|
||||
$(document.body).removeClass("body-console");
|
||||
if (this.stream_id) {
|
||||
return this.sidebar.wrapper.ws.cmd("consoleLogStreamRemove", {
|
||||
stream_id: this.stream_id
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Internals.prototype.stopDragY = function() {
|
||||
Console.prototype.cleanup = function() {
|
||||
if (this.container) {
|
||||
this.container.remove();
|
||||
return this.container = null;
|
||||
}
|
||||
};
|
||||
|
||||
Console.prototype.stopDragY = function() {
|
||||
var targety;
|
||||
if (this.sidebar.fixbutton_targety === this.sidebar.fixbutton_inity) {
|
||||
targety = 0;
|
||||
|
@ -124,25 +264,26 @@
|
|||
return function() {
|
||||
_this.tag.css("transition", "");
|
||||
if (!_this.opened) {
|
||||
return _this.log("cleanup");
|
||||
return _this.cleanup();
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
this.log("stopdrag", "opened:", this.opened, targety);
|
||||
this.log("stopDragY", "opened:", this.opened, targety);
|
||||
if (!this.opened) {
|
||||
return this.onClosed();
|
||||
}
|
||||
};
|
||||
|
||||
return Internals;
|
||||
return Console;
|
||||
|
||||
})(Class);
|
||||
|
||||
window.Internals = Internals;
|
||||
window.Console = Console;
|
||||
|
||||
}).call(this);
|
||||
|
||||
|
||||
/* ---- plugins/Sidebar/media/Menu.coffee ---- */
|
||||
|
||||
|
||||
|
@ -374,7 +515,7 @@ window.initScrollable = function () {
|
|||
this.container = null;
|
||||
this.opened = false;
|
||||
this.width = 410;
|
||||
this.internals = new Internals(this);
|
||||
this.console = new Console(this);
|
||||
this.fixbutton = $(".fixbutton");
|
||||
this.fixbutton_addx = 0;
|
||||
this.fixbutton_addy = 0;
|
||||
|
@ -451,9 +592,9 @@ window.initScrollable = function () {
|
|||
};
|
||||
|
||||
Sidebar.prototype.startDrag = function() {
|
||||
this.move_lock = "x";
|
||||
this.log("startDrag");
|
||||
this.log("startDrag", this.fixbutton_initx, this.fixbutton_inity);
|
||||
this.fixbutton_targetx = this.fixbutton_initx;
|
||||
this.fixbutton_targety = this.fixbutton_inity;
|
||||
this.fixbutton.addClass("dragging");
|
||||
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
|
||||
this.fixbutton.css("pointer-events", "none");
|
||||
|
@ -505,8 +646,8 @@ window.initScrollable = function () {
|
|||
this.log("Moved", direction);
|
||||
this.move_lock = direction;
|
||||
if (direction === "y") {
|
||||
$(document.body).addClass("body-internals");
|
||||
return this.internals.createHtmltag();
|
||||
$(document.body).addClass("body-console");
|
||||
return this.console.createHtmltag();
|
||||
}
|
||||
this.createHtmltag();
|
||||
$(document.body).addClass("body-sidebar");
|
||||
|
@ -643,8 +784,8 @@ window.initScrollable = function () {
|
|||
}
|
||||
if (!this.move_lock || this.move_lock === "y") {
|
||||
this.fixbutton[0].style.top = (mousey + this.fixbutton_addy) + "px";
|
||||
if (this.internals.tag) {
|
||||
this.internals.tag[0].style.transform = "translateY(" + (0 - targety) + "px)";
|
||||
if (this.console.tag) {
|
||||
this.console.tag[0].style.transform = "translateY(" + (0 - targety) + "px)";
|
||||
}
|
||||
}
|
||||
if ((!this.opened && targetx > this.width / 3) || (this.opened && targetx > this.width * 0.9)) {
|
||||
|
@ -652,7 +793,7 @@ window.initScrollable = function () {
|
|||
} else {
|
||||
this.fixbutton_targetx = this.fixbutton_initx;
|
||||
}
|
||||
if ((!this.internals.opened && 0 - targety > this.page_height / 10) || (this.internals.opened && 0 - targety > this.page_height * 0.95)) {
|
||||
if ((!this.console.opened && 0 - targety > this.page_height / 10) || (this.console.opened && 0 - targety > this.page_height * 0.8)) {
|
||||
return this.fixbutton_targety = this.page_height - this.fixbutton_inity - 50;
|
||||
} else {
|
||||
return this.fixbutton_targety = this.fixbutton_inity;
|
||||
|
@ -669,7 +810,7 @@ window.initScrollable = function () {
|
|||
return;
|
||||
}
|
||||
this.fixbutton.removeClass("dragging");
|
||||
if (this.fixbutton_targetx !== this.fixbutton.offset().left) {
|
||||
if (this.fixbutton_targetx !== this.fixbutton.offset().left || this.fixbutton_targety !== this.fixbutton.offset().top) {
|
||||
if (this.move_lock === "y") {
|
||||
top = this.fixbutton_targety;
|
||||
left = this.fixbutton_initx;
|
||||
|
@ -692,7 +833,7 @@ window.initScrollable = function () {
|
|||
};
|
||||
})(this));
|
||||
this.stopDragX();
|
||||
this.internals.stopDragY();
|
||||
this.console.stopDragY();
|
||||
}
|
||||
return this.move_lock = null;
|
||||
};
|
||||
|
@ -814,16 +955,8 @@ window.initScrollable = function () {
|
|||
this.tag.find("#button-dbrebuild").off("click touchend").on("click touchend", (function(_this) {
|
||||
return function() {
|
||||
_this.wrapper.notifications.add("done-dbrebuild", "info", "Database rebuilding....");
|
||||
|
||||
_this.wrapper.ws.cmd("dbRebuild", [], function(response) {
|
||||
|
||||
if (response !== "ok") {
|
||||
_this.wrapper.notifications.add("done-dbrebuild", "error", response.error, 5000);
|
||||
return _this.updateHtmlTag();
|
||||
}
|
||||
|
||||
_this.wrapper.ws.cmd("dbRebuild", [], function() {
|
||||
_this.wrapper.notifications.add("done-dbrebuild", "done", "Database rebuilt!", 5000);
|
||||
|
||||
return _this.updateHtmlTag();
|
||||
});
|
||||
return false;
|
||||
|
@ -1050,7 +1183,7 @@ window.initScrollable = function () {
|
|||
$(window).on("resize", this.resized);
|
||||
$(document.body).css("transition", "0.6s ease-in-out").removeClass("body-sidebar").on(transitionEnd, (function(_this) {
|
||||
return function(e) {
|
||||
if (e.target === document.body && !$(document.body).hasClass("body-sidebar") && !$(document.body).hasClass("body-internals")) {
|
||||
if (e.target === document.body && !$(document.body).hasClass("body-sidebar") && !$(document.body).hasClass("body-console")) {
|
||||
$(document.body).css("height", "auto").css("perspective", "").css("will-change", "").css("transition", "").off(transitionEnd);
|
||||
return _this.unloadGlobe();
|
||||
}
|
||||
|
@ -1142,7 +1275,6 @@ window.initScrollable = function () {
|
|||
|
||||
}).call(this);
|
||||
|
||||
|
||||
/* ---- plugins/Sidebar/media/morphdom.js ---- */
|
||||
|
||||
|
||||
|
@ -1485,4 +1617,4 @@ function morphdom(fromNode, toNode, options) {
|
|||
|
||||
module.exports = morphdom;
|
||||
},{}]},{},[1])(1)
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue