diff --git a/config.cordovabuild.xml b/config.cordovabuild.xml
index 7b5244e04..e9d7d943c 100644
--- a/config.cordovabuild.xml
+++ b/config.cordovabuild.xml
@@ -132,6 +132,9 @@
+
+
+
diff --git a/package.cordovabuild.json b/package.cordovabuild.json
index 4c9905a2b..c1929db37 100644
--- a/package.cordovabuild.json
+++ b/package.cordovabuild.json
@@ -40,6 +40,9 @@
"UPDATE_API": "https://api.ionicjs.com",
"MAX_STORE": "2"
},
+ "cordova-plugin-advanced-http": {
+ "OKHTTP_VERSION": "3.10.0"
+ },
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
@@ -59,6 +62,7 @@
"dependencies": {
"cordova-android": "^8.1.0",
"cordova-ios": "^5.1.1",
+ "cordova-plugin-advanced-http": "^2.4.1",
"cordova-plugin-app-version": "~0.1.9",
"cordova-plugin-customurlscheme": "~4.3.0",
"cordova-plugin-device": "~2.0.1",
diff --git a/www/index.html b/www/index.html
index d5b9dec65..36892db16 100644
--- a/www/index.html
+++ b/www/index.html
@@ -3,7 +3,7 @@
-
+
diff --git a/www/js/app.js b/www/js/app.js
index 78139071a..6340df40a 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -55,18 +55,21 @@ angular.module('emission', ['ionic',
throw "blank string instead of missing file on dynamically served app";
}
Logger.log("connectionConfigString = "+JSON.stringify(connectionConfig.data));
+ $rootScope.connectUrl = connectionConfig.data.connectUrl;
window.cordova.plugins.BEMConnectionSettings.setSettings(connectionConfig.data);
}).catch(function(err) {
// not displaying the error here since we have a backup
Logger.log("error "+JSON.stringify(err)+" while reading connection config, reverting to defaults");
window.cordova.plugins.BEMConnectionSettings.getDefaultSettings().then(function(defaultConfig) {
Logger.log("defaultConfig = "+JSON.stringify(defaultConfig));
+ $rootScope.connectUrl = defaultConfig.connectUrl;
window.cordova.plugins.BEMConnectionSettings.setSettings(defaultConfig);
}).catch(function(err) {
// displaying the error here since we don't have a backup
Logger.displayError("Error reading or setting connection defaults", err);
});
});
+ cordova.plugin.http.setDataSerializer('json');
});
console.log("Ending run");
})
diff --git a/www/js/diary/current.js b/www/js/diary/current.js
index 996f3a453..491047ebb 100644
--- a/www/js/diary/current.js
+++ b/www/js/diary/current.js
@@ -8,7 +8,7 @@
'emission.plugin.logger'])
.controller('CurrMapCtrl', function($scope, Config, $state, $timeout, $ionicActionSheet,leafletData,
- Logger, $window, PostTripManualMarker, CommHelper, $http, KVStore, $ionicPlatform, $translate) {
+ Logger, $window, PostTripManualMarker, CommHelper, KVStore, $ionicPlatform, $translate) {
console.log("controller CurrMapCtrl called from current.js");
var _map;
@@ -232,7 +232,9 @@
var getServerIncidents = function() {
Logger.log("Getting server incidents with call "+JSON.stringify(incidentServerCalldata));
- $http.post("https://e-mission.eecs.berkeley.edu/result/heatmap/incidents/timestamp", incidentServerCalldata).then(function(res){
+ CommHelper.getAggregateData("result/heatmap/incidents/timestamp", incidentServerCalldata)
+ .then(function(res){
+ $scope.$apply(function() {
Logger.log("Server incidents result is "+JSON.stringify(res));
// Need to remove existing markers before adding new ones
// https://github.com/e-mission/e-mission-phone/pull/263#issuecomment-322669042
@@ -241,6 +243,7 @@
if(res.data.incidents.length > 0) {
addIncidents(res.data.incidents, _map, _serverIncidentMarkers);
}
+ });
}, function(error){
Logger.log("Error when getting incidents");
Logger.log(JSON.stringify(error));
diff --git a/www/js/heatmap.js b/www/js/heatmap.js
index 66d52e7c4..c76f18247 100644
--- a/www/js/heatmap.js
+++ b/www/js/heatmap.js
@@ -4,8 +4,8 @@ angular.module('emission.main.heatmap',['ui-leaflet', 'emission.services',
'emission.plugin.logger', 'emission.incident.posttrip.manual',
'ng-walkthrough', 'nzTour', 'emission.plugin.kvstore'])
-.controller('HeatmapCtrl', function($scope, $ionicLoading, $ionicActionSheet, $http,
- leafletData, Logger, Config, PostTripManualMarker,
+.controller('HeatmapCtrl', function($scope, $ionicLoading, $ionicActionSheet,
+ leafletData, Logger, Config, PostTripManualMarker, CommHelper,
$window, nzTour, KVStore, $translate) {
$scope.mapCtrl = {};
@@ -44,11 +44,13 @@ angular.module('emission.main.heatmap',['ui-leaflet', 'emission.services',
sel_region: null
};
Logger.log("Sending data "+JSON.stringify(data));
- return $http.post("https://e-mission.eecs.berkeley.edu/result/heatmap/pop.route/local_date", data)
+ return CommHelper.getAggregateData("result/heatmap/pop.route/local_date", data)
.then(function(response) {
if (angular.isDefined(response.data.lnglat)) {
Logger.log("Got points in heatmap "+response.data.lnglat.length);
- $scope.showHeatmap(response.data.lnglat);
+ $scope.$apply(function() {
+ $scope.showHeatmap(response.data.lnglat);
+ });
} else {
Logger.log("did not find latlng in response data "+JSON.stringify(response.data));
}
@@ -240,7 +242,10 @@ angular.module('emission.main.heatmap',['ui-leaflet', 'emission.services',
// Don't set any layer - it will be filled in when the load completes
} else {
$ionicLoading.hide();
- if (angular.isDefined(selData) && angular.isDefined(selData.layer)) {
+ if (angular.isDefined(selData) &&
+ angular.isDefined(selData.layer) &&
+ angular.isDefined(selData.bounds) &&
+ selData.bounds.isValid()) {
selData.layer.addTo(map);
map.fitBounds(selData.bounds);
$scope.selData = selData;
@@ -286,11 +291,13 @@ angular.module('emission.main.heatmap',['ui-leaflet', 'emission.services',
sel_region: null
};
Logger.log("Sending data "+JSON.stringify(data));
- return $http.post("https://e-mission.eecs.berkeley.edu/result/heatmap/incidents/local_date", data)
+ return CommHelper.getAggregateData("result/heatmap/incidents/local_date", data)
.then(function(response) {
if (angular.isDefined(response.data.incidents)) {
- Logger.log("Got incidents"+response.data.incidents.length);
- $scope.showIncidents(response.data.incidents);
+ $scope.$apply(function() {
+ Logger.log("Got incidents"+response.data.incidents.length);
+ $scope.showIncidents(response.data.incidents);
+ });
} else {
Logger.log("did not find incidents in response data "+JSON.stringify(response.data));
}
diff --git a/www/js/metrics.js b/www/js/metrics.js
index bba469742..3b9cfa26c 100644
--- a/www/js/metrics.js
+++ b/www/js/metrics.js
@@ -11,7 +11,7 @@ angular.module('emission.main.metrics',['nvd3',
CommHelper, $window, $ionicPopup,
ionicDatePicker, $ionicPlatform,
FootprintHelper, CalorieCal, $ionicModal, $timeout, KVStore, CarbonDatasetHelper,
- $rootScope, $location, $state, ReferHelper, $http, Logger,
+ $rootScope, $location, $state, ReferHelper, Logger,
$translate) {
var lastTwoWeeksQuery = true;
var first = true;
@@ -419,9 +419,8 @@ angular.module('emission.main.metrics',['nvd3',
delete clonedData.metric;
clonedData.metric_list = [DURATION, MEDIAN_SPEED, COUNT, DISTANCE];
clonedData.is_return_aggregate = true;
- var getMetricsResult = $http.post(
- "https://e-mission.eecs.berkeley.edu/result/metrics/timestamp",
- clonedData)
+ var getMetricsResult = CommHelper.getAggregateData(
+ "result/metrics/timestamp", clonedData)
return getMetricsResult;
}
@@ -508,16 +507,16 @@ angular.module('emission.main.metrics',['nvd3',
$scope.uictrl.hasAggr = true;
if (angular.isDefined($scope.chartDataAggr)) { //Only have to check one because
// Restore the $apply if/when we go away from $http
- // $scope.$apply(function() {
+ $scope.$apply(function() {
if (!$scope.uictrl.showMe) {
$scope.showCharts($scope.chartDataAggr);
}
- // })
+ })
} else {
- // $scope.$apply(function() {
+ $scope.$apply(function() {
$scope.showCharts([]);
console.log("did not find aggregate result in response data "+JSON.stringify(results[2]));
- // });
+ });
}
})
.catch(function(error) {
diff --git a/www/js/services.js b/www/js/services.js
index 33a324f7d..716660f7d 100644
--- a/www/js/services.js
+++ b/www/js/services.js
@@ -3,7 +3,7 @@
angular.module('emission.services', ['emission.plugin.logger',
'emission.plugin.kvstore'])
-.service('CommHelper', function($http) {
+.service('CommHelper', function($rootScope) {
var getConnectURL = function(successCallback, errorCallback) {
window.cordova.plugins.BEMConnectionSettings.getSettings(
function(settings) {
@@ -159,6 +159,26 @@ angular.module('emission.services', ['emission.plugin.logger',
window.cordova.plugins.BEMServerComm.getUserPersonalData("/pipeline/get_complete_ts", resolve, reject);
});
};
+
+ // host is automatically read from $rootScope.connectUrl, which is set in app.js
+ this.getAggregateData = function(path, data) {
+ return new Promise(function(resolve, reject) {
+ const full_url = $rootScope.connectUrl+"/"+path;
+ console.log("getting aggregate data without user authentication from "
+ + full_url +" with arguments "+JSON.stringify(data));
+ const options = {
+ method: 'post',
+ data: data,
+ responseType: 'json'
+ }
+ cordova.plugin.http.sendRequest(full_url, options,
+ function(response) {
+ resolve(response);
+ }, function(error) {
+ reject(error);
+ });
+ });
+ };
})
.service('ReferHelper', function($http) {