2023-11-09 13:29:01 +00:00
|
|
|
nopaque.resource_displays.CorpusDisplay = class CorpusDisplay extends nopaque.resource_displays.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-11-09 13:29:01 +00:00
|
|
|
nopaque.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-05 14:07:13 +00:00
|
|
|
async setTitle(title) {
|
|
|
|
const corpusTitleElements = this.displayElement.querySelectorAll('.corpus-title');
|
|
|
|
this.setElements(corpusTitleElements, title);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 13:15:20 +00:00
|
|
|
setNumTokens(numTokens) {
|
2024-12-05 14:07:13 +00:00
|
|
|
const corpusTokenRatioElements = this.displayElement.querySelectorAll('.corpus-token-ratio');
|
|
|
|
const maxNumTokens = 2147483647;
|
|
|
|
|
|
|
|
this.setElements(corpusTokenRatioElements, `${numTokens}/${maxNumTokens}`);
|
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
|
|
|
}
|
|
|
|
|
2024-12-05 14:07:13 +00:00
|
|
|
async 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"]');
|
2024-12-05 14:07:13 +00:00
|
|
|
const user = await app.userHub.get(this.userId);
|
|
|
|
const corpusFiles = user.corpora[this.corpusId].files;
|
2022-09-02 11:07:30 +00:00
|
|
|
for (let element of elements) {
|
2024-12-05 14:07:13 +00:00
|
|
|
if (['UNPREPARED', 'FAILED'].includes(status) && Object.values(corpusFiles.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) {
|
2024-05-21 08:29:12 +00:00
|
|
|
element.dataset.corpusStatus = status;
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|