correct indents on model.js with gg=G
This commit is contained in:
102
src/model.js
102
src/model.js
@@ -3,15 +3,15 @@ this.recline = this.recline || {};
|
|||||||
// Models module following classic module pattern
|
// Models module following classic module pattern
|
||||||
recline.Model = function($) {
|
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:
|
// 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)
|
// * 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)
|
// * 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();
|
||||||
@@ -46,29 +46,29 @@ my.Dataset = Backbone.Model.extend({
|
|||||||
data.docCount = this.docCount;
|
data.docCount = this.docCount;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
my.Document = Backbone.Model.extend({
|
my.Document = Backbone.Model.extend({
|
||||||
__type__: 'Document'
|
__type__: 'Document'
|
||||||
});
|
});
|
||||||
|
|
||||||
my.DocumentList = Backbone.Collection.extend({
|
my.DocumentList = Backbone.Collection.extend({
|
||||||
__type__: 'DocumentList',
|
__type__: 'DocumentList',
|
||||||
// webStore: new WebStore(this.url),
|
// webStore: new WebStore(this.url),
|
||||||
model: my.Document
|
model: my.Document
|
||||||
});
|
});
|
||||||
|
|
||||||
// Backends section
|
// Backends section
|
||||||
// ================
|
// ================
|
||||||
|
|
||||||
my.setBackend = function(backend) {
|
my.setBackend = function(backend) {
|
||||||
Backbone.sync = backend.sync;
|
Backbone.sync = backend.sync;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Backend which just caches in memory
|
// Backend which just caches in memory
|
||||||
//
|
//
|
||||||
// Does not need to be a backbone model but provides some conveniences
|
// Does not need to be a backbone model but provides some conveniences
|
||||||
my.BackendMemory = Backbone.Model.extend({
|
my.BackendMemory = Backbone.Model.extend({
|
||||||
// Initialize a Backend with a local in-memory dataset.
|
// Initialize a Backend with a local in-memory dataset.
|
||||||
//
|
//
|
||||||
// NB: We can handle one and only one dataset at a time.
|
// NB: We can handle one and only one dataset at a time.
|
||||||
@@ -158,16 +158,16 @@ my.BackendMemory = Backbone.Model.extend({
|
|||||||
dfd.resolve(results);
|
dfd.resolve(results);
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Webstore Backend for connecting to the Webstore
|
// Webstore Backend for connecting to the Webstore
|
||||||
//
|
//
|
||||||
// Initializing model argument must contain a url attribute pointing to
|
// Initializing model argument must contain a url attribute pointing to
|
||||||
// relevant Webstore table.
|
// relevant Webstore table.
|
||||||
//
|
//
|
||||||
// Designed to only attach to one dataset and one dataset only ...
|
// Designed to only attach to one dataset and one dataset only ...
|
||||||
// Could generalize to support attaching to different datasets
|
// Could generalize to support attaching to different datasets
|
||||||
my.BackendWebstore = Backbone.Model.extend({
|
my.BackendWebstore = Backbone.Model.extend({
|
||||||
getDataset: function(id) {
|
getDataset: function(id) {
|
||||||
var dataset = new my.Dataset({
|
var dataset = new my.Dataset({
|
||||||
id: id
|
id: id
|
||||||
@@ -224,21 +224,21 @@ my.BackendWebstore = Backbone.Model.extend({
|
|||||||
});
|
});
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// DataProxy Backend for connecting to the DataProxy
|
// DataProxy Backend for connecting to the DataProxy
|
||||||
//
|
//
|
||||||
// Example initialization:
|
// Example initialization:
|
||||||
//
|
//
|
||||||
// BackendDataProxy({
|
// BackendDataProxy({
|
||||||
// model: {
|
// model: {
|
||||||
// url: {url-of-data-to-proxy},
|
// url: {url-of-data-to-proxy},
|
||||||
// type: xls || csv,
|
// type: xls || csv,
|
||||||
// format: json || jsonp # return format (defaults to jsonp)
|
// format: json || jsonp # return format (defaults to jsonp)
|
||||||
// dataproxy: {url-to-proxy} # defaults to http://jsonpdataproxy.appspot.com
|
// dataproxy: {url-to-proxy} # defaults to http://jsonpdataproxy.appspot.com
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
my.BackendDataProxy = Backbone.Model.extend({
|
my.BackendDataProxy = Backbone.Model.extend({
|
||||||
defaults: {
|
defaults: {
|
||||||
dataproxy: 'http://jsonpdataproxy.appspot.com'
|
dataproxy: 'http://jsonpdataproxy.appspot.com'
|
||||||
, type: 'csv'
|
, type: 'csv'
|
||||||
@@ -311,11 +311,11 @@ my.BackendDataProxy = Backbone.Model.extend({
|
|||||||
});
|
});
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Google spreadsheet backend
|
// Google spreadsheet backend
|
||||||
my.BackendGDoc = Backbone.Model.extend({
|
my.BackendGDoc = Backbone.Model.extend({
|
||||||
getDataset: function(id) {
|
getDataset: function(id) {
|
||||||
var dataset = new my.Dataset({
|
var dataset = new my.Dataset({
|
||||||
id: id
|
id: id
|
||||||
@@ -354,7 +354,7 @@ my.BackendGDoc = Backbone.Model.extend({
|
|||||||
return dfd;
|
return dfd;
|
||||||
},
|
},
|
||||||
gdocsToJavascript: function(gdocsSpreadsheet) {
|
gdocsToJavascript: function(gdocsSpreadsheet) {
|
||||||
/*
|
/*
|
||||||
:options: (optional) optional argument dictionary:
|
:options: (optional) optional argument dictionary:
|
||||||
columnsToUse: list of columns to use (specified by header names)
|
columnsToUse: list of columns to use (specified by header names)
|
||||||
colTypes: dictionary (with column names as keys) specifying types (e.g. range, percent for use in conversion).
|
colTypes: dictionary (with column names as keys) specifying types (e.g. range, percent for use in conversion).
|
||||||
@@ -412,11 +412,11 @@ my.BackendGDoc = Backbone.Model.extend({
|
|||||||
results.data.push(row);
|
results.data.push(row);
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return my;
|
return my;
|
||||||
|
|
||||||
}(jQuery);
|
}(jQuery);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
(function ($) {
|
(function ($) {
|
||||||
|
|
||||||
module("Dataset");
|
module("Dataset");
|
||||||
|
|
||||||
test('new Dataset', function () {
|
test('new Dataset', function () {
|
||||||
var datasetId = 'test-dataset';
|
var datasetId = 'test-dataset';
|
||||||
var metadata = {
|
var metadata = {
|
||||||
title: 'My Test Dataset'
|
title: 'My Test Dataset'
|
||||||
@@ -55,10 +55,10 @@ test('new Dataset', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: move to fixtures
|
// TODO: move to fixtures
|
||||||
var webstoreSchema = {
|
var webstoreSchema = {
|
||||||
"count": 3,
|
"count": 3,
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
@@ -93,9 +93,9 @@ var webstoreSchema = {
|
|||||||
"name": "values_url"
|
"name": "values_url"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
webstoreData = {
|
webstoreData = {
|
||||||
"count": null,
|
"count": null,
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
@@ -131,9 +131,9 @@ webstoreData = {
|
|||||||
"name": "amount"
|
"name": "amount"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
test('Webstore Backend', function() {
|
test('Webstore Backend', function() {
|
||||||
var backend = new recline.Model.BackendWebstore({
|
var backend = new recline.Model.BackendWebstore({
|
||||||
url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
|
url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
|
||||||
});
|
});
|
||||||
@@ -165,10 +165,10 @@ test('Webstore Backend', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
$.ajax.restore();
|
$.ajax.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var dataProxyData = {
|
var dataProxyData = {
|
||||||
"data": [
|
"data": [
|
||||||
[
|
[
|
||||||
"1",
|
"1",
|
||||||
@@ -229,9 +229,9 @@ var dataProxyData = {
|
|||||||
"length": null,
|
"length": null,
|
||||||
"max_results": 10,
|
"max_results": 10,
|
||||||
"url": "http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv"
|
"url": "http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv"
|
||||||
};
|
};
|
||||||
|
|
||||||
test('DataProxy Backend', function() {
|
test('DataProxy Backend', function() {
|
||||||
// needed only if not stubbing
|
// needed only if not stubbing
|
||||||
// stop();
|
// stop();
|
||||||
var backend = new recline.Model.BackendDataProxy({
|
var backend = new recline.Model.BackendDataProxy({
|
||||||
@@ -262,10 +262,10 @@ test('DataProxy Backend', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
$.ajax.restore();
|
$.ajax.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var sample_gdocs_spreadsheet_data = {
|
var sample_gdocs_spreadsheet_data = {
|
||||||
"feed": {
|
"feed": {
|
||||||
"category": [
|
"category": [
|
||||||
{
|
{
|
||||||
@@ -429,14 +429,14 @@ var sample_gdocs_spreadsheet_data = {
|
|||||||
},
|
},
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"encoding": "UTF-8"
|
"encoding": "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test("GDoc Backend", function() {
|
test("GDoc Backend", function() {
|
||||||
var backend = new recline.Model.BackendGDoc({url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
var backend = new recline.Model.BackendGDoc({url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
||||||
});
|
});
|
||||||
recline.Model.setBackend(backend);
|
recline.Model.setBackend(backend);
|
||||||
dataset = backend.getDataset();
|
dataset = backend.getDataset();
|
||||||
|
|
||||||
@@ -466,7 +466,7 @@ test("GDoc Backend", function() {
|
|||||||
$.getJSON.restore();
|
$.getJSON.restore();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
})(this.jQuery);
|
})(this.jQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user