[ckan-changes] commit/ckan: 7 new changesets

Bitbucket commits-noreply at bitbucket.org
Thu Oct 6 11:54:45 UTC 2011


7 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/47e837ed6156/
changeset:   47e837ed6156
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-02 09:37:01
summary:     [js,theme][xs]: use local jquery by default (rather than google cdn version).

* Consistent with other external libs we have.
* Means can work offline without faff.
affected #:  1 file (-1 bytes)

--- a/ckan/templates/layout_base.html	Sat Oct 01 00:19:21 2011 +0100
+++ b/ckan/templates/layout_base.html	Sun Oct 02 08:37:01 2011 +0100
@@ -201,8 +201,9 @@
   </div><!-- eo #container -->
 
 
-  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
-  <!--script><![CDATA[window.jQuery || document.write("<script src='${g.site_url}/scripts/vendor/jquery/1.6.2/jquery.js'>\x3C/script>")]]></script-->
+  <!--script
+  src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script-->
+  <script src="${g.site_url}/scripts/vendor/jquery/1.6.2/jquery.js"></script><script type="text/javascript" src="${g.site_url}/scripts/vendor/json2.js"></script><script type="text/javascript" src="${g.site_url}/scripts/vendor/jquery.tmpl/beta1/jquery.tmpl.js"></script><script type="text/javascript" src="${g.site_url}/scripts/vendor/jquery.cookie/jquery.cookie.min.js"></script>


http://bitbucket.org/okfn/ckan/changeset/748357143f85/
changeset:   748357143f85
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-02 09:44:05
summary:     [package/read][s]: inject json version of package into page for use by js (esp datapreview).
affected #:  3 files (-1 bytes)

--- a/ckan/controllers/package.py	Sun Oct 02 08:37:01 2011 +0100
+++ b/ckan/controllers/package.py	Sun Oct 02 08:44:05 2011 +0100
@@ -209,6 +209,7 @@
         try:
             c.pkg_dict = get_action('package_show')(context, data_dict)
             c.pkg = context['package']
+            c.pkg_json = json.dumps(c.pkg_dict)
         except NotFound:
             abort(404, _('Package not found'))
         except NotAuthorized:


--- a/ckan/public/scripts/application.js	Sun Oct 02 08:37:01 2011 +0100
+++ b/ckan/public/scripts/application.js	Sun Oct 02 08:44:05 2011 +0100
@@ -20,7 +20,8 @@
 
     var isDatasetView = $('body.package.read').length > 0;
     if (isDatasetView) {
-      CKAN.Utils.setupDataPreview();
+      var _dataset = new CKAN.Model.Dataset(preload_dataset);
+      CKAN.Utils.setupDataPreview(_dataset);
     }
 
     var isDatasetNew = $('body.package.new').length > 0;
@@ -274,7 +275,7 @@
     });  
   };
 
-  my.setupDataPreview = function() {
+  my.setupDataPreview = function(dataset) {
     var dialogId = 'ckanext-datapreview-dialog';
     my.createPreviewButtons($('.resources'));
   };


--- a/ckan/templates/package/read.html	Sun Oct 02 08:37:01 2011 +0100
+++ b/ckan/templates/package/read.html	Sun Oct 02 08:44:05 2011 +0100
@@ -150,7 +150,7 @@
     </py:if><script type="text/javascript">
-      var LOCAL_packageId = '${c.pkg.id}';
+      var preload_dataset = ${c.pkg_json};
     </script></py:def>
 


http://bitbucket.org/okfn/ckan/changeset/e9c34549293a/
changeset:   e9c34549293a
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-02 18:38:10
summary:     [js,refactor][s]: move datapreview stuff into own section and into module named CKANEXT.DATAPREVIEW.
affected #:  1 file (-1 bytes)

--- a/ckan/public/scripts/application.js	Sun Oct 02 08:44:05 2011 +0100
+++ b/ckan/public/scripts/application.js	Sun Oct 02 17:38:10 2011 +0100
@@ -21,7 +21,7 @@
     var isDatasetView = $('body.package.read').length > 0;
     if (isDatasetView) {
       var _dataset = new CKAN.Model.Dataset(preload_dataset);
-      CKAN.Utils.setupDataPreview(_dataset);
+      CKANEXT.DATAPREVIEW.setupDataPreview(_dataset);
     }
 
     var isDatasetNew = $('body.package.new').length > 0;
@@ -275,92 +275,6 @@
     });  
   };
 
