nopaque/app/static/js/JobStatusNotifier.js

23 lines
700 B
JavaScript
Raw Normal View History

2021-11-30 15:22:16 +00:00
class JobStatusNotifier {
constructor(userId) {
this.userId = userId;
}
usersPatchHandler(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;
2021-11-30 15:22:16 +00:00
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));
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="nopaque-job-status-text" data-job-status="${operation.value}"></span>`, 'job');
2021-11-30 15:22:16 +00:00
}
}
}