Only handle difference of changes to the job list.

This commit is contained in:
Patrick Jentsch
2019-08-19 17:09:01 +02:00
parent 5ba08a21f4
commit 74c863e0f7
3 changed files with 42 additions and 15 deletions

View File

@ -14,24 +14,20 @@ const STATUS_COLORS = {"pending": "amber",
function createJobElement(job) {
jobElement = document.createElement("a");
jobElement.classList.add("avatar", "collection-item");
jobElement.dataset.key = "id";
jobElement.dataset.value = job.id;
jobElement.dataset.id = job.id;
jobElement.href = `/jobs/${job.id}`;
jobDescriptionElement = document.createElement("p");
jobDescriptionElement.dataset.key = "description";
jobDescriptionElement.classList.add("description");
jobDescriptionElement.innerText = job.description;
jobServiceElement = document.createElement("i");
jobServiceElement.classList.add("circle", "material-icons", SERVICE_COLORS[job.service]);
jobServiceElement.dataset.key = "service";
jobServiceElement.classList.add("circle", "material-icons", "service-icon", SERVICE_COLORS[job.service]);
jobServiceElement.innerText = SERVICE_ICONS[job.service];
jobStatusElement = document.createElement("span");
jobStatusElement.classList.add("badge", "new", "status", STATUS_COLORS[job.status]);
jobStatusElement.dataset.badgeCaption = "";
jobStatusElement.dataset.key = "status";
jobStatusElement.innerText = job.status;
jobTitleElement = document.createElement("span");
jobTitleElement.classList.add("title");
jobTitleElement.dataset.key = "title";
jobTitleElement.innerText = job.title;
jobElement.appendChild(jobServiceElement);

View File

@ -39,11 +39,12 @@ function getJobs() {
.then(function(response) {
return response.json();
})
.then(function(data) {
if (JSON.stringify(jobs) != JSON.stringify(data)) {
jobs = data;
.then(function(json) {
var delta = jsondiffpatch.diff(jobs, json);
if (delta) {
jobs = json;
for (subscriber of subscribers.jobs) {
subscriber();
subscriber(delta);
}
}
})