Merge branch 'master' of github.com:okfn/recline

This commit is contained in:
Rufus Pollock
2012-10-02 16:17:09 +01:00
12 changed files with 165 additions and 33 deletions

View File

@@ -42,6 +42,7 @@
--> -->
<!-- model and backends --> <!-- model and backends -->
<script type="text/javascript" src="{{page.root}}src/ecma-fixes.js"></script>
<script type="text/javascript" src="{{page.root}}src/model.js"></script> <script type="text/javascript" src="{{page.root}}src/model.js"></script>
<script type="text/javascript" src="{{page.root}}src/backend.memory.js"></script> <script type="text/javascript" src="{{page.root}}src/backend.memory.js"></script>
<script type="text/javascript" src="{{page.root}}src/backend.dataproxy.js"></script> <script type="text/javascript" src="{{page.root}}src/backend.dataproxy.js"></script>

View File

@@ -74,21 +74,21 @@ var createExplorer = function(dataset, state) {
label: 'Grid', label: 'Grid',
view: new recline.View.SlickGrid({ view: new recline.View.SlickGrid({
model: dataset model: dataset
}), })
}, },
{ {
id: 'graph', id: 'graph',
label: 'Graph', label: 'Graph',
view: new recline.View.Graph({ view: new recline.View.Graph({
model: dataset model: dataset
}), })
}, },
{ {
id: 'map', id: 'map',
label: 'Map', label: 'Map',
view: new recline.View.Map({ view: new recline.View.Map({
model: dataset model: dataset
}), })
}, },
{ {
id: 'transform', id: 'transform',

View File

@@ -608,7 +608,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
}); });
}; };
this.delete = function(doc) { this.remove = function(doc) {
var newdocs = _.reject(self.data, function(internalDoc) { var newdocs = _.reject(self.data, function(internalDoc) {
return (doc.id === internalDoc.id); return (doc.id === internalDoc.id);
}); });
@@ -623,7 +623,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
self.update(record); self.update(record);
}); });
_.each(changes.deletes, function(record) { _.each(changes.deletes, function(record) {
self.delete(record); self.remove(record);
}); });
dfd.resolve(); dfd.resolve();
return dfd.promise(); return dfd.promise();

89
dist/recline.js vendored
View File

@@ -529,7 +529,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
// //
// @param {Object} id id of object to delete // @param {Object} id id of object to delete
// @return deferred supporting promise API // @return deferred supporting promise API
this.delete = function(id) { this.remove = function(id) {
url = this.endpoint; url = this.endpoint;
url += '/' + id; url += '/' + id;
return makeRequest({ return makeRequest({
@@ -669,7 +669,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
else if (changes.updates.length >0) { else if (changes.updates.length >0) {
return es.upsert(changes.updates[0]); return es.upsert(changes.updates[0]);
} else if (changes.deletes.length > 0) { } else if (changes.deletes.length > 0) {
return es.delete(changes.deletes[0].id); return es.remove(changes.deletes[0].id);
} }
}; };
@@ -680,7 +680,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
var jqxhr = es.query(queryObj); var jqxhr = es.query(queryObj);
jqxhr.done(function(results) { jqxhr.done(function(results) {
var out = { var out = {
total: results.hits.total, total: results.hits.total
}; };
out.hits = _.map(results.hits.hits, function(hit) { out.hits = _.map(results.hits.hits, function(hit) {
if (!('id' in hit._source) && hit._id) { if (!('id' in hit._source) && hit._id) {
@@ -930,7 +930,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
}); });
}; };
this.delete = function(doc) { this.remove = function(doc) {
var newdocs = _.reject(self.data, function(internalDoc) { var newdocs = _.reject(self.data, function(internalDoc) {
return (doc.id === internalDoc.id); return (doc.id === internalDoc.id);
}); });
@@ -945,7 +945,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
self.update(record); self.update(record);
}); });
_.each(changes.deletes, function(record) { _.each(changes.deletes, function(record) {
self.delete(record); self.remove(record);
}); });
dfd.resolve(); dfd.resolve();
return dfd.promise(); return dfd.promise();
@@ -1180,7 +1180,73 @@ my.Transform.mapDocs = function(docs, editFunc) {
}; };
}(this.recline.Data)) }(this.recline.Data))
// # Recline Backbone Models // This file adds in full array method support in browsers that don't support it
// see: http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-etc
// Add ECMA262-5 Array methods if not supported natively
if (!('indexOf' in Array.prototype)) {
Array.prototype.indexOf= function(find, i /*opt*/) {
if (i===undefined) i= 0;
if (i<0) i+= this.length;
if (i<0) i= 0;
for (var n= this.length; i<n; i++)
if (i in this && this[i]===find)
return i;
return -1;
};
}
if (!('lastIndexOf' in Array.prototype)) {
Array.prototype.lastIndexOf= function(find, i /*opt*/) {
if (i===undefined) i= this.length-1;
if (i<0) i+= this.length;
if (i>this.length-1) i= this.length-1;
for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */
if (i in this && this[i]===find)
return i;
return -1;
};
}
if (!('forEach' in Array.prototype)) {
Array.prototype.forEach= function(action, that /*opt*/) {
for (var i= 0, n= this.length; i<n; i++)
if (i in this)
action.call(that, this[i], i, this);
};
}
if (!('map' in Array.prototype)) {
Array.prototype.map= function(mapper, that /*opt*/) {
var other= new Array(this.length);
for (var i= 0, n= this.length; i<n; i++)
if (i in this)
other[i]= mapper.call(that, this[i], i, this);
return other;
};
}
if (!('filter' in Array.prototype)) {
Array.prototype.filter= function(filter, that /*opt*/) {
var other= [], v;
for (var i=0, n= this.length; i<n; i++)
if (i in this && filter.call(that, v= this[i], i, this))
other.push(v);
return other;
};
}
if (!('every' in Array.prototype)) {
Array.prototype.every= function(tester, that /*opt*/) {
for (var i= 0, n= this.length; i<n; i++)
if (i in this && !tester.call(that, this[i], i, this))
return false;
return true;
};
}
if (!('some' in Array.prototype)) {
Array.prototype.some= function(tester, that /*opt*/) {
for (var i= 0, n= this.length; i<n; i++)
if (i in this && tester.call(that, this[i], i, this))
return true;
return false;
};
}// # Recline Backbone Models
this.recline = this.recline || {}; this.recline = this.recline || {};
this.recline.Model = this.recline.Model || {}; this.recline.Model = this.recline.Model || {};
@@ -1974,7 +2040,7 @@ my.Graph = Backbone.View.extend({
horizontal: true, horizontal: true,
shadowSize: 0, shadowSize: 0,
barWidth: 0.8 barWidth: 0.8
}, }
}, },
columns: { columns: {
legend: legend, legend: legend,
@@ -1995,9 +2061,9 @@ my.Graph = Backbone.View.extend({
horizontal: false, horizontal: false,
shadowSize: 0, shadowSize: 0,
barWidth: 0.8 barWidth: 0.8
}, }
}, },
grid: { hoverable: true, clickable: true }, grid: { hoverable: true, clickable: true }
}; };
return optionsPerGraphType[typeId]; return optionsPerGraphType[typeId];
}, },
@@ -2177,7 +2243,7 @@ my.GraphControls = Backbone.View.extend({
addSeries: function (idx) { addSeries: function (idx) {
var data = _.extend({ var data = _.extend({
seriesIndex: idx, seriesIndex: idx,
seriesName: String.fromCharCode(idx + 64 + 1), seriesName: String.fromCharCode(idx + 64 + 1)
}, this.model.toTemplateJSON()); }, this.model.toTemplateJSON());
var htmls = Mustache.render(this.templateSeriesEditor, data); var htmls = Mustache.render(this.templateSeriesEditor, data);
@@ -3183,7 +3249,7 @@ my.MultiView = Backbone.View.extend({
<div class="recline-data-explorer"> \ <div class="recline-data-explorer"> \
<div class="alert-messages"></div> \ <div class="alert-messages"></div> \
\ \
<div class="header"> \ <div class="header clearfix"> \
<div class="navigation"> \ <div class="navigation"> \
<div class="btn-group" data-toggle="buttons-radio"> \ <div class="btn-group" data-toggle="buttons-radio"> \
{{#views}} \ {{#views}} \
@@ -3202,7 +3268,6 @@ my.MultiView = Backbone.View.extend({
</div> \ </div> \
</div> \ </div> \
<div class="query-editor-here" style="display:inline;"></div> \ <div class="query-editor-here" style="display:inline;"></div> \
<div class="clearfix"></div> \
</div> \ </div> \
<div class="data-view-sidebar"></div> \ <div class="data-view-sidebar"></div> \
<div class="data-view-container"></div> \ <div class="data-view-container"></div> \

View File

@@ -97,7 +97,7 @@ my.__type__ = 'couchdb';
// //
// @param {Object} id id of object to delete // @param {Object} id id of object to delete
// @return deferred supporting promise API // @return deferred supporting promise API
this.delete = function(_id) { this.remove = function(_id) {
url = self.endpoint; url = self.endpoint;
url += '/' + _id; url += '/' + _id;
return self._makeRequest({ return self._makeRequest({
@@ -475,7 +475,7 @@ _deleteDocument = function (del_doc, dataset) {
var cdb = new my.CouchDBWrapper(db_url, view_url); var cdb = new my.CouchDBWrapper(db_url, view_url);
if (view_url.search('_all_docs') !== -1) if (view_url.search('_all_docs') !== -1)
return cdb.delete(_id); return cdb.remove(_id);
else { else {
_id = model.get('_id').split('__')[0]; _id = model.get('_id').split('__')[0];
var jqxhr = cdb.get(_id); var jqxhr = cdb.get(_id);
@@ -484,7 +484,7 @@ _deleteDocument = function (del_doc, dataset) {
if (dataset.record_delete) if (dataset.record_delete)
old_doc = dataset.record_delete(del_doc, old_doc); old_doc = dataset.record_delete(del_doc, old_doc);
if (_.isNull(del_doc)) if (_.isNull(del_doc))
dfd.resolve(cdb.delete(_id)); // XXX is this the right thing to do? dfd.resolve(cdb.remove(_id)); // XXX is this the right thing to do?
else { else {
// couchdb uses _id to identify documents, Backbone models use id. // couchdb uses _id to identify documents, Backbone models use id.
// we should remove it before sending it to the server. // we should remove it before sending it to the server.

View File

@@ -79,7 +79,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
// //
// @param {Object} id id of object to delete // @param {Object} id id of object to delete
// @return deferred supporting promise API // @return deferred supporting promise API
this.delete = function(id) { this.remove = function(id) {
url = this.endpoint; url = this.endpoint;
url += '/' + id; url += '/' + id;
return makeRequest({ return makeRequest({
@@ -219,7 +219,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
else if (changes.updates.length >0) { else if (changes.updates.length >0) {
return es.upsert(changes.updates[0]); return es.upsert(changes.updates[0]);
} else if (changes.deletes.length > 0) { } else if (changes.deletes.length > 0) {
return es.delete(changes.deletes[0].id); return es.remove(changes.deletes[0].id);
} }
}; };
@@ -230,7 +230,7 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
var jqxhr = es.query(queryObj); var jqxhr = es.query(queryObj);
jqxhr.done(function(results) { jqxhr.done(function(results) {
var out = { var out = {
total: results.hits.total, total: results.hits.total
}; };
out.hits = _.map(results.hits.hits, function(hit) { out.hits = _.map(results.hits.hits, function(hit) {
if (!('id' in hit._source) && hit._id) { if (!('id' in hit._source) && hit._id) {

View File

@@ -37,7 +37,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
}); });
}; };
this.delete = function(doc) { this.remove = function(doc) {
var newdocs = _.reject(self.data, function(internalDoc) { var newdocs = _.reject(self.data, function(internalDoc) {
return (doc.id === internalDoc.id); return (doc.id === internalDoc.id);
}); });
@@ -52,7 +52,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
self.update(record); self.update(record);
}); });
_.each(changes.deletes, function(record) { _.each(changes.deletes, function(record) {
self.delete(record); self.remove(record);
}); });
dfd.resolve(); dfd.resolve();
return dfd.promise(); return dfd.promise();

67
src/ecma-fixes.js Normal file
View File

@@ -0,0 +1,67 @@
// This file adds in full array method support in browsers that don't support it
// see: http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-etc
// Add ECMA262-5 Array methods if not supported natively
if (!('indexOf' in Array.prototype)) {
Array.prototype.indexOf= function(find, i /*opt*/) {
if (i===undefined) i= 0;
if (i<0) i+= this.length;
if (i<0) i= 0;
for (var n= this.length; i<n; i++)
if (i in this && this[i]===find)
return i;
return -1;
};
}
if (!('lastIndexOf' in Array.prototype)) {
Array.prototype.lastIndexOf= function(find, i /*opt*/) {
if (i===undefined) i= this.length-1;
if (i<0) i+= this.length;
if (i>this.length-1) i= this.length-1;
for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */
if (i in this && this[i]===find)
return i;
return -1;
};
}
if (!('forEach' in Array.prototype)) {
Array.prototype.forEach= function(action, that /*opt*/) {
for (var i= 0, n= this.length; i<n; i++)
if (i in this)
action.call(that, this[i], i, this);
};
}
if (!('map' in Array.prototype)) {
Array.prototype.map= function(mapper, that /*opt*/) {
var other= new Array(this.length);
for (var i= 0, n= this.length; i<n; i++)
if (i in this)
other[i]= mapper.call(that, this[i], i, this);
return other;
};
}
if (!('filter' in Array.prototype)) {
Array.prototype.filter= function(filter, that /*opt*/) {
var other= [], v;
for (var i=0, n= this.length; i<n; i++)
if (i in this && filter.call(that, v= this[i], i, this))
other.push(v);
return other;
};
}
if (!('every' in Array.prototype)) {
Array.prototype.every= function(tester, that /*opt*/) {
for (var i= 0, n= this.length; i<n; i++)
if (i in this && !tester.call(that, this[i], i, this))
return false;
return true;
};
}
if (!('some' in Array.prototype)) {
Array.prototype.some= function(tester, that /*opt*/) {
for (var i= 0, n= this.length; i<n; i++)
if (i in this && tester.call(that, this[i], i, this))
return true;
return false;
};
}

View File

@@ -221,7 +221,7 @@ my.Graph = Backbone.View.extend({
horizontal: true, horizontal: true,
shadowSize: 0, shadowSize: 0,
barWidth: 0.8 barWidth: 0.8
}, }
}, },
columns: { columns: {
legend: legend, legend: legend,
@@ -242,9 +242,9 @@ my.Graph = Backbone.View.extend({
horizontal: false, horizontal: false,
shadowSize: 0, shadowSize: 0,
barWidth: 0.8 barWidth: 0.8
}, }
}, },
grid: { hoverable: true, clickable: true }, grid: { hoverable: true, clickable: true }
}; };
return optionsPerGraphType[typeId]; return optionsPerGraphType[typeId];
}, },
@@ -424,7 +424,7 @@ my.GraphControls = Backbone.View.extend({
addSeries: function (idx) { addSeries: function (idx) {
var data = _.extend({ var data = _.extend({
seriesIndex: idx, seriesIndex: idx,
seriesName: String.fromCharCode(idx + 64 + 1), seriesName: String.fromCharCode(idx + 64 + 1)
}, this.model.toTemplateJSON()); }, this.model.toTemplateJSON());
var htmls = Mustache.render(this.templateSeriesEditor, data); var htmls = Mustache.render(this.templateSeriesEditor, data);

View File

@@ -98,7 +98,7 @@ my.MultiView = Backbone.View.extend({
<div class="recline-data-explorer"> \ <div class="recline-data-explorer"> \
<div class="alert-messages"></div> \ <div class="alert-messages"></div> \
\ \
<div class="header"> \ <div class="header clearfix"> \
<div class="navigation"> \ <div class="navigation"> \
<div class="btn-group" data-toggle="buttons-radio"> \ <div class="btn-group" data-toggle="buttons-radio"> \
{{#views}} \ {{#views}} \
@@ -117,7 +117,6 @@ my.MultiView = Backbone.View.extend({
</div> \ </div> \
</div> \ </div> \
<div class="query-editor-here" style="display:inline;"></div> \ <div class="query-editor-here" style="display:inline;"></div> \
<div class="clearfix"></div> \
</div> \ </div> \
<div class="data-view-sidebar"></div> \ <div class="data-view-sidebar"></div> \
<div class="data-view-container"></div> \ <div class="data-view-container"></div> \

View File

@@ -220,7 +220,7 @@ test("write", function() {
equal(data._version, 2); equal(data._version, 2);
// delete // delete
var jqxhr = backend.delete(rec.id); var jqxhr = backend.remove(rec.id);
jqxhr.done(function(data) { jqxhr.done(function(data) {
ok(data.ok); ok(data.ok);
rec = null; rec = null;

View File

@@ -135,7 +135,7 @@ test('update and delete', function () {
equal(data.data[0].x, newVal); equal(data.data[0].x, newVal);
// Test Delete // Test Delete
data.delete(doc1); data.remove(doc1);
equal(data.data.length, 5); equal(data.data.length, 5);
equal(data.data[0].x, memoryData[1].x); equal(data.data[0].x, memoryData[1].x);
}); });