mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +00:00
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
var subscribers = {"corpora": [], "jobs": []};
|
|
|
|
|
|
function getCorpora() {
|
|
fetch("/api/v1.0/corpora")
|
|
.then(function(response) {
|
|
if (response.status >= 200 && response.status < 300) {
|
|
return Promise.resolve(response);
|
|
} else {
|
|
return Promise.reject(new Error(response.statusText));
|
|
}
|
|
})
|
|
.then(function(response) {
|
|
return response.json();
|
|
})
|
|
.then(function(data) {
|
|
if (JSON.stringify(corpora) != JSON.stringify(data)) {
|
|
corpora = data;
|
|
for (subscriber of subscribers.corpora) {
|
|
subscriber.corporaUpdateHandler();
|
|
}
|
|
}
|
|
})
|
|
.catch(function(error) {
|
|
console.log('Request failed', error);
|
|
});
|
|
}
|
|
|
|
|
|
function getJobs() {
|
|
fetch("/api/v1.0/jobs")
|
|
.then(function(response) {
|
|
if (response.status >= 200 && response.status < 300) {
|
|
return Promise.resolve(response);
|
|
} else {
|
|
return Promise.reject(new Error(response.statusText));
|
|
}
|
|
})
|
|
.then(function(response) {
|
|
return response.json();
|
|
})
|
|
.then(function(json) {
|
|
var delta = jsondiffpatch.diff(jobs, json);
|
|
if (delta) {
|
|
jobs = json;
|
|
for (subscriber of subscribers.jobs) {
|
|
subscriber.jobsUpdateHandler(delta);
|
|
}
|
|
}
|
|
})
|
|
.catch(function(error) {
|
|
console.log('Request failed', error);
|
|
});
|
|
}
|
|
|
|
|
|
setInterval(getCorpora, 5000);
|
|
setInterval(getJobs, 5000);
|