Skip to content

Commit

Permalink
Merge pull request #14 from jsheunis/tab-display
Browse files Browse the repository at this point in the history
ENH: pull in JS updates re tab display from catalog
  • Loading branch information
mslw authored Apr 19, 2023
2 parents b09dfb6 + 8590640 commit b43135a
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 20 deletions.
106 changes: 106 additions & 0 deletions docs/assets/app_component_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const datasetView = () =>
disp_dataset.url = disp_dataset.url.replace('ssh://', '');
disp_dataset.url = disp_dataset.url.replace('[email protected]:', 'https://gin.g-node.org');
disp_dataset.url = disp_dataset.url.replace('[email protected]', 'https://gin.g-node.org');
disp_dataset.url = disp_dataset.url.replace('.git', '');
}
}
if (!disp_dataset.url) {
Expand Down Expand Up @@ -258,10 +259,19 @@ const datasetView = () =>
},
},
methods: {
newTabActivated(newTabIndex, prevTabIndex, bvEvent) {
if (newTabIndex == 1) {
this.getFiles()
}
},
copyCloneCommand(index) {
// https://stackoverflow.com/questions/60581285/execcommand-is-now-obsolete-whats-the-alternative
// https://www.sitepoint.com/clipboard-api/
selectText = document.getElementById("clone_code").textContent;
selectText = '\n ' + selectText + ' \n\n '
console.log(selectText)
selectText = selectText.replace(/^\s+|\s+$/g, '');
console.log(selectText)
navigator.clipboard
.writeText(selectText)
.then(() => {})
Expand Down Expand Up @@ -468,8 +478,59 @@ const datasetView = () =>
}
}
},
tabsChanged(currentTabs, previousTabs) {
console.log("TABS-CHANGED-EVENT")
console.log('current')
console.log(currentTabs)
console.log('previous')
console.log(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) {
console.log('setting tabIndex = 2 (no datasets or files, has extra tabs)')
this.tabIndex = 2;
} else {
console.log('setting tabIndex = 0 (no datasets or files or extra tabs)')
this.tabIndex = 0;
}
}
}
}
else {
selectTab = tabs.indexOf(tab_param)
if (selectTab >= 0) {
this.tabIndex = selectTab;
console.log('setting tabIndex = ' + selectTab + ' based on URLparam')
} 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;
Expand Down Expand Up @@ -555,16 +616,41 @@ const datasetView = () =>
this.$root.selectedDataset.subdatasets_available_count = subdatasets_available.length
this.$root.selectedDataset.subdatasets_unavailable_count = subdatasets_unavailable.length
this.subdatasets_ready = 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;
this.$root.selectedDataset.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
) {
this.$root.selectedDataset.has_files = true;
}
else {
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,
Expand Down Expand Up @@ -622,13 +708,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;
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;
this.$root.selectedDataset.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
) {
this.$root.selectedDataset.has_files = true;
}
else {
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;
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/app_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const routes = [
},
},
{
path: "/dataset/:dataset_id/:dataset_version",
path: "/dataset/:dataset_id/:dataset_version/:tab_name?",
component: datasetView,
name: "dataset",
},
Expand Down
35 changes: 16 additions & 19 deletions docs/templates/dataset-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
</b-card-sub-title>
<!-- DATASET VERSION ETC -->
<b-card-text>
<strong>Version:</strong> {{selectedDataset.dataset_version.substring(0,7)}}&nbsp;
<strong>Last updated:</strong> {{displayData.last_updated}}&nbsp;
<strong>DOI:</strong> <span v-if="selectedDataset.doi"><a :href="selectedDataset.doi" target="_blank"> {{selectedDataset.doi.replace("https://doi.org/", "")}}</a></span>
<span v-else><em>not available</em></span>&nbsp;
<span v-else><em>unknown</em></span>&nbsp;
<strong>License:</strong> <span v-if="selectedDataset.license && selectedDataset.license.name"><a :href="selectedDataset.license.url" target="_blank"> {{selectedDataset.license.name}}</a></span>
<span v-else><em>not available</em></span>
<span v-else><em>unknown</em></span>
</b-card-text>
<!-- DATASET BUTTONS -->
<div style="text-align: left;">
Expand Down Expand Up @@ -132,19 +131,19 @@ <h3>Cite dataset</h3>

