2023-10-11 12:26:07 +00:00
|
|
|
ResourceDisplays.CorpusDisplay = class CorpusDisplay extends ResourceDisplays.ResourceDisplay {
|
2023-10-09 12:21:31 +00:00
|
|
|
static htmlClass = 'corpus-display';
|
|
|
|
|
2021-01-11 12:36:45 +00:00
|
|
|
constructor(displayElement) {
|
|
|
|
super(displayElement);
|
2021-02-01 08:57:10 +00:00
|
|
|
this.corpusId = displayElement.dataset.corpusId;
|
2022-09-02 11:07:30 +00:00
|
|
|
this.displayElement
|
|
|
|
.querySelector('.action-button[data-action="build-request"]')
|
|
|
|
.addEventListener('click', (event) => {
|
2023-10-06 13:04:36 +00:00
|
|
|
Requests.corpora.entity.build(this.corpusId);
|
2022-09-02 11:07:30 +00:00
|
|
|
});
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
init(user) {
|
2022-09-02 11:07:30 +00:00
|
|
|
let corpus = user.corpora[this.corpusId];
|
2021-11-30 15:22:16 +00:00
|
|
|
this.setCreationDate(corpus.creation_date);
|
|
|
|
this.setDescription(corpus.description);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
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) {
|
2021-01-11 12:36:45 +00:00
|
|
|
switch(operation.op) {
|
2022-09-02 11:07:30 +00:00
|
|
|
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': {
|
2021-12-01 13:15:20 +00:00
|
|
|
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;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
|
|
|
default: {
|
2021-01-11 12:36:45 +00:00
|
|
|
break;
|
2022-09-02 11:07:30 +00:00
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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'),
|
2022-07-08 09:46:47 +00:00
|
|
|
`${numTokens}/${app.data.users[this.userId].corpora[this.corpusId].max_num_tokens}`
|
2021-12-01 13:15:20 +00:00
|
|
|
);
|
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) {
|
2023-03-01 15:31:41 +00:00
|
|
|
let elements = this.displayElement.querySelectorAll('.action-button[data-action="analyze"]');
|
2022-09-02 11:07:30 +00:00
|
|
|
for (let element of elements) {
|
2022-02-08 11:26:20 +00:00
|
|
|
if (['BUILT', 'STARTING_ANALYSIS_SESSION', 'RUNNING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'].includes(status)) {
|
2021-01-11 14:43:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2022-09-02 11:07:30 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.action-button[data-action="build-request"]');
|
|
|
|
for (let element of elements) {
|
2022-07-08 09:46:47 +00:00
|
|
|
if (['UNPREPARED', 'FAILED'].includes(status) && Object.values(app.data.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');
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 11:26:20 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.corpus-status');
|
2022-09-02 11:07:30 +00:00
|
|
|
for (let element of elements) {
|
2023-01-10 09:01:54 +00:00
|
|
|
element.dataset.status = status;
|
2021-01-13 14:43:23 +00:00
|
|
|
}
|
2022-02-08 11:26:20 +00:00
|
|
|
elements = this.displayElement.querySelectorAll('.corpus-status-spinner');
|
2022-09-02 11:07:30 +00:00
|
|
|
for (let element of elements) {
|
2022-02-08 11:26:20 +00:00
|
|
|
if (['SUBMITTED', 'QUEUED', 'BUILDING', 'STARTING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'].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
|
|
|
}
|
2023-10-05 14:08:04 +00:00
|
|
|
};
|