pandora/static/js/pandora/logsDialog.js

234 lines
7.6 KiB
JavaScript
Raw Normal View History

2011-11-01 16:08:09 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-11-05 17:04:10 +00:00
'use strict';
2011-11-01 16:08:09 +00:00
pandora.ui.logsDialog = function() {
var height = Math.round((window.innerHeight - 48) * 0.9),
width = Math.round(window.innerWidth * 0.9),
numberOfLogs = 0,
$findSelect = Ox.Select({
items: [
{id: 'all', title: 'Find: All', checked: true},
{id: 'user', title: 'Find: User'},
{id: 'url', title: 'Find: URL'},
{id: 'text', title: 'Find: Text'}
2011-11-01 16:08:09 +00:00
],
overlap: 'right',
type: 'image'
})
.bindEvent({
change: function(data) {
2011-12-21 15:34:28 +00:00
var key = data.value,
2011-11-01 16:08:09 +00:00
value = $findInput.value();
value && updateList(key, value);
$findInput.options({
2011-12-21 15:34:28 +00:00
placeholder: data.title
2011-11-01 16:08:09 +00:00
});
}
}),
$findInput = Ox.Input({
changeOnKeypress: true,
clear: true,
placeholder: 'Find: All',
width: 192
})
.bindEvent({
change: function(data) {
var key = $findSelect.value(),
value = data.value;
updateList(key, value);
}
}),
$findElement = Ox.FormElementGroup({
elements: [
$findSelect,
$findInput
]
})
.css({float: 'right', margin: '4px'}),
$list = Ox.TextList({
columns: [
{
id: 'id',
title: 'ID',
unique: true,
visible: false,
},
{
2011-11-02 17:58:16 +00:00
id: 'user',
title: 'User',
2011-11-01 16:08:09 +00:00
visible: true,
2011-11-02 17:58:16 +00:00
width: 72
2011-11-01 16:08:09 +00:00
},
{
2011-11-02 17:58:16 +00:00
id: 'created',
title: 'Date',
align: 'right',
2011-11-01 16:08:09 +00:00
format: function(value) {
return value.replace(/[TZ]/g, ' ');
},
operator: '-',
visible: true,
2011-11-02 17:58:16 +00:00
width: 144
2011-11-01 16:08:09 +00:00
},
{
2011-11-02 17:58:16 +00:00
id: 'url',
title: 'URL',
format: function(value, data) {
2011-11-03 01:52:15 +00:00
return formatURL(value, data.line);
2011-11-02 17:58:16 +00:00
},
operator: '+',
visible: true,
width: 320
2011-11-01 16:08:09 +00:00
},
{
id: 'text',
title: 'Text',
2011-11-02 17:58:16 +00:00
visible: true,
width: 640
2011-11-01 16:08:09 +00:00
},
],
2011-11-02 17:58:16 +00:00
columnsMovable: true,
columnsResizable: true,
2011-11-01 16:08:09 +00:00
columnsVisible: true,
items: pandora.api.findLogs,
2011-11-02 17:58:16 +00:00
keys: ['line'],
2011-11-01 16:08:09 +00:00
scrollbarVisible: true,
sort: [
{key: 'created', operator: '-'}
]
})
.bindEvent({
init: function(data) {
numberOfLogs = data.items;
$status.html(
2011-11-03 12:58:22 +00:00
Ox.formatNumber(numberOfLogs) + ' '
+ (numberOfLogs == 1 ? 'entry' : 'entries')
2011-11-01 16:08:09 +00:00
);
},
'delete': function(data) {
pandora.api.removeLogs({ids: data.ids}, function(result) {
$list.reloadList();
2011-11-01 16:13:26 +00:00
Ox.Request.clearCache('findLogs');
2011-11-01 16:08:09 +00:00
});
2011-11-03 01:52:15 +00:00
},
open: function(data) {
var value = $list.value(Ox.last(data.ids)),
$dialog;
if (/^Traceback/.test(value.text)) {
$dialog = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
title: 'Close'
})
.bindEvent({
click: function() {
$dialog.close();
}
})
],
closeButton: true,
content: $('<code>').append($('<pre>').css({margin: '16px'}).html(value.text)),
height: height - 48,
keys: {enter: 'close', escape: 'close'},
maximizeButton: true,
title: formatURL(value.url, value.line),
width: width - 48
})
.open();
}
2011-11-01 16:08:09 +00:00
}
}),
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'done',
title: 'Done',
width: 48
}).bindEvent({
click: function() {
Ox.Request.clearCache('findLogs');
2011-11-01 16:08:09 +00:00
that.close();
}
})
],
closeButton: true,
content: Ox.SplitPanel({
elements: [
{
2011-11-02 17:58:16 +00:00
element: Ox.Bar({size: 24})
.append($status)
.append(
$findElement
),
size: 24
2011-11-01 16:08:09 +00:00
},
{
2011-11-02 17:58:16 +00:00
element: $list
2011-11-01 16:08:09 +00:00
}
],
2011-11-02 17:58:16 +00:00
orientation: 'vertical'
2011-11-01 16:08:09 +00:00
}),
height: height,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
title: 'Manage Logs',
width: width
}),
$status = $('<div>')
.css({
position: 'absolute',
top: '4px',
2011-11-03 12:58:22 +00:00
left: '128px',
right: '128px',
2011-11-01 16:08:09 +00:00
bottom: '4px',
paddingTop: '2px',
fontSize: '9px',
textAlign: 'center',
})
.appendTo(that.$element.find('.OxButtonsbar'));
2011-11-03 01:52:15 +00:00
function formatURL(url, line) {
return url.split('?')[0] + ':' + line;
}
2011-11-01 16:08:09 +00:00
function renderLog(logData) {
var $checkbox;
return Ox.Element()
.css({
padding: '8px'
})
.append($('<pre>').html(logData.text));
}
function updateList(key, value) {
var query = {
conditions: Ox.merge(
key != 'url' ? [{key: 'user', value: value, operator: '='}] : [],
key != 'user' ? [{key: 'url', value: value, operator: '='}] : []
),
operator: key == 'all' ? '|' : '&'
};
$list.options({
items: function(data, callback) {
return pandora.api.findLogs(Ox.extend(data, {
query: query
}), callback);
}
});
}
return that;
};