diff --git a/_includes/recline-deps.html b/_includes/recline-deps.html index 2d0784c0..5b114eb7 100644 --- a/_includes/recline-deps.html +++ b/_includes/recline-deps.html @@ -21,8 +21,8 @@ - - + + diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index 86359d90..0ac5b397 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -470,16 +470,15 @@ my.Query = Backbone.Model.extend({ } } }, - // ### addFilter + // ### addFilter(filter) // - // Add a new filter (appended to the list of filters) + // Add a new filter specified by the filter hash and append to the list of filters // // @param filter an object specifying the filter - see _filterTemplates for examples. If only type is provided will generate a filter by cloning _filterTemplates addFilter: function(filter) { // crude deep copy var ourfilter = JSON.parse(JSON.stringify(filter)); - // not full specified so use template and over-write - // 3 as for 'type', 'field' and 'fieldType' + // not fully specified so use template and over-write if (_.keys(filter).length <= 3) { ourfilter = _.extend(this._filterTemplates[filter.type], ourfilter); } @@ -595,7 +594,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; } else { if (data) { this.fields = _.map(data[0], function(value, key) { - return {id: key}; + return {id: key, type: 'string'}; }); } } @@ -670,10 +669,20 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; geo_distance : geo_distance }; var dataParsers = { - number : function (e) { return parseFloat(e, 10); }, + integer: function (e) { return parseFloat(e, 10); }, + 'float': function (e) { return parseFloat(e, 10); }, string : function (e) { return e.toString() }, - date : function (e) { return new Date(e).valueOf() } + date : function (e) { return new Date(e).valueOf() }, + datetime : function (e) { return new Date(e).valueOf() } }; + var keyedFields = {}; + _.each(self.fields, function(field) { + keyedFields[field.id] = field; + }); + function getDataParser(filter) { + var fieldType = keyedFields[filter.field].type || 'string'; + return dataParsers[fieldType]; + } // filter records return _.filter(results, function (record) { @@ -686,9 +695,8 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }); // filters definitions - function term(record, filter) { - var parse = dataParsers[filter.fieldType]; + var parse = getDataParser(filter); var value = parse(record[filter.field]); var term = parse(filter.term); @@ -696,7 +704,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; } function range(record, filter) { - var parse = dataParsers[filter.fieldType]; + var parse = getDataParser(filter); var value = parse(record[filter.field]); var start = parse(filter.start); var stop = parse(filter.stop); diff --git a/dist/recline.js b/dist/recline.js index a0bbbd77..b9949ece 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -917,7 +917,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; } else { if (data) { this.fields = _.map(data[0], function(value, key) { - return {id: key}; + return {id: key, type: 'string'}; }); } } @@ -992,10 +992,20 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; geo_distance : geo_distance }; var dataParsers = { - number : function (e) { return parseFloat(e, 10); }, + integer: function (e) { return parseFloat(e, 10); }, + 'float': function (e) { return parseFloat(e, 10); }, string : function (e) { return e.toString() }, - date : function (e) { return new Date(e).valueOf() } + date : function (e) { return new Date(e).valueOf() }, + datetime : function (e) { return new Date(e).valueOf() } }; + var keyedFields = {}; + _.each(self.fields, function(field) { + keyedFields[field.id] = field; + }); + function getDataParser(filter) { + var fieldType = keyedFields[filter.field].type || 'string'; + return dataParsers[fieldType]; + } // filter records return _.filter(results, function (record) { @@ -1008,9 +1018,8 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }); // filters definitions - function term(record, filter) { - var parse = dataParsers[filter.fieldType]; + var parse = getDataParser(filter); var value = parse(record[filter.field]); var term = parse(filter.term); @@ -1018,7 +1027,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; } function range(record, filter) { - var parse = dataParsers[filter.fieldType]; + var parse = getDataParser(filter); var value = parse(record[filter.field]); var start = parse(filter.start); var stop = parse(filter.stop); @@ -1718,16 +1727,15 @@ my.Query = Backbone.Model.extend({ } } }, - // ### addFilter + // ### addFilter(filter) // - // Add a new filter (appended to the list of filters) + // Add a new filter specified by the filter hash and append to the list of filters // // @param filter an object specifying the filter - see _filterTemplates for examples. If only type is provided will generate a filter by cloning _filterTemplates addFilter: function(filter) { // crude deep copy var ourfilter = JSON.parse(JSON.stringify(filter)); - // not full specified so use template and over-write - // 3 as for 'type', 'field' and 'fieldType' + // not fully specified so use template and over-write if (_.keys(filter).length <= 3) { ourfilter = _.extend(this._filterTemplates[filter.type], ourfilter); } @@ -4301,20 +4309,27 @@ this.recline.View = this.recline.View || {}; (function($, my) { +// ## FacetViewer +// +// Widget for displaying facets +// +// Usage: +// +// var viewer = new FacetViewer({ +// model: dataset +// }); my.FacetViewer = Backbone.View.extend({ - className: 'recline-facet-viewer well', + className: 'recline-facet-viewer', template: ' \ - × \ -
\ -
\ -

Facets

\ -
\ +
\ {{#facets}} \ -