Skip to content

Commit

Permalink
Merge pull request #179 from shankari/remove_unncessary_plugins
Browse files Browse the repository at this point in the history
Remove unncessary plugins
  • Loading branch information
shankari authored Nov 3, 2016
2 parents 9619f47 + 58b0d63 commit ae55d66
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 44 deletions.
15 changes: 1 addition & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard",
{
"locator": "https://github.com/litehelpers/Cordova-sqlite-storage.git",
"id": "cordova-sqlite-storage"
},
{
"locator": "https://github.com/e-mission/cordova-connection-settings.git",
"id": "edu.berkeley.eecs.emission.cordova.settings"
Expand All @@ -54,10 +49,6 @@
"locator": "https://github.com/e-mission/cordova-jwt-auth.git",
"id": "edu.berkeley.eecs.emission.cordova.auth"
},
{
"locator": "https://github.com/e-mission/cordova-stats.git",
"id": "edu.berkeley.eecs.emission.cordova.clientstats"
},
{
"locator": "https://github.com/e-mission/e-mission-data-collection.git",
"id": "edu.berkeley.eecs.emission.cordova.datacollection"
Expand All @@ -72,10 +63,6 @@
"locator": "https://github.com/e-mission/cordova-server-sync.git",
"id": "edu.berkeley.eecs.emission.cordova.serversync"
},
{
"locator": "https://github.com/apla/me.apla.cordova.app-preferences",
"id": "cordova-plugin-app-preferences"
},
"ionic-plugin-deploy",
"cordova-plugin-crosswalk-webview",
{
Expand All @@ -95,4 +82,4 @@
"ios",
"android"
]
}
}
1 change: 1 addition & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/stats/clientstats.js"></script>
<script src="js/splash/referral.js"></script>
<script src="js/splash/customURL.js"></script>
<script src="js/splash/updatecheck.js"></script>
Expand Down
34 changes: 22 additions & 12 deletions www/js/common/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module('emission.main.common.services', [])

var db = window.cordova.plugins.BEMUserCache;
var selKey = "common-trips";

