1
0
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:
James Hillyerd
2017-01-16 21:30:40 -08:00
parent 86365a047c
commit 63a76696bf
7 changed files with 127 additions and 12 deletions

View 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();
}