meilisearch/public/updates-script.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

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");
const attribute = document.createElement('div');
attribute.classList.add("attribute");
attribute.innerHTML = "TEXT";
const content = document.createElement('div');
content.classList.add("content");
2020-10-20 18:09:38 +08:00
content.innerHTML = 'Pending ' + status.update_id;
2020-10-20 01:57:15 +08:00
field.appendChild(attribute);
field.appendChild(content);
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;
const content = $(`#${id} .content`);
content.html('Processing ' + status.update_id);
}
if (status.type == "Processed") {
const id = 'update-' + status.update_id;
const content = $(`#${id} .content`);
content.html('Processed ' + status.update_id);
}
2020-10-20 01:57:15 +08:00
}
});
function prependChild(parent, newFirstChild) {
parent.insertBefore(newFirstChild, parent.firstChild)
}