New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deeplink to resource - fix #1275 #1289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ function parseUrl(url) { | |
return a; | ||
} | ||
|
||
const RESOURCE_REGEX = /^#resource(-community)?-([0-9a-f-]{36})$/; | ||
|
||
new Vue({ | ||
mixins: [FrontMixin], | ||
components: { | ||
|
@@ -43,6 +45,11 @@ new Vue({ | |
this.loadCoverageMap(); | ||
this.checkResources(); | ||
this.fetchReuses(); | ||
if (document.location.hash) { | ||
this.$nextTick(() => { // Wait for data to be binded | ||
this.openResourceFromHash(document.location.hash); | ||
}); | ||
} | ||
log.debug('Dataset display page ready'); | ||
}, | ||
methods: { | ||
|
@@ -64,13 +71,16 @@ new Vue({ | |
/** | ||
* Display a resource or a community ressource in a modal | ||
*/ | ||
showResource(id, e, isCommunity) { | ||
// Ensure edit button work | ||
if ([e.target, e.target.parentNode].some(el => el.classList.contains('btn-edit'))) return; | ||
e.preventDefault(); | ||
showResource(id, isCommunity) { | ||
const attr = isCommunity ? 'communityResources' : 'resources'; | ||
const resource = this.dataset[attr].find(resource => resource['@id'] === id); | ||
this.$modal(ResourceModal, {resource}); | ||
const communityPrefix = isCommunity ? '-community' : ''; | ||
location.hash = `resource${communityPrefix}-${id}`; | ||
const modal = this.$modal(ResourceModal, {resource}); | ||
modal.$on('modal:closed', () => { | ||
// prevent scrolling to top | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this behavior common to all modals on close ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, it's for this one only: since I set the |
||
location.hash = '_'; | ||
}); | ||
}, | ||
|
||
/** | ||
|
@@ -233,6 +243,18 @@ new Vue({ | |
this._('New tag suggestion to improve metadata'), | ||
this._('Hello,\n\nI propose this new tag: ') | ||
); | ||
} | ||
}, | ||
|
||
/** | ||
* Open resource modal if corresponding hash in URL. | ||
* /!\ there is a similar function in <discussion-threads> (jumpToHash), | ||
* jump may come from there too. | ||
*/ | ||
openResourceFromHash(hash) { | ||
if (RESOURCE_REGEX.test(hash)) { | ||
const [, isCommunity, id] = hash.match(RESOURCE_REGEX); | ||
this.showResource(id, isCommunity); | ||
} | ||
}, | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
{% set resource_format = resource.format|trim|lower or 'data' %} | ||
<div id="resource-{{resource.id}}" class="list-group-item" | ||
<div id="resource{% if resource.from_community %}-community{% endif %}-{{resource.id}}" class="list-group-item" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum, this distinction comes from this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need the distinction to use The only alternative I can think of right now is to try to find the resource by id in both |
||
data-checkurl="{{ url_for('api.check_dataset_resource', dataset=dataset.id, rid=resource.id) }}" | ||
@click="showResource('{{resource.id}}', $event, {{ resource.owner is defined|tojson }})"> | ||
@click.prevent="showResource('{{resource.id}}', {{ resource.owner is defined|tojson }})"> | ||
<div class="format-label pull-left" v-tooltip tooltip-placement="left"> | ||
<span class="ellipsis" data-format="{{ resource_format }}"> | ||
{{ resource_format }} | ||
</span> | ||
</div> | ||
<span class="list-group-item-link"> | ||
<a @click.stop href="#resource{% if resource.from_community %}-community{% endif %}-{{ resource.id }}"> | ||
<span class="fa fa-link"></span> | ||
</a> | ||
</span> | ||
<h4 class="list-group-item-heading ellipsis"> | ||
<a href="{{resource.url}}"> | ||
<span>{{ resource.title or _('Nameless resource') }}</span> | ||
|
@@ -28,7 +33,7 @@ <h4 class="list-group-item-heading ellipsis"> | |
{% set edit_path = 'dataset/{id}/resource/{rid}' %} | ||
{% endif %} | ||
<div class="btn-group btn-group-xs tools"> | ||
<a class="btn btn-default btn-edit" v-tooltip title="{{ _('Edit') }}" | ||
<a @click.stop class="btn btn-default btn-edit" v-tooltip title="{{ _('Edit') }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OMG, is this working ? If so I understand the above removal !! 😍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, it should work ;-) At least it does on my machine. |
||
href="{{ url_for('admin.index', path=edit_path.format(id=dataset.id, rid=resource.id)) }}"> | ||
<span class="fa fa-pencil"></span> | ||
</a> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this has been removed ?