mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 19:34:19 +00:00
32 lines
1000 B
JavaScript
32 lines
1000 B
JavaScript
class JobStatusNotifier {
|
|
constructor(userId) {
|
|
this.userId = userId;
|
|
this.isInitialized = false;
|
|
app.subscribeUser(this.userId).then((response) => {
|
|
app.socket.on('PATCH', (patch) => {this.onPATCH(patch);});
|
|
});
|
|
app.getUser(this.userId).then((user) => {
|
|
this.isInitialized = true;
|
|
});
|
|
}
|
|
|
|
onPATCH(patch) {
|
|
if (!this.isInitialized) {return;}
|
|
|
|
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) => {return operation.op === 'replace';})
|
|
.filter((operation) => {return re.test(operation.path);});
|
|
for (operation of filteredPatch) {
|
|
[match, jobId] = operation.path.match(re);
|
|
app.flash(`[<a href="/jobs/${jobId}">${app.data.users[this.userId].jobs[jobId].title}</a>] New status: <span class="job-status-text" data-job-status="${operation.value}"></span>`, 'job');
|
|
}
|
|
}
|
|
}
|