From 5314fc7112c206f8c7aadaab910eeae5715705f4 Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 24 Aug 2015 21:35:21 +0200 Subject: [PATCH] Log cleanup --- couchpotato/core/plugins/log/main.py | 5 +- couchpotato/core/plugins/log/static/log.js | 116 +++++++++++---------- couchpotato/core/plugins/log/static/log.scss | 12 +-- couchpotato/static/scripts/combined.plugins.min.js | 105 ++++++++++--------- couchpotato/static/style/combined.min.css | 2 +- 5 files changed, 130 insertions(+), 110 deletions(-) diff --git a/couchpotato/core/plugins/log/main.py b/couchpotato/core/plugins/log/main.py index 003529b..19edc19 100644 --- a/couchpotato/core/plugins/log/main.py +++ b/couchpotato/core/plugins/log/main.py @@ -131,11 +131,12 @@ class Logging(Plugin): def toList(self, log_content = ''): - logs_raw = toUnicode(log_content).split('[0m\n') + logs_raw = re.split(r'\[0m\n', toUnicode(log_content)) logs = [] + re_split = r'\x1b' for log_line in logs_raw: - split = splitString(log_line, '\x1b') + split = re.split(re_split, log_line) if split: try: date, time, log_type = splitString(split[0], ' ') diff --git a/couchpotato/core/plugins/log/static/log.js b/couchpotato/core/plugins/log/static/log.js index 5cc2f50..ee471bc 100644 --- a/couchpotato/core/plugins/log/static/log.js +++ b/couchpotato/core/plugins/log/static/log.js @@ -7,6 +7,7 @@ Page.Log = new Class({ title: 'Show recent logs.', has_tab: false, + navigation: null, log_items: [], report_text: '### Steps to reproduce:\n'+ '1. ..\n'+ @@ -43,7 +44,15 @@ Page.Log = new Class({ } }).inject(self.content); - Api.request('logging.get', { + if(self.navigation){ + var nav = self.navigation.getElement('.nav'); + nav.getElements('.active').removeClass('active'); + + self.navigation.getElements('li')[nr+1].addClass('active'); + } + + if(self.request && self.request.running) self.request.cancel(); + self.request = Api.request('logging.get', { 'data': { 'nr': nr }, @@ -52,67 +61,68 @@ Page.Log = new Class({ self.log_items = self.createLogElements(json.log); self.log.adopt(self.log_items); self.log.removeClass('loading'); + self.scrollToBottom(); - var navigation = new Element('div.navigation').adopt( - new Element('h2[text=Logs]'), - new Element('div.hint', { - 'text': 'Select multiple lines & report an issue' - }) - ); + if(!self.navigation){ + self.navigation = new Element('div.navigation').adopt( + new Element('h2[text=Logs]'), + new Element('div.hint', { + 'text': 'Select multiple lines & report an issue' + }) + ); - var nav = new Element('ul.nav', { - 'events': { - 'click:relay(li.select)': function (e, el) { - self.getLogs(parseInt(el.get('text')) - 1); + var nav = new Element('ul.nav', { + 'events': { + 'click:relay(li.select)': function (e, el) { + self.getLogs(parseInt(el.get('text')) - 1); + } } + }).inject(self.navigation); + + // Type selection + new Element('li.filter').grab( + new Element('select', { + 'events': { + 'change': function () { + var type_filter = this.getSelected()[0].get('value'); + self.content.set('data-filter', type_filter); + self.scrollToBottom(); + } + } + }).adopt( + new Element('option', {'value': 'ALL', 'text': 'Show all logs'}), + new Element('option', {'value': 'INFO', 'text': 'Show only INFO'}), + new Element('option', {'value': 'DEBUG', 'text': 'Show only DEBUG'}), + new Element('option', {'value': 'ERROR', 'text': 'Show only ERROR'}) + ) + ).inject(nav); + + // Selections + for (var i = 0; i <= json.total; i++) { + new Element('li', { + 'text': i + 1, + 'class': 'select ' + (nr == i ? 'active' : '') + }).inject(nav); } - }).inject(navigation); - // Type selection - new Element('li.filter').grab( - new Element('select', { + // Clear button + new Element('li.clear', { + 'text': 'clear', 'events': { - 'change': function () { - var type_filter = this.getSelected()[0].get('value'); - self.content.set('data-filter', type_filter); - self.scrollToBottom(); + 'click': function () { + Api.request('logging.clear', { + 'onComplete': function () { + self.getLogs(0); + } + }); + } } - }).adopt( - new Element('option', {'value': 'ALL', 'text': 'Show all logs'}), - new Element('option', {'value': 'INFO', 'text': 'Show only INFO'}), - new Element('option', {'value': 'DEBUG', 'text': 'Show only DEBUG'}), - new Element('option', {'value': 'ERROR', 'text': 'Show only ERROR'}) - ) - ).inject(nav); - - // Selections - for (var i = 0; i <= json.total; i++) { - new Element('li', { - 'text': i + 1, - 'class': 'select ' + (nr == i ? 'active' : '') }).inject(nav); - } - - // Clear button - new Element('li.clear', { - 'text': 'clear', - 'events': { - 'click': function () { - Api.request('logging.clear', { - 'onComplete': function () { - self.getLogs(0); - } - }); - - } - } - }).inject(nav); - - // Add to page - navigation.inject(self.content, 'top'); - self.scrollToBottom(); + // Add to page + self.navigation.inject(self.content, 'top'); + } } }); @@ -142,7 +152,7 @@ Page.Log = new Class({ }, scrollToBottom: function () { - new Fx.Scroll(this.el, {'duration': 0}).toBottom(); + new Fx.Scroll(this.content, {'duration': 0}).toBottom(); }, showSelectionButton: function(e){ diff --git a/couchpotato/core/plugins/log/static/log.scss b/couchpotato/core/plugins/log/static/log.scss index 3929ac0..6226e02 100644 --- a/couchpotato/core/plugins/log/static/log.scss +++ b/couchpotato/core/plugins/log/static/log.scss @@ -34,17 +34,17 @@ margin-top: 3px; } - .loading { - text-align: center; - font-size: 20px; - padding: 50px; - } - .container { padding: $padding; overflow: hidden; line-height: 150%; + &.loading { + text-align: center; + font-size: 20px; + padding: 100px 50px; + } + select { vertical-align: top; } diff --git a/couchpotato/static/scripts/combined.plugins.min.js b/couchpotato/static/scripts/combined.plugins.min.js index 9fbef4f..d4cf027 100644 --- a/couchpotato/static/scripts/combined.plugins.min.js +++ b/couchpotato/static/scripts/combined.plugins.min.js @@ -2952,6 +2952,7 @@ Page.Log = new Class({ name: "log", title: "Show recent logs.", has_tab: false, + navigation: null, log_items: [], report_text: "### Steps to reproduce:\n" + "1. ..\n" + "2. ..\n" + "\n" + "### Information:\n" + "Movie(s) I have this with: ...\n" + "Quality of the movie being searched: ...\n" + "Providers I use: ...\n" + "Version of CouchPotato: {version}\n" + "Running on: ...\n" + "\n" + "### Logs:\n" + "```\n{issue}```", indexAction: function() { @@ -2969,7 +2970,13 @@ Page.Log = new Class({ } } }).inject(self.content); - Api.request("logging.get", { + if (self.navigation) { + var nav = self.navigation.getElement(".nav"); + nav.getElements(".active").removeClass("active"); + self.navigation.getElements("li")[nr + 1].addClass("active"); + } + if (self.request && self.request.running) self.request.cancel(); + self.request = Api.request("logging.get", { data: { nr: nr }, @@ -2978,57 +2985,59 @@ Page.Log = new Class({ self.log_items = self.createLogElements(json.log); self.log.adopt(self.log_items); self.log.removeClass("loading"); - var navigation = new Element("div.navigation").adopt(new Element("h2[text=Logs]"), new Element("div.hint", { - text: "Select multiple lines & report an issue" - })); - var nav = new Element("ul.nav", { - events: { - "click:relay(li.select)": function(e, el) { - self.getLogs(parseInt(el.get("text")) - 1); + self.scrollToBottom(); + if (!self.navigation) { + self.navigation = new Element("div.navigation").adopt(new Element("h2[text=Logs]"), new Element("div.hint", { + text: "Select multiple lines & report an issue" + })); + var nav = new Element("ul.nav", { + events: { + "click:relay(li.select)": function(e, el) { + self.getLogs(parseInt(el.get("text")) - 1); + } } - } - }).inject(navigation); - new Element("li.filter").grab(new Element("select", { - events: { - change: function() { - var type_filter = this.getSelected()[0].get("value"); - self.content.set("data-filter", type_filter); - self.scrollToBottom(); + }).inject(self.navigation); + new Element("li.filter").grab(new Element("select", { + events: { + change: function() { + var type_filter = this.getSelected()[0].get("value"); + self.content.set("data-filter", type_filter); + self.scrollToBottom(); + } } + }).adopt(new Element("option", { + value: "ALL", + text: "Show all logs" + }), new Element("option", { + value: "INFO", + text: "Show only INFO" + }), new Element("option", { + value: "DEBUG", + text: "Show only DEBUG" + }), new Element("option", { + value: "ERROR", + text: "Show only ERROR" + }))).inject(nav); + for (var i = 0; i <= json.total; i++) { + new Element("li", { + text: i + 1, + class: "select " + (nr == i ? "active" : "") + }).inject(nav); } - }).adopt(new Element("option", { - value: "ALL", - text: "Show all logs" - }), new Element("option", { - value: "INFO", - text: "Show only INFO" - }), new Element("option", { - value: "DEBUG", - text: "Show only DEBUG" - }), new Element("option", { - value: "ERROR", - text: "Show only ERROR" - }))).inject(nav); - for (var i = 0; i <= json.total; i++) { - new Element("li", { - text: i + 1, - class: "select " + (nr == i ? "active" : "") + new Element("li.clear", { + text: "clear", + events: { + click: function() { + Api.request("logging.clear", { + onComplete: function() { + self.getLogs(0); + } + }); + } + } }).inject(nav); + self.navigation.inject(self.content, "top"); } - new Element("li.clear", { - text: "clear", - events: { - click: function() { - Api.request("logging.clear", { - onComplete: function() { - self.getLogs(0); - } - }); - } - } - }).inject(nav); - navigation.inject(self.content, "top"); - self.scrollToBottom(); } }); }, @@ -3048,7 +3057,7 @@ Page.Log = new Class({ return elements; }, scrollToBottom: function() { - new Fx.Scroll(this.el, { + new Fx.Scroll(this.content, { duration: 0 }).toBottom(); }, diff --git a/couchpotato/static/style/combined.min.css b/couchpotato/static/style/combined.min.css index 56d62c8..0fb3f46 100644 --- a/couchpotato/static/style/combined.min.css +++ b/couchpotato/static/style/combined.min.css @@ -402,8 +402,8 @@ .page.log .nav li.clear,.page.log .nav li.select{cursor:pointer} .page.log .nav li.active{font-weight:700;cursor:default} .page.log .hint{font-style:italic;opacity:.5;margin-top:3px} -.page.log .loading{text-align:center;font-size:20px;padding:50px} .page.log .container{padding:20px;overflow:hidden;line-height:150%} +.page.log .container.loading{text-align:center;font-size:20px;padding:100px 50px} .page.log .container select{vertical-align:top} .page.log .container .time{clear:both;font-size:11px;border-top:1px solid rgba(255,255,255,.1);position:relative;overflow:hidden;padding:0 3px;font-family:Lucida Console,Monaco,Nimbus Mono L,monospace,serif} .page.log .container .time.highlight{background:#eaeaea}