Skip to content

Commit

Permalink
[build][xs]: regular build of docs and lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
rufuspollock committed Feb 6, 2014
1 parent 306c0e6 commit e2ab6a5
Show file tree
Hide file tree
Showing 19 changed files with 1,004 additions and 515 deletions.
90 changes: 76 additions & 14 deletions dist/recline.dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ my.Dataset = Backbone.Model.extend({
// store will either be the backend or be a memory store if Backend fetch
// tells us to use memory store
this._store = this.backend;

// if backend has a handleQueryResultFunction, use that
this._handleResult = (this.backend != null && _.has(this.backend, 'handleQueryResult')) ?
this.backend.handleQueryResult : this._handleQueryResult;
if (this.backend == recline.Backend.Memory) {
this.fetch();
}
},

sync: function(method, model, options) {
return this.backend.sync(method, model, options);
},

// ### fetch
//
// Retrieve dataset and (some) records from the backend.
Expand Down Expand Up @@ -189,7 +197,7 @@ my.Dataset = Backbone.Model.extend({

this._store.query(actualQuery, this.toJSON())
.done(function(queryResult) {
self._handleQueryResult(queryResult);
self._handleResult(queryResult);
self.trigger('query:done');
dfd.resolve(self.records);
})
Expand Down Expand Up @@ -481,8 +489,8 @@ my.Query = Backbone.Model.extend({
},
range: {
type: 'range',
start: '',
stop: ''
from: '',
to: ''
},
geo_distance: {
type: 'geo_distance',
Expand Down Expand Up @@ -510,6 +518,23 @@ my.Query = Backbone.Model.extend({
filters.push(ourfilter);
this.trigger('change:filters:new-blank');
},
replaceFilter: function(filter) {
// delete filter on the same field, then add
var filters = this.get('filters');
var idx = -1;
_.each(this.get('filters'), function(f, key, list) {
if (filter.field == f.field) {
idx = key;
}
});
// trigger just one event (change:filters:new-blank) instead of one for remove and
// one for add
if (idx >= 0) {
filters.splice(idx, 1);
this.set({filters: filters});
}
this.addFilter(filter);
},
updateFilter: function(index, value) {
},
// ### removeFilter
Expand All @@ -526,7 +551,7 @@ my.Query = Backbone.Model.extend({
// Add a Facet to this query
//
// See <http://www.elasticsearch.org/guide/reference/api/search/facets/>
addFacet: function(fieldId) {
addFacet: function(fieldId, size, silent) {
var facets = this.get('facets');
// Assume id and fieldId should be the same (TODO: this need not be true if we want to add two different type of facets on same field)
if (_.contains(_.keys(facets), fieldId)) {
Expand All @@ -535,8 +560,13 @@ my.Query = Backbone.Model.extend({
facets[fieldId] = {
terms: { field: fieldId }
};
if (!_.isUndefined(size)) {
facets[fieldId].terms.size = size;
}
this.set({facets: facets}, {silent: true});
this.trigger('facet:add', this);
if (!silent) {
this.trigger('facet:add', this);
}
},
addHistogramFacet: function(fieldId) {
var facets = this.get('facets');
Expand All @@ -548,7 +578,30 @@ my.Query = Backbone.Model.extend({
};
this.set({facets: facets}, {silent: true});
this.trigger('facet:add', this);
},
removeFacet: function(fieldId) {
var facets = this.get('facets');
// Assume id and fieldId should be the same (TODO: this need not be true if we want to add two different type of facets on same field)
if (!_.contains(_.keys(facets), fieldId)) {
return;
}
delete facets[fieldId];
this.set({facets: facets}, {silent: true});
this.trigger('facet:remove', this);
},
clearFacets: function() {
var facets = this.get('facets');
_.each(_.keys(facets), function(fieldId) {
delete facets[fieldId];
});
this.trigger('facet:remove', this);
},
// trigger a facet add; use this to trigger a single event after adding
// multiple facets
refreshFacets: function() {
this.trigger('facet:add', this);
}

});


Expand Down Expand Up @@ -586,9 +639,9 @@ my.ObjectState = Backbone.Model.extend({
// ## Backbone.sync
//
// Override Backbone.sync to hand off to sync function in relevant backend
Backbone.sync = function(method, model, options) {
return model.backend.sync(method, model, options);
};
// Backbone.sync = function(method, model, options) {
// return model.backend.sync(method, model, options);
// };

}(this.recline.Model));

Expand Down Expand Up @@ -695,6 +748,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
// register filters
var filterFunctions = {
term : term,
terms : terms,
range : range,
geo_distance : geo_distance
};
Expand Down Expand Up @@ -734,20 +788,28 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
return (value === term);
}

function terms(record, filter) {
var parse = getDataParser(filter);
var value = parse(record[filter.field]);
var terms = parse(filter.terms).split(",");

return (_.indexOf(terms, value) >= 0);
}

function range(record, filter) {
var startnull = (filter.start === null || filter.start === '');
var stopnull = (filter.stop === null || filter.stop === '');
var fromnull = (_.isUndefined(filter.from) || filter.from === null || filter.from === '');
var tonull = (_.isUndefined(filter.to) || filter.to === null || filter.to === '');
var parse = getDataParser(filter);
var value = parse(record[filter.field]);
var start = parse(filter.start);
var stop = parse(filter.stop);
var from = parse(fromnull ? '' : filter.from);
var to = parse(tonull ? '' : filter.to);

// if at least one end of range is set do not allow '' to get through
// note that for strings '' <= {any-character} e.g. '' <= 'a'
if ((!startnull || !stopnull) && value === '') {
if ((!fromnull || !tonull) && value === '') {
return false;
}
return ((startnull || value >= start) && (stopnull || value <= stop));
return ((fromnull || value >= from) && (tonull || value <= to));
}

function geo_distance() {
Expand Down
Loading

0 comments on commit e2ab6a5

Please sign in to comment.