You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
5.8 KiB

Page.Log = new Class({
Extends: PageBase,
order: 60,
name: 'log',
title: 'Show recent logs.',
has_tab: false,
11 years ago
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: ...\n\
Running on: ...\n\
\n\
### Logs:\n\
```\n{issue}```',
indexAction: function () {
var self = this;
14 years ago
self.getLogs(0);
},
11 years ago
getLogs: function (nr) {
14 years ago
var self = this;
11 years ago
if (self.log) self.log.destroy();
self.log = new Element('div.container.loading', {
11 years ago
'text': 'loading...',
'events': {
'mouseup:relay(.time)': function(e){
self.showSelectionButton.delay(100, self, e);
}
}
14 years ago
}).inject(self.el);
Api.request('logging.get', {
'data': {
14 years ago
'nr': nr
},
11 years ago
'onComplete': function (json) {
self.log.set('text', '');
self.log.adopt(self.createLogElements(json.log));
self.log.removeClass('loading');
14 years ago
var nav = new Element('ul.nav', {
'events': {
11 years ago
'click:relay(li.select)': function (e, el) {
self.getLogs(parseInt(el.get('text')) - 1);
}
}
});
14 years ago
// Type selection
new Element('li.filter').grab(
new Element('select', {
14 years ago
'events': {
11 years ago
'change': function () {
var type_filter = this.getSelected()[0].get('value');
self.log.set('data-filter', type_filter);
self.scrollToBottom();
}
14 years ago
}
}).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', {
11 years ago
'text': i + 1,
'class': 'select ' + (nr == i ? 'active' : '')
}).inject(nav);
11 years ago
}
14 years ago
// Clear button
new Element('li.clear', {
14 years ago
'text': 'clear',
'events': {
11 years ago
'click': function () {
14 years ago
Api.request('logging.clear', {
11 years ago
'onComplete': function () {
14 years ago
self.getLogs(0);
}
});
}
}
}).inject(nav);
11 years ago
// Hint
new Element('li.hint', {
'text': 'Select multiple lines & report an issue'
}).inject(nav);
// Add to page
nav.inject(self.log, 'top');
self.scrollToBottom();
}
14 years ago
});
14 years ago
},
11 years ago
createLogElements: function (logs) {
14 years ago
11 years ago
var elements = [];
14 years ago
11 years ago
logs.each(function (log) {
elements.include(new Element('div', {
'class': 'time ' + log.type.toLowerCase()
}).adopt(
new Element('span', {
'text': log.time
}),
new Element('span.type', {
'text': log.type
}),
new Element('span.message', {
'text': log.message
})
))
});
return elements;
},
11 years ago
scrollToBottom: function () {
new Fx.Scroll(window, {'duration': 0}).toBottom();
11 years ago
},
showSelectionButton: function(e){
var self = this,
selection = self.getSelected(),
start_node = selection.anchorNode,
parent_start = start_node.parentNode.getParent('.time'),
end_node = selection.focusNode.parentNode.getParent('.time'),
text = '';
var remove_button = function(){
self.log.getElements('.highlight').removeClass('highlight');
if(self.do_report)
self.do_report.destroy();
document.body.removeEvent('click', remove_button);
};
remove_button();
if(parent_start)
start_node = parent_start;
var nodes = [start_node],
current_node = start_node;
while(current_node != end_node){
current_node = current_node.getNext('.time');
nodes.include(current_node);
}
nodes.each(function(node, nr){
node.addClass('highlight');
node.getElements('span').each(function(span){
text += self.spaceFill(span.get('text') + ' ', 6);
});
text += '\n';
});
self.do_report = new Element('a.do_report.button', {
'text': 'Report issue',
'styles': {
'top': e.page.y,
'left': e.page.x
},
'events': {
'click': function(e){
(e).stop();
self.showReport(text);
}
}
}).inject(document.body);
setTimeout(function(){
document.body.addEvent('click', remove_button);
}, 0);
},
showReport: function(text){
var self = this;
var overlay = new Element('div.report', {
'method': 'post',
'events': {
'click': function(e){
overlay.destroy();
}
}
}).grab(
new Element('div.bug', {
'events': {
'click': function(e){
(e).stopPropagation();
}
}
}).adopt(
new Element('h1', {
'text': 'Report a bug'
}),
new Element('span').adopt(
new Element('span', {
'text': 'Read '
}),
new Element('a.button', {
'target': '_blank',
'text': 'the contributing guide',
'href': 'https://github.com/RuudBurger/CouchPotatoServer/blob/develop/contributing.md'
}),
new Element('span', {
'text': ' before posting, then copy the text below'
})
),
new Element('textarea', {
'text': self.report_text.replace('{issue}', text),
'events': {
'click': function(){
this.select();
}
}
}),
new Element('a.button', {
'target': '_blank',
'text': 'Create a new issue on GitHub with the text above',
'href': 'https://github.com/RuudBurger/CouchPotatoServer/issues/new?body=Paste the text here'
})
)
);
overlay.inject(self.log);
},
getSelected: function(){
if (window.getSelection)
return window.getSelection();
else if (document.getSelection)
return document.getSelection();
else {
var selection = document.selection && document.selection.createRange();
if (selection.text)
return selection.text;
}
return false;
},
spaceFill: function( number, width ){
if ( number.toString().length >= width )
return number;
return ( new Array( width ).join( ' ' ) + number.toString() ).substr( -width );
}
11 years ago
});