2020-10-20 01:57:15 +08:00
|
|
|
$(window).on('load', function () {
|
2020-10-20 18:09:38 +08:00
|
|
|
let wsProtcol = "ws";
|
|
|
|
if (window.location.protocol === 'https') {
|
|
|
|
wsProtcol = 'wss';
|
|
|
|
}
|
|
|
|
|
|
|
|
let url = wsProtcol + '://' + window.location.hostname + ':' + window.location.port + '/updates/ws';
|
2020-10-20 01:57:15 +08:00
|
|
|
var socket = new WebSocket(url);
|
|
|
|
|
|
|
|
socket.onmessage = function (event) {
|
2020-10-20 18:09:38 +08:00
|
|
|
let status = JSON.parse(event.data);
|
2020-10-20 01:57:15 +08:00
|
|
|
|
2020-10-20 18:09:38 +08:00
|
|
|
if (status.type == 'Pending') {
|
2020-10-20 01:57:15 +08:00
|
|
|
const elem = document.createElement('li');
|
|
|
|
elem.classList.add("document");
|
2020-10-20 18:09:38 +08:00
|
|
|
elem.setAttribute("id", 'update-' + status.update_id);
|
2020-10-20 01:57:15 +08:00
|
|
|
|
|
|
|
const ol = document.createElement('ol');
|
|
|
|
const field = document.createElement('li');
|
|
|
|
field.classList.add("field");
|
|
|
|
|
2020-10-20 18:19:48 +08:00
|
|
|
const attributeUpdateId = document.createElement('div');
|
|
|
|
attributeUpdateId.classList.add("attribute");
|
|
|
|
attributeUpdateId.innerHTML = "update id";
|
2020-10-20 01:57:15 +08:00
|
|
|
|
2020-10-20 18:19:48 +08:00
|
|
|
const contentUpdateId = document.createElement('div');
|
|
|
|
contentUpdateId.classList.add("updateId");
|
|
|
|
contentUpdateId.classList.add("content");
|
|
|
|
contentUpdateId.innerHTML = status.update_id;
|
2020-10-20 01:57:15 +08:00
|
|
|
|
2020-10-20 18:19:48 +08:00
|
|
|
field.appendChild(attributeUpdateId);
|
|
|
|
field.appendChild(contentUpdateId);
|
|
|
|
|
|
|
|
const attributeUpdateStatus = document.createElement('div');
|
|
|
|
attributeUpdateStatus.classList.add("attribute");
|
|
|
|
attributeUpdateStatus.innerHTML = "update status";
|
|
|
|
|
|
|
|
const contentUpdateStatus = document.createElement('div');
|
|
|
|
contentUpdateStatus.classList.add("updateStatus");
|
|
|
|
contentUpdateStatus.classList.add("content");
|
|
|
|
contentUpdateStatus.innerHTML = 'pending';
|
|
|
|
|
|
|
|
field.appendChild(attributeUpdateStatus);
|
|
|
|
field.appendChild(contentUpdateStatus);
|
2020-10-20 01:57:15 +08:00
|
|
|
|
|
|
|
ol.appendChild(field);
|
|
|
|
elem.appendChild(ol);
|
|
|
|
|
|
|
|
prependChild(results, elem);
|
|
|
|
}
|
2020-10-20 18:09:38 +08:00
|
|
|
|
|
|
|
if (status.type == "Processing") {
|
|
|
|
const id = 'update-' + status.update_id;
|
2020-10-20 18:19:48 +08:00
|
|
|
const content = $(`#${id} .updateStatus.content`);
|
2020-10-20 18:28:10 +08:00
|
|
|
content.html('processing...');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.type == "Progressing") {
|
|
|
|
const id = 'update-' + status.update_id;
|
|
|
|
const content = $(`#${id} .updateStatus.content`);
|
|
|
|
content.html('progressing...');
|
2020-10-20 18:09:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status.type == "Processed") {
|
|
|
|
const id = 'update-' + status.update_id;
|
2020-10-20 18:19:48 +08:00
|
|
|
const content = $(`#${id} .updateStatus.content`);
|
|
|
|
content.html('processed');
|
2020-10-20 18:09:38 +08:00
|
|
|
}
|
2020-10-20 01:57:15 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function prependChild(parent, newFirstChild) {
|
|
|
|
parent.insertBefore(newFirstChild, parent.firstChild)
|
|
|
|
}
|
2020-10-20 18:19:48 +08:00
|
|
|
|
|
|
|
// Make the number of document a little bit prettier
|
|
|
|
$('#docs-count').text(function(index, text) {
|
|
|
|
return parseInt(text).toLocaleString()
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make the database a little bit easier to read
|
|
|
|
$('#db-size').text(function(index, text) {
|
|
|
|
return filesize(parseInt(text))
|
|
|
|
});
|