Fix missing RessourceList import.

This commit is contained in:
Stephan Porada 2020-09-17 11:12:08 +02:00
parent ad21fe178c
commit 269368e940

View File

@ -157,145 +157,146 @@
</div> </div>
<script> <script type="module">
class InformationUpdater { import {RessourceList} from '../../static/js/nopaque.lists.js';
constructor(jobId, foreignJobFlag) { class InformationUpdater {
this.jobId = jobId; constructor(jobId, foreignJobFlag) {
this.foreignJobFlag = foreignJobFlag; this.jobId = jobId;
this.foreignJobFlag = foreignJobFlag;
if (this.foreignJobFlag) { if (this.foreignJobFlag) {
nopaque.foreignJobsSubscribers.push(this); nopaque.foreignJobsSubscribers.push(this);
} else { } else {
nopaque.jobsSubscribers.push(this); nopaque.jobsSubscribers.push(this);
}
} }
}
_init() { _init() {
let job; let job;
job = (this.foreignJobFlag ? nopaque.foreignUser.jobs[this.jobId] job = (this.foreignJobFlag ? nopaque.foreignUser.jobs[this.jobId]
: nopaque.user.jobs[this.jobId]); : nopaque.user.jobs[this.jobId]);
// Results // Results
this.addResults(job.results); this.addResults(job.results);
// End date // End date
this.setEndDate(job.end_date); this.setEndDate(job.end_date);
// Status // Status
this.setStatus(job.status); this.setStatus(job.status);
} }
_update(patch) { _update(patch) {
let pathArray; let pathArray;
for (let operation of patch) { for (let operation of patch) {
/* "/jobs/{jobId}/..." -> ["{jobId}", ...] */ /* "/jobs/{jobId}/..." -> ["{jobId}", ...] */
pathArray = operation.path.split("/").slice(2); pathArray = operation.path.split("/").slice(2);
if (pathArray[0] != this.jobId) {continue;} if (pathArray[0] != this.jobId) {continue;}
switch(operation.op) { switch(operation.op) {
case "add": case "add":
if (pathArray[1] === "results") { if (pathArray[1] === "results") {
this.addResults([operation.value]); this.addResults([operation.value]);
} }
break; break;
case "delete": case "delete":
location.reload(); location.reload();
break; break;
case "replace": case "replace":
if (pathArray[1] === "end_date") { if (pathArray[1] === "end_date") {
this.setEndDate(operation.value); this.setEndDate(operation.value);
} else if (pathArray[1] === "status") { } else if (pathArray[1] === "status") {
this.setStatus(operation.value); this.setStatus(operation.value);
} }
break; break;
default: default:
break; break;
}
}
}
addResults(results) {
let resultsArray, resultsElements, resultsHTML, resultType;
resultsArray = Object.values(results);
resultsArray.sort(function (a, b) {
if (a.filename < b.filename) {return -1;}
if (a.filename > b.filename) {return 1;}
return 0;
});
resultsHTML = ``;
for (let result of resultsArray) {
if (result.filename.endsWith(".pdf.zip")) {
resultType = "PDF file with text layer";
} else if (result.filename.endsWith(".txt.zip")) {
resultType = "Raw text files";
} else if (result.filename.endsWith(".vrt.zip")) {
resultType = "VRT(XML dialect) files holding the NLP data";
} else if (result.filename.endsWith(".xml.zip")) {
resultType = "XML files";
} else if (result.filename.endsWith(".poco.zip")) {
resultType = "HCOR und image files needed for Post correction(PoCo)";
} else {
resultType = "All result files created during this job";
}
resultsHTML += `
<tr>
<td>${resultType}</td>
<td>${result.filename}</td>
<td class="right-align">
<a class="btn-floating tooltipped waves-effect waves-light"
download href="/jobs/${result.job_id}/results/${result.id}/download"
data-position="top"
data-tooltip="Download">
<i class="material-icons">file_download</i>
</a>
</td>
</tr>
`;
};
resultsHTML += `
</tbody>
</table>
`;
resultsElements = document.querySelectorAll(".results");
for (let resultsElement of resultsElements) {
resultsElement.innerHTML += resultsHTML;
}
}
setEndDate(timestamp) {
let endDate;
if (timestamp === null) {
endDate = "N.a.";
} else {
endDate = new Date(timestamp * 1000).toLocaleString("en-US");
}
document.getElementById("end-date").value = endDate;
M.updateTextFields();
}
setStatus(status) {
let progressIndicator, statusElements;
if (status === "complete" || status === "failed") {
progressIndicator = document.getElementById("progress-indicator");
progressIndicator.classList.add("hide");
}
statusElements = document.querySelectorAll(".status");
for (let statusElement of statusElements) {
statusElement.dataset.status = status;
} }
} }
} }
{% if job.creator == current_user %} addResults(results) {
var informationUpdater = new InformationUpdater({{ job.id }}, false); let resultsArray, resultsElements, resultsHTML, resultType;
{% else %} resultsArray = Object.values(results);
var informationUpdater = new InformationUpdater({{ job.id }}, true); resultsArray.sort(function (a, b) {
document.addEventListener("DOMContentLoaded", () => { if (a.filename < b.filename) {return -1;}
nopaque.socket.emit("foreign_user_data_stream_init", {{ job.user_id }}); if (a.filename > b.filename) {return 1;}
}); return 0;
{% endif %} });
let jobInputsList = new RessourceList("inputs", null, "JobInput"); resultsHTML = ``;
document.addEventListener("DOMContentLoaded", () => { for (let result of resultsArray) {
jobInputsList._add({{ job_inputs|tojson|safe }}); if (result.filename.endsWith(".pdf.zip")) {
}); resultType = "PDF file with text layer";
} else if (result.filename.endsWith(".txt.zip")) {
resultType = "Raw text files";
} else if (result.filename.endsWith(".vrt.zip")) {
resultType = "VRT(XML dialect) files holding the NLP data";
} else if (result.filename.endsWith(".xml.zip")) {
resultType = "XML files";
} else if (result.filename.endsWith(".poco.zip")) {
resultType = "HCOR und image files needed for Post correction(PoCo)";
} else {
resultType = "All result files created during this job";
}
resultsHTML += `
<tr>
<td>${resultType}</td>
<td>${result.filename}</td>
<td class="right-align">
<a class="btn-floating tooltipped waves-effect waves-light"
download href="/jobs/${result.job_id}/results/${result.id}/download"
data-position="top"
data-tooltip="Download">
<i class="material-icons">file_download</i>
</a>
</td>
</tr>
`;
};
resultsHTML += `
</tbody>
</table>
`;
resultsElements = document.querySelectorAll(".results");
for (let resultsElement of resultsElements) {
resultsElement.innerHTML += resultsHTML;
}
}
setEndDate(timestamp) {
let endDate;
if (timestamp === null) {
endDate = "N.a.";
} else {
endDate = new Date(timestamp * 1000).toLocaleString("en-US");
}
document.getElementById("end-date").value = endDate;
M.updateTextFields();
}
setStatus(status) {
let progressIndicator, statusElements;
if (status === "complete" || status === "failed") {
progressIndicator = document.getElementById("progress-indicator");
progressIndicator.classList.add("hide");
}
statusElements = document.querySelectorAll(".status");
for (let statusElement of statusElements) {
statusElement.dataset.status = status;
}
}
}
{% if job.creator == current_user %}
var informationUpdater = new InformationUpdater({{ job.id }}, false);
{% else %}
var informationUpdater = new InformationUpdater({{ job.id }}, true);
document.addEventListener("DOMContentLoaded", () => {
nopaque.socket.emit("foreign_user_data_stream_init", {{ job.user_id }});
});
{% endif %}
let jobInputsList = new RessourceList("inputs", null, "JobInput");
document.addEventListener("DOMContentLoaded", () => {
jobInputsList._add({{ job_inputs|tojson|safe }});
});
</script> </script>
{% endblock %} {% endblock %}