<b-card-text>
<strong>Properties:</strong> <br>
<span><b-button disabled size="sm" variant="outline-dark">Subdatasets: {{selectedDataset.subdatasets_available_count}}</b-button>&nbsp;</span>
<span v-if="selectedDataset.subdatasets_available_count"><b-button disabled size="sm" variant="outline-dark">Subdatasets: {{selectedDataset.subdatasets_available_count}}</b-button>&nbsp;</span>
<span v-if="selectedDataset.top_display && selectedDataset.top_display.length">
<span v-for="display_property in selectedDataset.top_display"><b-button disabled size="sm" variant="outline-dark">{{display_property.name}}: {{display_property.value}}</b-button>&nbsp;
<span v-for="display_property in selectedDataset.top_display" v-if="display_property.value"><b-button disabled size="sm" variant="outline-dark">{{display_property.name}}: {{display_property.value}}</b-button>&nbsp;</span>
</span>
</b-card-text>
</b-col>
</b-row>
</b-card-body>
<!-- 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">
<b-tabs card content-class="mt-3" fill active-nav-item-class="font-weight-bold" v-model="tabIndex" @activate-tab="newTabActivated" ref="alltabs" v-show="subdatasets_ready && files_ready" @changed="tabsChanged">
<!-- SUBDATASETS -->
<b-tab>
<b-tab key="subdatasets" ref="tabelement">
<template v-slot:title>
<i class="fas fa-list-ol"></i> Subdatasets <span v-if="subdatasets_ready">({{selectedDataset.subdatasets_available_count}})</span>
</template>
Expand Down Expand Up @@ -172,9 +171,8 @@ <h3>Cite dataset</h3>
Modified
</b-button>
</b-button-group>&nbsp;&nbsp;
<b-form-input id="input-1" type="search" placeholder="Search by dataset or author name" required v-model="search_text" ref="text_search_input"></b-form-input>
<b-form-input id="input-1" type="search" placeholder="Filter by dataset or author name" required v-model="search_text" ref="text_search_input"></b-form-input>
</b-input-group>

</b-col>
<b-col md="5">
<b-input-group>
Expand All @@ -185,7 +183,7 @@ <h3>Cite dataset</h3>
v-bind="inputAttrs"
v-model="tag_text"
v-on="inputHandlers"
placeholder="Search by keyword (select or press enter to add)"
placeholder="Filter by keyword (select or press enter to add)"
class="form-control"
ref="tag_search_input"
@input="inputTagText()"
Expand Down Expand Up @@ -226,7 +224,6 @@ <h5><a @click="selectDataset($event, ds)" class="newlink">{{ds.dirs_from_path.at
</span>
<b-card-text>
<small>
<strong>Version:</strong> {{ds.dataset_version.substring(0,7)}}&nbsp;
<strong>Modified:</strong> {{getDateFromUTCseconds(ds.source_time)}}&nbsp;
</small>
</b-card-text>
Expand All @@ -243,12 +240,12 @@ <h5><a @click="selectDataset($event, ds)" class="newlink">{{ds.dirs_from_path.at
</span>
</b-tab>
<!-- FILE TREE -->
<b-tab @click="getFiles">
<b-tab @click="getFiles" key="content" ref="tabelement">
<template v-slot:title>
<i class="far fa-folder"></i> Files
<i class="far fa-folder"></i> Content
</template>
<span v-if="files_ready">
<span v-if="!selectedDataset.tree || !selectedDataset.tree.length"><em>There are no files listed for the current dataset</em></span>
<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>
Expand Down Expand Up @@ -279,7 +276,7 @@ <h3>Dataset not found</h3>
</b-tab>
<!-- PUBLICATIONS -->
<span v-if="selectedDataset.publications && selectedDataset.publications.length">
<b-tab>
<b-tab key="publications" ref="tabelement">
<template v-slot:title>
<i class="fas fa-book"></i> Publications
</template>
Expand Down Expand Up @@ -312,9 +309,9 @@ <h5>{{pub.title}}</h5>
</span>
<!-- FUNDING -->
<span v-if="selectedDataset.funding && selectedDataset.funding.length">
<b-tab>
<b-tab key="funding" ref="tabelement">
<template v-slot:title>
<i class="fas fa-dollar-sign"></i> Funding
<i class="fas fa-building-columns"></i> Funding
</template>
<span v-if="!selectedDataset.funding || !selectedDataset.funding.length"><em>There are no funding sources listed for the current dataset</em></span>
<span v-else v-for="fund in selectedDataset.funding">
Expand All @@ -337,7 +334,7 @@ <h5><span v-if="fund.name">{{fund.name}}</span><span v-else><em>(fund name missi
</span>
<!-- PROVENANCE -->
<span v-if="selectedDataset.provenance && selectedDataset.provenance.length">
<b-tab>
<b-tab key="provenance" ref="tabelement">
<template v-slot:title>
<i class="fas fa-laptop-code"></i> Provenance
</template>
Expand Down Expand Up @@ -449,7 +446,7 @@ <h5><span v-if="fund.name">{{fund.name}}</span><span v-else><em>(fund name missi
<!-- EXTRA TABS -->
<span v-if="selectedDataset.additional_display && selectedDataset.additional_display.length">
<span v-for="new_tab in selectedDataset.additional_display">
<b-tab>
<b-tab :key="new_tab.name" ref="tabelement">
<template v-slot:title>
<span v-if="new_tab.icon"><i :class="new_tab.icon"></i></span><span v-else><i class="fas fa-bars"></i></span> {{new_tab.name}}
</template>
Expand Down

0 comments on commit b43135a

Please sign in to comment.