Skip to content

Commit

Permalink
Update resource_view.html
Browse files Browse the repository at this point in the history
including latest changes from CKAN core and including helpers to cope with the many possible frontend configurations for CKAN templates across different versions
  • Loading branch information
mattfullerton committed Oct 4, 2017
1 parent 3608191 commit a7306e3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 28 deletions.
24 changes: 24 additions & 0 deletions ckanext/pdfview/plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import logging

import ckan.plugins as p
import ckan.lib.helpers as h
import ckan.lib.datapreview as datapreview

log = logging.getLogger(__name__)

def get_ckan_version():
return float(h.ckan_version()[0:3])

def get_ckan_with_fa():
if get_ckan_version() >= 2.7:
return True
else:
return False

def get_bootstrap_version():
public_setting = config.get('ckan.base_public_folder', 'public')
if public_setting == 'public-bs2' or get_ckan_version() <= 2.7:
return 2
#Otherwise we're on 2.8+, or other folder; in that case assume 3 (future proofing)
else:
return 3

class PdfView(p.SingletonPlugin):
'''This extension views PDFs. '''
Expand All @@ -16,6 +33,7 @@ class PdfView(p.SingletonPlugin):
'CKAN repository.')

p.implements(p.IConfigurer, inherit=True)
p.implements(p.ITemplateHelpers, inherit=True)
p.implements(p.IConfigurable, inherit=True)
p.implements(p.IResourceView, inherit=True)

Expand Down Expand Up @@ -52,3 +70,9 @@ def can_view(self, data_dict):

def view_template(self, context, data_dict):
return 'pdf.html'

def get_helpers(self):
return {
'pdfview_get_ckan_with_fa': get_ckan_with_fa,
'pdfview_get_bootstrap_version': get_bootstrap_version
}
86 changes: 58 additions & 28 deletions ckanext/pdfview/theme/templates/package/snippets/resource_view.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
{% import 'macros/form.html' as form %}

{% if h.pdfview_get_ckan_with_fa() %}
{% set fullscreen_icon = "fa fa-arrows-alt" %}
{% set code_icon = "fa fa-code" %}
{% set info_icon = "fa fa-info-circle" %}
{% set download_icon = "fa fa-lg fa-arrow-circle-o-down" %}
{% else %}
{% set fullscreen_icon = "icon-fullscreen" %}
{% set code_icon = "icon-code" %}
{% set info_icon = "icon-info-sign" %}
{% set download_icon = "icon-large icon-download" %}
{% endif %}

{% if h.pdfview_get_bootstrap_version >= 3 %}
{% set span6 = "col-md-6" %}
{% else %}
{% set span6 = "span6" %}
{% endif %}

