diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index f6a899e1de3..871c6d7af36 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -1319,13 +1319,12 @@ def resource_preview(resource, pkg_id): format_lower = resource['format'].lower() directly = False - - url = url_for(controller='package', action='resource_datapreview', - resource_id=resource['id'], id=pkg_id, qualified=True) + url = '' + no_preview = False if resource.get('datastore_active') or format_lower in ['csv', 'xls', 'tsv']: - #default - pass + url = url_for(controller='package', action='resource_datapreview', + resource_id=resource['id'], id=pkg_id, qualified=True) elif format_lower == 'pdf': url = url_for(controller='package', action='resource_pdfpreview', resource_id=resource['id'], id=pkg_id, qualified=True) @@ -1335,9 +1334,16 @@ def resource_preview(resource, pkg_id): directly = True url = resource['url'] else: - log.warn('not handler for {}'.format(resource['format'])) - - return snippet("package/snippets/data_preview.html", embed=directly, resource_url=url) + log.info('no handler for {}'.format(resource['format'])) + no_preview = True + + return snippet( + "package/snippets/data_preview.html", + embed=directly, + resource_url=url, + no_preview=no_preview, + resource_type=resource['format'] + ) # these are the functions that will end up in `h` template helpers diff --git a/ckan/public/base/datapreview/datapreview.js b/ckan/public/base/datapreview/datapreview.js index 4c08007c309..3b3f2fe0bd2 100644 --- a/ckan/public/base/datapreview/datapreview.js +++ b/ckan/public/base/datapreview/datapreview.js @@ -211,13 +211,10 @@ CKAN.DataPreview = function ($, my) { } - // 4 situations + // 3 situations // a) something was posted to the datastore - need to check for this // b) csv or xls (but not datastore) // c) can be treated as plain text - // d) none of the above but worth iframing (assumption is - // that if we got here (i.e. preview shown) worth doing - // something ...) resourceData.formatNormalized = my.normalizeFormat(resourceData.format); resourceData.url = my.normalizeUrl(resourceData.url); @@ -293,35 +290,6 @@ CKAN.DataPreview = function ($, my) { my.showPlainTextData(data); }); } - else if (resourceData.formatNormalized in {'html':'', 'htm':''} - || resourceData.url.substring(0,23)=='http://docs.google.com/') { - // we displays a fullscreen dialog with the url in an iframe. - my.$dialog.empty(); - var el = $(''); - el.attr('src', resourceData.url); - el.attr('width', '100%'); - el.attr('height', '100%'); - my.$dialog.append(el); - } - // images - else if (resourceData.formatNormalized in {'png':'', 'jpg':'', 'gif':''} - || resourceData.resource_type=='image') { - // we displays a fullscreen dialog with the url in an iframe. - my.$dialog.empty(); - var el = $(''); - el.attr('src', resourceData.url); - el.css('max-width', '100%'); - el.css('border', 'solid 4px black'); - my.$dialog.append(el); - } - else { - // Cannot reliably preview this item - with no mimetype/format information, - // can't guarantee it's not a remote binary file such as an executable. - my.showError({ - title: CKAN.Strings.previewNotAvailableForDataType + resourceData.formatNormalized, - message: '' - }); - } }; // Public: Requests the formatted resource data from the webstore and @@ -404,7 +372,7 @@ CKAN.DataPreview = function ($, my) { } else { return url; } - } + }; // Public: Escapes HTML entities to prevent broken layout and XSS attacks // when inserting user generated or external content. diff --git a/ckan/public/base/datapreview/pdfpreview.js b/ckan/public/base/datapreview/pdfpreview.js index c65a65318c5..2488be32977 100644 --- a/ckan/public/base/datapreview/pdfpreview.js +++ b/ckan/public/base/datapreview/pdfpreview.js @@ -23,10 +23,10 @@ CKAN.PdfPreview = function ($, pdf, my) { my.loadPreview = function(resourceData) { var params = { file: resourceData['url'] - } + }; pdf(params); - } + }; // Export the CKANEXT object onto the window. $.extend(true, window, {CKANEXT: {}}); diff --git a/ckan/templates/package/snippets/data_preview.html b/ckan/templates/package/snippets/data_preview.html index ba64d9813a0..f78ed335892 100644 --- a/ckan/templates/package/snippets/data_preview.html +++ b/ckan/templates/package/snippets/data_preview.html @@ -1,10 +1,18 @@
- {% if embed %} - {# images can be embedded directly #} - - {% else %} - - {% endif %} + {% if no_preview %} +
+ +

{{_('Preview not available')}}

+ {{_('No handler defined for data type:')}} {{ resource_type }} +
+ {% else %} + {% if embed %} + {# images can be embedded directly #} + + {% else %} + + {% endif %} + {% endif %}