nopaque/app/static/js/JobStatusNotifier.js
2022-07-04 14:09:17 +02:00

24 lines
746 B
JavaScript

class JobStatusNotifier {
constructor(userId) {
this.userId = userId;
app.socket.on('PATCH', (patch) => {this.onPATCH(patch);});
}
onPATCH(patch) {
let filteredPatch;
let jobId;
let match;
let operation;
let re;
re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)/status$`);
filteredPatch = patch
.filter(operation => operation.op === 'replace')
.filter(operation => re.test(operation.path));
for (operation of filteredPatch) {
[match, jobId] = operation.path.match(re);
app.flash(`[<a href="/jobs/${jobId}">${app.users[this.userId].jobs[jobId].title}</a>] New status: <span class="job-status-text" data-job-status="${operation.value}"></span>`, 'job');
}
}
}