diff --git a/app/static/js/CorpusAnalysis/CorpusAnalysisStaticVisualization.js b/app/static/js/CorpusAnalysis/CorpusAnalysisStaticVisualization.js index 38c48c3c..4d51b014 100644 --- a/app/static/js/CorpusAnalysis/CorpusAnalysisStaticVisualization.js +++ b/app/static/js/CorpusAnalysis/CorpusAnalysisStaticVisualization.js @@ -104,7 +104,7 @@ class CorpusAnalysisStaticVisualization { renderTextInfoList() { let corpusData = this.data.corpus.o.staticData; let corpusTextInfoListElement = document.querySelector('.corpus-text-info-list'); - let corpusTextInfoList = new CorpusTextInfoList(corpusTextInfoListElement); + let corpusTextInfoList = new ResourceLists.CorpusTextInfoList(corpusTextInfoListElement); let texts = corpusData.s_attrs.text.lexicon; let textData = []; for (let i = 0; i < Object.entries(texts).length; i++) { @@ -213,7 +213,7 @@ class CorpusAnalysisStaticVisualization { async renderTokenList() { let corpusTokenListElement = document.querySelector('.corpus-token-list'); - let corpusTokenList = new CorpusTokenList(corpusTokenListElement); + let corpusTokenList = new ResourceLists.CorpusTokenList(corpusTokenListElement); let filteredData = this.filterData(); let stopwords = this.data.stopwords; if (this.data.stopwords === undefined) { diff --git a/app/static/js/resource-displays/index.js b/app/static/js/resource-displays/index.js index 4ec7e997..8cc8809e 100644 --- a/app/static/js/resource-displays/index.js +++ b/app/static/js/resource-displays/index.js @@ -3,9 +3,9 @@ var ResourceDisplays = {}; ResourceDisplays.autoInit = () => { for (let propertyName in ResourceDisplays) { let property = ResourceDisplays[propertyName]; - // Call autoInit of all properties that are subclasses of `ResourceDisplays.BaseDisplay`. - // This does not include `ResourceDisplays.BaseDisplay` itself. - if (property.prototype instanceof ResourceDisplays.BaseDisplay) { + // Call autoInit of all properties that are subclasses of `ResourceDisplays.ResourceDisplay`. + // This does not include `ResourceDisplays.ResourceDisplay` itself. + if (property.prototype instanceof ResourceDisplays.ResourceDisplay) { // Check if the static `htmlClass` property is defined. if (property.htmlClass === undefined) {return;} // Gather all HTML elements that have the `this.htmlClass` class @@ -15,4 +15,4 @@ ResourceDisplays.autoInit = () => { for (let displayElement of displayElements) {new property(displayElement);} } } -} +}; diff --git a/app/static/js/ResourceLists/AdminUserList.js b/app/static/js/resource-lists/admin-user-list.js similarity index 93% rename from app/static/js/ResourceLists/AdminUserList.js rename to app/static/js/resource-lists/admin-user-list.js index 0b8f0c16..40feab27 100644 --- a/app/static/js/ResourceLists/AdminUserList.js +++ b/app/static/js/resource-lists/admin-user-list.js @@ -1,9 +1,5 @@ -class AdminUserList extends ResourceList { - static autoInit() { - for (let adminUserListElement of document.querySelectorAll('.admin-user-list:not(.no-autoinit)')) { - new AdminUserList(adminUserListElement); - } - } +ResourceLists.AdminUserList = class AdminUserList extends ResourceLists.ResourceList { + static htmlClass = 'admin-user-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -108,4 +104,4 @@ class AdminUserList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/CorpusFileList.js b/app/static/js/resource-lists/corpus-file-list.js similarity index 98% rename from app/static/js/ResourceLists/CorpusFileList.js rename to app/static/js/resource-lists/corpus-file-list.js index 9997b061..7e6a5da9 100644 --- a/app/static/js/ResourceLists/CorpusFileList.js +++ b/app/static/js/resource-lists/corpus-file-list.js @@ -1,9 +1,5 @@ -class CorpusFileList extends ResourceList { - static autoInit() { - for (let corpusFileListElement of document.querySelectorAll('.corpus-file-list:not(.no-autoinit)')) { - new CorpusFileList(corpusFileListElement); - } - } +ResourceLists.CorpusFileList = class CorpusFileList extends ResourceLists.ResourceList { + static htmlClass = 'corpus-file-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -369,4 +365,4 @@ class CorpusFileList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/CorpusFollowerList.js b/app/static/js/resource-lists/corpus-follower-list.js similarity index 96% rename from app/static/js/ResourceLists/CorpusFollowerList.js rename to app/static/js/resource-lists/corpus-follower-list.js index ca70a6c7..b8a4c255 100644 --- a/app/static/js/ResourceLists/CorpusFollowerList.js +++ b/app/static/js/resource-lists/corpus-follower-list.js @@ -1,9 +1,5 @@ -class CorpusFollowerList extends ResourceList { - static autoInit() { - for (let corpusFollowerListElement of document.querySelectorAll('.corpus-follower-list:not(.no-autoinit)')) { - new CorpusFollowerList(corpusFollowerListElement); - } - } +ResourceLists.CorpusFollowerList = class CorpusFollowerList extends ResourceLists.ResourceList { + static htmlClass = 'corpus-follower-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -196,4 +192,4 @@ class CorpusFollowerList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/CorpusList.js b/app/static/js/resource-lists/corpus-list.js similarity index 98% rename from app/static/js/ResourceLists/CorpusList.js rename to app/static/js/resource-lists/corpus-list.js index 985ff1d1..f4289d8b 100644 --- a/app/static/js/ResourceLists/CorpusList.js +++ b/app/static/js/resource-lists/corpus-list.js @@ -1,9 +1,5 @@ -class CorpusList extends ResourceList { - static autoInit() { - for (let corpusListElement of document.querySelectorAll('.corpus-list:not(.no-autoinit)')) { - new CorpusList(corpusListElement); - } - } +ResourceLists.CorpusList = class CorpusList extends ResourceLists.ResourceList { + static htmlClass = 'corpus-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -370,4 +366,4 @@ class CorpusList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/CorpusTextInfoList.js b/app/static/js/resource-lists/corpus-text-info-list.js similarity index 93% rename from app/static/js/ResourceLists/CorpusTextInfoList.js rename to app/static/js/resource-lists/corpus-text-info-list.js index f1545d70..00c5467c 100644 --- a/app/static/js/ResourceLists/CorpusTextInfoList.js +++ b/app/static/js/resource-lists/corpus-text-info-list.js @@ -1,10 +1,5 @@ -class CorpusTextInfoList extends ResourceList { - - static autoInit() { - for (let corpusTextInfoListElement of document.querySelectorAll('.corpus-text-info-list:not(.no-autoinit)')) { - new CorpusTextInfoList(corpusTextInfoListElement); - } - } +ResourceLists.CorpusTextInfoList = class CorpusTextInfoList extends ResourceLists.ResourceList { + static htmlClass = 'corpus-text-info-list'; static defaultOptions = { page: 5 @@ -12,7 +7,7 @@ class CorpusTextInfoList extends ResourceList { constructor(listContainerElement, options = {}) { let _options = Utils.mergeObjectsDeep( - CorpusTextInfoList.defaultOptions, + ResourceLists.CorpusTextInfoList.defaultOptions, options ); super(listContainerElement, _options); @@ -109,4 +104,4 @@ class CorpusTextInfoList extends ResourceList { clickedSortElement.style.color = '#aa9cc9'; clickedSortElement.innerHTML = clickedSortElement.classList.contains('asc') ? 'arrow_drop_down' : 'arrow_drop_up'; } -} +}; diff --git a/app/static/js/ResourceLists/CorpusTokenList.js b/app/static/js/resource-lists/corpus-token-list.js similarity index 94% rename from app/static/js/ResourceLists/CorpusTokenList.js rename to app/static/js/resource-lists/corpus-token-list.js index cc16692b..eddd82ea 100644 --- a/app/static/js/ResourceLists/CorpusTokenList.js +++ b/app/static/js/resource-lists/corpus-token-list.js @@ -1,9 +1,5 @@ -class CorpusTokenList extends ResourceList { - static autoInit() { - for (let corpusTokenListElement of document.querySelectorAll('.corpus-token-list:not(.no-autoinit)')) { - new CorpusTokenList(corpusTokenListElement); - } - } +ResourceLists.CorpusTokenList = class CorpusTokenList extends ResourceLists.ResourceList { + static htmlClass = 'corpus-token-list'; static defaultOptions = { page: 7 @@ -11,7 +7,7 @@ class CorpusTokenList extends ResourceList { constructor(listContainerElement, options = {}) { let _options = Utils.mergeObjectsDeep( - CorpusTokenList.defaultOptions, + ResourceLists.CorpusTokenList.defaultOptions, options ); super(listContainerElement, _options); @@ -138,4 +134,4 @@ class CorpusTokenList extends ResourceList { } } -} +}; diff --git a/app/static/js/ResourceLists/DetailledPublicCorpusList.js b/app/static/js/resource-lists/detailed-public-corpus-list.js similarity index 93% rename from app/static/js/ResourceLists/DetailledPublicCorpusList.js rename to app/static/js/resource-lists/detailed-public-corpus-list.js index 5bfc59ff..e855e07b 100644 --- a/app/static/js/ResourceLists/DetailledPublicCorpusList.js +++ b/app/static/js/resource-lists/detailed-public-corpus-list.js @@ -1,4 +1,6 @@ -class DetailledPublicCorpusList extends CorpusList { +ResourceLists.DetailedPublicCorpusList = class DetailedPublicCorpusList extends ResourceLists.ResourceList { + static htmlClass = 'detailed-public-corpus-list'; + get item() { return (values) => { return ` @@ -68,4 +70,4 @@ class DetailledPublicCorpusList extends CorpusList { 'current-user-is-following': Object.values(corpus.corpus_follower_associations).some(association => association.follower.id === currentUserId) }; } -} +}; diff --git a/app/static/js/resource-lists/index.js b/app/static/js/resource-lists/index.js new file mode 100644 index 00000000..513da46b --- /dev/null +++ b/app/static/js/resource-lists/index.js @@ -0,0 +1,18 @@ +var ResourceLists = {}; + +ResourceLists.autoInit = () => { + for (let propertyName in ResourceLists) { + let property = ResourceLists[propertyName]; + // Call autoInit of all properties that are subclasses of `ResourceLists.ResourceList`. + // This does not include `ResourceLists.ResourceList` itself. + if (property.prototype instanceof ResourceLists.ResourceList) { + // Check if the static `htmlClass` property is defined. + if (property.htmlClass === undefined) {return;} + // Gather all HTML elements that have the `this.htmlClass` class + // and do not have the `no-autoinit` class. + let listElements = document.querySelectorAll(`.${property.htmlClass}:not(.no-autoinit)`); + // Create an instance of this class for each display element. + for (let listElement of listElements) {new property(listElement);} + } + } +}; diff --git a/app/static/js/ResourceLists/JobInputList.js b/app/static/js/resource-lists/job-input-list.js similarity index 92% rename from app/static/js/ResourceLists/JobInputList.js rename to app/static/js/resource-lists/job-input-list.js index 97a8dd14..609702b5 100644 --- a/app/static/js/ResourceLists/JobInputList.js +++ b/app/static/js/resource-lists/job-input-list.js @@ -1,9 +1,5 @@ -class JobInputList extends ResourceList { - static autoInit() { - for (let jobInputListElement of document.querySelectorAll('.job-input-list:not(.no-autoinit)')) { - new JobInputList(jobInputListElement); - } - } +ResourceLists.JobInputList = class JobInputList extends ResourceLists.ResourceList { + static htmlClass = 'job-input-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -90,4 +86,4 @@ class JobInputList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/JobList.js b/app/static/js/resource-lists/job-list.js similarity index 98% rename from app/static/js/ResourceLists/JobList.js rename to app/static/js/resource-lists/job-list.js index 1cb3ea60..c751e705 100644 --- a/app/static/js/ResourceLists/JobList.js +++ b/app/static/js/resource-lists/job-list.js @@ -1,9 +1,5 @@ -class JobList extends ResourceList { - static autoInit() { - for (let jobListElement of document.querySelectorAll('.job-list:not(.no-autoinit)')) { - new JobList(jobListElement); - } - } +ResourceLists.JobList = class JobList extends ResourceLists.ResourceList { + static htmlClass = 'job-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -323,4 +319,4 @@ class JobList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/JobResultList.js b/app/static/js/resource-lists/job-result-list.js similarity index 93% rename from app/static/js/ResourceLists/JobResultList.js rename to app/static/js/resource-lists/job-result-list.js index b0cbc088..e71759a5 100644 --- a/app/static/js/ResourceLists/JobResultList.js +++ b/app/static/js/resource-lists/job-result-list.js @@ -1,9 +1,5 @@ -class JobResultList extends ResourceList { - static autoInit() { - for (let jobResultListElement of document.querySelectorAll('.job-result-list:not(.no-autoinit)')) { - new JobResultList(jobResultListElement); - } - } +ResourceLists.JobResultList = class JobResultList extends ResourceLists.ResourceList { + static htmlClass = 'job-result-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); @@ -115,4 +111,4 @@ class JobResultList extends ResourceList { } } } -} +}; diff --git a/app/static/js/ResourceLists/PublicCorpusList.js b/app/static/js/resource-lists/public-corpus-list.js similarity index 93% rename from app/static/js/ResourceLists/PublicCorpusList.js rename to app/static/js/resource-lists/public-corpus-list.js index 1ef98273..659dfd09 100644 --- a/app/static/js/ResourceLists/PublicCorpusList.js +++ b/app/static/js/resource-lists/public-corpus-list.js @@ -1,4 +1,6 @@ -class PublicCorpusList extends CorpusList { +ResourceLists.PublicCorpusList = class PublicCorpusList extends ResourceLists.ResourceList { + static htmlClass = 'public-corpus-list'; + get item() { return (values) => { return ` @@ -52,4 +54,4 @@ class PublicCorpusList extends CorpusList {