Skip to content

Commit

Permalink
[#715] Checks if resource can be previewed and that changes the UX
Browse files Browse the repository at this point in the history
Adds new helper function to check if a resource can be previewed and adds it to
the templates.
  • Loading branch information
johnmartin committed Jun 11, 2013
1 parent a865639 commit 1c7b086
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1466,6 +1466,11 @@ def format_resource_items(items):
return sorted(output, key=lambda x: x[0])


def can_be_previewed(resource, package):
data_dict = {'resource': resource, 'package': package}
return datapreview.can_be_previewed(data_dict)


def resource_preview(resource, pkg_id):
'''
Returns a rendered snippet for a embedded resource preview.
Expand Down Expand Up @@ -1633,6 +1638,7 @@ def SI_number_span(number):
'render_markdown',
'format_resource_items',
'resource_preview',
'can_be_previewed',
'SI_number_span',
'localised_number',
'localised_SI_number',
Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/package/resource_read.html
Expand Up @@ -29,6 +29,8 @@
<i class="icon-eye-open"></i> {{ _('View') }}
{% elif res.resource_type == 'api' %}
<i class="icon-key"></i> {{ _('API Endpoint') }}
{% elif not h.can_be_previewed(res, pkg) %}
<i class="icon-external-link"></i> {{ _('Go to resource') }}
{% else %}
<i class="icon-download"></i> {{ _('Download') }}
{% endif %}
Expand Down
19 changes: 15 additions & 4 deletions ckan/templates/package/snippets/resource_item.html
@@ -1,4 +1,5 @@
{% set url = h.url_for(controller='package', action='resource_read', id=pkg.name, resource_id=res.id) %}
{% set can_be_previewed = h.can_be_previewed(resource=res, package=pkg) %}
<li class="resource-item">
{% block resource_item_title %}
<a class="heading" href="{{ url }}" title="{{ res.name or res.description }}">
Expand All @@ -24,14 +25,24 @@
{% block resource_item_explore_links %}
<li>
<a href="{{ url }}">
<i class="icon-bar-chart"></i>
{{ _('Preview') }}
{% if can_be_previewed %}
<i class="icon-bar-chart"></i>
{{ _('Preview') }}
{% else %}
<i class="icon-info-sign"></i>
{{ _('More information') }}
{% endif %}
</a>
</li>
<li>
<a href="{{ res.url }}" class="resource-url-analytics" target="_blank">
<i class="icon-download"></i>
{{ _('Download') }}
{% if can_be_previewed %}
<i class="icon-download"></i>
{{ _('Download') }}
{% else %}
<i class="icon-external-link"></i>
{{ _('Go to resource') }}
{% endif %}
</a>
</li>
{% endblock %}
Expand Down

0 comments on commit 1c7b086

Please sign in to comment.