Skip to content

Commit 95c4eac

Browse files
committed
Merge branch 'feature/download-visible-columns' into 'master'
Extract/Download only visible columns. See merge request datopian/clients/nhs-dataexplorer!12
2 parents 678c5ed + a126f73 commit 95c4eac

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

ckanext/dataexplorer/controllers/dataexplorer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def extract(self):
5454

5555
try:
5656
resource_data = self._get_action('datastore_search', data)
57-
for key in resource_data['fields']:
58-
columns.append(key['id'])
57+
for key in data['fields']:
58+
columns.append(key)
5959

6060
try:
6161
columns.remove('_id')

ckanext/dataexplorer/public/vendor/ckan.js/ckan.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ if (isNodeModule) {
171171
}
172172
});
173173
}
174+
174175
return actualQuery;
175176
};
176177

ckanext/dataexplorer/public/vendor/recline/recline.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ my.Query = Backbone.Model.extend({
869869
from: 0,
870870
q: '',
871871
facets: {},
872-
filters: []
872+
filters: [],
873+
fields: []
873874
};
874875
},
875876
_filterTemplates: {
@@ -3232,6 +3233,8 @@ my.SlickGrid = Backbone.View.extend({
32323233
return $('<div>').text(name).html();
32333234
}
32343235

3236+
var fields = []
3237+
32353238
_.each(this.model.fields.toJSON(),function(field){
32363239
var column = {
32373240
id: field.id,
@@ -3269,7 +3272,11 @@ my.SlickGrid = Backbone.View.extend({
32693272
}
32703273
}
32713274
columns.push(column);
3275+
fields.push(column.id);
32723276
});
3277+
3278+
this.model.queryState.set({fields:fields})
3279+
32733280
// Restrict the visible columns
32743281
var visibleColumns = _.filter(columns, function(column) {
32753282
return _.indexOf(self.state.get('hiddenColumns'), column.id) === -1;
@@ -3402,7 +3409,7 @@ my.SlickGrid = Backbone.View.extend({
34023409
model.destroy()
34033410
}
34043411
}) ;
3405-
var columnpicker = new Slick.Controls.ColumnPicker(columns, this.grid,
3412+
var columnpicker = new Slick.Controls.ColumnPicker(columns, this.grid, this.model,
34063413
_.extend(options,{state:this.state}));
34073414
if (self.visible){
34083415
self.grid.init();
@@ -3536,7 +3543,7 @@ my.GridControl= Backbone.View.extend({
35363543
*
35373544
*/
35383545
(function ($) {
3539-
function SlickColumnPicker(columns, grid, options) {
3546+
function SlickColumnPicker(columns, grid, model, options) {
35403547
var $menu;
35413548
var columnCheckboxes;
35423549

@@ -3558,6 +3565,7 @@ my.GridControl= Backbone.View.extend({
35583565
}
35593566

35603567
function handleHeaderContextMenu(e, args) {
3568+
var current_columns = grid.getColumns()
35613569
e.preventDefault();
35623570
$menu.empty();
35633571
columnCheckboxes = [];
@@ -3569,7 +3577,14 @@ my.GridControl= Backbone.View.extend({
35693577
columnCheckboxes.push($input);
35703578

35713579
if (grid.getColumnIndex(columns[i].id) !== null) {
3572-
$input.attr('checked', 'checked');
3580+
3581+
$input.attr('checked', false);
3582+
3583+
for (var j = 0; j < current_columns.length; j++) {
3584+
if (current_columns[j].id == columns[i].id){
3585+
$input.attr('checked', 'checked');
3586+
}
3587+
}
35733588
}
35743589
$input.appendTo($li);
35753590
$('<label />')
@@ -3639,6 +3654,12 @@ my.GridControl= Backbone.View.extend({
36393654
}
36403655

36413656
grid.setColumns(visibleColumns);
3657+
3658+
var fields = []
3659+
for (var i = 0; i < visibleColumns.length; i++){
3660+
fields.push(visibleColumns[i].id)
3661+
}
3662+
model.queryState.attributes.fields = fields;
36423663
options.state.set({hiddenColumns:hiddenColumnsIds});
36433664
}
36443665
}
@@ -4483,12 +4504,14 @@ my.Extractor = Backbone.View.extend({
44834504
e.preventDefault();
44844505

44854506
var format = this.$el.find('.select-format').val();
4507+
var fields = self.model.queryState.attributes.fields;
44864508
var query = CKAN._normalizeQuery(self.model.queryState.attributes);
44874509
query.ckan_resource_id = self.model.attributes.id;
44884510
query.resource_id = self.model.attributes.bq_table_name;
44894511
query.limit = 200000;
44904512
query.format = format;
44914513
query.offset = 0;
4514+
query.fields = fields;
44924515
var input = this.$el.find('.extract-data-input').val(JSON.stringify(query));
44934516

44944517
if (this.model.recordCount > query.limit){

0 commit comments

Comments
 (0)