mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Add user interface for monitor, #44
This commit is contained in:
39
themes/bootstrap/public/monitor.js
Normal file
39
themes/bootstrap/public/monitor.js
Normal file
@@ -0,0 +1,39 @@
|
||||
var baseURL = window.location.protocol + '//' + window.location.host;
|
||||
|
||||
function startMonitor() {
|
||||
$.addTemplateFormatter({
|
||||
"date": function(value, template) {
|
||||
return moment(value).calendar();
|
||||
},
|
||||
"subject": function(value, template) {
|
||||
if (value == null || value.length == 0) {
|
||||
return "(No Subject)";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
});
|
||||
|
||||
var uri = '/api/v1/monitor/all/messages'
|
||||
var l = window.location;
|
||||
var url = ((l.protocol === "https:") ? "wss://" : "ws://") + l.host + uri
|
||||
var ws = new WebSocket(url);
|
||||
|
||||
ws.addEventListener('message', function (e) {
|
||||
var msg = JSON.parse(e.data);
|
||||
msg['href'] = '/mailbox?name=' + msg.mailbox + '&id=' + msg.id;
|
||||
$('#monitor-message-list').loadTemplate(
|
||||
$('#message-template'),
|
||||
msg,
|
||||
{ append: true });
|
||||
});
|
||||
}
|
||||
|
||||
function messageClick(node) {
|
||||
var href = node.attributes['href'].value;
|
||||
var url = baseURL + href;
|
||||
window.location.assign(url);
|
||||
}
|
||||
|
||||
function clearClick() {
|
||||
$('#monitor-message-list').empty();
|
||||
}
|
||||
Reference in New Issue
Block a user