nopaque/app/static/js/JobStatusNotifier.js

24 lines
746 B
JavaScript
Raw Normal View History

2021-11-30 15:22:16 +00:00
class JobStatusNotifier {
constructor(userId) {
this.userId = userId;
2022-07-04 12:09:17 +00:00
app.socket.on('PATCH', (patch) => {this.onPATCH(patch);});
2021-11-30 15:22:16 +00:00
}
2022-07-04 12:09:17 +00:00
onPATCH(patch) {
2021-12-01 13:15:20 +00:00
let filteredPatch;
let jobId;
let match;
2021-12-06 13:42:49 +00:00
let operation;
2021-12-01 13:15:20 +00:00
let re;
2022-07-04 12:09:17 +00:00
re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)/status$`);
2021-11-30 15:22:16 +00:00
filteredPatch = patch
.filter(operation => operation.op === 'replace')
.filter(operation => re.test(operation.path));
2021-12-06 13:42:49 +00:00
for (operation of filteredPatch) {
2021-11-30 15:22:16 +00:00
[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');
2021-11-30 15:22:16 +00:00
}
}
}