From fc72fb04691621ab9bd86542e448fb8f1969540b Mon Sep 17 00:00:00 2001 From: Cristhian Parra Date: Sun, 5 Nov 2017 20:23:39 -0300 Subject: [PATCH 1/5] Fix for #85 and #90 --- www/js/controllers/profileCtrl.js | 2 ++ www/js/services/user.js | 1 + 2 files changed, 3 insertions(+) diff --git a/www/js/controllers/profileCtrl.js b/www/js/controllers/profileCtrl.js index 888888f..051ad91 100644 --- a/www/js/controllers/profileCtrl.js +++ b/www/js/controllers/profileCtrl.js @@ -4,6 +4,8 @@ angular.module('starter.controllers') $ionicLoading.show({hideOnStateChange: true}) User.current().then(function(user) { + console.log("Retrieved current User: "+JSON.stringify(user)) + user.data = JSON.parse(user.data) $scope.user = user.data.user; return User.save(user.data.user) }).catch(function(res) { diff --git a/www/js/services/user.js b/www/js/services/user.js index df2dfff..49b1e83 100644 --- a/www/js/services/user.js +++ b/www/js/services/user.js @@ -69,6 +69,7 @@ angular.module('starter.services') current: function () { return this.getToken().then(function (token) { + console.log("getToken: "+token) return cordovaHTTP.get(denguechat.env.baseURL + 'sessions/current', {}, { 'Authorization': 'Bearer ' + token } ); From f25535e1541fb9bebdaa887cd3d01c7c15f905a9 Mon Sep 17 00:00:00 2001 From: Cristhian Parra Date: Sun, 5 Nov 2017 21:07:45 -0300 Subject: [PATCH 2/5] Fix for post getting stuck loading refs #88 --- www/js/controllers/postsCtrl.js | 48 +++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/www/js/controllers/postsCtrl.js b/www/js/controllers/postsCtrl.js index bb01f34..2f4ca24 100644 --- a/www/js/controllers/postsCtrl.js +++ b/www/js/controllers/postsCtrl.js @@ -100,23 +100,43 @@ angular.module('starter.controllers') $scope.createPost = function() { $ionicLoading.show({template: "
Creando post...", hideOnStateChange: true}) - - $scope.post.created_at = new Date() - doc_id = Post.documentID($scope.post.user, $scope.post) - Post.save(doc_id, $scope.post, {remote: true, synced: false}).then(function(response) { - return Post.get(doc_id).then(function(doc) { - $scope.posts.unshift(doc) - $scope.post = {}; - $ionicLoading.hide().then(function() { - $scope.closeModal() + if (!$scope.post.user || !$scope.post.user.id) { + User.get().then(function(user) { + $scope.post.user_id = user.id + $scope.post.user = user + $scope.post.neighborhood_id = user.neighborhood.id + doc_id = Post.documentID($scope.post.user, $scope.post) + Post.save(doc_id, $scope.post, {remote: true, synced: false}).then(function(response) { + return Post.get(doc_id).then(function(doc) { + $scope.posts.unshift(doc) + $scope.post = {}; + $ionicLoading.hide().then(function() { + $scope.closeModal() + }) + }) + }).catch(function(res) { + $scope.$emit(denguechat.error, res) + }).finally(function() { + $ionicLoading.hide() }) }) - }).catch(function(res) { - $scope.$emit(denguechat.error, res) - }).finally(function() { - $ionicLoading.hide() - }) + } else { + doc_id = Post.documentID($scope.post.user, $scope.post) + Post.save(doc_id, $scope.post, {remote: true, synced: false}).then(function(response) { + return Post.get(doc_id).then(function(doc) { + $scope.posts.unshift(doc) + $scope.post = {}; + $ionicLoading.hide().then(function() { + $scope.closeModal() + }) + }) + }).catch(function(res) { + $scope.$emit(denguechat.error, res) + }).finally(function() { + $ionicLoading.hide() + }) + } } From b64d51543773c3caac4623adf51ac3c763416568 Mon Sep 17 00:00:00 2001 From: Cristhian Parra Date: Sun, 5 Nov 2017 21:26:38 -0300 Subject: [PATCH 3/5] Final fix for #85 and #88 --- www/js/app.js | 3 ++- www/js/controllers/profileCtrl.js | 2 +- www/js/services/user.js | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index f1435a5..28be5cd 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -21,7 +21,7 @@ angular.module('starter', [ }) - .run(function ($ionicPlatform, $rootScope, $ionicModal, User, $state, $ionicHistory, + .run(function ($ionicPlatform, $rootScope, $ionicModal, User, $state, $ionicHistory, Pouch, Post, Location, Visit, Inspection, $ionicSideMenuDelegate) { cordova.plugin.http.setDataSerializer('json'); Pouch.createLocationNeighborhoodView(); @@ -159,6 +159,7 @@ angular.module('starter', [ }, function (isOpen) { if (isOpen == true) { User.current().then(function (user) { + user.data = JSON.parse(user.data) $rootScope.user = user.data.user; return User.save(user.data.user) }).catch(function () { diff --git a/www/js/controllers/profileCtrl.js b/www/js/controllers/profileCtrl.js index 051ad91..9b63a44 100644 --- a/www/js/controllers/profileCtrl.js +++ b/www/js/controllers/profileCtrl.js @@ -4,11 +4,11 @@ angular.module('starter.controllers') $ionicLoading.show({hideOnStateChange: true}) User.current().then(function(user) { - console.log("Retrieved current User: "+JSON.stringify(user)) user.data = JSON.parse(user.data) $scope.user = user.data.user; return User.save(user.data.user) }).catch(function(res) { + console.log("Error when getting current user: "+JSON.stringify(res)) $scope.$emit(denguechat.error, res) }).finally(function() { $ionicLoading.hide() diff --git a/www/js/services/user.js b/www/js/services/user.js index 49b1e83..df2dfff 100644 --- a/www/js/services/user.js +++ b/www/js/services/user.js @@ -69,7 +69,6 @@ angular.module('starter.services') current: function () { return this.getToken().then(function (token) { - console.log("getToken: "+token) return cordovaHTTP.get(denguechat.env.baseURL + 'sessions/current', {}, { 'Authorization': 'Bearer ' + token } ); From e17cb6e84c2e36c0df2dc846063db2dc54219c3d Mon Sep 17 00:00:00 2001 From: Cristhian Parra Date: Sun, 5 Nov 2017 22:18:21 -0300 Subject: [PATCH 4/5] Added geolocation plugin to generate the right permissions --- config.xml | 9 +++++++++ package-lock.json | 5 +++++ package.json | 12 +++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/config.xml b/config.xml index 6575d1d..6c54148 100644 --- a/config.xml +++ b/config.xml @@ -96,6 +96,15 @@ + + + + + + + + + diff --git a/package-lock.json b/package-lock.json index b7cbd81..dc046df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -890,6 +890,11 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-file/-/cordova-plugin-file-4.3.3.tgz", "integrity": "sha1-AS6Xqhr7kfhJFuY0G1SDZtI96bk=" }, + "cordova-plugin-mauron85-background-geolocation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/cordova-plugin-mauron85-background-geolocation/-/cordova-plugin-mauron85-background-geolocation-2.3.1.tgz", + "integrity": "sha1-knEy0Q1q96ODk8c4PkNpSW57UlU=" + }, "cordova-plugin-sqlite-2": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/cordova-plugin-sqlite-2/-/cordova-plugin-sqlite-2-1.0.4.tgz", diff --git a/package.json b/package.json index ecdbfc4..944935d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "cordova-plugin-crosswalk-certificate": "^2.0.1", "cordova-plugin-crosswalk-webview": "^2.3.0", "cordova-plugin-file": "^4.3.3", + "cordova-plugin-mauron85-background-geolocation": "^2.3.1", "cordova-plugin-sqlite-2": "^1.0.4", "cordova-plugin-sslcertificatechecker": "^5.1.0", "cordova-plugin-whitelist": "^1.3.2", @@ -73,7 +74,16 @@ "cordova-plugin-sqlite-2": {}, "cordova-plugin-whitelist": {}, "cordova-plugin-sslcertificatechecker": {}, - "cordova-plugin-advanced-http": {} + "cordova-plugin-advanced-http": {}, + "cordova-plugin-mauron85-background-geolocation": { + "ICON": "@mipmap/icon", + "SMALL_ICON": "@mipmap/icon", + "ACCOUNT_NAME": "@string/app_name", + "ACCOUNT_LABEL": "@string/app_name", + "ACCOUNT_TYPE": "$PACKAGE_NAME.account", + "CONTENT_AUTHORITY": "$PACKAGE_NAME", + "ALWAYS_USAGE_DESCRIPTION": "This app requires background location tracking" + } } } } \ No newline at end of file From 0c9ad212fb26eb8bff9d89b3bc7e291d6e88b2ab Mon Sep 17 00:00:00 2001 From: Cristhian Parra Date: Sun, 5 Nov 2017 22:18:46 -0300 Subject: [PATCH 5/5] Fixed registrations endpoint to point the new endpoint created --- www/js/services/user.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/www/js/services/user.js b/www/js/services/user.js index df2dfff..40cf24f 100644 --- a/www/js/services/user.js +++ b/www/js/services/user.js @@ -46,9 +46,11 @@ angular.module('starter.services') }, create: function (username, password) { - return cordovaHTTP.post(denguechat.env.baseURL + 'registrations', { - username: username, - password: password + return cordovaHTTP.post(denguechat.env.baseURL + 'sessions/registrations', { + user: { + username: username, + password: password + }, }, { 'content-type': 'application/json'}); },