2021-01-11 12:36:45 +00:00
|
|
|
class CorpusDisplay extends RessourceDisplay {
|
|
|
|
constructor(displayElement) {
|
|
|
|
super(displayElement);
|
2021-02-01 08:57:10 +00:00
|
|
|
this.corpusId = displayElement.dataset.corpusId;
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
init(user) {
|
|
|
|
let corpus;
|
2021-12-01 13:15:20 +00:00
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
corpus = user.corpora[this.corpusId];
|
|
|
|
this.setCreationDate(corpus.creation_date);
|
|
|
|
this.setDescription(corpus.description);
|
|
|
|
this.setLastEditedDate(corpus.last_edited_date);
|
|
|
|
this.setStatus(corpus.status);
|
|
|
|
this.setTitle(corpus.title);
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setNumTokens(corpus.num_tokens);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 15:10:54 +00:00
|
|
|
usersPatchHandler(patch) {
|
2021-12-01 13:15:20 +00:00
|
|
|
let filteredPatch;
|
|
|
|
let operation;
|
|
|
|
let re;
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}`);
|
|
|
|
filteredPatch = patch.filter(operation => re.test(operation.path));
|
2021-12-01 13:15:20 +00:00
|
|
|
for (operation of filteredPatch) {
|
2021-01-11 12:36:45 +00:00
|
|
|
switch(operation.op) {
|
|
|
|
case 'replace':
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/last_edited_date$`);
|
2021-12-01 13:15:20 +00:00
|
|
|
if (re.test(operation.path)) {
|
|
|
|
this.setLastEditedDate(operation.value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/num_tokens`);
|
|
|
|
if (re.test(operation.path)) {
|
2021-12-03 15:10:54 +00:00
|
|
|
this.setNumTokens(operation.value);
|
2021-12-01 13:15:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/status$`);
|
2021-12-01 13:15:20 +00:00
|
|
|
if (re.test(operation.path)) {
|
2021-12-03 15:10:54 +00:00
|
|
|
this.setStatus(operation.value);
|
2021-12-01 13:15:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTitle(title) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(this.displayElement.querySelectorAll('.corpus-title'), title);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 13:15:20 +00:00
|
|
|
setNumTokens(numTokens) {
|
|
|
|
this.setElements(
|
|
|
|
this.displayElement.querySelectorAll('.corpus-token-ratio'),
|
|
|
|
`${numTokens}/${app.users[this.userId].corpora[this.corpusId].max_num_tokens}`
|
|
|
|
);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setDescription(description) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(this.displayElement.querySelectorAll('.corpus-description'), description);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setStatus(status) {
|
2021-12-01 13:15:20 +00:00
|
|
|
let element;
|
|
|
|
let elements;
|
|
|
|
|
|
|
|
this.setElements(this.displayElement.querySelectorAll('.corpus-status'), status);
|
|
|
|
elements = this.displayElement.querySelectorAll('.analyse-corpus-trigger')
|
|
|
|
for (element of elements) {
|
2021-01-11 14:43:15 +00:00
|
|
|
if (['analysing', 'prepared', 'start analysis'].includes(status)) {
|
|
|
|
element.classList.remove('disabled');
|
2021-01-11 12:36:45 +00:00
|
|
|
} else {
|
2021-01-11 14:43:15 +00:00
|
|
|
element.classList.add('disabled');
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-01 13:15:20 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.build-corpus-trigger');
|
|
|
|
for (element of elements) {
|
2021-11-30 15:22:16 +00:00
|
|
|
if (status === 'unprepared' && Object.values(app.users[this.userId].corpora[this.corpusId].files).length > 0) {
|
2021-01-11 14:43:15 +00:00
|
|
|
element.classList.remove('disabled');
|
|
|
|
} else {
|
|
|
|
element.classList.add('disabled');
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 13:15:20 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.status');
|
|
|
|
for (element of elements) {
|
|
|
|
element.dataset.status = status;
|
2021-01-13 14:43:23 +00:00
|
|
|
}
|
2021-12-01 13:15:20 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.status-spinner');
|
|
|
|
for (element of elements) {
|
2021-01-11 14:43:15 +00:00
|
|
|
if (['submitted', 'queued', 'running', 'canceling', 'start analysis', 'stop analysis'].includes(status)) {
|
2021-01-11 12:36:45 +00:00
|
|
|
element.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
element.classList.add('hide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
setCreationDate(creationDate) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(
|
|
|
|
this.displayElement.querySelectorAll('.corpus-creation-date'),
|
|
|
|
new Date(creationDate).toLocaleString("en-US")
|
|
|
|
);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
setLastEditedDate(lastEditedDate) {
|
2021-12-01 13:15:20 +00:00
|
|
|
this.setElements(
|
|
|
|
this.displayElement.querySelectorAll('.corpus-end-date'),
|
|
|
|
new Date(lastEditedDate).toLocaleString("en-US")
|
|
|
|
);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|