[refactor][s]: rename rowCount to docCount and remove getLength method as can just use dataset.docCount.
This commit is contained in:
14
src/model.js
14
src/model.js
@@ -6,14 +6,16 @@ recline.Model = function($) {
|
|||||||
var my = {};
|
var my = {};
|
||||||
|
|
||||||
// A Dataset model.
|
// A Dataset model.
|
||||||
|
//
|
||||||
|
// Other than standard list of Backbone attributes it has two important attributes:
|
||||||
|
//
|
||||||
|
// * currentDocuments: a DocumentList containing the Documents we have currently loaded for viewing (you update currentDocuments by calling getRows)
|
||||||
|
// * docCount: total number of documents in this dataset (obtained on a fetch for this Dataset)
|
||||||
my.Dataset = Backbone.Model.extend({
|
my.Dataset = Backbone.Model.extend({
|
||||||
__type__: 'Dataset',
|
__type__: 'Dataset',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.currentDocuments = new my.DocumentList();
|
this.currentDocuments = new my.DocumentList();
|
||||||
},
|
this.docCount = null;
|
||||||
|
|
||||||
getLength: function() {
|
|
||||||
return this.rowCount;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get rows (documents) from the backend returning a recline.DocumentList
|
// Get rows (documents) from the backend returning a recline.DocumentList
|
||||||
@@ -103,7 +105,7 @@ my.BackendMemory = Backbone.Model.extend({
|
|||||||
dataset.set({
|
dataset.set({
|
||||||
headers: rawDataset.data.headers
|
headers: rawDataset.data.headers
|
||||||
});
|
});
|
||||||
dataset.rowCount = rawDataset.data.rows.length;
|
dataset.docCount = rawDataset.data.rows.length;
|
||||||
dfd.resolve(dataset);
|
dfd.resolve(dataset);
|
||||||
}
|
}
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
@@ -184,7 +186,7 @@ my.BackendWebstore = Backbone.Model.extend({
|
|||||||
dataset.set({
|
dataset.set({
|
||||||
headers: headers
|
headers: headers
|
||||||
});
|
});
|
||||||
dataset.rowCount = schema.count;
|
dataset.docCount = schema.count;
|
||||||
dfd.resolve(dataset, jqxhr);
|
dfd.resolve(dataset, jqxhr);
|
||||||
});
|
});
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ test('new Dataset', function () {
|
|||||||
dataset.fetch().then(function(dataset) {
|
dataset.fetch().then(function(dataset) {
|
||||||
equal(dataset.get('name'), metadata.name);
|
equal(dataset.get('name'), metadata.name);
|
||||||
deepEqual(dataset.get('headers'), indata.headers);
|
deepEqual(dataset.get('headers'), indata.headers);
|
||||||
equal(dataset.getLength(), 6);
|
equal(dataset.docCount, 6);
|
||||||
dataset.getRows(4, 2).then(function(documentList) {
|
dataset.getRows(4, 2).then(function(documentList) {
|
||||||
deepEqual(indata.rows[2], documentList.models[0].toJSON());
|
deepEqual(indata.rows[2], documentList.models[0].toJSON());
|
||||||
});
|
});
|
||||||
@@ -158,7 +158,7 @@ test('Webstore Backend', function() {
|
|||||||
|
|
||||||
dataset.fetch().then(function(dataset) {
|
dataset.fetch().then(function(dataset) {
|
||||||
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
|
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
|
||||||
equal(3, dataset.rowCount)
|
equal(3, dataset.docCount)
|
||||||
dataset.getRows().then(function(docList) {
|
dataset.getRows().then(function(docList) {
|
||||||
equal(3, docList.length)
|
equal(3, docList.length)
|
||||||
equal("2009-01-01", docList.models[0].get('date'));
|
equal("2009-01-01", docList.models[0].get('date'));
|
||||||
|
|||||||
Reference in New Issue
Block a user