commonGraph.createEmpty = function() {
return { 'user_id': 'unknown',
'common_trips': [],
Expand All @@ -18,19 +18,19 @@ angular.module('emission.main.common.services', [])
};

commonGraph.updateCurrent = function() {
db.getDocument(selKey).then(function(entryList) {
db.getDocument(selKey, false).then(function(entryList) {
try{
var cmGraph = entryList;
if (db.isEmptyDoc(cmGraph)) {
cmGraph = createEmpty();
cmGraph = commonGraph.createEmpty();
}
} catch(err) {
window.Logger.log("Error "+err+" while parsing common trip data");
// If there was an error in parsing the current common trips, and
// there is no existing cached common trips, we create a blank
// version so that other things don't crash
if (angular.isUndefined(cmGraph)) {
cmGraph = createEmpty();
cmGraph = commonGraph.createEmpty();
}
}
commonGraph.data.graph = cmGraph;
Expand All @@ -46,11 +46,21 @@ angular.module('emission.main.common.services', [])
* Returns the common trip corresponding to the specified tripId
*/
commonGraph.trip2Common = function(tripId) {
return commonGraph.data.trip2CommonMap[tripId];
if (angular.isDefined(commonGraph.data)) {
return commonGraph.data.trip2CommonMap[tripId];
} else {
// return undefined because that is what the invoking locations expect
return;
}
};

commonGraph.place2Common = function(placeId) {
return commonGraph.data.place2CommonMap[placeId];
if (angular.isDefined(commonGraph.data)) {
return commonGraph.data.place2CommonMap[placeId];
} else {
// return undefined because that is what the invoking locations expect
return;
}
};

commonGraph.time_fns = {};
Expand All @@ -60,7 +70,7 @@ angular.module('emission.main.common.services', [])
return localTime.hour;
}
var hourMap = binEntries(timeArray, binFn);
return hourMap;
return hourMap;
}
commonGraph.time_fns.getMostFrequentHour = function(timeArray) {
var binFn = function(localTime) {
Expand Down Expand Up @@ -162,7 +172,7 @@ angular.module('emission.main.common.services', [])
obj.start_displayName = name;
break;
}

};
var responseListener1 = function(data) {
var address = data["address"];
Expand All @@ -183,11 +193,11 @@ angular.module('emission.main.common.services', [])
}
console.log("got response, setting display name to "+name);
obj.end_displayName = name;

};
switch (mode) {
case 'place':
var url = "http://nominatim.openstreetmap.org/reverse?format=json&lat=" + obj.geometry.coordinates[1]
var url = "http://nominatim.openstreetmap.org/reverse?format=json&lat=" + obj.geometry.coordinates[1]
+ "&lon=" + obj.geometry.coordinates[0];
$http.get(url).then(function(response) {
console.log("while reading data from nominatim, status = "+response.status
Expand All @@ -200,7 +210,7 @@ angular.module('emission.main.common.services', [])
case 'cplace':
var url = "http://nominatim.openstreetmap.org/reverse?format=json&lat=" + obj.location.coordinates[1]
+ "&lon=" + obj.location.coordinates[0];

$http.get(url).then(function(response) {
console.log("while reading data from nominatim, status = "+response.status
+" data = "+JSON.stringify(response.data));
Expand Down Expand Up @@ -229,7 +239,7 @@ angular.module('emission.main.common.services', [])
responseListener1(response.data);
}, function(error) {
console.log("while reading data from nominatim, error = "+error);
});
});
break;
}
};
Expand Down
17 changes: 12 additions & 5 deletions www/js/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
angular.module('emission.main.control',['emission.services',
'emission.splash.startprefs',
'emission.splash.updatecheck',
'emission.main.metrics.factory'])
'emission.main.metrics.factory',
'emission.stats.clientstats',
'angularLocalStorage'])

.controller('ControlCtrl', function($scope, $window, $ionicScrollDelegate,
$state, $ionicPopup, $ionicActionSheet, $ionicPopover,
$rootScope, StartPrefs, ControlHelper, UpdateCheck,
CalorieCal) {
$rootScope, storage, StartPrefs, ControlHelper, UpdateCheck,
CalorieCal, ClientStats) {
$scope.emailLog = ControlHelper.emailLog;
$scope.dark_theme = $rootScope.dark_theme;
$scope.userData = []
Expand Down Expand Up @@ -173,7 +175,7 @@ angular.module('emission.main.control',['emission.services',
$scope.showMap = function() {
$state.go("root.main.map");
}
$scope.getState = function() {
$scope.getState = function() {
ControlHelper.getState().then(function(response) {
$scope.$apply(function() {
$scope.settings.collect.state = response;
Expand All @@ -186,7 +188,8 @@ angular.module('emission.main.control',['emission.services',
$scope.nukeUserCache = function() {
$ionicPopup.alert({template: "WATCH OUT! If there is unsynced data, you may lose it. If you want to keep the data, use 'Force Sync' before doing this"})
.then(function(result) {
if (result) {
if (result) {
storage.clearAll();
window.cordova.plugins.BEMUserCache.clearAll()
.then(function(result) {
$scope.$apply(function() {
Expand Down Expand Up @@ -253,6 +256,10 @@ angular.module('emission.main.control',['emission.services',
};

$scope.forceSync = function() {
ClientStats.addEvent(ClientStats.getStatKeys().BUTTON_FORCE_SYNC).then(
function() {
console.log("Added "+ClientStats.getStatKeys().BUTTON_FORCE_SYNC+" event");
});
ControlHelper.forceSync().then(function(response) {
$ionicPopup.alert({template: 'success -> '+response});
}, function(error) {
Expand Down
10 changes: 9 additions & 1 deletion www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
angular.module('emission.controllers', ['emission.splash.updatecheck',
'emission.splash.startprefs',
'emission.splash.referral',
'emission.stats.clientstats',
'customURLScheme'])

.controller('RootCtrl', function($scope) {})

.controller('DashCtrl', function($scope) {})

.controller('SplashCtrl', function($scope, $state, $interval, $rootScope,
CustomURLScheme, UpdateCheck, StartPrefs, ReferralHandler) {
CustomURLScheme, UpdateCheck, StartPrefs, ReferralHandler, ClientStats) {
console.log('SplashCtrl invoked');
// alert("attach debugger!");
CustomURLScheme.onLaunch(function(event, url){
console.log("GOT URL:"+url);

var kvList = ReferralHandler.parseURL(url);
// There are 3 types of users in total
if (kvList.route == 'join') {
Expand All @@ -35,16 +37,22 @@ angular.module('emission.controllers', ['emission.splash.updatecheck',
UpdateCheck.checkForUpdates();
$rootScope.checkedForUpdates = true;
} */
ClientStats.addReading(ClientStats.getStatKeys().STATE_CHANGED,
fromState.name + '-2-' + toState.name).then(function() {}, function() {});
});
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error){
console.log("Error "+error+" while changing state from "+JSON.stringify(fromState)
+" to "+JSON.stringify(toState));
ClientStats.addError(ClientStats.getStatKeys().STATE_CHANGED,
fromState.name + '-2-' + toState.name+ "_" + error).then(function() {}, function() {});
});
$rootScope.$on('$stateNotFound',
function(event, unfoundState, fromState, fromParams){
console.log("unfoundState.to = "+unfoundState.to); // "lazy.state"
console.log("unfoundState.toParams = " + unfoundState.toParams); // {a:1, b:2}
console.log("unfoundState.options = " + unfoundState.options); // {inherit:false} + default options
ClientStats.addError(ClientStats.getStatKeys().STATE_CHANGED,
fromState.name + '-2-' + unfoundState.name).then(function() {}, function() {});
});

var isInList = function(element, list) {
Expand Down
1 change: 0 additions & 1 deletion www/js/diary/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ angular.module('emission.main.diary.list',['ui-leaflet',
data.leafletObject.invalidateSize();
});

StatusBar.styleDefault();
var readAndUpdateForDay = function(day) {
// This just launches the update. The update can complete in the background
// based on the time when the database finishes reading.
Expand Down
2 changes: 1 addition & 1 deletion www/js/diary/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ angular.module('emission.main.diary.services', ['emission.services', 'emission.m
$ionicLoading.show({
template: 'Reading from cache...'
});
window.cordova.plugins.BEMUserCache.getDocument(getKeyForDate(day))
window.cordova.plugins.BEMUserCache.getDocument(getKeyForDate(day), false)
.then(function (timelineDoc) {
if (!window.cordova.plugins.BEMUserCache.isEmptyDoc(timelineDoc)) {
var tripList = timelineDoc;
Expand Down
12 changes: 10 additions & 2 deletions www/js/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
return getMetricsResult;
}

var isValidNumber = function(number) {
if (angular.isDefined(Number.isFinite)) {
return Number.isFinite(number);
} else {
return !isNaN(number);
}
}

var getMetrics = function() {
$ionicLoading.show({
template: 'Loading...'
Expand Down Expand Up @@ -600,7 +608,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
// TODO: Refactor this so that we can filter out bad values ahead of time
// instead of having to work around it here
var calorieCalculation = Math.abs(Math.round((lastWeekCalories/twoWeeksAgoCalories) * 100 - 100));
if (Number.isFinite(calorieCalculation)) {
if (isValidNumber(calorieCalculation)) {
$scope.caloriesData.changeInPercentage = calorieCalculation + "%";
if(lastWeekCalories > twoWeeksAgoCalories){
$scope.caloriesData.change = " increase over a week";
Expand Down Expand Up @@ -697,7 +705,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date

// TODO: Refactor this so that we can filter out bad values ahead of time
// instead of having to work around it here
if (Number.isFinite(calculation)) {
if (isValidNumber(calculation)) {
if(lastWeekCarbonInt[0] > twoWeeksAgoCarbonInt[0]){
$scope.carbonData.change = " increase over a week";
$scope.carbonUp = true;
Expand Down
18 changes: 11 additions & 7 deletions www/js/recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ angular.module('emission.main.recent', ['ngCordova', 'emission.services'])
$scope.logCtrl = {};

$scope.refreshEntries = function() {
window.Logger.getMaxIndex(function(maxIndex) {
window.Logger.getMaxIndex().then(function(maxIndex) {
console.log("maxIndex = "+maxIndex);
$scope.logCtrl.currentStart = maxIndex;
$scope.logCtrl.gotMaxIndex = true;
Expand All @@ -46,8 +46,8 @@ angular.module('emission.main.recent', ['ngCordova', 'emission.services'])

$scope.addEntries = function() {
console.log("calling addEntries");
window.Logger.getMessagesFromIndex($scope.logCtrl.currentStart, RETRIEVE_COUNT,
function(entryList) {
window.Logger.getMessagesFromIndex($scope.logCtrl.currentStart, RETRIEVE_COUNT)
.then(function(entryList) {
$scope.$apply($scope.processEntries(entryList));
console.log("entry list size = "+$scope.entries.length);
console.log("Broadcasting infinite scroll complete");
Expand All @@ -64,6 +64,7 @@ angular.module('emission.main.recent', ['ngCordova', 'emission.services'])
$scope.processEntries = function(entryList) {
for (i = 0; i < entryList.length; i++) {
var currEntry = entryList[i];
currEntry.fmt_time = moment.unix(currEntry.ts).format("llll");
$scope.entries.push(currEntry);
}
if (entryList.length == 0) {
Expand Down Expand Up @@ -182,20 +183,23 @@ angular.module('emission.main.recent', ['ngCordova', 'emission.services'])
usercacheFn = $scope.config.key_data_mapping[$scope.selected.key]["fn"]
usercacheKey = $scope.config.key_data_mapping[$scope.selected.key]["key"]
}
usercacheFn(usercacheKey, function(entryList) {
usercacheFn(usercacheKey).then(function(entryList) {
$scope.entries = [];
$scope.$apply(function() {
for (i = 0; i < entryList.length; i++) {
// $scope.entries.push({metadata: {write_ts: 1, write_fmt_time: "1"}, data: "1"})
var currEntry = entryList[i];
currEntry.data = JSON.stringify(JSON.parse(currEntry.data), null, 2);
currEntry.metadata.write_fmt_time = moment.unix(currEntry.metadata.write_ts)
.tz(currEntry.metadata.time_zone)
.format("llll");
currEntry.data = JSON.stringify(currEntry.data, null, 2);
// window.Logger.log(window.Logger.LEVEL_DEBUG,
// "currEntry.data = "+currEntry.data);
$scope.entries.push(currEntry);
// This should really be within a try/catch/finally block
$scope.$broadcast('scroll.refreshComplete');
}
})
// This should really be within a try/catch/finally block
$scope.$broadcast('scroll.refreshComplete');
}, function(error) {
$ionicPopup.alert({template: JSON.stringify(error)})
.then(function(res) {console.log("finished showing alert");});
Expand Down
2 changes: 1 addition & 1 deletion www/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ angular.module('emission.services', [])
};

this.getConsentDocument = function() {
return window.cordova.plugins.BEMUserCache.getDocument("config/consent");
return window.cordova.plugins.BEMUserCache.getDocument("config/consent", false);
};
})

Expand Down
Loading

0 comments on commit ae55d66

Please sign in to comment.