-  my.setupDataPreview = function(dataset) {
-    var dialogId = 'ckanext-datapreview-dialog';
-    my.createPreviewButtons($('.resources'));
-  };
-
-  /* Public: Creates the base UI for the plugin.
-   *
-   * Adds an additonal preview column to the resources table in the CKAN
-   * UI. Also requests the package from the api to see if there is any chart
-   * data stored and updates the preview icons accordingly.
-   *
-   * resources - The resources table wrapped in jQuery.
-   *
-   * Returns nothing.
-   */
-  my.createPreviewButtons = function(resources) {
-    resources.find('tr td:last-child').each(function(idx, element) {
-      var element = $(element);
-      var _format = $.trim(element.prev().text());
-
-      // do not create previews for some items
-      var _tformat = _format.toLowerCase();
-      if (
-        _tformat.indexOf('zip') != -1
-        ||
-        _tformat.indexOf('tgz') != -1
-        ||
-        _tformat.indexOf('targz') != -1
-        ||
-        _tformat.indexOf('gzip') != -1
-        ||
-        _tformat.indexOf('gz:') != -1
-        ||
-        _tformat.indexOf('word') != -1
-        ||
-        _tformat.indexOf('pdf') != -1
-        ||
-        _tformat === 'other'
-        )
-      {
-        return;
-      }
-
-      // TODO: get this from resource
-      var _url = "/resource.jsonp?_limit=30";
-
-      // An object that holds information about the currently previewed data.
-      var _preview = {
-        'source': element.find('a').attr('href'),
-        'format': _format
-      };
-
-      var _previewSpan = $('<a />', {
-        text: 'Preview',
-        href: _url,
-        click: function(e) {
-          e.preventDefault();
-          alert('Loading preview');
-          // dp.loadPreviewDialog(e.target);
-        },
-        'class': 'resource-preview-button'
-      }).data('preview', _preview).appendTo(element);
-
-      // TODO: get dataset info
-      var dataset = null;
-      var resource = null; // dp.getResourceFromDataset(_preview.hash, dataset),
-      var chartString, charts = {};
-
-      if (resource) {
-        chartString = resource[dp.resourceChartKey];
-        if (chartString) {
-          try {
-            charts = $.parseJSON(chartString);
-
-            // If parsing succeeds add a class to the preview button.
-            _previewSpan.addClass('resource-preview-chart');
-          } catch (e) {}
-        }
-      }
-
-      _preview.dataset = dataset;
-      _preview.resource = resource;
-      _preview.charts = charts;
-    });
-  };
-
   // Name slug generator for $name element using $title element
   //
   // Also does nice things like show errors if name not available etc
@@ -771,3 +685,98 @@
 });
 
 
+(function ($) {
+  var my = {};
+
+  my.setupDataPreview = function(dataset) {
+    var dialogId = 'ckanext-datapreview-dialog';
+    my.createPreviewButtons($('.resources'));
+  };
+
+  /* Public: Creates the base UI for the plugin.
+   *
+   * Adds an additonal preview column to the resources table in the CKAN
+   * UI. Also requests the package from the api to see if there is any chart
+   * data stored and updates the preview icons accordingly.
+   *
+   * resources - The resources table wrapped in jQuery.
+   *
+   * Returns nothing.
+   */
+  my.createPreviewButtons = function(resources) {
+    resources.find('tr td:last-child').each(function(idx, element) {
+      var element = $(element);
+      var _format = $.trim(element.prev().text());
+
+      // do not create previews for some items
+      var _tformat = _format.toLowerCase();
+      if (
+        _tformat.indexOf('zip') != -1
+        ||
+        _tformat.indexOf('tgz') != -1
+        ||
+        _tformat.indexOf('targz') != -1
+        ||
+        _tformat.indexOf('gzip') != -1
+        ||
+        _tformat.indexOf('gz:') != -1
+        ||
+        _tformat.indexOf('word') != -1
+        ||
+        _tformat.indexOf('pdf') != -1
+        ||
+        _tformat === 'other'
+        )
+      {
+        return;
+      }
+
+      // TODO: get this from resource
+      var _url = "/resource.jsonp?_limit=30";
+
+      // An object that holds information about the currently previewed data.
+      var _preview = {
+        'source': element.find('a').attr('href'),
+        'format': _format
+      };
+
+      var _previewSpan = $('<a />', {
+        text: 'Preview',
+        href: _url,
+        click: function(e) {
+          e.preventDefault();
+          alert('Loading preview');
+          // dp.loadPreviewDialog(e.target);
+        },
+        'class': 'resource-preview-button'
+      }).data('preview', _preview).appendTo(element);
+
+      // TODO: get dataset info
+      var dataset = null;
+      var resource = null; // dp.getResourceFromDataset(_preview.hash, dataset),
+      var chartString, charts = {};
+
+      if (resource) {
+        chartString = resource[dp.resourceChartKey];
+        if (chartString) {
+          try {
+            charts = $.parseJSON(chartString);
+
+            // If parsing succeeds add a class to the preview button.
+            _previewSpan.addClass('resource-preview-chart');
+          } catch (e) {}
+        }
+      }
+
+      _preview.dataset = dataset;
+      _preview.resource = resource;
+      _preview.charts = charts;
+    });
+  };
+
+
+  // Export the CKANEXT object onto the window.
+  $.extend(true, window, {CKANEXT: {}});
+  CKANEXT.DATAPREVIEW = my;
+}(jQuery));
+


