mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
105 lines
2.9 KiB
JavaScript
105 lines
2.9 KiB
JavaScript
var socket = io();
|
|
|
|
var corpora;
|
|
var corporaSubscribers = [];
|
|
var jobs;
|
|
var jobsSubscribers = [];
|
|
|
|
var foreignCorpora;
|
|
var foreignCorporaSubscribers = [];
|
|
var foreignJobs;
|
|
var foreignJobsSubscribers = [];
|
|
|
|
|
|
function toast(message) {
|
|
var toast;
|
|
var toastActionElement;
|
|
|
|
toast = M.toast({"html": `<span>${message}</span>
|
|
<button class="btn-flat toast-action red-text" data-action="close">
|
|
<i class="material-icons">close</i>
|
|
</button>`});
|
|
toastActionElement = toast.el.querySelector(`.toast-action[data-action="close"]`);
|
|
if (toastActionElement) {
|
|
toastActionElement.addEventListener("click", function() {
|
|
toast.dismiss();
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
socket.on('init-corpora', function(msg) {
|
|
corpora = JSON.parse(msg);
|
|
for (let subscriber of corporaSubscribers) {subscriber._init(corpora);}
|
|
});
|
|
|
|
|
|
socket.on('init-jobs', function(msg) {
|
|
jobs = JSON.parse(msg);
|
|
for (let subscriber of jobsSubscribers) {subscriber._init(jobs);}
|
|
});
|
|
|
|
|
|
socket.on('update-corpora', function(msg) {
|
|
var patch;
|
|
|
|
patch = JSON.parse(msg);
|
|
corpora = jsonpatch.apply_patch(corpora, patch);
|
|
for (let subscriber of corporaSubscribers) {subscriber._update(patch);}
|
|
});
|
|
|
|
|
|
socket.on('update-jobs', function(msg) {
|
|
var patch;
|
|
|
|
patch = JSON.parse(msg);
|
|
jobs = jsonpatch.apply_patch(jobs, patch);
|
|
for (let subscriber of jobsSubscribers) {subscriber._update(patch);}
|
|
});
|
|
|
|
|
|
socket.on('init-foreign-corpora', function(msg) {
|
|
foreignCorpora = JSON.parse(msg);
|
|
for (let subscriber of foreignCorporaSubscribers) {subscriber._init(foreignCorpora);}
|
|
});
|
|
|
|
|
|
socket.on('init-foreign-jobs', function(msg) {
|
|
foreignJobs = JSON.parse(msg);
|
|
for (let subscriber of foreignJobsSubscribers) {subscriber._init(foreignJobs);}
|
|
});
|
|
|
|
|
|
socket.on('update-foreign-corpora', function(msg) {
|
|
var patch;
|
|
|
|
patch = JSON.parse(msg);
|
|
foreignCorpora = jsonpatch.apply_patch(foreignCorpora, patch);
|
|
for (let subscriber of foreignCorporaSubscribers) {subscriber._update(patch);}
|
|
});
|
|
|
|
|
|
socket.on('update-foreign-jobs', function(msg) {
|
|
var patch;
|
|
|
|
patch = JSON.parse(msg);
|
|
foreignJobs = jsonpatch.apply_patch(foreignJobs, patch);
|
|
for (let subscriber of foreignJobsSubscribers) {subscriber._update(patch);}
|
|
});
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
M.AutoInit();
|
|
M.CharacterCounter.init(document.querySelectorAll(`input[data-length][type="text"]`));
|
|
M.Dropdown.init(document.getElementById("nav-notifications"),
|
|
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
|
|
M.Dropdown.init(document.getElementById("nav-account"),
|
|
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
|
|
for (let entry of document.querySelectorAll("#slide-out a:not(.subheader)")) {
|
|
if (entry.href === window.location.href) {
|
|
entry.parentNode.classList.add("active");
|
|
}
|
|
}
|
|
socket.emit("subscribe_user_ressources");
|
|
});
|