Skip to content

Commit

Permalink
Merge branch 'main' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Almighty committed Oct 26, 2023
2 parents 835aafc + 397ee4d commit e7814d5
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 54 deletions.
76 changes: 57 additions & 19 deletions assets/app_component_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ const datasetView = () =>
},
methods: {
newTabActivated(newTabIndex, prevTabIndex, bvEvent) {
if (newTabIndex == 1) {
var tabs = this.selectedDataset.available_tabs
if (tabs[newTabIndex] == 'content') {
this.getFiles()
}
},
Expand Down Expand Up @@ -398,15 +399,15 @@ const datasetView = () =>
router.push(current_route_info)
} else {
this.clearFilters();
this.tabIndex = 0;
this.tabIndex = this.getDefaultTabIdx();
}
} else {
if (this.currentIsHome()) {
if (this.$route.params.tab_name) {
router.push(current_route_info)
} else {
this.clearFilters();
this.tabIndex = 0;
this.tabIndex = this.getDefaultTabIdx();
}
} else {
router.push({ name: "home" });
Expand Down Expand Up @@ -545,28 +546,37 @@ const datasetView = () =>
}
}
},
setCorrectTab(tab_param) {
setCorrectTab(tab_param, available_tabs, default_tab) {
// the set of available tabs have been updated in component
// data in either created() or beforeRouteUpdate()
var tabs = this.$root.selectedDataset.available_tabs.map(v => v.toLowerCase());
// If no tab parameter is supplied via the router, set to first tab
// data in either created() or beforeRouteUpdate() and have been passed
// as the second argument
default_tab = default_tab ? default_tab : "content"
var idx = available_tabs.indexOf(default_tab.toLowerCase())
var default_tab_idx = idx >= 0 ? idx : 0

// If no tab parameter is supplied via the router, set to default tab
if (!tab_param) {
this.tabIndex = 0
this.tabIndex = default_tab_idx;
}
// If a tab parameter is supplied via the router, navigate to that tab if
// part of available tabs, otherwise first tab
// part of available tabs, otherwise default tab
else {
selectTab = tabs.indexOf(tab_param.toLowerCase())
if (selectTab >= 0) {
this.tabIndex = selectTab;
} else {
this.tabIndex = 0;
this.tabIndex = default_tab_idx;
}
}
}
},
getDefaultTabIdx() {
var default_tab = this.selectedDataset.config?.dataset_options?.default_tab
default_tab = default_tab ? default_tab : "content"
var idx = this.selectedDataset.available_tabs.indexOf(default_tab.toLowerCase())
return idx >= 0 ? idx : 0
},
},
async beforeRouteUpdate(to, from, next) {
this.tabIndex = 0;
this.subdatasets_ready = false;
this.dataset_ready = false;

Expand Down Expand Up @@ -677,7 +687,7 @@ const datasetView = () =>
// Now list all tabs and set the correct one
// order in DOM: subdatasets, content, publications, funding, provenance,
sDs = this.$root.selectedDataset
available_tabs = ['subdatasets', 'content']
available_tabs = ['content', 'subdatasets']
standard_tabs = ['publications', 'funding', 'provenance']
// add available standard tabs
for (var t=0; t<standard_tabs.length; t++) {
Expand All @@ -691,10 +701,24 @@ const datasetView = () =>
available_tabs.push(sDs.additional_display[t].name)
}
}
// finally set the root data and then set the correct tab
this.$root.selectedDataset.available_tabs = available_tabs
// set the root data for available tabs
available_tabs_lower = available_tabs
this.$root.selectedDataset.available_tabs = available_tabs_lower
// Now get dataset config if it exists
dataset_config_path = metadata_dir + "/" + sDs.dataset_id + "/" + sDs.dataset_version + "/config.json";
configresponse = await fetch(dataset_config_path);
if (configresponse.status == 404) {
this.$root.selectedDataset.config = {};
} else {
configtext = await configresponse.text();
config = JSON.parse(configtext);
this.$root.selectedDataset.config = config;
}
// Set the correct tab to be rendered
this.setCorrectTab(
to.params.tab_name,
available_tabs_lower,
this.$root.selectedDataset.config?.dataset_options?.default_tab
)
// if navigated to using vue router (i.e. internal to the app), show the back button
if (this.currentIsHome()) {
Expand Down Expand Up @@ -798,9 +822,9 @@ const datasetView = () =>
this.$root.selectedDataset.has_files = false;
}
// Now list all tabs and set the correct one
// order in DOM: subdatasets, content, publications, funding, provenance,
// order in DOM: content, subdatasets, publications, funding, provenance,
sDs = this.$root.selectedDataset
available_tabs = ['subdatasets', 'content']
available_tabs = ['content', 'subdatasets']
standard_tabs = ['publications', 'funding', 'provenance']
// add available standard tabs
for (var t=0; t<standard_tabs.length; t++) {
Expand All @@ -814,10 +838,24 @@ const datasetView = () =>
available_tabs.push(sDs.additional_display[t].name)
}
}
// finally set the root data and then set the correct tab
this.$root.selectedDataset.available_tabs = available_tabs
available_tabs_lower = available_tabs
// set the root data for available tabs
this.$root.selectedDataset.available_tabs = available_tabs_lower
// Now get dataset config if it exists
dataset_config_path = metadata_dir + "/" + sDs.dataset_id + "/" + sDs.dataset_version + "/config.json";
configresponse = await fetch(dataset_config_path);
if (configresponse.status == 404) {
this.$root.selectedDataset.config = {};
} else {
configtext = await configresponse.text();
config = JSON.parse(configtext);
this.$root.selectedDataset.config = config;
}
// Set the correct tab to be rendered
this.setCorrectTab(
this.$route.params.tab_name,
available_tabs_lower,
this.$root.selectedDataset.config?.dataset_options?.default_tab
)
},
mounted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"catalog_name": "DataCat",
"link_color": "#fba304",
"link_hover_color": "#af7714",
"social_links": {
"about": null,
"documentation": "https://docs.datalad.org/projects/catalog/en/latest/",
"github": "https://github.com/datalad/datalad-catalog",
"mastodon": "https://fosstodon.org/@datalad",
"x": "https://x.com/datalad"
},
"dataset_options": {
"include_metadata_export": true,
"default_tab": "subdatasets"
},
"property_sources": {
"dataset": {
"authors": {
"rule": "merge",
"source": [
"metalad_studyminimeta"
]
},
"description": {
"rule": "priority",
"source": [
"metalad_studyminimeta",
"bids_dataset"
]
},
"keywords": {
"rule": "merge",
"source": "any"
},
"additional_display": {
"rule": "merge",
"source": []
},
"top_display": {
"rule": "merge",
"source": []
}
},
"file": {
}
}
}
70 changes: 35 additions & 35 deletions templates/dataset-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,41 @@ <h3>Cite dataset</h3>
<!-- BOTTOM SECTION WITH TABS-->
<b-card-body>
<b-tabs card content-class="mt-3" fill active-nav-item-class="font-weight-bold" v-model="tabIndex" @activate-tab="newTabActivated" ref="alltabs">
<!-- FILE TREE -->
<b-tab @click="getFiles" key="content" ref="tabelement">
<template v-slot:title>
<i class="far fa-folder"></i> Content
</template>
<span v-if="files_ready">
<span v-if="!selectedDataset.tree || !selectedDataset.tree.length"><em>There is no content available for the current dataset</em></span>
<span v-else>
<b-card no-body class="p-2">
<ul>
<tree-item class="item" v-for="item in selectedDataset.tree" :item="item" @clear-filters="clearFilters"></tree-item>
</ul>
</b-card>
</span>
<b-modal id="modal-3" size="md"
header-bg-variant="light"
footer-bg-variant="light"
body-bg-variant="light"
body-text-variant="dark"
ok-only
>
<template #modal-header="{ close }">
<div class="d-block text-center">
<h3>Dataset not found</h3>
<p class="my-4">The selected dataset is currently not available in the catalog.</p>
</div>
</template>
</b-modal>
</span>
<span v-else>
<div class="d-flex justify-content-center mb-3">
<b-spinner label="Loading..."></b-spinner>
</div>
</span>
</b-tab>
<!-- SUBDATASETS -->
<b-tab key="subdatasets" ref="tabelement">
<template v-slot:title>
Expand Down Expand Up @@ -259,41 +294,6 @@ <h5><a @click="selectDataset($event, ds)" class="newlink">{{ds.dirs_from_path.at
</span>
</span>
</b-tab>
<!-- FILE TREE -->
<b-tab @click="getFiles" key="content" ref="tabelement">
<template v-slot:title>
<i class="far fa-folder"></i> Content
</template>
<span v-if="files_ready">
<span v-if="!selectedDataset.tree || !selectedDataset.tree.length"><em>There is no content available for the current dataset</em></span>
<span v-else>
<b-card no-body class="p-2">
<ul>
<tree-item class="item" v-for="item in selectedDataset.tree" :item="item" @clear-filters="clearFilters"></tree-item>
</ul>
</b-card>
</span>
<b-modal id="modal-3" size="md"
header-bg-variant="light"
footer-bg-variant="light"
body-bg-variant="light"
body-text-variant="dark"
ok-only
>
<template #modal-header="{ close }">
<div class="d-block text-center">
<h3>Dataset not found</h3>
<p class="my-4">The selected dataset is currently not available in the catalog.</p>
</div>
</template>
</b-modal>
</span>
<span v-else>
<div class="d-flex justify-content-center mb-3">
<b-spinner label="Loading..."></b-spinner>
</div>
</span>
</b-tab>
<!-- PUBLICATIONS -->
<span v-if="selectedDataset.publications && selectedDataset.publications.length">
<b-tab key="publications" ref="tabelement">
Expand Down

0 comments on commit e7814d5

Please sign in to comment.