Merge sidebar js, css

This commit is contained in:
shortcutme 2019-10-06 03:08:32 +02:00
parent d5da404ed4
commit 1f9eafa619
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
2 changed files with 96 additions and 16 deletions

View file

@ -70,6 +70,8 @@
function Console(sidebar) {
var handleMessageWebsocket_original;
this.sidebar = sidebar;
this.handleTabClick = bind(this.handleTabClick, this);
this.changeFilter = bind(this.changeFilter, this);
this.stopDragY = bind(this.stopDragY, this);
this.cleanup = bind(this.cleanup, this);
this.onClosed = bind(this.onClosed, this);
@ -83,6 +85,23 @@
this.tag = null;
this.opened = false;
this.filter = null;
this.tab_types = [
{
title: "All",
filter: ""
}, {
title: "Info",
filter: "INFO"
}, {
title: "Warning",
filter: "WARNING"
}, {
title: "Error",
filter: "ERROR"
}
];
this.read_size = 32 * 1024;
this.tab_active = "";
handleMessageWebsocket_original = this.sidebar.wrapper.handleMessageWebsocket;
this.sidebar.wrapper.handleMessageWebsocket = (function(_this) {
return function(message) {
@ -93,7 +112,14 @@
}
};
})(this);
if (window.top.location.hash === "#console") {
$(window).on("hashchange", (function(_this) {
return function() {
if (window.top.location.hash === "#ZeroNet:console") {
return _this.open();
}
};
})(this));
if (window.top.location.hash === "#ZeroNet:console") {
setTimeout(((function(_this) {
return function() {
return _this.open();
@ -103,10 +129,12 @@
}
Console.prototype.createHtmltag = function() {
var j, len, ref, tab, tab_type;
if (!this.container) {
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.container = $("<div class=\"console-container\">\n <div class=\"console\">\n <div class=\"console-top\">\n <div class=\"console-tabs\"></div>\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.tabs = this.container.find(".console-tabs");
this.text.on("mousewheel", (function(_this) {
return function(e) {
if (e.originalEvent.deltaY < 0) {
@ -118,6 +146,19 @@
this.text.is_bottom = true;
this.container.appendTo(document.body);
this.tag = this.container.find(".console");
ref = this.tab_types;
for (j = 0, len = ref.length; j < len; j++) {
tab_type = ref[j];
tab = $("<a></a>", {
href: "#",
"data-filter": tab_type.filter
}).text(tab_type.title);
if (tab_type.filter === this.tab_active) {
tab.addClass("active");
}
tab.on("click", this.handleTabClick);
this.tabs.append(tab);
}
this.container.on("mousedown touchend touchcancel", (function(_this) {
return function(e) {
if (e.target !== e.currentTarget) {
@ -193,7 +234,8 @@
Console.prototype.loadConsoleText = function() {
this.sidebar.wrapper.ws.cmd("consoleLogRead", {
filter: this.filter
filter: this.filter,
read_size: this.read_size
}, (function(_this) {
return function(res) {
var pos_diff, size_read, size_total;
@ -201,11 +243,17 @@
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("<br><br>");
_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));
if (this.stream_id) {
this.sidebar.wrapper.ws.cmd("consoleLogStreamRemove", {
stream_id: this.stream_id
});
}
return this.sidebar.wrapper.ws.cmd("consoleLogStream", {
filter: this.filter
}, (function(_this) {
@ -216,15 +264,17 @@
};
Console.prototype.close = function() {
window.top.location.hash = "";
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();
this.sidebar.startDrag();
this.sidebar.moved("y");
this.sidebar.fixbutton_targety = this.sidebar.page_height - this.sidebar.fixbutton_inity - 50;
return this.sidebar.stopDrag();
};
Console.prototype.onOpened = function() {
@ -275,6 +325,26 @@
}
};
Console.prototype.changeFilter = function(filter) {
this.filter = filter;
if (this.filter === "") {
this.read_size = 32 * 1024;
} else {
this.read_size = 1024 * 1024;
}
return this.loadConsoleText();
};
Console.prototype.handleTabClick = function(e) {
var elem;
elem = $(e.currentTarget);
this.tab_active = elem.data("filter");
$("a", this.tabs).removeClass("active");
elem.addClass("active");
this.changeFilter(this.tab_active);
return false;
};
return Console;
})(Class);
@ -283,6 +353,7 @@
}).call(this);
/* ---- Menu.coffee ---- */
@ -530,9 +601,9 @@ window.initScrollable = function () {
this.globe = null;
this.preload_html = null;
this.original_set_site_info = this.wrapper.setSiteInfo;
if (window.top.location.hash === "#ZeroNet:OpenSidebar") {
if (false) {
this.startDrag();
this.moved("x");
this.moved();
this.fixbutton_targetx = this.fixbutton_initx - this.width;
this.stopDrag();
}
@ -1274,7 +1345,6 @@ window.initScrollable = function () {
}).call(this);
/* ---- morphdom.js ---- */