mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-14 18:10:40 +00:00
Change the Subscription Logic for Socket.IO Data exchange
This commit is contained in:
@ -5,9 +5,8 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
}
|
||||
|
||||
init(user) {
|
||||
let corpus;
|
||||
const corpus = user.corpora[this.corpusId];
|
||||
|
||||
corpus = user.corpora[this.corpusId];
|
||||
this.setCreationDate(corpus.creation_date);
|
||||
this.setDescription(corpus.description);
|
||||
this.setLastEditedDate(corpus.last_edited_date);
|
||||
@ -17,12 +16,15 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
}
|
||||
|
||||
onPATCH(patch) {
|
||||
if (!this.isInitialized) {return;}
|
||||
|
||||
let filteredPatch;
|
||||
let operation;
|
||||
let re;
|
||||
|
||||
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}`);
|
||||
filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||
|
||||
for (operation of filteredPatch) {
|
||||
switch(operation.op) {
|
||||
case 'replace':
|
||||
@ -55,7 +57,7 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
setNumTokens(numTokens) {
|
||||
this.setElements(
|
||||
this.displayElement.querySelectorAll('.corpus-token-ratio'),
|
||||
`${numTokens}/${app.users[this.userId].corpora[this.corpusId].max_num_tokens}`
|
||||
`${numTokens}/${app.data.users[this.userId].corpora[this.corpusId].max_num_tokens}`
|
||||
);
|
||||
}
|
||||
|
||||
@ -77,7 +79,7 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.corpus-build-trigger');
|
||||
for (element of elements) {
|
||||
if (['UNPREPARED', 'FAILED'].includes(status) && Object.values(app.users[this.userId].corpora[this.corpusId].files).length > 0) {
|
||||
if (['UNPREPARED', 'FAILED'].includes(status) && Object.values(app.data.users[this.userId].corpora[this.corpusId].files).length > 0) {
|
||||
element.classList.remove('disabled');
|
||||
} else {
|
||||
element.classList.add('disabled');
|
||||
|
@ -5,9 +5,8 @@ class JobDisplay extends RessourceDisplay {
|
||||
}
|
||||
|
||||
init(user) {
|
||||
let job;
|
||||
const job = user.jobs[this.jobId];
|
||||
|
||||
job = user.jobs[this.jobId];
|
||||
this.setCreationDate(job.creation_date);
|
||||
this.setEndDate(job.creation_date);
|
||||
this.setDescription(job.description);
|
||||
@ -19,12 +18,15 @@ class JobDisplay extends RessourceDisplay {
|
||||
}
|
||||
|
||||
onPATCH(patch) {
|
||||
if (!this.isInitialized) {return;}
|
||||
|
||||
let filteredPatch;
|
||||
let operation;
|
||||
let re;
|
||||
|
||||
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}`);
|
||||
filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||
|
||||
for (operation of filteredPatch) {
|
||||
switch(operation.op) {
|
||||
case 'replace':
|
||||
|
@ -2,8 +2,16 @@ class RessourceDisplay {
|
||||
constructor(displayElement) {
|
||||
this.displayElement = displayElement;
|
||||
this.userId = this.displayElement.dataset.userId;
|
||||
app.socket.on('PATCH', (patch) => {this.onPATCH(patch);});
|
||||
app.subscribeUser(this.userId).then((user) => {this.init(user);});
|
||||
this.isInitialized = false;
|
||||
if (this.userId) {
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {this.onPATCH(patch);});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.init(user);
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
init(user) {throw 'Not implemented';}
|
||||
|
Reference in New Issue
Block a user