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;
|
2022-09-02 11:07:30 +00:00
|
|
|
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);
|
|
|
|
});
|
2023-02-09 15:22:37 +00:00
|
|
|
this.displayElement
|
|
|
|
.querySelector('.action-switch[data-action="toggle-is-public"]')
|
|
|
|
.addEventListener('click', (event) => {
|
|
|
|
if (event.target.tagName !== 'INPUT') {return;}
|
|
|
|
if (event.target.checked) {
|
|
|
|
Utils.enableCorpusIsPublicRequest(this.userId, this.corpusId);
|
|
|
|
} else {
|
|
|
|
Utils.disableCorpusIsPublicRequest(this.userId, this.corpusId);
|
|
|
|
}
|
|
|
|
});
|
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);
|
2023-02-22 15:00:04 +00:00
|
|
|
this.setShareLink();
|
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) {
|
2022-09-02 11:07:30 +00:00
|
|
|
let elements = this.displayElement.querySelectorAll('.corpus-analyse-trigger')
|
|
|
|
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-02-22 15:00:04 +00:00
|
|
|
|
|
|
|
setShareLink() {
|
|
|
|
let generateShareLinkButton = this.displayElement.querySelector('#generate-share-link-button');
|
|
|
|
let copyShareLinkButton = this.displayElement.querySelector('#copy-share-link-button');
|
|
|
|
let shareLinkInput = this.displayElement.querySelector('#share-link-input');
|
|
|
|
// let permissionSelect = this.displayElement.querySelector('#permission-select');
|
|
|
|
let expirationDate = this.displayElement.querySelector('#expiration');
|
|
|
|
|
|
|
|
|
|
|
|
generateShareLinkButton.addEventListener('click', () => {
|
|
|
|
// Utils.generateCorpusShareLinkRequest(`${this.corpusId}`, permissionSelect.value, expirationDate.value)
|
|
|
|
Utils.generateCorpusShareLinkRequest(`${this.corpusId}`, expirationDate.value)
|
|
|
|
.then((shareLink) => {
|
|
|
|
shareLinkInput.parentElement.classList.remove('hide');
|
|
|
|
shareLinkInput.value = shareLink;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
copyShareLinkButton.addEventListener('click', () => {
|
|
|
|
shareLinkInput.select();
|
|
|
|
navigator.clipboard.writeText(shareLinkInput.value);
|
|
|
|
app.flash(`Copied!`, 'success');
|
|
|
|
});
|
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|