http://bitbucket.org/okfn/ckan/changeset/3072458c0e87/
changeset:   3072458c0e87
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-03 10:39:59
summary:     [js/datapreview][s]: (refs #1357) wire up datapreview to point where we will use DataExplorer, plus get resource info (url, format etc) via dataset json injected into page rather than extraction from HTML.
affected #:  1 file (-1 bytes)

--- a/ckan/public/scripts/application.js	Sun Oct 02 17:38:10 2011 +0100
+++ b/ckan/public/scripts/application.js	Mon Oct 03 09:39:59 2011 +0100
@@ -690,26 +690,29 @@
 
   my.setupDataPreview = function(dataset) {
     var dialogId = 'ckanext-datapreview-dialog';
-    my.createPreviewButtons($('.resources'));
+    my.createPreviewButtons(dataset, $('.resources'));
   };
 
-  /* Public: Creates the base UI for the plugin.
-   *
-   * Adds an additonal preview column to the resources table in the CKAN
-   * UI. Also requests the package from the api to see if there is any chart
-   * data stored and updates the preview icons accordingly.
-   *
-   * resources - The resources table wrapped in jQuery.
-   *
-   * Returns nothing.
-   */
-  my.createPreviewButtons = function(resources) {
-    resources.find('tr td:last-child').each(function(idx, element) {
+  // Public: Creates the base UI for the plugin.
+  //
+  // Also requests the package from the api to see if there is any chart
+  // data stored and updates the preview icons accordingly.
+  //
+  // dataset: Dataset model for the dataset on this page.
+  // resourceElements - The resources table wrapped in jQuery.
+  //
+  // Returns nothing.
+  my.createPreviewButtons = function(dataset, resourceElements) {
+    // rather pointless, but w/o assignment dataset not available in loop below (??!)
+    var currentDataset = dataset;
+    resourceElements.find('tr td:last-child').each(function(idx, element) {
       var element = $(element);
-      var _format = $.trim(element.prev().text());
+      var resource = currentDataset.get('resources').models[idx];
+      var resourceData = resource.toJSON();
+      resourceData.formatNormalized = my.normalizeFormat(resourceData.format);
 
       // do not create previews for some items
-      var _tformat = _format.toLowerCase();
+      var _tformat = resourceData.format.toLowerCase();
       if (
         _tformat.indexOf('zip') != -1
         ||
@@ -734,30 +737,20 @@
       // TODO: get this from resource
       var _url = "/resource.jsonp?_limit=30";
 
-      // An object that holds information about the currently previewed data.
-      var _preview = {
-        'source': element.find('a').attr('href'),
-        'format': _format
-      };
-
       var _previewSpan = $('<a />', {
         text: 'Preview',
         href: _url,
         click: function(e) {
           e.preventDefault();
-          alert('Loading preview');
-          // dp.loadPreviewDialog(e.target);
+          my.loadPreviewDialog(e.target);
         },
         'class': 'resource-preview-button'
-      }).data('preview', _preview).appendTo(element);
+      }).data('preview', resourceData).appendTo(element);
 
-      // TODO: get dataset info
-      var dataset = null;
-      var resource = null; // dp.getResourceFromDataset(_preview.hash, dataset),
       var chartString, charts = {};
 
       if (resource) {
-        chartString = resource[dp.resourceChartKey];
+        chartString = resource[my.resourceChartKey];
         if (chartString) {
           try {
             charts = $.parseJSON(chartString);
@@ -767,13 +760,108 @@
           } catch (e) {}
         }
       }
-
-      _preview.dataset = dataset;
-      _preview.resource = resource;
-      _preview.charts = charts;
     });
   };
 
+  // **Public: Loads a data preview dialog for a preview button.**
+  //
+  // Fetches the preview data object from the link provided and loads the
+  // parsed data from the webstore displaying it in the most appropriate
+  // manner.
+  //
+  // link - Preview button.
+  //
+  // Returns nothing.
+  my.loadPreviewDialog = function(link) {
+    var preview  = $(link).data('preview');
+    preview.url  = my.normalizeUrl(link.href);
+
+    $(link).addClass('resource-preview-loading').text('Loading');
+
+    // 4 situations
+    // a) have a webstore_url
+    // b) csv or xls (but not webstore)
+    // 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 ...)
+    if (preview.formatNormalized === '') {
+      var tmp = preview.url.split('/');
+      tmp = tmp[tmp.length - 1];
+      tmp = tmp.split('?'); // query strings
+      tmp = tmp[0];
+      var ext = tmp.split('.');
+      if (ext.length > 1) {
+        preview.formatNormalized = ext[ext.length-1];
+      }
+    }
+
+    if (preview.webstore_url) {
+      var _url = preview.webstore_url + '.jsontuples?_limit=500';
+      my.getResourceDataDirect(_url, function(data) {
+        alert('Showing data for ' + _url);
+        // my.showData(preview, data);
+        // dp.$dialog.dialog('open');
+      });
+    }
+  };
+
+  // Public: Requests the formatted resource data from the webstore and
+  // passes the data into the callback provided.
+  //
+  // preview - A preview object containing resource metadata.
+  // callback - A Function to call with the data when loaded.
+  //
+  // Returns nothing.
+  my.getResourceDataDirect = function(url, callback) {
+    // $.ajax() does not call the "error" callback for JSONP requests so we
+    // set a timeout to provide the callback with an error after x seconds.
+    var timeout = 5000;
+    var timer = setTimeout(function error() {
+      callback({}, {
+        error: {
+          title: 'Request Error',
+          message: 'Dataproxy server did not respond after ' + (timeout / 1000) + ' seconds'
+        }
+      });
+    }, timeout);
+
+    // have to set jsonp because webstore requires _callback but that breaks jsonpdataproxy
+    var jsonp = '_callback';
+    if (url.indexOf('jsonpdataproxy') != -1) {
+      jsonp = 'callback';
+    }
+
+    // We need to provide the `cache: true` parameter to prevent jQuery appending
+    // a cache busting `={timestamp}` parameter to the query as the webstore
+    // currently cannot handle custom parameters.
+    $.ajax({
+      url: url,
+      cache: true,
+      dataType: 'jsonp',
+      jsonp: jsonp,
+      success: function(data) {
+        clearTimeout(timer);
+        callback(data);
+      }
+    });
+  };
+
+  my.normalizeFormat = function(format) {
+    var out = format.toLowerCase();
+    out = out.split('/');
+    out = out[out.length-1];
+    return out;
+  };
+
+  my.normalizeUrl = function(url) {
+    if (url.indexOf('https') === 0) {
+      return 'http' + url.slice(5);
+    } else {
+      return url;
+    }
+  }
+
 
   // Export the CKANEXT object onto the window.
   $.extend(true, window, {CKANEXT: {}});


http://bitbucket.org/okfn/ckan/changeset/579f6d574f0c/
changeset:   579f6d574f0c
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-05 11:34:42
summary:     [js/vendor][m]: (refs #1357) introduce all vendor material needed for data-preview and pull it in package/read template.
affected #:  41 files (-1 bytes)
Diff too large to display.
http://bitbucket.org/okfn/ckan/changeset/13e2b6b5f443/
changeset:   13e2b6b5f443
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-05 11:35:41
summary:     [js][s]: data preview now working for resources with webstore_url attribute.
affected #:  1 file (-1 bytes)

--- a/ckan/public/scripts/application.js	Wed Oct 05 10:34:42 2011 +0100
+++ b/ckan/public/scripts/application.js	Wed Oct 05 10:35:41 2011 +0100
@@ -690,6 +690,8 @@
 
   my.setupDataPreview = function(dataset) {
     var dialogId = 'ckanext-datapreview-dialog';
+    // initialize the tableviewer system
+    DATAEXPLORER.TABLEVIEW.initialize(dialogId);
     my.createPreviewButtons(dataset, $('.resources'));
   };
 
@@ -799,9 +801,8 @@
     if (preview.webstore_url) {
       var _url = preview.webstore_url + '.jsontuples?_limit=500';
       my.getResourceDataDirect(_url, function(data) {
-        alert('Showing data for ' + _url);
-        // my.showData(preview, data);
-        // dp.$dialog.dialog('open');
+        DATAEXPLORER.TABLEVIEW.showData(data);
+        DATAEXPLORER.TABLEVIEW.$dialog.dialog('open');
       });
     }
   };
@@ -862,7 +863,6 @@
     }
   }
 
-
   // Export the CKANEXT object onto the window.
   $.extend(true, window, {CKANEXT: {}});
   CKANEXT.DATAPREVIEW = my;


http://bitbucket.org/okfn/ckan/changeset/449ead2e5ffd/
changeset:   449ead2e5ffd
branch:      feature-1357-datapreview
user:        rgrp
date:        2011-10-05 19:09:27
summary:     [js/vendor/jqueryui][s]: change to jquery ui version and (slightly custom) css that dataexplorer uses (v1.8.11 -> v1.8.14).

* css looks a bit nicer and in terms of js makes no difference.
affected #:  35 files (-1 bytes)
Diff too large to display.

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