mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
146 lines
5.2 KiB
JavaScript
146 lines
5.2 KiB
JavaScript
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);
|
|
});
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
init(user) {
|
|
let corpus = user.corpora[this.corpusId];
|
|
this.setCreationDate(corpus.creation_date);
|
|
this.setDescription(corpus.description);
|
|
this.setStatus(corpus.status);
|
|
this.setTitle(corpus.title);
|
|
this.setNumTokens(corpus.num_tokens);
|
|
this.setShareLink();
|
|
}
|
|
|
|
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 'remove': {
|
|
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}$`);
|
|
if (re.test(operation.path)) {
|
|
window.location.href = '/dashboard#corpora';
|
|
}
|
|
break;
|
|
}
|
|
case 'replace': {
|
|
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/num_tokens`);
|
|
if (re.test(operation.path)) {
|
|
this.setNumTokens(operation.value);
|
|
break;
|
|
}
|
|
re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/status$`);
|
|
if (re.test(operation.path)) {
|
|
this.setStatus(operation.value);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
setTitle(title) {
|
|
this.setElements(this.displayElement.querySelectorAll('.corpus-title'), title);
|
|
}
|
|
|
|
setNumTokens(numTokens) {
|
|
this.setElements(
|
|
this.displayElement.querySelectorAll('.corpus-token-ratio'),
|
|
`${numTokens}/${app.data.users[this.userId].corpora[this.corpusId].max_num_tokens}`
|
|
);
|
|
}
|
|
|
|
setDescription(description) {
|
|
this.setElements(this.displayElement.querySelectorAll('.corpus-description'), description);
|
|
}
|
|
|
|
setStatus(status) {
|
|
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('.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 {
|
|
element.classList.add('disabled');
|
|
}
|
|
}
|
|
elements = this.displayElement.querySelectorAll('.corpus-status');
|
|
for (let element of elements) {
|
|
element.dataset.status = status;
|
|
}
|
|
elements = this.displayElement.querySelectorAll('.corpus-status-spinner');
|
|
for (let element of elements) {
|
|
if (['SUBMITTED', 'QUEUED', 'BUILDING', 'STARTING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'].includes(status)) {
|
|
element.classList.remove('hide');
|
|
} else {
|
|
element.classList.add('hide');
|
|
}
|
|
}
|
|
}
|
|
|
|
setCreationDate(creationDate) {
|
|
this.setElements(
|
|
this.displayElement.querySelectorAll('.corpus-creation-date'),
|
|
new Date(creationDate).toLocaleString("en-US")
|
|
);
|
|
}
|
|
|
|
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');
|
|
});
|
|
}
|
|
}
|