Change the Subscription Logic for Socket.IO Data exchange

This commit is contained in:
Patrick Jentsch
2022-07-08 11:46:47 +02:00
parent 5771e156ce
commit 4e5957eea2
17 changed files with 137 additions and 134 deletions

View File

@ -65,7 +65,7 @@ class CorpusFileList extends RessourceList {
<div class="modal">
<div class="modal-content">
<h4>Confirm corpus deletion</h4>
<p>Do you really want to delete the corpus file <b>${app.users[this.userId].corpora[this.corpusId].files[corpusFileId].filename}</b>? It will be permanently deleted!</p>
<p>Do you really want to delete the corpus file <b>${app.data.users[this.userId].corpora[this.corpusId].files[corpusFileId].filename}</b>? It will be permanently deleted!</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
@ -97,6 +97,8 @@ class CorpusFileList extends RessourceList {
}
onPATCH(patch) {
if (!this.isInitialized) {return;}
let corpusFileId;
let filteredPatch;
let match;

View File

@ -60,7 +60,7 @@ class CorpusList extends RessourceList {
<div class="modal">
<div class="modal-content">
<h4>Confirm corpus deletion</h4>
<p>Do you really want to delete the corpus <b>${app.users[this.userId].corpora[corpusId].title}</b>? All files will be permanently deleted!</p>
<p>Do you really want to delete the corpus <b>${app.data.users[this.userId].corpora[corpusId].title}</b>? All files will be permanently deleted!</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
@ -89,6 +89,8 @@ class CorpusList extends RessourceList {
}
onPATCH(patch) {
if (!this.isInitialized) {return;}
let corpusId;
let filteredPatch;
let match;

View File

@ -36,7 +36,6 @@ class JobList extends RessourceList {
]
};
constructor(listElement, options = {}) {
super(listElement, {...JobList.options, ...options});
}
@ -66,7 +65,7 @@ class JobList extends RessourceList {
<div class="modal">
<div class="modal-content">
<h4>Confirm job deletion</h4>
<p>Do you really want to delete the job <b>${app.users[this.userId].jobs[jobId].title}</b>? All files will be permanently deleted!</p>
<p>Do you really want to delete the job <b>${app.data.users[this.userId].jobs[jobId].title}</b>? All files will be permanently deleted!</p>
</div>
<div class="modal-footer">
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
@ -95,6 +94,8 @@ class JobList extends RessourceList {
}
onPATCH(patch) {
if (!this.isInitialized) {return;}
let filteredPatch;
let jobId;
let match;

View File

@ -58,6 +58,8 @@ class JobResultList extends RessourceList {
}
onPATCH(patch) {
if (!this.isInitialized) {return;}
let filteredPatch;
let operation;
let re;

View File

@ -90,12 +90,15 @@ class RessourceList {
this.listjs.list.style.cursor = 'pointer';
this.userId = this.listjs.listContainer.dataset.userId;
this.listjs.list.addEventListener('click', event => this.onclick(event));
this.isInitialized = false;
if (this.userId) {
app.socket.on('PATCH', (patch) => {this.onPATCH(patch);});
app.subscribeUser(this.userId).then(
(user) => {this.init(user);},
(error) => {throw JSON.stringify(error);}
);
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;
});
}
}

View File

@ -20,7 +20,7 @@ class UserList extends RessourceList {
'id-1': user.id,
'username': user.username,
'email': user.email,
'last-seen': new Date(user.last_seen).toLocaleString("en-US"),
'last-seen': new Date(user.last_seen).toLocaleString('en-US'),
'member-since': user.member_since,
'role': user.role.name
};