From 2a88a7ab06b208ade6443d20b10a1616c1294135 Mon Sep 17 00:00:00 2001 From: sean barclay Date: Tue, 14 Apr 2015 23:47:13 -0700 Subject: [PATCH 1/3] leveraging cloudant query to get docs back in the correct order based on properties.timestamp. --- _attachments/script/app.js | 63 ++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/_attachments/script/app.js b/_attachments/script/app.js index 88e81f1..4c75172 100755 --- a/_attachments/script/app.js +++ b/_attachments/script/app.js @@ -279,23 +279,8 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute']) /* triggered from velocity callback within the animation module `enter` hook */ $scope.transEnter = function() { - var db = pouchResult; - var _len; - - // get the length of docs and store it in _len - db.info(function(err, info) { - _len = info.doc_count; - }); - - // use alldocs to get the object rows, then run a loop to draw on the map. - db.allDocs({ - include_docs: true, - endkey: "_" - }, function(err, response) { - for (var i = 0; i < _len - 1; i++) { - updateMovingLayer(response.rows[i].doc); - }; - }) + var db = pouchResult.$$state.value.docs; + var _len = db.length; /* instantiate Leaflet map */ mapResult = new L.Map('mapResult'); @@ -356,9 +341,17 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute']) }).addTo(mapResult); function updateMovingLayer(doc) { + // console.log(doc.properties.timestamp); + // console.log(doc.geometry.coordinates); movementLayer.addData(doc); mapResult.fitBounds(movementLayer.getBounds()); } + + /* Run loop to take docs and begin drawing map points*/ + for (var i = 0; i < _len - 1; i++) { + updateMovingLayer(db[i]); + }; + }; /* triggered from velocity callback within the animation module `enter` hook */ @@ -377,12 +370,42 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute']) /* cloudant db storage for result map */ -.factory('pouchResult', ["remotedb", function(remotedb) { - var db = new PouchDB(remotedb); - return db; +// .factory('pouchResult', ["remotedb", function(remotedb) { +// var db = new PouchDB(remotedb); +// return db; +// }]) +/* cloudant db storage for result map */ +.factory('pouchResult', ['remotedb', '$http', function(remotedb, $http) { + + function handleSuccess( response ) { + console.log(response.data); + return( response.data ); + }; + + function handleError( response ) { + console.log("err"); + return( response.data ); + }; + + var request = $http({ + method: "post", + url: remotedb +'/_find', + + data: { + "selector": {"properties.timestamp": {"$gt":1}}, + "sort": [{"properties.timestamp": "asc"}], + // "limit": 400, + "skip": 0 + } + } + ); + + return (request.then( handleSuccess, handleError)); }]) + + /* Directive used on controller items to allow for multiple trans in/out */ .directive('animationdirective', ['$animate', '$timeout', function($animate, $timeout) { From e6a00aec2c85804bdbaf11cd14e505b02723ec52 Mon Sep 17 00:00:00 2001 From: Raj Singh Date: Wed, 15 Apr 2015 09:48:16 -0400 Subject: [PATCH 2/3] modified app.js line 386 to get back a more verbose error message --- _attachments/script/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_attachments/script/app.js b/_attachments/script/app.js index 4c75172..7e0c3a8 100755 --- a/_attachments/script/app.js +++ b/_attachments/script/app.js @@ -7,7 +7,7 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute']) .value("map", {}) .value("watchID", null) - .value("remotedb", 'https://USERNAME:PASSWORD@USERNAME.cloudant.com/locationtracker') + .value("remotedb", 'https://rajsingh:genjisan@rajsingh.cloudant.com/locationtracker') .value("num", 0) .value("successMessage", {}) .value("errorMessage", "error") @@ -383,7 +383,7 @@ angular.module('locationTrackingApp', ['ngAnimate', 'ngRoute']) }; function handleError( response ) { - console.log("err"); + console.log("err: "+JSON.stringify(response.data)); return( response.data ); }; From ea7ffdb7bf4cfe3f0676dc2e1bf7d89f47414ea7 Mon Sep 17 00:00:00 2001 From: Raj Singh Date: Tue, 15 Sep 2015 13:21:48 -0400 Subject: [PATCH 3/3] now using latest pouchdb via CDN --- _attachments/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_attachments/index.html b/_attachments/index.html index a7a4b52..9a00f4e 100755 --- a/_attachments/index.html +++ b/_attachments/index.html @@ -25,7 +25,7 @@ - +