[ckan-changes] commit/ckan: rgrp: [js/datapreview][s]: (refs #1357) reinstate support for previewing csv and xls via jsonpdataproxy.
Bitbucket
commits-noreply at bitbucket.org
Sat Oct 8 16:51:39 UTC 2011
1 new changeset in ckan:
http://bitbucket.org/okfn/ckan/changeset/77a47f497a50/
changeset: 77a47f497a50
branch: feature-1357-datapreview
user: rgrp
date: 2011-10-08 18:51:11
summary: [js/datapreview][s]: (refs #1357) reinstate support for previewing csv and xls via jsonpdataproxy.
affected #: 1 file (-1 bytes)
--- a/ckan/public/scripts/application.js Wed Oct 05 18:09:27 2011 +0100
+++ b/ckan/public/scripts/application.js Sat Oct 08 17:51:11 2011 +0100
@@ -687,6 +687,7 @@
(function ($) {
var my = {};
+ my.jsonpdataproxyUrl = 'http://jsonpdataproxy.appspot.com/';
my.setupDataPreview = function(dataset) {
var dialogId = 'ckanext-datapreview-dialog';
@@ -736,12 +737,9 @@
return;
}
- // TODO: get this from resource
- var _url = "/resource.jsonp?_limit=30";
-
var _previewSpan = $('<a />', {
text: 'Preview',
- href: _url,
+ href: resourceData.url,
click: function(e) {
e.preventDefault();
my.loadPreviewDialog(e.target);
@@ -805,6 +803,46 @@
DATAEXPLORER.TABLEVIEW.$dialog.dialog('open');
});
}
+ else if (preview.formatNormalized in {'csv': '', 'xls': ''}) {
+ var _url = my.jsonpdataproxyUrl + '?url=' + preview.url + '&type=' + preview.formatNormalized;
+ my.getResourceDataDirect(_url, function(data) {
+ DATAEXPLORER.TABLEVIEW.showData(data);
+ DATAEXPLORER.TABLEVIEW.$dialog.dialog('open');
+ });
+ }
+ else if (preview.formatNormalized in {
+ 'rdf+xml': '',
+ 'owl+xml': '',
+ 'xml': '',
+ 'n3': '',
+ 'n-triples': '',
+ 'turtle': '',
+ 'plain': '',
+ 'atom': '',
+ 'tsv': '',
+ 'rss': '',
+ 'txt': ''
+ }) {
+ // HACK: treat as plain text / csv
+ // pass url to jsonpdataproxy so we can load remote data (and tell dataproxy to treat as csv!)
+ var _url = my.jsonpdataproxyUrl + '?type=csv&url=' + preview.url;
+ my.getResourceDataDirect(_url, function(data) {
+ my.showPlainTextData(data);
+ });
+ }
+ else {
+ // HACK: but should work
+ // we displays a fullscreen dialog with the url in an iframe.
+ // HACK: we borrow dialog from DATAEXPLORER.TABLEVIEW
+ var $dialog = DATAEXPLORER.TABLEVIEW.$dialog;
+ $dialog.empty();
+ $dialog.dialog('option', 'title', 'Preview: ' + preview.url);
+ var el = $('<iframe></iframe>');
+ el.attr('src', preview.url);
+ el.attr('width', '100%');
+ el.attr('height', '100%');
+ $dialog.append(el).dialog('open');;
+ }
};
// Public: Requests the formatted resource data from the webstore and
@@ -819,7 +857,7 @@
// set a timeout to provide the callback with an error after x seconds.
var timeout = 5000;
var timer = setTimeout(function error() {
- callback({}, {
+ callback({
error: {
title: 'Request Error',
message: 'Dataproxy server did not respond after ' + (timeout / 1000) + ' seconds'
@@ -848,6 +886,27 @@
});
};
+ // Public: Displays a String of data in a fullscreen dialog.
+ //
+ // data - An object of parsed CSV data returned by the webstore.
+ //
+ // Returns nothing.
+ my.showPlainTextData = function(data) {
+ // HACK: have to reach into DATAEXPLORER.TABLEVIEW dialog a lot ...
+ DATAEXPLORER.TABLEVIEW.setupFullscreenDialog();
+
+ if(data.error) {
+ DATAEXPLORER.TABLEVIEW.showError(data.error);
+ } else {
+ var content = $('<pre></pre>');
+ for (var i=0; i<data.data.length; i++) {
+ var row = data.data[i].join(',') + '\n';
+ content.append(dp.escapeHTML(row));
+ }
+ DATAEXPLORER.TABLEVIEW.$dialog.dialog('option', DATAEXPLORER.TABLEVIEW.dialogOptions).append(content);
+ }
+ };
+
my.normalizeFormat = function(format) {
var out = format.toLowerCase();
out = out.split('/');
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list