diff --git a/demos/couchdb_multiview/app.js b/demos/couchdb_multiview/app.js new file mode 100755 index 00000000..4929ff64 --- /dev/null +++ b/demos/couchdb_multiview/app.js @@ -0,0 +1,90 @@ +jQuery(function($) { + window.dataExplorer = null; + window.explorerDiv = $('.data-explorer-here'); + + // This is some fancy stuff to allow configuring the multiview from + // parameters in the query string + // + // For more on state see the view documentation. + var state = recline.View.parseQueryString(decodeURIComponent(window.location.search)); + if (state) { + _.each(state, function(value, key) { + try { + value = JSON.parse(value); + } catch(e) {} + state[key] = value; + }); + } else { + state.url = 'demo'; + } + +//Add your couchdb here!!! +//"couchdb" is what a choose for my reverse proxy. look up apache reverse or nginx reverse proxy. you need to set this up before you can connect your db +var dataset = new recline.Model.Dataset({ + db_url: '/couchdb/yourcouchdb', + view_url: '/couchdb/yourcouchdb/_design/yourdesigndoc/_view/yourview', + backend: 'couchdb', + query_options: { + 'key': '_id' + } +}); + + +dataset.fetch().done(function(dataset) { + console.log('records: ' + dataset.records); +}); + + createExplorer(dataset, state); +}); + +// make Explorer creation / initialization in a function so we can call it +// again and again +var createExplorer = function(dataset, state) { + // remove existing data explorer view + var reload = false; + if (window.dataExplorer) { + window.dataExplorer.remove(); + reload = true; + } + window.dataExplorer = null; + var $el = $('
'); + $el.appendTo(window.explorerDiv); + + var views = [ + { + id: 'grid', + label: 'Grid', + view: new recline.View.SlickGrid({ + model: dataset + }), + }, + { + id: 'graph', + label: 'Graph', + view: new recline.View.Graph({ + model: dataset + }), + }, + { + id: 'map', + label: 'Map', + view: new recline.View.Map({ + model: dataset + }), + }, + { + id: 'transform', + label: 'Transform', + view: new recline.View.Transform({ + model: dataset + }) + } + ]; + + window.dataExplorer = new recline.View.MultiView({ + model: dataset, + el: $el, + state: state, + views: views + }); +} diff --git a/demos/couchdb_multiview/index.html b/demos/couchdb_multiview/index.html new file mode 100755 index 00000000..6fd1ab6b --- /dev/null +++ b/demos/couchdb_multiview/index.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/index.html b/demos/index.html index 35e95ada..9b49e6b8 100644 --- a/demos/index.html +++ b/demos/index.html @@ -13,6 +13,10 @@ root: ../You will need to modify the "app.js" file in "demos/couchdb_multiview" + to connect to your couch database. Also, don't forget to configure your + reverse proxy or proxy so you can connect to your database.
See the integrated multiview in action on a sample dataset - the multiview incorporates most the main views diff --git a/src/backend.couchdb.js b/src/backend.couchdb.js old mode 100644 new mode 100755 index 3fa930f2..4634ef0e --- a/src/backend.couchdb.js +++ b/src/backend.couchdb.js @@ -2,8 +2,8 @@ this.recline = this.recline || {}; this.recline.Backend = this.recline.Backend || {}; this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {}; -(function($, my) { - my.__type__ = 'couchdb'; +(function($, my) { +my.__type__ = 'couchdb'; // ## CouchDB Wrapper // @@ -11,9 +11,10 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {}; // @param {String} endpoint: url for CouchDB database, e.g. for Couchdb running // on localhost:5984 with database // ckan-std it would be: // - //
http://localhost:5984/ckan-std// // TODO Add user/password arguments for couchdb authentication support. + // + // See the example how to use this in: "demos/couchdb_multiview" my.CouchDBWrapper = function(db_url, view_url, options) { var self = this; self.endpoint = db_url; @@ -150,17 +151,16 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {}; // // Backbone connector for a CouchDB backend. // - // Usage: - // - // var backend = new recline.Backend.CouchDB(); + // Usage: (also see demos/couchdb_multiview) // var dataset = new recline.Model.Dataset({ - // db_url: '/couchdb/mydb', - // view_url: '/couchdb/mydb/_design/design1/_views/view1', - // query_options: { - // 'key': 'some_document_key' - // } + // db_url: '/couchdb/iid', + // view_url: '/couchdb/iid/_design/latlon/_view/latlon', + // backend: 'couchdb', + // query_options: { + // 'key': '_id' + // } // }); - // backend.fetch(dataset.toJSON()); + // // backend.query(query, dataset.toJSON()).done(function () { ... }); // // Alternatively: @@ -494,6 +494,6 @@ _deleteDocument = function (del_doc, dataset) { dfd.reject(args); }); return dfd.promise(); + } }; - }(jQuery, this.recline.Backend.CouchDB));