Commit 5178d076 authored by Marko Kuder's avatar Marko Kuder
Browse files

fix json preview data type, improve resource preview info for non-tabular formats

parent a0f008ad
......@@ -221,23 +221,34 @@ def is_wms(resource):
from ckanext.dgu.lib.helpers import get_resource_wms
return bool(get_resource_wms(resource))
def get_resource_datastore_info(resource_dict):
in_datastore = resource_dict.get('datastore_active', False)
if in_datastore:
message = u'Za to datoteko je omogočen predogled celotne vsebine datoteke.'
if resource_dict.get('url_type', None) != 'upload':
message = message + u' Opozorilo: podatki v predogledu morda niso povsem ažurni, če se datoteka na viru spreminja.'
return message
else:
return u'Za to datoteko je omogočen le osnovni predogled. Količina prikazanih podatkov in urejanje sta zato lahko omejena. Za vpogled v celotne podatke datoteko prenesite ali zaprosite objavitelja za vklop polnega predogleda.'
def get_resource_additional_info(resource_dict):
if is_datastore_compatible(resource_dict):
in_datastore = resource_dict.get('datastore_active', False)
if in_datastore:
message = u'Za to datoteko je omogočen tabelarični predogled celotne vsebine.'
if resource_dict.get('url_type', None) != 'upload':
message = message + u' Opozorilo: podatki v predogledu morda niso povsem ažurni, če se datoteka na viru spreminja.'
return message
else:
return u'Za to datoteko je omogočen le osnovni tabelarični predogled. Količina prikazanih podatkov in urejanje sta zato lahko omejena. Za vpogled v celotne podatke datoteko prenesite ali zaprosite objavitelja za vklop polnega predogleda.'
elif is_geo_preview_compatible(resource_dict):
return u'Za opredeljeni format je omogočen predogled na zemljevidu. V primeru, da prikaz ni pravilen (ni podatkov oz. so na napačnem mestu), vas prosimo, da kontaktirate skrbnika ali uredništvo.'
return ''
def is_datastore_compatible(resource):
'''we are not overly strict about this - iv either qa detects a tabular format or a user
'''we are not overly strict about this - if either qa detects a tabular format or a user
insists that it is a tabular format, we accept it as such'''
supported_formats = ['csv', 'xls', 'xlsx', 'tsv', 'ods']
return ((resource.get('qa') and resource.get('qa')['format'] and resource.get('qa')['format'].lower() in supported_formats) or
(resource.get('format') and resource.get('format').lower() in supported_formats))
def is_geo_preview_compatible(resource):
'''we are not overly strict about this - if either qa detects a supported format or a user
insists that it is a supported format, we accept it as such'''
supported_formats = ['geojson']
return ((resource.get('qa') and resource.get('qa')['format'] and resource.get('qa')['format'].lower() in supported_formats) or
(resource.get('format') and resource.get('format').lower() in supported_formats))
def get_resource_wms(resource_dict):
'''For a given resource, return the WMS url if it is a WMS data type.'''
# plenty of WMS resources have res['format']='' so
......
......@@ -282,7 +282,19 @@ CKAN.Dgu.resourcePreviewer = (function($,my) {
$('#ckanext-xml-preview').append(el);
//my.$dialog().append(el);
}
else if (resourceData.formatNormalized in {'txt':'','json':''} || resourceData.resource_type=='plain' || resourceData.resource_type=='txt' || resourceData.resource_type=='json') {
else if (resourceData.formatNormalized in {'json':''} || resourceData.resource_type=='json') {
// we displays a fullscreen dialog with the url in an iframe.
my.$dialog().empty();
var el = $('<iframe></iframe>');
el.attr('src', resourceData.url);
el.attr('type','application/json');
el.attr('width', '100%');
el.attr('height', '100%');
$('#ckanext-json-preview').append(el);
}
else if (resourceData.formatNormalized in {'txt':''} || resourceData.resource_type=='plain' || resourceData.resource_type=='txt') {
// we displays a fullscreen dialog with the url in an iframe.
my.$dialog().empty();
......
......@@ -46,7 +46,7 @@
<link rel="stylesheet" href="/css/dgu-recline-pack.min.css" />
{% if not h.is_wms(c.resource) %}
<!-- data preview -->
<script type="text/javascript" src="{{h.url_for_static('/scripts/dgu-recline-pack.min.js')}}"></script>
<script type="text/javascript" src="{{h.url_for_static('/scripts/dgu-recline-pack.min.js')}}?{{h.ckan_asset_timestamp()}}"></script>
<!--[if lt IE 8]>
<script>
CKAN.Dgu.resourcePreviewer.loadPreviewDialog = function(x){};
......@@ -150,7 +150,7 @@
{% if not h.is_wms(c.resource)%}
<div class="preview-header">
<h2>Predogled</h2>
<p>Predogled je na voljo le za datoteke CSV, XML, XLS, XLSX, GEOJSON, slike (PNG, JPG, GIF) ter prosto besedilo. {{h.get_resource_datastore_info(c.resource)}}{#<span id="ckanext-datapreview-source">#}</span></p>
<p>Predogled je na voljo le za datoteke CSV, XML, XLS, XLSX, JSON, GEOJSON, slike (PNG, JPG, GIF) ter prosto besedilo. {{h.get_resource_additional_info(c.resource)}}{#<span id="ckanext-datapreview-source">#}</span></p>
</div>
{% endif %}
{% if c.resource.get('format').lower() == 'geojson' %}
......@@ -163,6 +163,7 @@
<div id="ckanext-html-preview"></div>
<div id="ckanext-image-preview"></div>
<div id="ckanext-xml-preview"></div>
<div id="ckanext-json-preview"></div>
<div id="ckanext-txt-preview"></div>
{% endif %}
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment