Merge branch 'master' into gh-pages
This commit is contained in:
@@ -4,6 +4,8 @@ toolkit, all in pure javascript and html.
|
|||||||
|
|
||||||
Designed for standalone use or as a library to integrate into your own app.
|
Designed for standalone use or as a library to integrate into your own app.
|
||||||
|
|
||||||
|
Live demo: http://okfnlabs.org/recline/demo/
|
||||||
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -24,13 +26,8 @@ Open demo/index.html in your favourite browser.
|
|||||||
|
|
||||||
## Developer Notes
|
## Developer Notes
|
||||||
|
|
||||||
### Minifying dependencies
|
Running the tests by opening `test/index.html` in your browser.
|
||||||
|
|
||||||
npm install -g uglify
|
|
||||||
cd vendor
|
|
||||||
cat *.js | uglifyjs -o ../src/deps-min.js
|
|
||||||
|
|
||||||
note: make sure underscore.js goes in at the top of the file as a few deps currently depend on it
|
|
||||||
|
|
||||||
|
|
||||||
## Copyright and License
|
## Copyright and License
|
||||||
|
|||||||
@@ -15,7 +15,12 @@
|
|||||||
<link rel="stylesheet" href="../css/graph-flot.css">
|
<link rel="stylesheet" href="../css/graph-flot.css">
|
||||||
<link rel="stylesheet" href="../css/bootstrap.css">
|
<link rel="stylesheet" href="../css/bootstrap.css">
|
||||||
|
|
||||||
<script type="text/javascript" src="../src/deps-min.js"></script>
|
<script type="text/javascript" src="../vendor/000-jquery-1.6.1.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/000-underscore-1.1.6.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/backbone-0.5.1.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery-ui-1.8.14.custom.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery.flot-0.7.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery.mustache.js"></script>
|
||||||
<script type="text/javascript" src="../vendor/bootstrap/1.4.0/bootstrap-alerts.js"></script>
|
<script type="text/javascript" src="../vendor/bootstrap/1.4.0/bootstrap-alerts.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="../src/util.js"></script>
|
<script type="text/javascript" src="../src/util.js"></script>
|
||||||
|
|||||||
@@ -7,7 +7,13 @@
|
|||||||
<link rel="stylesheet" href="style/data-table.css" media="screen">
|
<link rel="stylesheet" href="style/data-table.css" media="screen">
|
||||||
<link rel="stylesheet" href="style/flot-graph.css" media="screen">
|
<link rel="stylesheet" href="style/flot-graph.css" media="screen">
|
||||||
<link rel="stylesheet" href="style/style.css" media="screen">
|
<link rel="stylesheet" href="style/style.css" media="screen">
|
||||||
<script type="text/javascript" src="../src/deps-min.js"></script>
|
|
||||||
|
<script type="text/javascript" src="../vendor/000-jquery-1.6.1.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/000-underscore-1.1.6.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/backbone-0.5.1.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery-ui-1.8.14.custom.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery.flot-0.7.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery.mustache.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="../src/util.js"></script>
|
<script type="text/javascript" src="../src/util.js"></script>
|
||||||
<script type="text/javascript" src="../src/costco.js"></script>
|
<script type="text/javascript" src="../src/costco.js"></script>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
importScripts('lib/underscore.js');
|
// importScripts('lib/underscore.js');
|
||||||
|
|
||||||
onmessage = function(message) {
|
onmessage = function(message) {
|
||||||
|
|
||||||
|
|||||||
21
src/deps-min.js
vendored
21
src/deps-min.js
vendored
File diff suppressed because one or more lines are too long
94
src/model.js
94
src/model.js
@@ -162,13 +162,12 @@ my.BackendMemory = Backbone.Model.extend({
|
|||||||
|
|
||||||
// Webstore Backend for connecting to the Webstore
|
// 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 ...
|
// 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({
|
||||||
// require url attribute in initialization data
|
|
||||||
initialize: function() {
|
|
||||||
this.webstoreTableUrl = this.get('url');
|
|
||||||
},
|
|
||||||
getDataset: function(id) {
|
getDataset: function(id) {
|
||||||
var dataset = new my.Dataset({
|
var dataset = new my.Dataset({
|
||||||
id: id
|
id: id
|
||||||
@@ -227,6 +226,93 @@ my.BackendWebstore = 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'
|
||||||
|
, format: 'jsonp'
|
||||||
|
},
|
||||||
|
getDataset: function(id) {
|
||||||
|
var dataset = new my.Dataset({
|
||||||
|
id: id
|
||||||
|
});
|
||||||
|
dataset.backend = this;
|
||||||
|
return dataset;
|
||||||
|
},
|
||||||
|
sync: function(method, model, options) {
|
||||||
|
if (method === "read") {
|
||||||
|
// this switching on object type is rather horrible
|
||||||
|
// think may make more sense to do work in individual objects rather than in central Backbone.sync
|
||||||
|
if (this.__type__ == 'Dataset') {
|
||||||
|
var dataset = this;
|
||||||
|
// get the schema and return
|
||||||
|
var base = this.backend.get('dataproxy');
|
||||||
|
var data = this.backend.toJSON();
|
||||||
|
delete data['dataproxy'];
|
||||||
|
// TODO: should we cache for extra efficiency
|
||||||
|
data['max-results'] = 1;
|
||||||
|
var jqxhr = $.ajax({
|
||||||
|
url: base
|
||||||
|
, data: data
|
||||||
|
, dataType: 'jsonp'
|
||||||
|
});
|
||||||
|
var dfd = $.Deferred();
|
||||||
|
jqxhr.then(function(results) {
|
||||||
|
dataset.set({
|
||||||
|
headers: results.fields
|
||||||
|
});
|
||||||
|
dfd.resolve(dataset, jqxhr);
|
||||||
|
});
|
||||||
|
return dfd.promise();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert('This backend only supports read operations');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getDocuments: function(datasetId, numRows, start) {
|
||||||
|
if (start === undefined) {
|
||||||
|
start = 0;
|
||||||
|
}
|
||||||
|
if (numRows === undefined) {
|
||||||
|
numRows = 10;
|
||||||
|
}
|
||||||
|
var base = this.get('dataproxy');
|
||||||
|
var data = this.toJSON();
|
||||||
|
delete data['dataproxy'];
|
||||||
|
data['max-results'] = numRows;
|
||||||
|
var jqxhr = $.ajax({
|
||||||
|
url: base
|
||||||
|
, data: data
|
||||||
|
, dataType: 'jsonp'
|
||||||
|
// , cache: true
|
||||||
|
});
|
||||||
|
var dfd = $.Deferred();
|
||||||
|
jqxhr.then(function(results) {
|
||||||
|
var _out = _.map(results.data, function(row) {
|
||||||
|
var tmp = {};
|
||||||
|
_.each(results.fields, function(key, idx) {
|
||||||
|
tmp[key] = row[idx];
|
||||||
|
});
|
||||||
|
return tmp;
|
||||||
|
});
|
||||||
|
dfd.resolve(_out);
|
||||||
|
});
|
||||||
|
return dfd.promise();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return my;
|
return my;
|
||||||
|
|
||||||
}(jQuery);
|
}(jQuery);
|
||||||
|
|||||||
@@ -5,7 +5,13 @@
|
|||||||
<title>Qunit Tests</title>
|
<title>Qunit Tests</title>
|
||||||
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen" />
|
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen" />
|
||||||
|
|
||||||
<script src="../src/deps-min.js"></script>
|
<script type="text/javascript" src="../vendor/000-jquery-1.6.1.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/000-underscore-1.1.6.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/backbone-0.5.1.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery-ui-1.8.14.custom.min.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery.flot-0.7.js"></script>
|
||||||
|
<script type="text/javascript" src="../vendor/jquery.mustache.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="qunit/qunit.js"></script>
|
<script type="text/javascript" src="qunit/qunit.js"></script>
|
||||||
<script src="sinon/1.1.1/sinon.js"></script>
|
<script src="sinon/1.1.1/sinon.js"></script>
|
||||||
<script src="sinon-qunit/1.0.0/sinon-qunit.js"></script>
|
<script src="sinon-qunit/1.0.0/sinon-qunit.js"></script>
|
||||||
|
|||||||
@@ -164,6 +164,104 @@ test('Webstore Backend', function() {
|
|||||||
equal("2009-01-01", docList.models[0].get('date'));
|
equal("2009-01-01", docList.models[0].get('date'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
$.ajax.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var dataProxyData = {
|
||||||
|
"data": [
|
||||||
|
[
|
||||||
|
"1",
|
||||||
|
"1950-01",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"2",
|
||||||
|
"1950-02",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"3",
|
||||||
|
"1950-03",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"4",
|
||||||
|
"1950-04",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"5",
|
||||||
|
"1950-05",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"6",
|
||||||
|
"1950-06",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"7",
|
||||||
|
"1950-07",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"8",
|
||||||
|
"1950-08",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"9",
|
||||||
|
"1950-09",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"10",
|
||||||
|
"1950-10",
|
||||||
|
"34.73"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
"__id__",
|
||||||
|
"date",
|
||||||
|
"price"
|
||||||
|
],
|
||||||
|
"length": null,
|
||||||
|
"max_results": 10,
|
||||||
|
"url": "http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv"
|
||||||
|
};
|
||||||
|
|
||||||
|
test('DataProxy Backend', function() {
|
||||||
|
// needed only if not stubbing
|
||||||
|
// stop();
|
||||||
|
var backend = new recline.Model.BackendDataProxy({
|
||||||
|
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
||||||
|
});
|
||||||
|
recline.Model.setBackend(backend);
|
||||||
|
dataset = backend.getDataset();
|
||||||
|
|
||||||
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
|
var partialUrl = 'jsonpdataproxy.appspot.com';
|
||||||
|
if (options.url.indexOf(partialUrl) != -1) {
|
||||||
|
return {
|
||||||
|
then: function(callback) {
|
||||||
|
callback(dataProxyData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dataset.fetch().then(function(dataset) {
|
||||||
|
deepEqual(['__id__', 'date', 'price'], dataset.get('headers'));
|
||||||
|
equal(null, dataset.docCount)
|
||||||
|
dataset.getDocuments().then(function(docList) {
|
||||||
|
equal(10, docList.length)
|
||||||
|
equal("1950-01", docList.models[0].get('date'));
|
||||||
|
// needed only if not stubbing
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$.ajax.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
})(this.jQuery);
|
})(this.jQuery);
|
||||||
|
|||||||
85
vendor/jquery.couch2.js
vendored
85
vendor/jquery.couch2.js
vendored
@@ -1,85 +0,0 @@
|
|||||||
(function($) {
|
|
||||||
|
|
||||||
window.couch = {};
|
|
||||||
|
|
||||||
var defaults = {
|
|
||||||
headers: {"Accept":"application/json"},
|
|
||||||
dataType:"json",
|
|
||||||
contentType: "application/json",
|
|
||||||
type: "GET",
|
|
||||||
url: "/"
|
|
||||||
};
|
|
||||||
|
|
||||||
couch.errors = {
|
|
||||||
forbidden: "You aren't allowed to do that."
|
|
||||||
}
|
|
||||||
|
|
||||||
couch.responseError = function(response) {
|
|
||||||
if(_.isArray(response) && (response.length > 0) ) response = response[0];
|
|
||||||
if (response.error) return couch.errors[response.error];
|
|
||||||
}
|
|
||||||
|
|
||||||
couch.request = function(opts) {
|
|
||||||
var ajaxOpts = $.extend({}, defaults, opts)
|
|
||||||
, dfd = $.Deferred()
|
|
||||||
;
|
|
||||||
|
|
||||||
$.ajax(ajaxOpts).then(
|
|
||||||
function(successResponse) {
|
|
||||||
var error = couch.responseError(successResponse);
|
|
||||||
if (error) app.emitter.emit(error, 'error');
|
|
||||||
dfd.resolve(successResponse);
|
|
||||||
},
|
|
||||||
function(errorResponse) {
|
|
||||||
app.emitter.emit("Fatal XHR Error", 'error');
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return dfd.promise();
|
|
||||||
}
|
|
||||||
|
|
||||||
couch.get = function(url) {
|
|
||||||
return couch.request({url:url, type:'GET'});
|
|
||||||
};
|
|
||||||
|
|
||||||
couch.login = function(credentials) {
|
|
||||||
return couch.request({
|
|
||||||
url: "/_session",
|
|
||||||
type: 'POST',
|
|
||||||
data: JSON.stringify({name: credentials.username, password: credentials.password})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
couch.logout = function() {
|
|
||||||
return couch.request({url: "/_session", type: 'DELETE'});
|
|
||||||
}
|
|
||||||
|
|
||||||
couch.session = function() {
|
|
||||||
return couch.request({url: "/_session"});
|
|
||||||
}
|
|
||||||
|
|
||||||
couch.db = function(name, couchRoot) {
|
|
||||||
if(!couchRoot) couchRoot = "";
|
|
||||||
return {
|
|
||||||
name: name,
|
|
||||||
uri: couchRoot + "/" + encodeURIComponent(name) + "/",
|
|
||||||
|
|
||||||
get: function(id) {
|
|
||||||
return couch.request({url:this.uri + id, type:"GET"});
|
|
||||||
},
|
|
||||||
|
|
||||||
put: function(id, data) {
|
|
||||||
return couch.request({url:this.uri + id, type:"PUT", data:data});
|
|
||||||
},
|
|
||||||
|
|
||||||
designDocs: function(opts) {
|
|
||||||
return couch.request($.extend(defaults, {
|
|
||||||
url: this.uri + "_all_docs",
|
|
||||||
data: {startkey:'"_design/"', endkey:'"_design0"', include_docs:true}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
})(jQuery);
|
|
||||||
50
vendor/microevent.js
vendored
50
vendor/microevent.js
vendored
@@ -1,50 +0,0 @@
|
|||||||
/**
|
|
||||||
* MicroEvent - to make any js object an event emitter (server or browser)
|
|
||||||
*
|
|
||||||
* - pure javascript - server compatible, browser compatible
|
|
||||||
* - dont rely on the browser doms
|
|
||||||
* - super simple - you get it immediatly, no mistery, no magic involved
|
|
||||||
*
|
|
||||||
* - create a MicroEventDebug with goodies to debug
|
|
||||||
* - make it safer to use
|
|
||||||
*/
|
|
||||||
|
|
||||||
var MicroEvent = function(){}
|
|
||||||
MicroEvent.prototype = {
|
|
||||||
on : function(event, fct){
|
|
||||||
this._events = this._events || {};
|
|
||||||
this._events[event] = this._events[event] || [];
|
|
||||||
this._events[event].push(fct);
|
|
||||||
},
|
|
||||||
clear : function(event, fct){
|
|
||||||
this._events = this._events || {};
|
|
||||||
if( event in this._events === false ) return;
|
|
||||||
this._events[event].splice(this._events[event].indexOf(fct), 1);
|
|
||||||
},
|
|
||||||
trigger : function(event /* , args... */){
|
|
||||||
this._events = this._events || {};
|
|
||||||
if( event in this._events === false ) return;
|
|
||||||
for(var i = 0; i < this._events[event].length; i++){
|
|
||||||
this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mixin will delegate all MicroEvent.js function in the destination object
|
|
||||||
*
|
|
||||||
* - require('MicroEvent').mixin(Foobar) will make Foobar able to use MicroEvent
|
|
||||||
*
|
|
||||||
* @param {Object} the object which will support MicroEvent
|
|
||||||
*/
|
|
||||||
MicroEvent.mixin = function(destObject){
|
|
||||||
var props = ['on', 'clear', 'trigger'];
|
|
||||||
for(var i = 0; i < props.length; i ++){
|
|
||||||
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// export in common js
|
|
||||||
if( typeof module !== "undefined" && ('exports' in module)){
|
|
||||||
module.exports = MicroEvent
|
|
||||||
}
|
|
||||||
5
vendor/sammy-0.6.3.min.js
vendored
5
vendor/sammy-0.6.3.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user