Skip to content

Commit 15e16f0

Browse files
authored
Merge pull request #1 from datopian/fix/enable-view
Fix/enable view
2 parents 92bb765 + 1026aff commit 15e16f0

File tree

4 files changed

+162
-16
lines changed

4 files changed

+162
-16
lines changed

ckanext/dataexplorer/public/recline_view.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,13 @@ this.ckan.module('recline_view', function (jQuery, _) {
207207
view: new recline.View.SlickGrid({
208208
model: dataset
209209
})
210-
}
211-
/** NOT IN USE
212-
,{
210+
},{
213211
id: 'graph',
214212
label: _('Graph').fetch(),
215213
view: new recline.View.Graph({
216214
model: dataset
217215
})
218-
},
219-
{
220-
id: 'map',
221-
label: _('Map').fetch(),
222-
view: new recline.View.Map(this._reclineMapViewOptions(dataset, map_config))
223216
}
224-
**/
225217
];
226218

227219
views = views.filter(function(view) {
Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,142 @@
1-
this.ckan.module("recline_view",function(e,i){return{options:{site_url:"",controlsClassName:"controls"},initialize:function(){var i,t,o,a,r=function(){e.proxyAll(this,/_on/),this.options.resource=JSON.parse(this.options.resource),this.options.resourceView=JSON.parse(this.options.resourceView),this.el.ready(this._onReady),L.Icon.Default.imagePath=this.options.site_url+"vendor/leaflet/0.7.7/images"}.bind(this);i="/vendor/recline/recline.js",t=r,o=document.getElementsByTagName("head")[0],(a=document.createElement("script")).type="text/javascript",a.src=i,a.onreadystatechange=t,a.onload=t,o.appendChild(a)},_onReady:function(){var e=this.options.resource,i=this.options.resourceView;this.loadView(e,i)},loadView:function(t,o){var a,r,n=this;if(""===t.formatNormalized){var l=t.url.split("/"),s=(l=(l=(l=l[l.length-1]).split("?"))[0]).split(".");s.length>1&&(t.formatNormalized=s[s.length-1])}t.backend="ckan",t.endpoint=e("body").data("site-root")+"api",r=new recline.Model.Dataset(t),this.options.map_config;var c=new recline.Model.Query;c.set({size:o.limit||100}),c.set({from:o.offset||0});var d={};try{window.parent.ckan.views&&window.parent.ckan.views.filters&&(d=window.parent.ckan.views.filters.get())}catch(e){}var p=o.filters||{},w=e.extend({},p,d);e.each(w,function(e,i){c.addFilter({type:"term",field:e,term:i})}),r.queryState.set(c.toJSON(),{silent:!0}),a=i("Could not load view").fetch()+": ","ckan"==t.backend?a+=i("DataStore returned an error").fetch():"dataproxy"==t.backend&&(a+=i("DataProxy returned an error").fetch()),r.fetch().done(function(e){n.initializeView(e,o)}).fail(function(e){var i;e.message&&(a+=" ("+e.message+")"),i=(i=a)||n._("error loading view").fetch(),window.parent.ckan.pubsub.publish("data-viewer-error",i)})},initializeView:function(i,t){var o,a,r=[];if("recline_graph_view"===t.view_type?(a={graphType:t.graph_type,group:t.group,series:[t.series]},o=new recline.View.Graph({model:i,state:a})):"recline_map_view"===t.view_type?(a={geomField:null,latField:null,lonField:null,autoZoom:Boolean(t.auto_zoom),cluster:Boolean(t.cluster_markers)},"geojson"===t.map_field_type?a.geomField=t.geojson_field:(a.latField=t.latitude_field,a.lonField=t.longitude_field),o=new recline.View.Map(this._reclineMapViewOptions(i,this.options.map_config))):"recline_view"===t.view_type||"dataexplorer"===t.view_type?o=this._newDataExplorer(i,this.options.map_config,t):(o=new recline.View.SlickGrid({model:i}),r=[new recline.View.Pager({model:o.model}),new recline.View.RecordCount({model:i}),new recline.View.QueryEditor({model:o.model.queryState})]),"recline_view"!==t.view_type&&"dataexplorer"!==t.view_type){var n=e("<div />");this._renderControls(n,r,this.options.controlsClassName),n.append(o.el),e(this.el).html(n),o.visible=!0,o.render()}"recline_graph_view"===t.view_type&&o.redraw()},_reclineMapViewOptions:function(e,i){var t,o,a;if(t=o=a="","mapbox"==i.type){if(!i["mapbox.map_id"]||!i["mapbox.access_token"])throw"[CKAN Map Widgets] You need to provide a map ID ([account].[handle]) and an access token when using a MapBox layer. See http://www.mapbox.com/developers/api-overview/ for details";t="//{s}.tiles.mapbox.com/v4/"+i["mapbox.map_id"]+"/{z}/{x}/{y}.png?access_token="+i["mapbox.access_token"],handle=i["mapbox.map_id"],a=i.subdomains||"abcd",o=i.attribution||'Data: <a href="http://osm.org/copyright" target="_blank">OpenStreetMap</a>, Design: <a href="http://mapbox.com/about/maps" target="_blank">MapBox</a>'}else if("custom"==i.type&&(t=i["custom.url"]||"",o=i.attribution||"",a=i.subdomains||"",i["custom.tms"]))i["custom.tms"];return{model:e,mapTilesURL:t,mapTilesAttribution:o,mapTilesSubdomains:a}},_newDataExplorer:function(e,t,o){var a=[{id:"grid",label:i("Grid").fetch(),view:new recline.View.SlickGrid({model:e})}];a=a.filter(function(e){return"show"===o[e.id+"_tab"]});var r=[{id:"valueFilter",label:i("Filters").fetch(),view:new recline.View.ValueFilter({model:e})},{id:"extractor",label:i("Extract").fetch(),view:new recline.View.Extractor({model:e,site_url:this.options.site_url})}];return new recline.View.MultiView({el:this.el,model:e,views:a,sidebarViews:r,config:{readOnly:!0}})},_renderControls:function(i,t,o){for(var a=e('<div class="clearfix '+o+'" />'),r=0;r<t.length;r++)a.append(t[r].el);e(i).append(a)}}});
1+
this.ckan.module("recline_view", function(e, i) {
2+
return {
3+
options: {
4+
site_url: "",
5+
controlsClassName: "controls"
6+
},
7+
initialize: function() {
8+
var i, t, o, a, r = function() {
9+
e.proxyAll(this, /_on/), this.options.resource = JSON.parse(this.options.resource), this.options.resourceView = JSON.parse(this.options.resourceView), this.el.ready(this._onReady), L.Icon.Default.imagePath = this.options.site_url + "vendor/leaflet/0.7.7/images"
10+
}.bind(this);
11+
i = "/vendor/recline/recline.js", t = r, o = document.getElementsByTagName("head")[0], (a = document.createElement("script")).type = "text/javascript", a.src = i, a.onreadystatechange = t, a.onload = t, o.appendChild(a)
12+
},
13+
_onReady: function() {
14+
var e = this.options.resource,
15+
i = this.options.resourceView;
16+
this.loadView(e, i)
17+
},
18+
loadView: function(t, o) {
19+
var a, r, n = this;
20+
if ("" === t.formatNormalized) {
21+
var l = t.url.split("/"),
22+
s = (l = (l = (l = l[l.length - 1]).split("?"))[0]).split(".");
23+
s.length > 1 && (t.formatNormalized = s[s.length - 1])
24+
}
25+
t.backend = "ckan", t.endpoint = e("body").data("site-root") + "api", r = new recline.Model.Dataset(t), this.options.map_config;
26+
var c = new recline.Model.Query;
27+
c.set({
28+
size: o.limit || 100
29+
}), c.set({
30+
from: o.offset || 0
31+
});
32+
var d = {};
33+
try {
34+
window.parent.ckan.views && window.parent.ckan.views.filters && (d = window.parent.ckan.views.filters.get())
35+
} catch (e) {}
36+
var p = o.filters || {},
37+
w = e.extend({}, p, d);
38+
e.each(w, function(e, i) {
39+
c.addFilter({
40+
type: "term",
41+
field: e,
42+
term: i
43+
})
44+
}), r.queryState.set(c.toJSON(), {
45+
silent: !0
46+
}), a = i("Could not load view").fetch() + ": ", "ckan" == t.backend ? a += i("DataStore returned an error").fetch() : "dataproxy" == t.backend && (a += i("DataProxy returned an error").fetch()), r.fetch().done(function(e) {
47+
n.initializeView(e, o)
48+
}).fail(function(e) {
49+
var i;
50+
e.message && (a += " (" + e.message + ")"), i = (i = a) || n._("error loading view").fetch(), window.parent.ckan.pubsub.publish("data-viewer-error", i)
51+
})
52+
},
53+
initializeView: function(i, t) {
54+
var o, a, r = [];
55+
if ("recline_graph_view" === t.view_type ? (a = {
56+
graphType: t.graph_type,
57+
group: t.group,
58+
series: [t.series]
59+
}, o = new recline.View.Graph({
60+
model: i,
61+
state: a
62+
})) : "recline_map_view" === t.view_type ? (a = {
63+
geomField: null,
64+
latField: null,
65+
lonField: null,
66+
autoZoom: Boolean(t.auto_zoom),
67+
cluster: Boolean(t.cluster_markers)
68+
}, "geojson" === t.map_field_type ? a.geomField = t.geojson_field : (a.latField = t.latitude_field, a.lonField = t.longitude_field), o = new recline.View.Map(this._reclineMapViewOptions(i, this.options.map_config))) : "recline_view" === t.view_type || "dataexplorer" === t.view_type ? o = this._newDataExplorer(i, this.options.map_config, t) : (o = new recline.View.SlickGrid({
69+
model: i
70+
}), r = [new recline.View.Pager({
71+
model: o.model
72+
}), new recline.View.RecordCount({
73+
model: i
74+
}), new recline.View.QueryEditor({
75+
model: o.model.queryState
76+
})]), "recline_view" !== t.view_type && "dataexplorer" !== t.view_type) {
77+
var n = e("<div />");
78+
this._renderControls(n, r, this.options.controlsClassName), n.append(o.el), e(this.el).html(n), o.visible = !0, o.render()
79+
}
80+
"recline_graph_view" === t.view_type && o.redraw()
81+
},
82+
_reclineMapViewOptions: function(e, i) {
83+
var t, o, a;
84+
if (t = o = a = "", "mapbox" == i.type) {
85+
if (!i["mapbox.map_id"] || !i["mapbox.access_token"]) throw "[CKAN Map Widgets] You need to provide a map ID ([account].[handle]) and an access token when using a MapBox layer. See http://www.mapbox.com/developers/api-overview/ for details";
86+
t = "//{s}.tiles.mapbox.com/v4/" + i["mapbox.map_id"] + "/{z}/{x}/{y}.png?access_token=" + i["mapbox.access_token"], handle = i["mapbox.map_id"], a = i.subdomains || "abcd", o = i.attribution || 'Data: <a href="http://osm.org/copyright" target="_blank">OpenStreetMap</a>, Design: <a href="http://mapbox.com/about/maps" target="_blank">MapBox</a>'
87+
} else if ("custom" == i.type && (t = i["custom.url"] || "", o = i.attribution || "", a = i.subdomains || "", i["custom.tms"])) i["custom.tms"];
88+
return {
89+
model: e,
90+
mapTilesURL: t,
91+
mapTilesAttribution: o,
92+
mapTilesSubdomains: a
93+
}
94+
},
95+
_newDataExplorer: function(e, t, o) {
96+
var a = [{
97+
id: "grid",
98+
label: i("Grid").fetch(),
99+
view: new recline.View.SlickGrid({
100+
model: e
101+
})
102+
},
103+
{
104+
id: "graph",
105+
label: i("Graph").fetch(),
106+
view: new recline.View.Graph({
107+
model: e
108+
})
109+
}];
110+
a = a.filter(function(e) {
111+
return "show" === o[e.id + "_tab"]
112+
});
113+
var r = [{
114+
id: "valueFilter",
115+
label: i("Filters").fetch(),
116+
view: new recline.View.ValueFilter({
117+
model: e
118+
})
119+
}, {
120+
id: "extractor",
121+
label: i("Extract").fetch(),
122+
view: new recline.View.Extractor({
123+
model: e,
124+
site_url: this.options.site_url
125+
})
126+
}];
127+
return new recline.View.MultiView({
128+
el: this.el,
129+
model: e,
130+
views: a,
131+
sidebarViews: r,
132+
config: {
133+
readOnly: !0
134+
}
135+
})
136+
},
137+
_renderControls: function(i, t, o) {
138+
for (var a = e('<div class="clearfix ' + o + '" />'), r = 0; r < t.length; r++) a.append(t[r].el);
139+
e(i).append(a)
140+
}
141+
}
142+
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ if (isNodeModule) {
157157
offset: queryObj.from || 0,
158158
api_call_type: 'browser-data-explorer'
159159
};
160+
if(queryObj?.filters?.length > 0){
161+
actualQuery.api_call_type = 'browser-data-explorer-filter'
162+
}
163+
160164

161165
if (queryObj.sort && queryObj.sort.length > 0) {
162166
var _tmp = _.map(queryObj.sort, function(sortObj) {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,10 +4787,19 @@ this.recline.View = this.recline.View || {};
47874787
this.render();
47884788
//Timeout of 2 seconds ensures that the form has been rendered before the select element is accessed
47894789
setTimeout(() => {
4790-
document.getElementById("download-format").innerHTML =
4791-
DATASTORE_SEARCH_ROWS_MAX <= self.model.recordCount
4792-
? '<option value="compressed-csv">Compressed CSV</option>'
4793-
: '<option value="csv">CSV</option><option value="compressed-csv">Compressed CSV</option><option value="json">JSON</option>';
4790+
const downloadFormatElement = document.getElementById("download-format");
4791+
const compressedOptions = `
4792+
<option value="compressed-csv">Compressed CSV (GZIP)</option>
4793+
`;
4794+
const regularOptions = `
4795+
<option value="csv">CSV</option>
4796+
<option value="compressed-csv">Compressed CSV (ZIP)</option>
4797+
<option value="json">JSON</option>
4798+
`;
4799+
4800+
downloadFormatElement.innerHTML = DATASTORE_SEARCH_ROWS_MAX <= self.model.recordCount
4801+
? compressedOptions
4802+
: regularOptions;
47944803
}, 2000);
47954804

47964805
//Pre-Load helper libraries JSZip for zipping files
@@ -4830,7 +4839,7 @@ this.recline.View = this.recline.View || {};
48304839
},
48314840
extractFile: function (self, sql_query, format, query={}) {
48324841
var base_path = self.model.attributes.endpoint || self.options.site_url;
4833-
var endpoint = `${base_path}/3/action/datastore_search_sql?sql=${escape(sql_query)}&resource_id=${query.resource_id}`; // USE BASE_PATH IN PRODUCTION
4842+
var endpoint = `${base_path}/3/action/datastore_search_sql?sql=${escape(sql_query)}&resource_id=${query.resource_id}&format=${format}`; // USE BASE_PATH IN PRODUCTION
48344843
self.progress();
48354844

48364845
fetch(endpoint)
@@ -4938,7 +4947,7 @@ this.recline.View = this.recline.View || {};
49384947
<div class="modal" style="display: flex;">
49394948
<div class="row">
49404949
<div class="modal-content">
4941-
<p>An error occurred while extracting your requested data. If this error persists, please, send a report to nhsbsa.help@nhs.net</p>
4950+
<p>An error occurred while extracting your requested data. If this error persists, please, send a report to dataservicessupport@nhsbsa.nhs.uk</p>
49424951
<button class="btn extract-button modal-btn" id="cancel-btn">Cancel</button>
49434952
</div>
49444953
</div>

0 commit comments

Comments
 (0)