<div id="view-{{ resource_view['id'] }}" class="resource-view" data-id="{{ resource_view['id'] }}" data-title="{{ resource_view['title'] }}" data-description="{{ resource_view['descripion'] }}">
<a class="btn pull-right"
href="#embed-{{ resource_view['id'] }}"
data-module="resource-view-embed"
data-module-id="{{ resource_view['id'] }}"
data-module-url="{{ h.url('resource_view', id=package['name'], resource_id=resource['id'], view_id=resource_view['id'], qualified=True) }}">
<i class="icon-code"></i>
{{ _("Embed") }}
</a>
<div class="actions">
<a class="btn"
target="_blank"
href="{{ h.url_for('resource_view', id=package['name'], resource_id=resource['id'], view_id=resource_view['id'], qualified=True) }}">
<i class="{{ fullscreen_icon }}"></i>
{{ _("Fullscreen") }}
</a>
<a class="btn"
href="#embed-{{ resource_view['id'] }}"
data-module="resource-view-embed"
data-module-id="{{ resource_view['id'] }}"
data-module-url="{{ h.url_for('resource_view', id=package['name'], resource_id=resource['id'], view_id=resource_view['id'], qualified=True) }}">
<i class="{{ code_icon }}"></i>
{{ _("Embed") }}
</a>
</div>
<p class="desc">{{ h.render_markdown(resource_view['description']) }}</p>
<div class="m-top ckanext-datapreview">
{% if not to_preview and h.resource_view_is_filterable(resource_view) %}
Expand All @@ -18,60 +44,64 @@
{{ h.rendered_resource_view(resource_view, resource, package) }}
{% else %}
<div class="data-viewer-error js-hide">
<p class="text-error">
<i class="icon-info-sign"></i>
<p class="text-danger">
<i class="{{ info_icon }}"></i>
{{ _('This resource view is not available at the moment.') }}
<a href="#" data-toggle="collapse" data-target="#data-view-error">
{{ _('Click here for more information.') }}
</a>
</p>
<p id="data-view-error" class="collapse"></p>
<p>
<a href="{{ raw_resource_url }}" class="btn btn-large resource-url-analytics" target="_blank">
<i class="icon-large icon-download"></i>
<a href="{{ resource.url }}" class="btn btn-default btn-lg resource-url-analytics" target="_blank">
<i class="{{ download_icon }}"></i>
{{ _('Download resource') }}
</a>
</p>
</div>
{% if not to_preview %}
{% set current_filters = request.str_GET.get('filters') %}
{% if current_filters %}
{% set src = h.url(qualified=true, controller='package',
{% set src = h.url_for(qualified=true, controller='package',
action='resource_view', id=package['name'],
resource_id=resource['id'],
view_id=resource_view['id'],
filters=current_filters) %}
{% else %}
{% set src = h.url(qualified=true, controller='package',
{% set src = h.url_for(qualified=true, controller='package',
action='resource_view', id=package['name'],
resource_id=resource['id'],
view_id=resource_view['id']) %}
{% endif %}
{% else %}
{# When previewing we need to stick the whole resource_view as a param as there is no other way to pass to information on to the iframe #}
{% set src = h.url(qualified=true, controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(resource_view)}) %}
{% set src = h.url_for(qualified=true, controller='package', action='resource_view', id=package['name'], resource_id=resource['id']) + '?' + h.urlencode({'resource_view': h.dump_json(resource_view)}) %}
{% endif %}
<iframe src="{{ src }}" frameborder="0" width="100%" data-module="data-viewer" allowfullscreen>
<p>{{ _('Your browser does not support iframes.') }}</p>
</iframe>
{% endif %}
</div>
<div id="embed-{{ resource_view['id'] }}" class="modal resource-view-embed hide">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h3>{{ _("Embed resource view") }}</h3>
</div>
<div class="modal-body">
<p class="embed-content">{{ _("You can copy and paste the embed code into a CMS or blog software that supports raw HTML") }}</p>
<div class="row-fluid">
<div class="span6">
{{ form.input("width", label=_("Width"), value=700, classes=["control-full"]) }}
<div id="embed-{{ resource_view['id'] }}" class="modal fade resource-view-embed">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h3>{{ _("Embed resource view") }}</h3>
</div>
<div class="span6">
{{ form.input("height", label=_("Height"), value=400, classes=["control-full"]) }}
<div class="modal-body">
<p class="embed-content">{{ _("You can copy and paste the embed code into a CMS or blog software that supports raw HTML") }}</p>
<div class="row">
<div class="{{ span6 }}">
{{ form.input("width", label=_("Width"), value=700, classes=["control-full"]) }}
</div>
<div class="{{ span6 }}">
{{ form.input("height", label=_("Height"), value=400, classes=["control-full"]) }}
</div>
</div>
{{ form.textarea("code", label=_("Code"), value="", classes=["pre"], rows=3) }}
</div>
</div>
{{ form.textarea("code", label=_("Code"), value="", classes=["pre"], rows=3) }}
</div>
</div>
</div>

0 comments on commit a7306e3

Please sign in to comment.