mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-14 18:10:40 +00:00
Restructure project
This commit is contained in:
@ -2,11 +2,20 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
constructor(displayElement) {
|
||||
super(displayElement);
|
||||
this.corpusId = displayElement.dataset.corpusId;
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="build-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.buildCorpusRequest(this.userId, this.corpusId);
|
||||
});
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="delete-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.deleteCorpusRequest(this.userId, this.corpusId);
|
||||
});
|
||||
}
|
||||
|
||||
init(user) {
|
||||
const corpus = user.corpora[this.corpusId];
|
||||
|
||||
let corpus = user.corpora[this.corpusId];
|
||||
this.setCreationDate(corpus.creation_date);
|
||||
this.setDescription(corpus.description);
|
||||
this.setLastEditedDate(corpus.last_edited_date);
|
||||
@ -15,20 +24,20 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
this.setNumTokens(corpus.num_tokens);
|
||||
}
|
||||
|
||||
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) {
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}`);
|
||||
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||
for (let operation of filteredPatch) {
|
||||
switch(operation.op) {
|
||||
case 'replace':
|
||||
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/last_edited_date$`);
|
||||
case 'remove': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}$`);
|
||||
if (re.test(operation.path)) {
|
||||
window.location.href = '/dashboard#corpora';
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/last_edited_date$`);
|
||||
if (re.test(operation.path)) {
|
||||
this.setLastEditedDate(operation.value);
|
||||
break;
|
||||
@ -44,8 +53,10 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -66,19 +77,16 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
}
|
||||
|
||||
setStatus(status) {
|
||||
let element;
|
||||
let elements;
|
||||
|
||||
elements = this.displayElement.querySelectorAll('.corpus-analyse-trigger')
|
||||
for (element of elements) {
|
||||
let elements = this.displayElement.querySelectorAll('.corpus-analyse-trigger')
|
||||
for (let element of elements) {
|
||||
if (['BUILT', 'STARTING_ANALYSIS_SESSION', 'RUNNING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'].includes(status)) {
|
||||
element.classList.remove('disabled');
|
||||
} else {
|
||||
element.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.corpus-build-trigger');
|
||||
for (element of elements) {
|
||||
elements = this.displayElement.querySelectorAll('.action-button[data-action="build-request"]');
|
||||
for (let element of elements) {
|
||||
if (['UNPREPARED', 'FAILED'].includes(status) && Object.values(app.data.users[this.userId].corpora[this.corpusId].files).length > 0) {
|
||||
element.classList.remove('disabled');
|
||||
} else {
|
||||
@ -86,11 +94,11 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
}
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.corpus-status');
|
||||
for (element of elements) {
|
||||
for (let element of elements) {
|
||||
element.dataset.corpusStatus = status;
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.corpus-status-spinner');
|
||||
for (element of elements) {
|
||||
for (let element of elements) {
|
||||
if (['SUBMITTED', 'QUEUED', 'BUILDING', 'STARTING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'].includes(status)) {
|
||||
element.classList.remove('hide');
|
||||
} else {
|
||||
|
@ -2,11 +2,25 @@ class JobDisplay extends RessourceDisplay {
|
||||
constructor(displayElement) {
|
||||
super(displayElement);
|
||||
this.jobId = this.displayElement.dataset.jobId;
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="delete-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.deleteJobRequest(this.userId, this.jobId);
|
||||
});
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="get-log-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.getJobLogRequest(this.userId, this.jobId);
|
||||
});
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="restart-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.restartJobRequest(this.userId, this.jobId);
|
||||
});
|
||||
}
|
||||
|
||||
init(user) {
|
||||
const job = user.jobs[this.jobId];
|
||||
|
||||
let job = user.jobs[this.jobId];
|
||||
this.setCreationDate(job.creation_date);
|
||||
this.setEndDate(job.creation_date);
|
||||
this.setDescription(job.description);
|
||||
@ -17,20 +31,20 @@ class JobDisplay extends RessourceDisplay {
|
||||
this.setTitle(job.title);
|
||||
}
|
||||
|
||||
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) {
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}`);
|
||||
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||
for (let operation of filteredPatch) {
|
||||
switch(operation.op) {
|
||||
case 'replace':
|
||||
re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/end_date$`);
|
||||
case 'remove': {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}$`);
|
||||
if (re.test(operation.path)) {
|
||||
window.location.href = '/dashboard#jobs';
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace': {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/end_date$`);
|
||||
if (re.test(operation.path)) {
|
||||
this.setEndDate(operation.value);
|
||||
break;
|
||||
@ -41,8 +55,10 @@ class JobDisplay extends RessourceDisplay {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,15 +72,12 @@ class JobDisplay extends RessourceDisplay {
|
||||
}
|
||||
|
||||
setStatus(status) {
|
||||
let element;
|
||||
let elements;
|
||||
|
||||
elements = this.displayElement.querySelectorAll('.job-status');
|
||||
for (element of elements) {
|
||||
let elements = this.displayElement.querySelectorAll('.job-status');
|
||||
for (let element of elements) {
|
||||
element.dataset.jobStatus = status;
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.job-status-spinner');
|
||||
for (element of elements) {
|
||||
for (let element of elements) {
|
||||
if (['COMPLETED', 'FAILED'].includes(status)) {
|
||||
element.classList.add('hide');
|
||||
} else {
|
||||
@ -72,19 +85,27 @@ class JobDisplay extends RessourceDisplay {
|
||||
}
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.job-log-trigger');
|
||||
for (element of elements) {
|
||||
for (let element of elements) {
|
||||
if (['COMPLETED', 'FAILED'].includes(status)) {
|
||||
element.classList.remove('hide');
|
||||
} else {
|
||||
element.classList.add('hide');
|
||||
}
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.job-restart-trigger');
|
||||
for (element of elements) {
|
||||
elements = this.displayElement.querySelectorAll('.action-button[data-action="get-log-request"]');
|
||||
for (let element of elements) {
|
||||
if (['COMPLETED', 'FAILED'].includes(status)) {
|
||||
element.classList.remove('hide');
|
||||
element.classList.remove('disabled');
|
||||
} else {
|
||||
element.classList.add('hide');
|
||||
element.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
elements = this.displayElement.querySelectorAll('.action-button[data-action="restart-request"]');
|
||||
for (let element of elements) {
|
||||
if (status === 'FAILED') {
|
||||
element.classList.remove('disabled');
|
||||
} else {
|
||||
element.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,36 +4,40 @@ class RessourceDisplay {
|
||||
this.userId = this.displayElement.dataset.userId;
|
||||
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;
|
||||
});
|
||||
app.subscribeUser(this.userId)
|
||||
.then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId)
|
||||
.then((user) => {
|
||||
this.init(user);
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
init(user) {throw 'Not implemented';}
|
||||
|
||||
onPATCH(patch) {throw 'Not implemented';}
|
||||
onPatch(patch) {throw 'Not implemented';}
|
||||
|
||||
setElement(element, value) {
|
||||
switch (element.tagName) {
|
||||
case 'INPUT':
|
||||
case 'INPUT': {
|
||||
element.value = value;
|
||||
M.updateTextFields();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
element.innerText = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setElements(elements, value) {
|
||||
let element;
|
||||
|
||||
for (element of elements) {
|
||||
for (let element of elements) {
|
||||
this.setElement(element, value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user