[#174,refactor][s]: rename currentRecords to records on Dataset.
This commit is contained in:
parent
21296aa18c
commit
a58f5e5bb0
@ -6,13 +6,13 @@ var $el = $('.ex-1');
|
||||
function display(dataset) {
|
||||
// total number of records resulting from latest query
|
||||
$el.append('Total found: ' + dataset.recordCount + '<br />');
|
||||
$el.append('Total returned: ' + dataset.currentRecords.length);
|
||||
$el.append('Total returned: ' + dataset.records.length);
|
||||
|
||||
$el.append('<hr />');
|
||||
|
||||
// dataset.currentRecords is a Backbone Collection of Records that resulted from latest query (hence "current")
|
||||
// dataset.records is a Backbone Collection of Records that resulted from latest query (hence "current")
|
||||
// Get the first record in the list - it returns an instance of the Record object
|
||||
var record = dataset.currentRecords.at(0);
|
||||
var record = dataset.records.at(0);
|
||||
|
||||
// Use the summary helper method which produces proper html
|
||||
// You could also do record.toJSON() to get a hash of the record data
|
||||
|
||||
@ -9,10 +9,10 @@ var $el = $('.ex-2');
|
||||
// On completion the display function will be called
|
||||
dataset.query({q: 'UK', size: 2}).done(function() {
|
||||
$('.ex-2').append('Total found: ' + dataset.recordCount);
|
||||
$('.ex-2').append(' Total returned: ' + dataset.currentRecords.length);
|
||||
$('.ex-2').append(' Total returned: ' + dataset.records.length);
|
||||
$('.ex-2').append(
|
||||
$('<pre />').html(
|
||||
JSON.stringify(dataset.currentRecords.toJSON(), null, 2)
|
||||
JSON.stringify(dataset.records.toJSON(), null, 2)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@ function onChange() {
|
||||
$('.ex-events').append('<br />');
|
||||
}
|
||||
|
||||
dataset.currentRecords.bind('reset', onChange);
|
||||
dataset.records.bind('reset', onChange);
|
||||
|
||||
dataset.query({q: 'DE'});
|
||||
dataset.query({q: 'UK'});
|
||||
|
||||
@ -5,6 +5,6 @@ dataset.fields.models[6] = new recline.Model.Field({
|
||||
label: 'Location',
|
||||
type: 'geo_point'
|
||||
});
|
||||
var rec = dataset.currentRecords.at(0);
|
||||
var rec = dataset.records.at(0);
|
||||
$el.append(dataset.recordSummary(rec));
|
||||
|
||||
|
||||
@ -41,13 +41,13 @@ dataset.fetch();
|
||||
|
||||
// we will now have the following (and more) set up - see below for details
|
||||
dataset.fields // collection of Fields (columns) for this Dataset
|
||||
dataset.currentRecords // collection of Records resulting from latest query
|
||||
dataset.records // collection of Records resulting from latest query
|
||||
dataset.docCount // total number of Records in the last query
|
||||
{% endhighlight %}
|
||||
|
||||
### Key Attributes
|
||||
|
||||
* currentRecords: a collection of `Record`s currently loaded for viewing
|
||||
* records: a collection of `Record`s currently loaded for viewing
|
||||
(updated by calling query method) - note that this need <strong>not</strong>
|
||||
be all the records in the dataset (for example, you may have connected to a
|
||||
source where the complete dataset contains a million records but you have
|
||||
|
||||
@ -47,7 +47,7 @@ Here's a summary of the main objects and their events:
|
||||
* Standard Backbone events for changes to attributes (note that this will **not** include changes to records)
|
||||
* *query:start / query:end* called at start and completion of a query
|
||||
|
||||
* Dataset.currentRecords: Backbone.Collection of "current" records (i.e. those resulting from latest query) with standard Backbone set of events: *add, reset, remove*
|
||||
* Dataset.records: Backbone.Collection of "current" records (i.e. those resulting from latest query) with standard Backbone set of events: *add, reset, remove*
|
||||
|
||||
* Dataset.queryState: queryState is a Query object with standard Backbone Model set of events
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ The basic thing we want to do with Datasets is query and filter them. This is ve
|
||||
{% include tutorial-basics-ex-2.js %}
|
||||
{% endhighlight %}
|
||||
|
||||
This results in the following. Note how recordCount is now 3 (the total number of records matched by the query) but that currentRecords only contains 2 records as we restricted number of returned records using the size attribute.
|
||||
This results in the following. Note how recordCount is now 3 (the total number of records matched by the query) but that records only contains 2 records as we restricted number of returned records using the size attribute.
|
||||
|
||||
<div class="ex-2 well"> </div>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ my.Dataset = Backbone.Model.extend({
|
||||
}
|
||||
}
|
||||
this.fields = new my.FieldList();
|
||||
this.currentRecords = new my.RecordList();
|
||||
this.records = new my.RecordList();
|
||||
this._changes = {
|
||||
deletes: [],
|
||||
updates: [],
|
||||
@ -172,7 +172,7 @@ my.Dataset = Backbone.Model.extend({
|
||||
// It will query based on current query state (given by this.queryState)
|
||||
// updated by queryObj (if provided).
|
||||
//
|
||||
// Resulting RecordList are used to reset this.currentRecords and are
|
||||
// Resulting RecordList are used to reset this.records and are
|
||||
// also returned.
|
||||
query: function(queryObj) {
|
||||
var self = this;
|
||||
@ -188,7 +188,7 @@ my.Dataset = Backbone.Model.extend({
|
||||
.done(function(queryResult) {
|
||||
self._handleQueryResult(queryResult);
|
||||
self.trigger('query:done');
|
||||
dfd.resolve(self.currentRecords);
|
||||
dfd.resolve(self.records);
|
||||
})
|
||||
.fail(function(arguments) {
|
||||
self.trigger('query:fail', arguments);
|
||||
@ -210,7 +210,7 @@ my.Dataset = Backbone.Model.extend({
|
||||
});
|
||||
return _doc;
|
||||
});
|
||||
self.currentRecords.reset(docs);
|
||||
self.records.reset(docs);
|
||||
if (queryResult.facets) {
|
||||
var facets = _.map(queryResult.facets, function(facetResult, facetId) {
|
||||
facetResult.id = facetId;
|
||||
|
||||
@ -43,8 +43,8 @@ my.Graph = Backbone.View.extend({
|
||||
this.model.bind('change', this.render);
|
||||
this.model.fields.bind('reset', this.render);
|
||||
this.model.fields.bind('add', this.render);
|
||||
this.model.currentRecords.bind('add', this.redraw);
|
||||
this.model.currentRecords.bind('reset', this.redraw);
|
||||
this.model.records.bind('add', this.redraw);
|
||||
this.model.records.bind('reset', this.redraw);
|
||||
// because we cannot redraw when hidden we may need when becoming visible
|
||||
this.bind('view:show', function() {
|
||||
if (this.needToRedraw) {
|
||||
@ -89,7 +89,7 @@ my.Graph = Backbone.View.extend({
|
||||
// Uncaught Invalid dimensions for plot, width = 0, height = 0
|
||||
// * There is no data for the plot -- either same error or may have issues later with errors like 'non-existent node-value'
|
||||
var areWeVisible = !jQuery.expr.filters.hidden(this.el[0]);
|
||||
if ((!areWeVisible || this.model.currentRecords.length === 0)) {
|
||||
if ((!areWeVisible || this.model.records.length === 0)) {
|
||||
this.needToRedraw = true;
|
||||
return;
|
||||
}
|
||||
@ -119,8 +119,8 @@ my.Graph = Backbone.View.extend({
|
||||
// However, that is non-trivial to work out from a dataset (datasets may
|
||||
// have no field type info). Thus at present we only do this for bars.
|
||||
var tickFormatter = function (val) {
|
||||
if (self.model.currentRecords.models[val]) {
|
||||
var out = self.model.currentRecords.models[val].get(self.state.attributes.group);
|
||||
if (self.model.records.models[val]) {
|
||||
var out = self.model.records.models[val].get(self.state.attributes.group);
|
||||
// if the value was in fact a number we want that not the
|
||||
if (typeof(out) == 'number') {
|
||||
return val;
|
||||
@ -176,7 +176,7 @@ my.Graph = Backbone.View.extend({
|
||||
tickLength: 1,
|
||||
tickFormatter: tickFormatter,
|
||||
min: -0.5,
|
||||
max: self.model.currentRecords.length - 0.5
|
||||
max: self.model.records.length - 0.5
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -214,8 +214,8 @@ my.Graph = Backbone.View.extend({
|
||||
y = _tmp;
|
||||
}
|
||||
// convert back from 'index' value on x-axis (e.g. in cases where non-number values)
|
||||
if (self.model.currentRecords.models[x]) {
|
||||
x = self.model.currentRecords.models[x].get(self.state.attributes.group);
|
||||
if (self.model.records.models[x]) {
|
||||
x = self.model.records.models[x].get(self.state.attributes.group);
|
||||
} else {
|
||||
x = x.toFixed(2);
|
||||
}
|
||||
@ -249,7 +249,7 @@ my.Graph = Backbone.View.extend({
|
||||
var series = [];
|
||||
_.each(this.state.attributes.series, function(field) {
|
||||
var points = [];
|
||||
_.each(self.model.currentRecords.models, function(doc, index) {
|
||||
_.each(self.model.records.models, function(doc, index) {
|
||||
var xfield = self.model.fields.get(self.state.attributes.group);
|
||||
var x = doc.getFieldValue(xfield);
|
||||
// time series
|
||||
|
||||
@ -17,9 +17,9 @@ my.Grid = Backbone.View.extend({
|
||||
var self = this;
|
||||
this.el = $(this.el);
|
||||
_.bindAll(this, 'render', 'onHorizontalScroll');
|
||||
this.model.currentRecords.bind('add', this.render);
|
||||
this.model.currentRecords.bind('reset', this.render);
|
||||
this.model.currentRecords.bind('remove', this.render);
|
||||
this.model.records.bind('add', this.render);
|
||||
this.model.records.bind('reset', this.render);
|
||||
this.model.records.bind('remove', this.render);
|
||||
this.tempState = {};
|
||||
var state = _.extend({
|
||||
hiddenFields: []
|
||||
@ -77,13 +77,13 @@ my.Grid = Backbone.View.extend({
|
||||
showColumn: function() { self.showColumn(e); },
|
||||
deleteRow: function() {
|
||||
var self = this;
|
||||
var doc = _.find(self.model.currentRecords.models, function(doc) {
|
||||
var doc = _.find(self.model.records.models, function(doc) {
|
||||
// important this is == as the currentRow will be string (as comes
|
||||
// from DOM) while id may be int
|
||||
return doc.id == self.tempState.currentRow;
|
||||
});
|
||||
doc.destroy().then(function() {
|
||||
self.model.currentRecords.remove(doc);
|
||||
self.model.records.remove(doc);
|
||||
self.trigger('recline:flash', {message: "Row deleted successfully"});
|
||||
}).fail(function(err) {
|
||||
self.trigger('recline:flash', {message: "Errorz! " + err});
|
||||
@ -213,7 +213,7 @@ my.Grid = Backbone.View.extend({
|
||||
});
|
||||
var htmls = Mustache.render(this.template, this.toTemplateJSON());
|
||||
this.el.html(htmls);
|
||||
this.model.currentRecords.forEach(function(doc) {
|
||||
this.model.records.forEach(function(doc) {
|
||||
var tr = $('<tr />');
|
||||
self.el.find('tbody').append(tr);
|
||||
var newView = new my.GridRow({
|
||||
|
||||
@ -48,13 +48,13 @@ my.Map = Backbone.View.extend({
|
||||
});
|
||||
|
||||
// Listen to changes in the records
|
||||
this.model.currentRecords.bind('add', function(doc){self.redraw('add',doc)});
|
||||
this.model.currentRecords.bind('change', function(doc){
|
||||
this.model.records.bind('add', function(doc){self.redraw('add',doc)});
|
||||
this.model.records.bind('change', function(doc){
|
||||
self.redraw('remove',doc);
|
||||
self.redraw('add',doc);
|
||||
});
|
||||
this.model.currentRecords.bind('remove', function(doc){self.redraw('remove',doc)});
|
||||
this.model.currentRecords.bind('reset', function(){self.redraw('reset')});
|
||||
this.model.records.bind('remove', function(doc){self.redraw('remove',doc)});
|
||||
this.model.records.bind('reset', function(){self.redraw('reset')});
|
||||
|
||||
this.bind('view:show',function(){
|
||||
// If the div was hidden, Leaflet needs to recalculate some sizes
|
||||
@ -130,7 +130,7 @@ my.Map = Backbone.View.extend({
|
||||
if (this._geomReady() && this.mapReady){
|
||||
if (action == 'reset' || action == 'refresh'){
|
||||
this.features.clearLayers();
|
||||
this._add(this.model.currentRecords.models);
|
||||
this._add(this.model.records.models);
|
||||
} else if (action == 'add' && doc){
|
||||
this._add(doc);
|
||||
} else if (action == 'remove' && doc){
|
||||
|
||||
@ -22,9 +22,9 @@ my.SlickGrid = Backbone.View.extend({
|
||||
this.el = $(this.el);
|
||||
this.el.addClass('recline-slickgrid');
|
||||
_.bindAll(this, 'render');
|
||||
this.model.currentRecords.bind('add', this.render);
|
||||
this.model.currentRecords.bind('reset', this.render);
|
||||
this.model.currentRecords.bind('remove', this.render);
|
||||
this.model.records.bind('add', this.render);
|
||||
this.model.records.bind('reset', this.render);
|
||||
this.model.records.bind('remove', this.render);
|
||||
|
||||
var state = _.extend({
|
||||
hiddenColumns: [],
|
||||
@ -126,7 +126,7 @@ my.SlickGrid = Backbone.View.extend({
|
||||
|
||||
var data = [];
|
||||
|
||||
this.model.currentRecords.each(function(doc){
|
||||
this.model.records.each(function(doc){
|
||||
var row = {};
|
||||
self.model.fields.each(function(field){
|
||||
row[field.id] = doc.getFieldValueUnrendered(field);
|
||||
|
||||
@ -41,7 +41,7 @@ my.Timeline = Backbone.View.extend({
|
||||
this.model.fields.bind('reset', function() {
|
||||
self._setupTemporalField();
|
||||
});
|
||||
this.model.currentRecords.bind('all', function() {
|
||||
this.model.records.bind('all', function() {
|
||||
self.reloadData();
|
||||
});
|
||||
var stateData = _.extend({
|
||||
@ -120,7 +120,7 @@ my.Timeline = Backbone.View.extend({
|
||||
]
|
||||
}
|
||||
};
|
||||
this.model.currentRecords.each(function(record) {
|
||||
this.model.records.each(function(record) {
|
||||
var newEntry = self.convertRecord(record, self.fields);
|
||||
if (newEntry) {
|
||||
out.timeline.date.push(newEntry);
|
||||
|
||||
@ -100,7 +100,7 @@ my.Transform = Backbone.View.extend({
|
||||
var editFunc = costco.evalFunction(e.target.value);
|
||||
if (!editFunc.errorMessage) {
|
||||
errors.text('No syntax error.');
|
||||
var docs = self.model.currentRecords.map(function(doc) {
|
||||
var docs = self.model.records.map(function(doc) {
|
||||
return doc.toJSON();
|
||||
});
|
||||
var previewData = costco.previewTransform(docs, editFunc);
|
||||
|
||||
@ -29,8 +29,8 @@ test("parseCSV", function() {
|
||||
backend: 'csv'
|
||||
});
|
||||
dataset.fetch();
|
||||
equal(dataset.currentRecords.length, 3);
|
||||
var row = dataset.currentRecords.models[0].toJSON();
|
||||
equal(dataset.records.length, 3);
|
||||
var row = dataset.records.models[0].toJSON();
|
||||
deepEqual(row, {Name: 'Jones, Jay', Value: 10});
|
||||
});
|
||||
|
||||
|
||||
@ -95,14 +95,14 @@ test('DataProxy Backend', function() {
|
||||
dataset.fetch().then(function() {
|
||||
deepEqual(['__id__', 'date', 'price'], _.pluck(dataset.fields.toJSON(), 'id'));
|
||||
equal(10, dataset.recordCount)
|
||||
equal(dataset.currentRecords.models[0].get('date'), "1950-01");
|
||||
equal(dataset.records.models[0].get('date'), "1950-01");
|
||||
// needed only if not stubbing
|
||||
// start();
|
||||
});
|
||||
|
||||
dataset.query({q: '1950-01'}).then(function() {
|
||||
equal(dataset.recordCount, 1);
|
||||
equal(dataset.currentRecords.models[0].get('price'), '34.73');
|
||||
equal(dataset.records.models[0].get('price'), '34.73');
|
||||
});
|
||||
$.ajax.restore();
|
||||
});
|
||||
|
||||
@ -302,7 +302,7 @@ test("write", function() {
|
||||
id: id,
|
||||
title: 'my title'
|
||||
});
|
||||
dataset.currentRecords.add(rec);
|
||||
dataset.records.add(rec);
|
||||
// have to do this explicitly as we not really supporting adding new items atm
|
||||
dataset._changes.creates.push(rec.toJSON());
|
||||
var jqxhr = dataset.save();
|
||||
|
||||
@ -181,7 +181,7 @@ test("GDocs Backend", function() {
|
||||
});
|
||||
|
||||
dataset.fetch().then(function() {
|
||||
var docList = dataset.currentRecords;
|
||||
var docList = dataset.records;
|
||||
deepEqual(['column-2', 'column-1'], _.pluck(dataset.fields.toJSON(), 'id'));
|
||||
equal(3, docList.length);
|
||||
equal("A", docList.models[0].get('column-1'));
|
||||
|
||||
@ -206,7 +206,7 @@ test('query sort', function () {
|
||||
]
|
||||
};
|
||||
dataset.query(queryObj).then(function() {
|
||||
var doc0 = dataset.currentRecords.models[0].toJSON();
|
||||
var doc0 = dataset.records.models[0].toJSON();
|
||||
equal(doc0.x, 6);
|
||||
});
|
||||
});
|
||||
@ -215,13 +215,13 @@ test('query string', function () {
|
||||
var dataset = makeBackendDataset();
|
||||
dataset.fetch();
|
||||
dataset.query({q: 'UK'}).then(function() {
|
||||
equal(dataset.currentRecords.length, 3);
|
||||
deepEqual(dataset.currentRecords.pluck('country'), ['UK', 'UK', 'UK']);
|
||||
equal(dataset.records.length, 3);
|
||||
deepEqual(dataset.records.pluck('country'), ['UK', 'UK', 'UK']);
|
||||
});
|
||||
|
||||
dataset.query({q: 'UK 6'}).then(function() {
|
||||
equal(dataset.currentRecords.length, 1);
|
||||
deepEqual(dataset.currentRecords.models[0].id, 1);
|
||||
equal(dataset.records.length, 1);
|
||||
deepEqual(dataset.records.models[0].id, 1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -229,8 +229,8 @@ test('filters', function () {
|
||||
var dataset = makeBackendDataset();
|
||||
dataset.queryState.addFilter({type: 'term', field: 'country', term: 'UK'});
|
||||
dataset.query().then(function() {
|
||||
equal(dataset.currentRecords.length, 3);
|
||||
deepEqual(dataset.currentRecords.pluck('country'), ['UK', 'UK', 'UK']);
|
||||
equal(dataset.records.length, 3);
|
||||
deepEqual(dataset.records.pluck('country'), ['UK', 'UK', 'UK']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -74,11 +74,11 @@ test('Lat/Lon geom fields', function () {
|
||||
equal(_getFeaturesCount(view.features),6);
|
||||
|
||||
// Delete a record
|
||||
view.model.currentRecords.remove(view.model.currentRecords.get('1'));
|
||||
view.model.records.remove(view.model.records.get('1'));
|
||||
equal(_getFeaturesCount(view.features),5);
|
||||
|
||||
// Add a new one
|
||||
view.model.currentRecords.add({id: 7, x: 7, y: 14, z: 21, country: 'KX', label: 'seventh', lat:13.23, lon:23.56}),
|
||||
view.model.records.add({id: 7, x: 7, y: 14, z: 21, country: 'KX', label: 'seventh', lat:13.23, lon:23.56}),
|
||||
equal(_getFeaturesCount(view.features),6);
|
||||
|
||||
view.remove();
|
||||
@ -98,11 +98,11 @@ test('GeoJSON geom field', function () {
|
||||
equal(_getFeaturesCount(view.features),3);
|
||||
|
||||
// Delete a record
|
||||
view.model.currentRecords.remove(view.model.currentRecords.get('2'));
|
||||
view.model.records.remove(view.model.records.get('2'));
|
||||
equal(_getFeaturesCount(view.features),2);
|
||||
|
||||
// Add it back
|
||||
view.model.currentRecords.add({id: 2, x: 3, y: 6, z: 9, geom: {type:"LineString",coordinates:[[100.0, 0.0],[101.0, 1.0]]}}),
|
||||
view.model.records.add({id: 2, x: 3, y: 6, z: 9, geom: {type:"LineString",coordinates:[[100.0, 0.0],[101.0, 1.0]]}}),
|
||||
equal(_getFeaturesCount(view.features),3);
|
||||
|
||||
view.remove();
|
||||
|
||||
@ -16,7 +16,7 @@ test('basic', function () {
|
||||
assertPresent('.slick-header-column[title="x"]');
|
||||
equal($('.slick-header-column').length,dataset.fields.length);
|
||||
|
||||
equal(dataset.currentRecords.length,view.grid.getDataLength());
|
||||
equal(dataset.records.length,view.grid.getDataLength());
|
||||
|
||||
view.remove();
|
||||
});
|
||||
|
||||
@ -27,14 +27,14 @@ test('basics', function () {
|
||||
$editForm.find('input').val('UK');
|
||||
$editForm.submit();
|
||||
equal(dataset.queryState.attributes.filters[0].term, 'UK');
|
||||
equal(dataset.currentRecords.length, 3);
|
||||
equal(dataset.records.length, 3);
|
||||
|
||||
// now remove filter
|
||||
$editForm.find('.js-remove-filter').click();
|
||||
// hmmm, not working yet but works by eye!
|
||||
// $editForm = view.el.find('form.js-edit');
|
||||
// equal($editForm.find('.filter-term').length, 0)
|
||||
// equal(dataset.currentRecords.length, 6);
|
||||
// equal(dataset.records.length, 6);
|
||||
|
||||
view.remove();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user