From d8ad54326b414d0d72003d9fcc06e01a3d8a7718 Mon Sep 17 00:00:00 2001 From: Stephan Heunis Date: Wed, 19 Apr 2023 13:58:38 +0200 Subject: [PATCH 1/2] do not let filtering options disappear if filtering returns no results --- datalad_catalog/catalog/templates/dataset-template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalad_catalog/catalog/templates/dataset-template.html b/datalad_catalog/catalog/templates/dataset-template.html index 86871c86..6a0a756e 100644 --- a/datalad_catalog/catalog/templates/dataset-template.html +++ b/datalad_catalog/catalog/templates/dataset-template.html @@ -154,7 +154,7 @@

Cite dataset

- There are no subdatasets listed for the current dataset + There are no subdatasets listed for the current dataset From 41b06885301dd79a664c798c8bd0f6d565eec9a4 Mon Sep 17 00:00:00 2001 From: Stephan Heunis Date: Wed, 19 Apr 2023 14:07:11 +0200 Subject: [PATCH 2/2] fix automatic tab display --- .../catalog/assets/app_component_dataset.js | 159 ++++++++---------- 1 file changed, 73 insertions(+), 86 deletions(-) diff --git a/datalad_catalog/catalog/assets/app_component_dataset.js b/datalad_catalog/catalog/assets/app_component_dataset.js index 9c024a6f..1566ad79 100644 --- a/datalad_catalog/catalog/assets/app_component_dataset.js +++ b/datalad_catalog/catalog/assets/app_component_dataset.js @@ -481,12 +481,46 @@ const datasetView = () => } } }, + tabsChanged(currentTabs, previousTabs) { + this.setCorrectTab( + this.$root.selectedDataset.has_subdatasets, + this.$root.selectedDataset.has_files + ) + }, + setCorrectTab(has_subdatasets, has_files) { + // now set the correct tab: + var tabs = this.$refs['alltabs'].$children.filter( + child => typeof child.$vnode.key === 'string' || child.$vnode.key instanceof String + ).map(child => child.$vnode.key) + var tab_param = this.$route.params.tab_name; + if (!tab_param) { + if (has_subdatasets) { + this.tabIndex = 0; + } + else { + if (has_files) { + this.tabIndex = 1; + } + else { + if (tabs.length > 2) { + this.tabIndex = 2; + } else { + this.tabIndex = 0; + } + } + } + } + else { + selectTab = tabs.indexOf(tab_param) + if (selectTab >= 0) { + this.tabIndex = selectTab; + } else { + this.tabIndex = 0; + } + } + } }, async beforeRouteUpdate(to, from, next) { - var has_subdatasets, has_files - console.log('\n---BEFORE ROUTE UPDATE---\n') - console.log(to.params.tab_name) - console.log('\n---BEFORE ROUTE UPDATE---\n') this.tabIndex = 0; this.subdatasets_ready = false; this.dataset_ready = false; @@ -572,62 +606,37 @@ const datasetView = () => this.$root.selectedDataset.subdatasets_available_count = subdatasets_available.length this.$root.selectedDataset.subdatasets_unavailable_count = subdatasets_unavailable.length this.subdatasets_ready = true; - has_subdatasets = true; + this.$root.selectedDataset.has_subdatasets = true; } else { this.$root.selectedDataset.subdatasets = []; this.$root.selectedDataset.subdatasets_count = 0 this.$root.selectedDataset.subdatasets_available_count = 0 this.$root.selectedDataset.subdatasets_unavailable_count = 0 this.subdatasets_ready = true; - has_subdatasets = false; - // Now check file content - this.files_ready = false; - this.$root.selectedDataset.tree = this.$root.selectedDataset["children"]; - this.files_ready = true; - if ( - this.$root.selectedDataset.hasOwnProperty("tree") && - this.$root.selectedDataset.tree instanceof Array && - this.$root.selectedDataset.tree.length > 0 - ) { - has_files = true; - } - else { - has_files = false; - } + this.$root.selectedDataset.has_subdatasets = false; } - // now set the correct tab: - var tab_param = this.$route.params.tab_name; - if (!tab_param) { - if (has_subdatasets) { - this.tabIndex = 0; - } - else { - if (has_files) { - this.tabIndex = 1; - } - else { - this.tabIndex = 2; - } - } + // Now check file content + this.files_ready = false; + this.$root.selectedDataset.tree = this.$root.selectedDataset["children"]; + this.files_ready = true; + if ( + this.$root.selectedDataset.hasOwnProperty("tree") && + this.$root.selectedDataset.tree instanceof Array && + this.$root.selectedDataset.tree.length > 0 + ) { + this.$root.selectedDataset.has_files = true; } else { - tabs = this.$refs['alltabs'].$children.filter( - child => typeof child.$vnode.key === 'string' || child.$vnode.key instanceof String - ).map(child => child.$vnode.key) - selectTab = tabs.indexOf(tab_param) - if (selectTab >= 0) { - this.tabIndex = selectTab; - } else { - this.tabIndex = 0; - } + this.$root.selectedDataset.has_files = false; } + // now set the correct tab: + this.setCorrectTab( + this.$root.selectedDataset.has_subdatasets, + this.$root.selectedDataset.has_files + ) next(); }, async created() { - var has_subdatasets, has_files - console.log('\n---CREATED---\n') - console.log(this.$route.params.tab_name) - console.log('\n---CREATED---\n') file = getFilePath( this.$route.params.dataset_id, this.$route.params.dataset_version, @@ -685,55 +694,33 @@ const datasetView = () => this.$root.selectedDataset.subdatasets_available_count = subdatasets_available.length this.$root.selectedDataset.subdatasets_unavailable_count = subdatasets_unavailable.length this.subdatasets_ready = true; - has_subdatasets = true; + this.$root.selectedDataset.has_subdatasets = true; } else { this.$root.selectedDataset.subdatasets = []; this.$root.selectedDataset.subdatasets_count = 0 this.$root.selectedDataset.subdatasets_available_count = 0 this.$root.selectedDataset.subdatasets_unavailable_count = 0 this.subdatasets_ready = true; - has_subdatasets = false; - // Now check file content - this.files_ready = false; - this.$root.selectedDataset.tree = this.$root.selectedDataset["children"]; - this.files_ready = true; - if ( - this.$root.selectedDataset.hasOwnProperty("tree") && - this.$root.selectedDataset.tree instanceof Array && - this.$root.selectedDataset.tree.length > 0 - ) { - has_files = true; - } - else { - has_files = false; - } + this.$root.selectedDataset.has_subdatasets = false; } - // now set the correct tab: - var tab_param = this.$route.params.tab_name; - if (!tab_param) { - if (has_subdatasets) { - this.tabIndex = 0; - } - else { - if (has_files) { - this.tabIndex = 1; - } - else { - this.tabIndex = 2; - } - } + // Now check file content + this.files_ready = false; + this.$root.selectedDataset.tree = this.$root.selectedDataset["children"]; + this.files_ready = true; + if ( + this.$root.selectedDataset.hasOwnProperty("tree") && + this.$root.selectedDataset.tree instanceof Array && + this.$root.selectedDataset.tree.length > 0 + ) { + this.$root.selectedDataset.has_files = true; } else { - tabs = this.$refs['alltabs'].$children.filter( - child => typeof child.$vnode.key === 'string' || child.$vnode.key instanceof String - ).map(child => child.$vnode.key) - selectTab = tabs.indexOf(tab_param) - if (selectTab >= 0) { - this.tabIndex = selectTab; - } else { - this.tabIndex = 0; - } + this.$root.selectedDataset.has_files = false; } + this.setCorrectTab( + this.$root.selectedDataset.has_subdatasets, + this.$root.selectedDataset.has_files + ) }, mounted() { this.tag_options_filtered = this.tag_options;