Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 3028-dashboard-act…
Browse files Browse the repository at this point in the history
…ivity-stream-filtering
  • Loading branch information
Sean Hammond committed Feb 13, 2013
2 parents 7a1aff2 + 27268da commit 5cd3c78
Show file tree
Hide file tree
Showing 80 changed files with 34,648 additions and 6,938 deletions.
33 changes: 15 additions & 18 deletions ckan/lib/helpers.py
Expand Up @@ -1380,8 +1380,8 @@ def resource_preview(resource, pkg_id):
Returns a rendered snippet for a embedded resource preview.
Depending on the type, different previews are loaded.
This could be an img tag where the image is loaded directly or an iframe that
embeds a web page, recline or a pdf preview.
This could be an img tag where the image is loaded directly or an iframe
that embeds a web page, recline or a pdf preview.
'''

format_lower = resource['format'].lower()
Expand All @@ -1392,11 +1392,9 @@ def resource_preview(resource, pkg_id):

if not resource['url']:
log.info('No url for resource {0} defined.'.format(resource['id']))
return snippet(
"dataviewer/snippets/no_preview.html",
resource_type=format_lower,
reason='No valid resource url has been defined.'
)
return snippet("dataviewer/snippets/no_preview.html",
resource_type=format_lower,
reason='No valid resource url has been defined.')
direct_embed = config.get('ckan.preview.direct', '').split()
if not direct_embed:
direct_embed = datapreview.DEFAULT_DIRECT_EMBED
Expand All @@ -1406,24 +1404,23 @@ def resource_preview(resource, pkg_id):

if datapreview.can_be_previewed(data_dict):
url = url_for(controller='package', action='resource_datapreview',
resource_id=resource['id'], id=pkg_id, qualified=True)
resource_id=resource['id'], id=pkg_id, qualified=True)
elif format_lower in direct_embed:
directly = True
url = resource['url']
elif format_lower in loadable_in_iframe:
url = resource['url']
else:
log.info('No preview handler for resource type {0}'.format(format_lower))
return snippet(
"dataviewer/snippets/no_preview.html",
resource_type=format_lower
)

return snippet(
"dataviewer/snippets/data_preview.html",
embed=directly,
resource_url=url
log.info(
'No preview handler for resource type {0}'.format(format_lower)
)
return snippet("dataviewer/snippets/no_preview.html",
resource_type=format_lower)

return snippet("dataviewer/snippets/data_preview.html",
embed=directly,
resource_url=url,
raw_resource_url=resource.get('url'))


def SI_number_span(number):
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/schema.py
Expand Up @@ -76,7 +76,7 @@ def default_resource_schema():
'last_modified': [ignore_missing, isodate],
'cache_last_updated': [ignore_missing, isodate],
'webstore_last_updated': [ignore_missing, isodate],
'tracking_summary': [ignore],
'tracking_summary': [ignore_missing],
'__extras': [ignore_missing, extras_unicode_convert, keep_extras],
}

Expand Down
8 changes: 8 additions & 0 deletions ckan/public/base/javascript/modules/data-viewer.js
Expand Up @@ -12,6 +12,14 @@ this.ckan.module('data-viewer', function (jQuery) {
jQuery.proxyAll(this, /_on/);
this.el.on('load', this._onLoad);
this._FirefoxFix();
this.sandbox.subscribe('data-viewer-error', this._onDataViewerError);
},

_onDataViewerError: function(message) {
var parent = this.el.parent();
$('.data-viewer-error .collapse', parent).html(message);
$('.data-viewer-error', parent).removeClass('js-hide');
this.el.hide();
},

_onLoad: function() {
Expand Down
24 changes: 20 additions & 4 deletions ckan/templates/dataviewer/snippets/data_preview.html
Expand Up @@ -3,8 +3,24 @@
{# images can be embedded directly #}
<img src="{{ resource_url }}"></img>
{% else %}
<iframe src="{{ resource_url }}" frameborder="0" width="100%" data-module="data-viewer">
<p>{{ _('Your browser does not support iframes.') }}</p>
</iframe>
<div class="data-viewer-error js-hide">
<p class="text-error">
<i class="icon-info-sign"></i>
{{ _('This resource can not be previewed 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" target="_blank">
<i class="icon-large icon-download"></i>
{{ _('Download resource') }}
</a>
</p>
</div>
<iframe src="{{ resource_url }}" frameborder="0" width="100%" data-module="data-viewer">
<p>{{ _('Your browser does not support iframes.') }}</p>
</iframe>
{% endif %}
</div>
</div>
2 changes: 2 additions & 0 deletions ckan/tests/lib/test_dictization_schema.py
Expand Up @@ -88,12 +88,14 @@ def test_1_package_schema(self):
'format': u'plain text',
'hash': u'abc123',
'size_extra': u'123',
'tracking_summary': {'recent': 0, 'total': 0},
'url': u'http://www.annakarenina.com/download/x=1&y=2'},
{'alt_url': u'alt345',
'description': u'Index of the novel',
'format': u'JSON',
'hash': u'def456',
'size_extra': u'345',
'tracking_summary': {'recent': 0, 'total': 0},
'url': u'http://www.annakarenina.com/index.json'}],
'tags': [{'name': u'Flexible \u30a1'},
{'name': u'russian'},
Expand Down
28 changes: 17 additions & 11 deletions ckanext/reclinepreview/theme/public/preview_recline.js
Expand Up @@ -7,12 +7,15 @@ this.ckan.module('reclinepreview', function (jQuery, _) {
errorDataProxy: "DataProxy returned an error",
errorDataStore: "DataStore returned an error",
previewNotAvailableForDataType: "Preview not available for data type: "
}
},
site_url: ""
},

initialize: function () {
jQuery.proxyAll(this, /_on/);
this.el.ready(this._onReady);
// hack to make leaflet use a particular location to look for images
L.Icon.Default.imagePath = this.options.site_url + 'vendor/leaflet/images'
},

_onReady: function() {
Expand All @@ -33,10 +36,7 @@ this.ckan.module('reclinepreview', function (jQuery, _) {

function showError(msg){
msg = msg || _('error loading preview');
return self.el
.append('<div></div>')
.addClass('alert alert-error fade in')
.html(msg);
window.parent.ckan.pubsub.publish('data-viewer-error', msg);
}

recline.Backend.DataProxy.timeout = 10000;
Expand Down Expand Up @@ -84,14 +84,12 @@ this.ckan.module('reclinepreview', function (jQuery, _) {
errorMsg = this.options.i18n.errorLoadingPreview + ': ' +this.options.i18n.errorDataProxy;
dataset.fetch()
.done(function(dataset){

dataset.bind('query:fail', function (error) {
jQuery('.data-view-container', self.el).hide();
jQuery('.header', self.el).hide();
});

self.initializeDataExplorer(dataset);
jQuery('.recline-query-editor .text-query').hide();
})
.fail(function(error){
if (error.message) errorMsg += ' (' + error.message + ')';
Expand Down Expand Up @@ -125,18 +123,26 @@ this.ckan.module('reclinepreview', function (jQuery, _) {
}
];

var sidebarViews = [
{
id: 'filterEditor',
label: 'Filters',
view: new recline.View.FilterEditor({
model: dataset
})
}
];

var dataExplorer = new recline.View.MultiView({
el: this.el,
model: dataset,
views: views,
sidebarViews: sidebarViews,
config: {
readOnly: true
}
});

// Hide the fields control by default
// (This should be done in recline!)
// jQuery('.menu-right a[data-action="fields"]', self.el).click();
},
normalizeFormat: function (format) {
var out = format.toLowerCase();
Expand All @@ -152,4 +158,4 @@ this.ckan.module('reclinepreview', function (jQuery, _) {
}
}
};
});
});
39 changes: 22 additions & 17 deletions ckanext/reclinepreview/theme/public/resource.config
@@ -1,8 +1,11 @@
[IE conditional]

lte IE 7 =
vendor/json/json2.js

lte IE 8 =
vendor/flotr2/excanvas.js
vendor/leaflet/leaflet.ie.css
vendor/flot/excanvas.js
vendor/leaflet/0.4.4/leaflet.ie.css
vendor/leaflet.markercluster/MarkerCluster.Default.ie.css

[depends]
Expand All @@ -12,29 +15,31 @@ main = base/main
[groups]

main =
vendor/underscore/underscore.js
vendor/backbone/backbone.js
vendor/mustache/mustache.js
vendor/bootstrap/bootstrap.js
vendor/flotr2/flotr2.js
vendor/leaflet/leaflet.js
vendor/underscore/1.4.2/underscore.js
vendor/backbone/0.9.2/backbone.js
vendor/mustache/0.5.0-dev/mustache.js
vendor/bootstrap/2.0.2/bootstrap.js
vendor/json/json2.js
vendor/flot/excanvas.js
vendor/flot/jquery.flot.js
vendor/leaflet/0.4.4/leaflet.js
vendor/leaflet.markercluster/leaflet.markercluster.js
vendor/slickgrid/jquery-ui-1.8.16.custom.js
vendor/slickgrid/jquery.event.drag-2.0.js
vendor/slickgrid/slick.grid.js
vendor/moment/moment.js
vendor/slickgrid/2.0.1/jquery-ui-1.8.16.custom.js
vendor/slickgrid/2.0.1/jquery.event.drag-2.0.js
vendor/slickgrid/2.0.1/slick.grid.js
vendor/moment/1.6.2/moment.js

vendor/recline/recline.js

preview_recline.js

vendor/bootstrap/css/bootstrap.css
vendor/leaflet/leaflet.css
vendor/leaflet/leaflet.ie.css
vendor/bootstrap/2.0.2/css/bootstrap.css
vendor/leaflet/0.4.4/leaflet.css
vendor/leaflet/0.4.4/leaflet.ie.css
vendor/leaflet.markercluster/MarkerCluster.css
vendor/leaflet.markercluster/MarkerCluster.Default.css
vendor/leaflet.markercluster/MarkerCluster.Default.ie.css
vendor/slickgrid/slick.grid.css
vendor/recline/css/recline.css
vendor/slickgrid/2.0.1/slick.grid.css
vendor/recline/recline.css

css/recline.css

0 comments on commit 5cd3c78

Please sign in to comment.