diff --git a/ckanext/reclinepreview/plugin.py b/ckanext/reclinepreview/plugin.py index 460eaa7b37b..b7759ee404d 100644 --- a/ckanext/reclinepreview/plugin.py +++ b/ckanext/reclinepreview/plugin.py @@ -41,25 +41,6 @@ def datastore_fields(resource, valid_field_types): if f['type'] in valid_field_types] -class ReclinePreview(p.SingletonPlugin): - '''DEPRECATED - - Wrapper that loads every Recline plugin to ease the transition to the new - Resource Views. - ''' - p.implements(p.IConfigurable) - - WRAPPED_PLUGINS = ['recline_grid', 'recline_graph', 'recline_map'] - - def configure(self, config): - log.warn("Plugin 'resource_preview' is deprecated. " - "Please, remove it and enable the Recline plugins " - "(recline_grid, recline_graph, and recline_map) as needed.") - for plugin in self.WRAPPED_PLUGINS: - if not p.plugin_loaded(plugin): - p.load(plugin) - - class ReclineView(p.SingletonPlugin): ''' This base class for the Recline view extensions. @@ -89,6 +70,17 @@ def view_template(self, context, data_dict): return 'recline_view.html' +class ReclinePreview(ReclineView): + ''' + This extension views resources using a Recline MultiView. + ''' + + def info(self): + return {'name': 'recline_preview', + 'title': 'Data Explorer', + 'icon': 'table'} + + class ReclineGrid(ReclineView): ''' This extension views resources using a Recline grid. diff --git a/ckanext/reclinepreview/tests/test_view.py b/ckanext/reclinepreview/tests/test_view.py index c6ddabc1f19..b6ae714578c 100644 --- a/ckanext/reclinepreview/tests/test_view.py +++ b/ckanext/reclinepreview/tests/test_view.py @@ -1,4 +1,3 @@ -import mock import paste.fixture import pylons.config as config @@ -11,56 +10,6 @@ import ckan.config.middleware as middleware -class TestReclinePreview(object): - @classmethod - def setup_class(cls): - cls.plugins = ['recline_grid', 'recline_graph', 'recline_map'] - - for plugin in cls.plugins: - if p.plugin_loaded(plugin): - p.unload(plugin) - - @classmethod - def teardown_class(cls): - p.load_all(config) - - def teardown(self): - for plugin in ['recline_preview'] + self.plugins: - if p.plugin_loaded(plugin): - p.unload(plugin) - - def test_loads_all_recline_plugins_when_its_loaded(self): - p.load('recline_preview') - - for plugin in self.plugins: - assert p.plugin_loaded(plugin), "%s wasn't loaded" % plugin - - def test_doesnt_try_to_load_already_loaded_plugins(self): - p.load('recline_grid') - p.load('recline_map') - - p.load('recline_preview') - - for plugin in self.plugins: - assert p.plugin_loaded(plugin), "%s wasn't loaded" % plugin - - @mock.patch('logging.getLogger') - def test_loading_this_plugin_gives_a_warning(self, getLogger): - log = mock.MagicMock() - getLogger.return_value = log - - p.load('recline_preview') - - log.warn.assert_called_once() - - def test_this_plugin_only_exists_on_ckan_2_3(self): - error_msg = ("Plugin 'resource_preview' plugin was created just to " - "ease the transition between 2.2 and 2.3. It should be " - "removed in later versions.") - - assert p.toolkit.check_ckan_version('2.2', '2.3'), error_msg - - class BaseTestReclineView(tests.WsgiAppCase): @classmethod def setup_class(cls): @@ -99,6 +48,15 @@ def test_title_description_iframe_shown(self): assert 'data-module="data-viewer"' in result.body +class TestReclinePreview(BaseTestReclineView): + view_type = 'recline_preview' + view_class = previewplugin.ReclinePreview + + def test_it_has_no_schema(self): + schema = self.p.info().get('schema') + assert schema is None, schema + + class TestReclineGrid(BaseTestReclineView): view_type = 'recline_grid' view_class = previewplugin.ReclineGrid diff --git a/ckanext/reclinepreview/theme/public/preview_recline.js b/ckanext/reclinepreview/theme/public/preview_recline.js index 3fa11e9699f..f448640f714 100644 --- a/ckanext/reclinepreview/theme/public/preview_recline.js +++ b/ckanext/reclinepreview/theme/public/preview_recline.js @@ -106,6 +106,8 @@ this.ckan.module('reclinepreview', function (jQuery, _) { } view = new recline.View.Map({model: dataset, state: state}); + } else if(reclineView.view_type === "recline_preview") { + view = this._newDataExplorer(dataset); } else { // default to Grid view = new recline.View.SlickGrid({model: dataset}); @@ -116,18 +118,70 @@ this.ckan.module('reclinepreview', function (jQuery, _) { ]; } - var newElements = $('
'); - this._renderControls(newElements, controls, this.options.controlsClassName); - newElements.append(view.el); - $(this.el).html(newElements); - view.visible = true; - view.render(); + // recline_preview automatically adds itself to the DOM, so we don't + // need to bother with it. + if(reclineView.view_type !== 'recline_preview') { + var newElements = $('
'); + this._renderControls(newElements, controls, this.options.controlsClassName); + newElements.append(view.el); + $(this.el).html(newElements); + view.visible = true; + view.render(); + } if(reclineView.view_type === "recline_graph") { view.redraw(); } }, + _newDataExplorer: function (dataset) { + var views = [ + { + id: 'grid', + label: 'Grid', + view: new recline.View.SlickGrid({ + model: dataset + }) + }, + { + id: 'graph', + label: 'Graph', + view: new recline.View.Graph({ + model: dataset + }) + }, + { + id: 'map', + label: 'Map', + view: new recline.View.Map({ + model: dataset + }) + } + ]; + + var sidebarViews = [ + { + id: 'valueFilter', + label: 'Filters', + view: new recline.View.ValueFilter({ + model: dataset + }) + } + ]; + + var dataExplorer = new recline.View.MultiView({ + el: this.el, + model: dataset, + views: views, + sidebarViews: sidebarViews, + config: { + readOnly: true + } + }); + + return dataExplorer; + }, + normalizeUrl: function (url) { if (url.indexOf('https') === 0) { return 'http' + url.slice(5);