2020-02-04 09:10:22 +00:00
|
|
|
/*
|
|
|
|
* The nopaque object is used as a namespace for nopaque specific functions and
|
|
|
|
* variables.
|
|
|
|
*/
|
2020-01-20 08:49:39 +00:00
|
|
|
var nopaque = {};
|
2020-01-17 09:42:02 +00:00
|
|
|
|
2020-01-20 08:49:39 +00:00
|
|
|
// nopaque ressources
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket = io();
|
2020-01-17 09:42:02 +00:00
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.corpora = undefined;
|
|
|
|
nopaque.corporaSubscribers = [];
|
|
|
|
nopaque.jobs = undefined;
|
|
|
|
nopaque.jobsSubscribers = [];
|
2020-01-17 09:42:02 +00:00
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.foreignCorpora = undefined;
|
|
|
|
nopaque.foreignCorporaSubscribers = [];
|
|
|
|
nopaque.foreignJobs = undefined;
|
|
|
|
nopaque.foreignJobsSubscribers = [];
|
2020-01-20 08:49:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
// nopaque functions
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.forms = {};
|
|
|
|
nopaque.forms.init = function() {
|
2020-01-24 09:27:11 +00:00
|
|
|
var abortRequestElement, progressElement, progressModal,
|
|
|
|
progressModalElement, request;
|
|
|
|
|
|
|
|
for (let form of document.querySelectorAll(".nopaque-job-form")) {
|
|
|
|
request = new XMLHttpRequest();
|
2020-01-31 12:41:46 +00:00
|
|
|
if (form.dataset.hasOwnProperty("progressModal")) {
|
2020-01-24 09:27:11 +00:00
|
|
|
progressModalElement = document.getElementById(form.dataset.progressModal);
|
|
|
|
progressModal = M.Modal.getInstance(progressModalElement);
|
|
|
|
progressModal.options.dismissible = false;
|
|
|
|
abortRequestElement = progressModalElement.querySelector(".abort-request");
|
|
|
|
abortRequestElement.addEventListener("click", function() {request.abort();});
|
|
|
|
progressElement = progressModalElement.querySelector(".determinate");
|
|
|
|
}
|
2020-01-23 10:19:37 +00:00
|
|
|
form.addEventListener("submit", function(event) {
|
|
|
|
event.preventDefault();
|
2020-01-24 09:27:11 +00:00
|
|
|
var formData, progressModalTitleElement;
|
|
|
|
|
|
|
|
formData = new FormData(form);
|
|
|
|
// Initialize progress modal
|
|
|
|
if (progressModalElement) {
|
|
|
|
progressModalTitleElement = progressModalElement.querySelector(".title");
|
|
|
|
progressModalTitleElement.innerText = formData.get("title");
|
|
|
|
progressElement.style.width = "0%";
|
|
|
|
progressModal.open();
|
|
|
|
}
|
|
|
|
request.open("POST", window.location.href);
|
|
|
|
request.send(formData);
|
|
|
|
});
|
|
|
|
request.addEventListener("load", function(event) {
|
2020-01-31 12:41:46 +00:00
|
|
|
var fieldElement;
|
2020-01-24 09:27:11 +00:00
|
|
|
|
|
|
|
if (request.status === 201) {
|
2020-01-31 12:41:46 +00:00
|
|
|
window.location.href = JSON.parse(this.responseText).redirect_url;
|
2020-01-23 10:19:37 +00:00
|
|
|
}
|
2020-01-24 09:27:11 +00:00
|
|
|
if (request.status === 400) {
|
|
|
|
for (let [field, errors] of Object.entries(JSON.parse(this.responseText))) {
|
|
|
|
fieldElement = form.querySelector(`input[name="${field}"]`).closest(".input-field");
|
|
|
|
for (let error of errors) {
|
2020-01-31 12:41:46 +00:00
|
|
|
fieldElement.insertAdjacentHTML("beforeend", `<span class="helper-text red-text">${error}</span>`);
|
2020-01-24 09:27:11 +00:00
|
|
|
}
|
2020-01-23 10:19:37 +00:00
|
|
|
}
|
2020-01-24 09:27:11 +00:00
|
|
|
if (progressModalElement) {
|
|
|
|
progressModal.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (request.status === 500) {
|
|
|
|
location.reload();
|
2020-01-23 10:19:37 +00:00
|
|
|
}
|
|
|
|
});
|
2020-01-24 09:27:11 +00:00
|
|
|
if (progressModalElement) {
|
|
|
|
request.upload.addEventListener("progress", function(event) {
|
|
|
|
progressElement.style.width = Math.floor(100 * event.loaded / event.total).toString() + "%";
|
|
|
|
});
|
|
|
|
}
|
2020-01-23 10:19:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.navigation = {};
|
|
|
|
nopaque.navigation.init = function() {
|
2020-02-07 14:21:59 +00:00
|
|
|
var slideOutElement, tocElement;
|
|
|
|
|
|
|
|
slideOutElement = document.getElementById("slide-out");
|
|
|
|
for (let entry of slideOutElement.querySelectorAll("a:not(.subheader)")) {
|
2020-01-20 08:49:39 +00:00
|
|
|
if (entry.href === window.location.href) {
|
|
|
|
entry.parentNode.classList.add("active");
|
|
|
|
}
|
|
|
|
}
|
2020-02-07 14:21:59 +00:00
|
|
|
tocElement = document.getElementById("roadmap");
|
|
|
|
if (!tocElement) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for (let entry of tocElement.querySelectorAll("a")) {
|
|
|
|
if (entry.href === window.location.href) {
|
|
|
|
entry.classList.add("active");
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 08:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.toast = function(message, color="") {
|
2020-02-04 09:10:22 +00:00
|
|
|
var toast, toastActionElement;
|
2020-01-17 09:42:02 +00:00
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
toast = M.toast({classes: color,
|
|
|
|
html: `<span>${message}</span>
|
|
|
|
<button data-action="close" class="btn-flat toast-action white-text">
|
|
|
|
<i class="material-icons">close</i>
|
|
|
|
</button>`});
|
|
|
|
toastActionElement = toast.el.querySelector('.toast-action[data-action="close"]');
|
2020-01-17 09:42:02 +00:00
|
|
|
if (toastActionElement) {
|
|
|
|
toastActionElement.addEventListener("click", function() {
|
|
|
|
toast.dismiss();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-20 08:49:39 +00:00
|
|
|
// socket event handlers
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("corpora_init", function(msg) {
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.corpora = JSON.parse(msg);
|
|
|
|
for (let subscriber of nopaque.corporaSubscribers) {subscriber._init(nopaque.corpora);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("jobs_init", function(msg) {
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.jobs = JSON.parse(msg);
|
|
|
|
for (let subscriber of nopaque.jobsSubscribers) {subscriber._init(nopaque.jobs);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("corpora_update", function(msg) {
|
2020-01-17 09:42:02 +00:00
|
|
|
var patch;
|
|
|
|
|
|
|
|
patch = JSON.parse(msg);
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.corpora = jsonpatch.apply_patch(nopaque.corpora, patch);
|
|
|
|
for (let subscriber of nopaque.corporaSubscribers) {subscriber._update(patch);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("jobs_update", function(msg) {
|
2020-01-17 09:42:02 +00:00
|
|
|
var patch;
|
|
|
|
|
|
|
|
patch = JSON.parse(msg);
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.jobs = jsonpatch.apply_patch(nopaque.jobs, patch);
|
|
|
|
for (let subscriber of nopaque.jobsSubscribers) {subscriber._update(patch);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("foreign_corpora_init", function(msg) {
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.foreignCorpora = JSON.parse(msg);
|
|
|
|
for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._init(nopaque.foreignCorpora);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("foreign_jobs_init", function(msg) {
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.foreignJobs = JSON.parse(msg);
|
|
|
|
for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._init(nopaque.foreignJobs);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("foreign_corpora_update", function(msg) {
|
2020-01-17 09:42:02 +00:00
|
|
|
var patch;
|
|
|
|
|
|
|
|
patch = JSON.parse(msg);
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.foreignCorpora = jsonpatch.apply_patch(nopaque.foreignCorpora, patch);
|
|
|
|
for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._update(patch);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-01-31 12:41:46 +00:00
|
|
|
nopaque.socket.on("foreign_jobs_update", function(msg) {
|
2020-01-17 09:42:02 +00:00
|
|
|
var patch;
|
|
|
|
|
|
|
|
patch = JSON.parse(msg);
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.foreignJobs = jsonpatch.apply_patch(nopaque.foreignJobs, patch);
|
|
|
|
for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._update(patch);}
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|
|
|
|
|
2020-02-03 12:01:26 +00:00
|
|
|
// get context of one match if inspected
|
|
|
|
nopaque.socket.on("match_context", function(message) {
|
|
|
|
console.log("### match_context ###");
|
2020-02-05 15:09:59 +00:00
|
|
|
console.log("Incoming data:", message);
|
2020-02-03 12:01:26 +00:00
|
|
|
contextResultsElement.innerHTML = "<p> </p>";
|
|
|
|
document.getElementById("context-modal-loading").classList.add("hide");
|
|
|
|
document.getElementById("context-modal-ready").classList.remove("hide");
|
|
|
|
|
|
|
|
let sentenceElement, token, tokenElement;
|
|
|
|
|
|
|
|
for (let [key, value] of Object.entries(message['context_s_cpos'])) {
|
|
|
|
sentenceElement = document.createElement("p");
|
|
|
|
for (cpos of value) {
|
2020-02-05 15:09:59 +00:00
|
|
|
token = message["cpos_lookup"][cpos];
|
2020-02-03 12:01:26 +00:00
|
|
|
tokenElement = document.createElement("span");
|
|
|
|
tokenElement.classList.add("token");
|
|
|
|
if (message["match_cpos_list"].includes(cpos)) {
|
|
|
|
tokenElement.classList.add("bold");
|
|
|
|
}
|
|
|
|
tokenElement.dataset.cpos = cpos;
|
|
|
|
tokenElement.innerText = token["word"];
|
|
|
|
// if (expertModeSwitchElement.checked) {
|
|
|
|
// tokenElement.classList.add("chip");
|
|
|
|
// addToolTipToTokenElement(tokenElement, token);
|
|
|
|
// }
|
|
|
|
// tokenElements.add(tokenElement);
|
|
|
|
sentenceElement.append(tokenElement);
|
|
|
|
sentenceElement.append(document.createTextNode(" "));
|
|
|
|
}
|
|
|
|
contextResultsElement.append(sentenceElement);
|
|
|
|
}
|
|
|
|
});
|
2020-01-17 09:42:02 +00:00
|
|
|
|
2020-01-17 09:49:04 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
2020-01-17 09:42:02 +00:00
|
|
|
M.AutoInit();
|
2020-01-31 12:41:46 +00:00
|
|
|
M.CharacterCounter.init(document.querySelectorAll('input[data-length][type="text"]'));
|
|
|
|
M.Dropdown.init(document.querySelectorAll("#nav-notifications, #nav-account"),
|
|
|
|
{alignment: "right", constrainWidth: false, coverTrigger: false});
|
2020-01-23 10:19:37 +00:00
|
|
|
nopaque.forms.init();
|
2020-01-20 08:49:39 +00:00
|
|
|
nopaque.navigation.init();
|
2020-01-28 09:08:09 +00:00
|
|
|
nopaque.socket.emit("user_ressources_init");
|
2020-01-17 09:42:02 +00:00
|
|
|
});
|