Merge branch '217-ckan-filters'
This commit is contained in:
@@ -66,15 +66,25 @@ this.recline.Backend.Ckan = this.recline.Backend.Ckan || {};
|
|||||||
var actualQuery = {
|
var actualQuery = {
|
||||||
resource_id: dataset.id,
|
resource_id: dataset.id,
|
||||||
q: queryObj.q,
|
q: queryObj.q,
|
||||||
|
filters: {},
|
||||||
limit: queryObj.size || 10,
|
limit: queryObj.size || 10,
|
||||||
offset: queryObj.from || 0
|
offset: queryObj.from || 0
|
||||||
};
|
};
|
||||||
|
|
||||||
if (queryObj.sort && queryObj.sort.length > 0) {
|
if (queryObj.sort && queryObj.sort.length > 0) {
|
||||||
var _tmp = _.map(queryObj.sort, function(sortObj) {
|
var _tmp = _.map(queryObj.sort, function(sortObj) {
|
||||||
return sortObj.field + ' ' + (sortObj.order || '');
|
return sortObj.field + ' ' + (sortObj.order || '');
|
||||||
});
|
});
|
||||||
actualQuery.sort = _tmp.join(',');
|
actualQuery.sort = _tmp.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (queryObj.filters && queryObj.filters.length > 0) {
|
||||||
|
_.each(queryObj.filters, function(filter) {
|
||||||
|
if (filter.type === "term") {
|
||||||
|
actualQuery.filters[filter.field] = filter.term;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
return actualQuery;
|
return actualQuery;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,15 +115,14 @@ this.recline.Backend.Ckan = this.recline.Backend.Ckan || {};
|
|||||||
//
|
//
|
||||||
// @param endpoint: CKAN api endpoint (e.g. http://datahub.io/api)
|
// @param endpoint: CKAN api endpoint (e.g. http://datahub.io/api)
|
||||||
my.DataStore = function(endpoint) {
|
my.DataStore = function(endpoint) {
|
||||||
var that = {
|
var that = {endpoint: endpoint || my.API_ENDPOINT};
|
||||||
endpoint: endpoint || my.API_ENDPOINT
|
|
||||||
};
|
|
||||||
that.search = function(data) {
|
that.search = function(data) {
|
||||||
var searchUrl = that.endpoint + '/3/action/datastore_search';
|
var searchUrl = that.endpoint + '/3/action/datastore_search';
|
||||||
var jqxhr = jQuery.ajax({
|
var jqxhr = jQuery.ajax({
|
||||||
url: searchUrl,
|
url: searchUrl,
|
||||||
data: data,
|
type: 'POST',
|
||||||
dataType: 'json'
|
data: JSON.stringify(data)
|
||||||
});
|
});
|
||||||
return jqxhr;
|
return jqxhr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ test('_normalizeQuery', function() {
|
|||||||
var exp = {
|
var exp = {
|
||||||
resource_id: dataset.id,
|
resource_id: dataset.id,
|
||||||
q: 'abc',
|
q: 'abc',
|
||||||
|
filters: {},
|
||||||
sort: 'location desc,last ',
|
sort: 'location desc,last ',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
offset: 0
|
offset: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user