diff --git a/_includes/data.js b/_includes/data.js
index 44015ffd..57065512 100644
--- a/_includes/data.js
+++ b/_includes/data.js
@@ -1,9 +1,9 @@
var data = [
- {id: 0, date: '2011-01-01', x: 1, y: 2, z: 3, country: 'DE', label: 'first', lat:52.56, lon:13.40},
- {id: 1, date: '2011-02-02', x: 2, y: 4, z: 24, country: 'UK', label: 'second', lat:54.97, lon:-1.60},
- {id: 2, date: '2011-03-03', x: 3, y: 6, z: 9, country: 'US', label: 'third', lat:40.00, lon:-75.5},
- {id: 3, date: '2011-04-04', x: 4, y: 8, z: 6, country: 'UK', label: 'fourth', lat:57.27, lon:-6.20},
- {id: 4, date: '2011-05-04', x: 5, y: 10, z: 15, country: 'UK', label: 'fifth', lat:51.58, lon:0},
- {id: 5, date: '2011-06-02', x: 6, y: 12, z: 18, country: 'DE', label: 'sixth', lat:51.04, lon:7.9}
+ {id: 0, date: '2011-01-01', x: 1, y: 2, z: 3, country: 'DE', geo: {lat:52.56, lon:13.40} },
+ {id: 1, date: '2011-02-02', x: 2, y: 4, z: 24, country: 'UK', geo: {lat:54.97, lon:-1.60}},
+ {id: 2, date: '2011-03-03', x: 3, y: 6, z: 9, country: 'US', geo: {lat:40.00, lon:-75.5}},
+ {id: 3, date: '2011-04-04', x: 4, y: 8, z: 6, country: 'UK', geo: {lat:57.27, lon:-6.20}},
+ {id: 4, date: '2011-05-04', x: 5, y: 10, z: 15, country: 'UK', geo: {lat:51.58, lon:0}},
+ {id: 5, date: '2011-06-02', x: 6, y: 12, z: 18, country: 'DE', geo: {lat:51.04, lon:7.9}}
];
diff --git a/_includes/example-backends-gdocs.js b/_includes/example-backends-gdocs.js
index 72fa38fd..555d6a2c 100644
--- a/_includes/example-backends-gdocs.js
+++ b/_includes/example-backends-gdocs.js
@@ -1,10 +1,8 @@
// Create a dataset with a Google Docs backend and a url to the Google Doc
var dataset = new recline.Model.Dataset({
- url: 'https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdGZPaUZsMjBxeGhfOWRlWm85MmV0UUE#gid=0'
- },
- // backend name or instance
- 'gdocs'
-);
+ url: 'https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdGZPaUZsMjBxeGhfOWRlWm85MmV0UUE#gid=0',
+ backend: 'gdocs'
+});
// Optional - display the results in a grid
// Note how we can set this up before any data has arrived
@@ -15,14 +13,9 @@ var grid = new recline.View.Grid({
$('#my-gdocs').append(grid.el);
// Now do the query to the backend to load data
-dataset.fetch().done(function() {
- dataset.query().done(function(data) {
- // The grid will update automatically
- // Log some data as an example
- if (console) {
- console.log(data);
- console.log(dataset.currentDocuments);
- }
- });
+dataset.fetch().done(function(dataset) {
+ if (console) {
+ console.log(dataset.currentDocuments);
+ }
});
diff --git a/_includes/tutorial-basics-ex-1.js b/_includes/tutorial-basics-ex-1.js
new file mode 100644
index 00000000..067a1f1b
--- /dev/null
+++ b/_includes/tutorial-basics-ex-1.js
@@ -0,0 +1,24 @@
+// (for convenience) assume availability of jquery
+// must have div with class="ex-1"
+var $el = $('.ex-1');
+
+// we will define this function display so we can reuse it below!
+function display(dataset) {
+ // total number of records resulting from latest query
+ $el.append('Total found: ' + dataset.recordCount + '
');
+ $el.append('Total returned: ' + dataset.currentRecords.length);
+
+ $el.append('
Note: often you are loading data from a given source in -order to display it using the various Recline views. However, you can also -happily use this data with your own code and app and this is a very common -use-case.
-Moreover, Recline is designed so you need only include the -backend and its dependencies without needing to include any of the dependencies -for the view portion of the Recline library.
+order to load it into a Recline Dataset and display it in a View. However, you can also +happily use a Backend to load data on its own without using any other part of the Recline library as all the Backends are designed to have no dependency on other parts of Recline.Download Recline v0.5 (master) (in-progress version)
diff --git a/src/backend.dataproxy.js b/src/backend.dataproxy.js index ac3eeab3..58f537d7 100644 --- a/src/backend.dataproxy.js +++ b/src/backend.dataproxy.js @@ -6,6 +6,9 @@ this.recline.Backend.DataProxy = this.recline.Backend.DataProxy || {}; my.__type__ = 'dataproxy'; // URL for the dataproxy my.dataproxy_url = 'http://jsonpdataproxy.appspot.com'; + // Timeout for dataproxy (after this time if no response we error) + // Needed because use JSONP so do not receive e.g. 500 errors + my.timeout = 5000; // ## load // @@ -48,12 +51,11 @@ this.recline.Backend.DataProxy = this.recline.Backend.DataProxy || {}; // a crude way to catch those errors. var _wrapInTimeout = function(ourFunction) { var dfd = $.Deferred(); - var timeout = 5000; var timer = setTimeout(function() { dfd.reject({ - message: 'Request Error: Backend did not respond after ' + (timeout / 1000) + ' seconds' + message: 'Request Error: Backend did not respond after ' + (my.timeout / 1000) + ' seconds' }); - }, timeout); + }, my.timeout); ourFunction.done(function(arguments) { clearTimeout(timer); dfd.resolve(arguments); diff --git a/src/model.js b/src/model.js index 50721278..1651559d 100644 --- a/src/model.js +++ b/src/model.js @@ -27,7 +27,7 @@ my.Dataset = Backbone.Model.extend({ creates: [] }; this.facets = new my.FacetList(); - this.docCount = null; + this.recordCount = null; this.queryState = new my.Query(); this.queryState.bind('change', this.query); this.queryState.bind('facet:add', this.query); @@ -178,7 +178,7 @@ my.Dataset = Backbone.Model.extend({ this.trigger('query:start'); if (queryObj) { - this.queryState.set(queryObj); + this.queryState.set(queryObj, {silent: true}); } var actualQuery = this.queryState.toJSON(); @@ -197,7 +197,7 @@ my.Dataset = Backbone.Model.extend({ _handleQueryResult: function(queryResult) { var self = this; - self.docCount = queryResult.total; + self.recordCount = queryResult.total; var docs = _.map(queryResult.hits, function(hit) { var _doc = new my.Record(hit); _doc.bind('change', function(doc) { @@ -220,11 +220,13 @@ my.Dataset = Backbone.Model.extend({ toTemplateJSON: function() { var data = this.toJSON(); - data.docCount = this.docCount; + data.recordCount = this.recordCount; data.fields = this.fields.toJSON(); return data; }, + // ### getFieldsSummary + // // Get a summary for each field in the form of a `Facet`. // // @return null as this is async function. Provides deferred/promise interface. @@ -250,6 +252,19 @@ my.Dataset = Backbone.Model.extend({ return dfd.promise(); }, + // ### recordSummary + // + // Get a simple html summary of a Dataset record in form of key/value list + recordSummary: function(record) { + var html = ''; + this.fields.each(function(field) { + if (field.id != 'id') { + html += '