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