Skip to content

Commit

Permalink
[#1251] Bring resource_preview with Recline.MultiView back
Browse files Browse the repository at this point in the history
I've named it Data Explorer, as it's more self-explanatory than "Recline
Preview". It works the same way as it used to work, and the plugin is still
named "recline_preview" (might be good to change its name as well).
  • Loading branch information
vitorbaptista committed May 14, 2014
1 parent 06781d2 commit a9cbaa6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 76 deletions.
30 changes: 11 additions & 19 deletions ckanext/reclinepreview/plugin.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
60 changes: 9 additions & 51 deletions ckanext/reclinepreview/tests/test_view.py
@@ -1,4 +1,3 @@
import mock
import paste.fixture
import pylons.config as config

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
66 changes: 60 additions & 6 deletions ckanext/reclinepreview/theme/public/preview_recline.js
Expand Up @@ -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});
Expand All @@ -116,18 +118,70 @@ this.ckan.module('reclinepreview', function (jQuery, _) {
];
}

var newElements = $('<div />');
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 = $('<div />');
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);
Expand Down

0 comments on commit a9cbaa6

Please sign in to comment.