Skip to content

Commit

Permalink
Merge pull request #30 from shankari/fix_config
Browse files Browse the repository at this point in the history
Fix config
  • Loading branch information
shankari committed Apr 11, 2016
2 parents 57c468e + 172e304 commit e94a980
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 48 deletions.
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: https://ssl.gstatic.com http://nominatim.openstreetmap.org 'unsafe-inline';
style-src 'self' 'unsafe-inline';
img-src 'self' http://*.tile.openstreetmap.org">
img-src 'self' data: http://*.tile.openstreetmap.org">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
Expand Down
1 change: 1 addition & 0 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ angular.module('emission.controllers', [])

.controller('SplashCtrl', function($scope, $ionicPlatform, $state, $interval, $rootScope) {
console.log('SplashCtrl invoked');
// alert("attach debugger!");
// Currently loads main or intro based on whether onboarding is complete.
// But easily extensible to storing the last screen that the user was on,
// or the users' preferred screen
Expand Down
2 changes: 1 addition & 1 deletion www/js/diary/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', 'nvd3ChartDirectives',
// the counts will be filled in when that is done. If the currDayTripWrappers
// is already defined, that may have won the race, and not been able to update
// the counts, so let us do it here.
if (!angular.isUndefined($scope.data.currDayTripWrappers)) {
if (!angular.isUndefined($scope.data) && !angular.isUndefined($scope.data.currDayTripWrappers)) {
$scope.data.currDayTripWrappers.forEach(function(tripWrapper, index, array) {
DiaryHelper.fillCommonTripCount(tripWrapper);
});
Expand Down
144 changes: 103 additions & 41 deletions www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ angular.module('emission.main', ['emission.main.diary', 'emission.main.common',
url: '/control',
views: {
'main-control': {
templateUrl: 'templates/main-control.html',
templateUrl: 'templates/control/main-control.html',
controller: 'ControlCtrl'
}
}
Expand All @@ -52,7 +52,7 @@ angular.module('emission.main', ['emission.main.diary', 'emission.main.common',
// controller for all the screens because none of them do anything for now.
})

.controller('ControlCtrl', function($scope, $state, $ionicPopup, $ionicActionSheet) {
.controller('ControlCtrl', function($scope, $state, $ionicPopup, $ionicActionSheet, $ionicPopover) {
$scope.getConnectURL = function() {
window.cordova.plugins.BEMConnectionSettings.getSettings(function(result) {
$scope.$apply(function() {
Expand All @@ -61,14 +61,30 @@ angular.module('emission.main', ['emission.main.diary', 'emission.main.common',
});
};

$scope.getConnectionSettings = function() {
window.cordova.plugins.BEMDataCollection.getConfig(function(result) {
$scope.$apply(function() {
var retVal = [];
for (var prop in result) {
retVal.push({'key': prop, 'val': result[prop]});
$scope.getCollectionSettings = function() {
var promiseList = []
promiseList.push(window.cordova.plugins.BEMDataCollection.getConfig());
promiseList.push(window.cordova.plugins.BEMDataCollection.getAccuracyOptions());

Promise.all(promiseList).then(function(resultList) {
var config = resultList[0];
var accuracyOptions = resultList[1];
$scope.settings.collect.config = config;
$scope.settings.collect.accuracyOptions = accuracyOptions;
var retVal = [];
for (var prop in config) {
if (prop == "accuracy") {
for (var name in accuracyOptions) {
if (accuracyOptions[name] == config[prop]) {
retVal.push({'key': prop, 'val': name});
}
}
} else {
retVal.push({'key': prop, 'val': config[prop]});
}
$scope.settings.collect= retVal;
}
$scope.$apply(function() {
$scope.settings.collect.show_config = retVal;
});
});
};
Expand Down Expand Up @@ -123,7 +139,7 @@ angular.module('emission.main', ['emission.main.diary', 'emission.main.common',
$scope.settings.connect = {};

$scope.getConnectURL();
$scope.getConnectionSettings();
$scope.getCollectionSettings();
$scope.getEmail();
$scope.getState();
};
Expand All @@ -132,32 +148,8 @@ angular.module('emission.main', ['emission.main.diary', 'emission.main.common',
$state.go("root.intro");
};

$scope.forceTripStart = function() {
window.cordova.plugins.BEMDataCollection.forceTripStart(function(result) {
$scope.$apply(function() {
$ionicPopup.alert({template: 'success -> '+result});
});
}, function(error) {
$scope.$apply(function() {
$ionicPopup.alert({template: 'error -> '+error});
});
});
};

$scope.forceTripEnd = function() {
window.cordova.plugins.BEMDataCollection.forceTripEnd(function(result) {
$scope.$apply(function() {
$ionicPopup.alert({template: 'success -> '+result});
});
}, function(error) {
$scope.$apply(function() {
$ionicPopup.alert({template: 'error -> '+error});
});
});
};

$scope.forceRemotePush = function() {
window.cordova.plugins.BEMDataCollection.forceRemotePush(function(result) {
$scope.forceTransition = function(transition) {
window.cordova.plugins.BEMDataCollection.forceTransition(transition).then(function(result) {
$scope.$apply(function() {
$ionicPopup.alert({template: 'success -> '+result});
});
Expand All @@ -181,22 +173,92 @@ angular.module('emission.main', ['emission.main.diary', 'emission.main.common',
};

$scope.forceState = function() {
var forceStateActions = [{text: 'Start trip',
action: $scope.forceTripStart},
var forceStateActions = [{text: "Initialize",
transition: "INITIALIZE"},
{text: 'Start trip',
transition: "EXITED_GEOFENCE"},
{text: 'End trip',
action: $scope.forceTripEnd},
transition: "STOPPED_MOVING"},
{text: 'Visit ended',
transition: "VISIT_ENDED"},
{text: 'Visit started',
transition: "VISIT_STARTED"},
{text: 'Remote push',
action: $scope.forceRemotePush}];
transition: "RECEIVED_SILENT_PUSH"}];
$ionicActionSheet.show({
buttons: forceStateActions,
titleText: "Force state",
cancelText: "Cancel",
buttonClicked: function(index, button) {
button.action();
$scope.forceTransition(button.transition);
return true;
}
});
};

$scope.editConfig = function($event) {
$scope.settings.collect.new_config = JSON.parse(JSON.stringify($scope.settings.collect.config));
console.log("settings popup = "+$scope.settingsPopup);
$scope.settingsPopup.show($event);
/*
var editPopup = $ionicPopup.confirm({
templateUrl: 'templates/control/main-collect-settings.html',
scope: $scope
});
editPopup.then($scope.saveAndReloadSettingsPopup);
});
*/
}

$scope.saveAndReloadSettingsPopup = function(result) {
console.log("new config = "+$scope.settings.collect.new_config);
if (result == true) {
window.cordova.plugins.BEMDataCollection.setConfig($scope.settings.collect.new_config)
.then($scope.getCollectionSettings);
}
};

$scope.saveAndReloadSettingsPopover = function() {
console.log("new config = "+$scope.settings.collect.new_config);
window.cordova.plugins.BEMDataCollection.setConfig($scope.settings.collect.new_config)
.then($scope.getCollectionSettings);
$scope.settingsPopup.hide();
};

// Execute action on hide popover
$scope.$on('$destroy', function() {
$scope.settingsPopup.remove();
});

$scope.setAccuracy= function() {
var accuracyActions = [];
for (name in $scope.settings.collect.accuracyOptions) {
accuracyActions.push({text: name, value: $scope.settings.collect.accuracyOptions[name]});
}
$ionicActionSheet.show({
buttons: accuracyActions,
titleText: "Select accuracy",
cancelText: "Cancel",
buttonClicked: function(index, button) {
$scope.settings.collect.new_config.accuracy = button.value;
return true;
}
});
};


$scope.isAndroid = function() {
return ionic.Platform.isAndroid();
}

$scope.isIOS = function() {
return ionic.Platform.isIOS();
}

$scope.refreshScreen();
$ionicPopover.fromTemplateUrl('templates/control/main-collect-settings.html', {
scope: $scope
}).then(function(popover) {
$scope.settingsPopup = popover;
});
});
43 changes: 43 additions & 0 deletions www/templates/control/main-collect-settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<ion-popover-view>
<ion-content class="has-header">
<ion-button-bar>
<button class="button button-active button-block" ng-click="saveAndReloadSettingsPopover()">Save</button>
</ion-button-bar>
<ion-list>
<ion-toggle ng-model="settings.collect.new_config.is_duty_cycling">Duty Cycling</ion-toggle>
<ion-toggle ng-model="settings.collect.new_config.simulate_user_interaction">Simulate User</ion-toggle>
<ion-item class="row item-input">
<div class="col">Accuracy</div>
<button class="col col-25" ng-click="setAccuracy()">
{{settings.collect.new_config.accuracy}}
</button>
</ion-item>
<label class="item item-input">
<span class="input-label">Accuracy Threshold</span>
<input ng-model="settings.collect.new_config.accuracy_threshold"
ng-disabled="true" type="number">
</label>
<label style="" class="item item-input">
<span class="input-label">Filter distance</span>
<input ng-model="settings.collect.new_config.filter_distance"
ng-disabled="isAndroid()" type="number">
</label>
<label style="" class="item item-input">
<span class="input-label">Filter Interval</span>
<input ng-model="settings.collect.new_config.filter_time"
ng-disabled="isIOS()" type="number">
</label>
<label style="" class="item item-input">
<span class="input-label">Geofence radius</span>
<input ng-model="settings.collect.new_config.geofence_radius" type="number">
</label>
<ion-toggle ng-disabled="isAndroid()" ng-model="settings.collect.new_config.ios_use_visit_notifications_for_detection">Use Visit Notifications</ion-toggle>
<ion-toggle ng-disabled="isAndroid()" ng-model="ios_use_remote_push_for_sync">Sync on remote push</ion-toggle>
<label style="" class="item item-input">
<span class="input-label">Geofence responsiveness</span>
<input ng-model="settings.collect.new_config.android_geofence_responsiveness"
ng-disabled="isIOS()" type="number">
</label>
</ion-list>
</ion-content>
</ion-popover-view>
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<ion-view view-title="Account">
<div align-title="center" class="bar bar-positive bar-subheader">
<div class="buttons" style="text-align:center">
<button class="button icon-right ion-refresh" ng-click="refreshScreen()"> Refresh </button>
<button class="button icon-right ion-cloud" ng-click="forceSync()"> Force Sync </button>
<button class="button button-assertive icon-right ion-stop"
ng-click="forceTransition('STOP_TRACKING')"> Stop Tracking </button>
<button class="button icon-right ion-refresh" ng-click="refreshScreen()"/> </button>
<button class="button icon-right ion-cloud" ng-click="forceSync()"> Sync </button>
<button class="button button-balanced icon-right ion-play"
ng-click="forceTransition('START_TRACKING')"> Start Tracking </button>
</div>
</div>
<ion-content class="has-subheader">
Expand Down Expand Up @@ -33,11 +37,14 @@
</div>
</div>
<div class="card">
<div class="item item-divider">
Collection
<div class="row item item-divider">
<div class="col">
Collection
</div>
<button class="col col-25 button button-positive" ng-click="editConfig($event)"> Edit </button>
</div>
<ion-list>
<ion-item class="row" ng-repeat="entry in settings.collect">
<ion-item class="row" ng-repeat="entry in settings.collect.show_config">
<div class="col timestamp item-text-wrap">{{entry.key}}</div>
<div class="col detail item-text-wrap"> {{entry.val}}</div>
</ion-item>
Expand Down

0 comments on commit e94a980

Please sign in to comment.