diff --git a/app/static/js/nopaque.js b/app/static/js/nopaque.js index b7d4e63d..bde7cb62 100644 --- a/app/static/js/nopaque.js +++ b/app/static/js/nopaque.js @@ -1,17 +1,32 @@ -var socket = io(); - -var corpora; -var corporaSubscribers = []; -var jobs; -var jobsSubscribers = []; - -var foreignCorpora; -var foreignCorporaSubscribers = []; -var foreignJobs; -var foreignJobsSubscribers = []; +var nopaque = {}; -function toast(message, color="") { +// nopaque ressources +nopaque["socket"] = io(); + +nopaque["corpora"] = undefined; +nopaque["corporaSubscribers"] = []; +nopaque["jobs"] = undefined; +nopaque["jobsSubscribers"] = []; + +nopaque["foreignCorpora"] = undefined; +nopaque["foreignCorporaSubscribers"] = []; +nopaque["foreignJobs"] = undefined; +nopaque["foreignJobsSubscribers"] = []; + + +// nopaque functions +nopaque["navigation"] = {}; +nopaque["navigation"]["init"] = function() { + for (let entry of document.querySelectorAll("#slide-out a:not(.subheader)")) { + if (entry.href === window.location.href) { + entry.parentNode.classList.add("active"); + } + } +} + + +nopaque["toast"] = function(message, color="") { var toast; var toastActionElement; @@ -29,63 +44,64 @@ function toast(message, color="") { } -socket.on('init-corpora', function(msg) { - corpora = JSON.parse(msg); - for (let subscriber of corporaSubscribers) {subscriber._init(corpora);} +// socket event handlers +nopaque.socket.on('init-corpora', function(msg) { + nopaque.corpora = JSON.parse(msg); + for (let subscriber of nopaque.corporaSubscribers) {subscriber._init(nopaque.corpora);} }); -socket.on('init-jobs', function(msg) { - jobs = JSON.parse(msg); - for (let subscriber of jobsSubscribers) {subscriber._init(jobs);} +nopaque.socket.on('init-jobs', function(msg) { + nopaque.jobs = JSON.parse(msg); + for (let subscriber of nopaque.jobsSubscribers) {subscriber._init(nopaque.jobs);} }); -socket.on('update-corpora', function(msg) { +nopaque.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);} + nopaque.corpora = jsonpatch.apply_patch(nopaque.corpora, patch); + for (let subscriber of nopaque.corporaSubscribers) {subscriber._update(patch);} }); -socket.on('update-jobs', function(msg) { +nopaque.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);} + nopaque.jobs = jsonpatch.apply_patch(nopaque.jobs, patch); + for (let subscriber of nopaque.jobsSubscribers) {subscriber._update(patch);} }); -socket.on('init-foreign-corpora', function(msg) { - foreignCorpora = JSON.parse(msg); - for (let subscriber of foreignCorporaSubscribers) {subscriber._init(foreignCorpora);} +nopaque.socket.on('init-foreign-corpora', function(msg) { + nopaque.foreignCorpora = JSON.parse(msg); + for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._init(nopaque.foreignCorpora);} }); -socket.on('init-foreign-jobs', function(msg) { - foreignJobs = JSON.parse(msg); - for (let subscriber of foreignJobsSubscribers) {subscriber._init(foreignJobs);} +nopaque.socket.on('init-foreign-jobs', function(msg) { + nopaque.foreignJobs = JSON.parse(msg); + for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._init(nopaque.foreignJobs);} }); -socket.on('update-foreign-corpora', function(msg) { +nopaque.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);} + nopaque.foreignCorpora = jsonpatch.apply_patch(nopaque.foreignCorpora, patch); + for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._update(patch);} }); -socket.on('update-foreign-jobs', function(msg) { +nopaque.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);} + nopaque.foreignJobs = jsonpatch.apply_patch(nopaque.foreignJobs, patch); + for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._update(patch);} }); @@ -96,10 +112,6 @@ document.addEventListener("DOMContentLoaded", function() { {"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"); + nopaque.navigation.init(); + nopaque.socket.emit("subscribe_user_ressources"); }); diff --git a/app/templates/admin/index.html.j2 b/app/templates/admin/index.html.j2 index 7c0a96cd..95b40db6 100644 --- a/app/templates/admin/index.html.j2 +++ b/app/templates/admin/index.html.j2 @@ -2,32 +2,27 @@ {% block page_content %}
"; diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index 4c246159..d620439c 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -102,21 +102,27 @@ this.corpusId = corpusId; this.foreignCorpusFlag = foreignCorpusFlag; if (this.foreignCorpusFlag) { - foreignCorporaSubscribers.push(this); + nopaque.foreignCorporaSubscribers.push(this); } else { - corporaSubscribers.push(this); + nopaque.corporaSubscribers.push(this); } } _init() { - var corpus = this.foreignCorpusFlag ? foreignCorpora[this.corpusId] : corpora[this.corpusId]; + let corpus; + + if (this.foreignCorpusFlag) { + corpus = nopaque.foreignCorpora[this.corpusId]; + } else { + corpus = nopaque.corpora[this.corpusId]; + } // Status this.setStatus(corpus.status); } _update(patch) { - var pathArray; + let pathArray; for (let operation of patch) { /* "/corpusId/valueName" -> ["corpusId", "valueName"] */ @@ -141,12 +147,13 @@ } setStatus(status) { - var statusElement; + let analyseBtn, statusElement; + statusElement = document.getElementById("status"); statusElement.classList.remove(...Object.values(CorpusList.STATUS_COLORS)); statusElement.classList.add(CorpusList.STATUS_COLORS[status] || CorpusList.STATUS_COLORS['default']); statusElement.innerText = status; - var analyseBtn = document.getElementById('analyse'); + analyseBtn = document.getElementById('analyse'); if (status === 'prepared' || status === 'analysing' || status === 'failed') { analyseBtn.classList.remove('hide', 'disabled'); } else if (status === 'start analysis' || status === 'stop analysis') { @@ -164,7 +171,7 @@ var informationUpdater = new InformationUpdater({{ corpus.id }}, false); {% else %} var informationUpdater = new InformationUpdater({{ corpus.id }}, true); - socket.emit('subscribe_foreign_user_ressources', {{ corpus.user_id }}); + nopaque.socket.emit('subscribe_foreign_user_ressources', {{ corpus.user_id }}); {% endif %} {% endblock %} diff --git a/app/templates/jobs/job.html.j2 b/app/templates/jobs/job.html.j2 index bdc9599e..dd6d75f0 100644 --- a/app/templates/jobs/job.html.j2 +++ b/app/templates/jobs/job.html.j2 @@ -122,14 +122,20 @@ this.jobId = jobId; this.foreignJobFlag = foreignJobFlag; if (this.foreignJobFlag) { - foreignJobsSubscribers.push(this); + nopaque.foreignJobsSubscribers.push(this); } else { - jobsSubscribers.push(this); + nopaque.jobsSubscribers.push(this); } } _init() { - var job = this.foreignJobFlag ? foreignJobs[this.jobId] : jobs[this.jobId]; + let job; + + if (this.foreignJobFlag) { + job = nopaque.foreignJobs[this.jobId]; + } else { + job = nopaque.jobs[this.jobId]; + } // End date this.setEndDate(job.end_date); @@ -146,7 +152,7 @@ } _update(patch) { - var pathArray; + let pathArray; for (let operation of patch) { /* "/jobId/valueName" -> ["jobId", "valueName"] */ @@ -175,7 +181,8 @@ } setEndDate(timestamp) { - var end_date; + let end_date; + if (timestamp === null) { end_date = "N.a."; } else { @@ -186,8 +193,9 @@ } setResult(result) { - var resultsElement, resultDownloadButtonElement, + let resultsElement, resultDownloadButtonElement, resultDownloadButtonIconElement; + resultsElement = document.getElementById(`input-${result.job_input_id}-results`); resultDownloadButtonElement = document.createElement("a"); resultDownloadButtonElement.classList.add("waves-effect", "waves-light", "btn-small"); @@ -203,7 +211,8 @@ } setStatus(status) { - var statusElement; + let statusElement; + statusElement = document.getElementById("status"); statusElement.classList.remove(...Object.values(JobList.STATUS_COLORS)); statusElement.classList.add(JobList.STATUS_COLORS[status] || JobList.STATUS_COLORS['default']); @@ -215,7 +224,7 @@ var informationUpdater = new InformationUpdater({{ job.id }}, false); {% else %} var informationUpdater = new InformationUpdater({{ job.id }}, true); - socket.emit('subscribe_foreign_user_ressources', {{ job.user_id }}); + nopaque.socket.emit('subscribe_foreign_user_ressources', {{ job.user_id }}); {% endif %} {% endblock %} diff --git a/app/templates/main/dashboard.html.j2 b/app/templates/main/dashboard.html.j2 index d7d488db..1b175270 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -86,10 +86,7 @@