class CorpusDisplay extends RessourceDisplay { constructor(displayElement) { super(displayElement); this.corpusId = displayElement.dataset.corpusId; } init(user) { let corpus; 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); this.setNumTokens(corpus.num_tokens); } usersPatchHandler(patch) { let filteredPatch; let operation; let re; re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}`); filteredPatch = patch.filter(operation => re.test(operation.path)); for (operation of filteredPatch) { switch(operation.op) { case 'replace': re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/last_edited_date$`); 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)) { 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.users[this.userId].corpora[this.corpusId].max_num_tokens}` ); } setDescription(description) { this.setElements(this.displayElement.querySelectorAll('.corpus-description'), description); } setStatus(status) { let element; let elements; this.setElements(this.displayElement.querySelectorAll('.corpus-status'), status); elements = this.displayElement.querySelectorAll('.analyse-corpus-trigger') for (element of elements) { if (['analysing', 'prepared', 'start analysis'].includes(status)) { element.classList.remove('disabled'); } else { element.classList.add('disabled'); } } elements = this.displayElement.querySelectorAll('.build-corpus-trigger'); for (element of elements) { if (status === 'unprepared' && Object.values(app.users[this.userId].corpora[this.corpusId].files).length > 0) { element.classList.remove('disabled'); } else { element.classList.add('disabled'); } } elements = this.displayElement.querySelectorAll('.status'); for (element of elements) { element.dataset.status = status; } elements = this.displayElement.querySelectorAll('.status-spinner'); for (element of elements) { if (['submitted', 'queued', 'running', 'canceling', 'start analysis', 'stop analysis'].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") ); } setLastEditedDate(lastEditedDate) { this.setElements( this.displayElement.querySelectorAll('.corpus-end-date'), new Date(lastEditedDate).toLocaleString("en-US") ); } }