From 36081910d5bc38dcfbe82ac596c34c3b3be36107 Mon Sep 17 00:00:00 2001 From: Matt Fullerton Date: Tue, 16 May 2017 07:09:16 +0000 Subject: [PATCH 1/6] Sync body height with CKAN data preview min. height This prevents large amounts of black space at the bottom of the PDF --- ckanext/pdfview/theme/public/css/pdf.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ckanext/pdfview/theme/public/css/pdf.css b/ckanext/pdfview/theme/public/css/pdf.css index a4d0800..2c80c1b 100644 --- a/ckanext/pdfview/theme/public/css/pdf.css +++ b/ckanext/pdfview/theme/public/css/pdf.css @@ -1,4 +1,4 @@ body { - height: 500px; + height: 650px; overflow: hidden; -} \ No newline at end of file +} From 5955d2af5670dda5f11cd1450447dc08a7d42153 Mon Sep 17 00:00:00 2001 From: Matt Fullerton Date: Wed, 4 Oct 2017 14:31:37 +0200 Subject: [PATCH 2/6] Update resource_view.html including latest changes from CKAN core and including helpers to cope with the many possible frontend configurations for CKAN templates across different versions --- ckanext/pdfview/plugin.py | 28 ++++++ .../package/snippets/resource_view.html | 86 +++++++++++++------ 2 files changed, 86 insertions(+), 28 deletions(-) diff --git a/ckanext/pdfview/plugin.py b/ckanext/pdfview/plugin.py index 7717646..495437a 100644 --- a/ckanext/pdfview/plugin.py +++ b/ckanext/pdfview/plugin.py @@ -1,10 +1,31 @@ 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(): + try: + return float(h.ckan_version()[0:3]) + except AttributeError: + #So old that we can't ask CKAN this way, but let's be optimistic + return 2.4 + +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. ''' @@ -16,6 +37,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) @@ -52,3 +74,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 + } diff --git a/ckanext/pdfview/theme/templates/package/snippets/resource_view.html b/ckanext/pdfview/theme/templates/package/snippets/resource_view.html index 1e5413e..e8eff45 100644 --- a/ckanext/pdfview/theme/templates/package/snippets/resource_view.html +++ b/ckanext/pdfview/theme/templates/package/snippets/resource_view.html @@ -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 %} +
- - - {{ _("Embed") }} - +

{{ h.render_markdown(resource_view['description']) }}

{% if not to_preview and h.resource_view_is_filterable(resource_view) %} @@ -18,8 +44,8 @@ {{ h.rendered_resource_view(resource_view, resource, package) }} {% else %}
-

- +

+ {{ _('This resource view is not available at the moment.') }} {{ _('Click here for more information.') }} @@ -27,8 +53,8 @@

- - + + {{ _('Download resource') }}

@@ -36,42 +62,46 @@ {% 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 %} {% endif %}
-