Skip to content

Commit

Permalink
Merge pull request #24 from shankari/version_4_javascript_fixes
Browse files Browse the repository at this point in the history
Version 4 javascript fixes
  • Loading branch information
shankari committed Feb 29, 2016
2 parents 226a3d3 + 033ae7a commit ca79150
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 301 deletions.
6 changes: 3 additions & 3 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="edu.berkeley.eecs.emission"
version="0.0.3"
android-versionCode="3"
ios-CFBundleVersion="3"
version="0.0.4"
android-versionCode="4"
ios-CFBundleVersion="4"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>emission</name>
<description>
Expand Down
4 changes: 4 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<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">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
Expand Down
296 changes: 0 additions & 296 deletions www/js/diary.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,136 +547,6 @@ angular.module('emission.main.diary',['ui-leaflet', 'nvd3ChartDirectives',
* END: Functions for customizing our geojson display
*/

var getStartTs = function(trip) {
return trip.features[0].properties.exit_ts
};

var getDateOfTrip = function(date) {
var month;
var date;

/*
* In order to be consistent with the spec, these need to be
* date.getMonth() + 1 and date.getDay() + 1. However, that doesn't
* actually work, probably because the date is being parsed incorrectly.
*
* Working around this for now since we should switch to timestamps
* anyway.
*/
switch (date.getMonth()) {
case 1:
month = "January";
break;
case 2:
month = "February";
break;
case 3:
month = "March";
break;
case 4:
month = "April";
break;
case 5:
month = "May";
break;
case 6:
month = "June";
break;
case 7:
month = "July";
break;
case 8:
month = "August";
break;
case 9:
month = "September";
break;
case 10:
month = "October";
break;
case 11:
month = "November";
break;
case 12:
month = "December";
break;

}
switch (date.getDay()) {
case 1:
day = "Sunday";
break;
case 2:
day = "Monday";
break;
case 3:
day = "Tuesday";
break;
case 4:
day = "Wednesday";
break;
case 5:
day = "Thursday";
break;
case 6:
day = "Friday";
break;
case 7:
day = "Saturday";
break;
}
return (day + ", " + month + " " + date.getDate() + ", " + date.getFullYear());
};


$scope.getTime = function(date) {
var min = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
return ("" + date.getHours() + ":" + min);
};

$scope.notSingleOrLast = function(index, list) {
if (index == list.length - 1) {
return false;
} else {
return true;
}
};

$scope.slideHasChanged = function(index) {
console.log("slide changed to index: " + index+" when ionic delegate index = "+$ionicSlideBoxDelegate.currentIndex+
" and our cached index is "+$scope.currIndex);
$scope.days = $scope.allDays.slice($scope.currIndex, $scope.currIndex+1);
$scope.currIndex = $scope.currIndex + 1;
$ionicSlideBoxDelegate.update();
};

$scope.mapCreated = function(map) {
console.log("maps here");
console.log(map);
$scope.map = map;
$scope.setupMap($scope.data.slides[0]["trip_val"][0]);
};

$scope.centerOnMe = function() {
console.log("Centering");
if (!$scope.map) {
return;
}

$scope.loading = $ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});

navigator.geolocation.getCurrentPosition(function(pos) {
console.log('Got pos', pos);
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
$scope.loading.hide();
}, function(error) {
alert('Unable to get location: ' + error.message);
});
};

$scope.getDisplayName = function(place_feature) {
var responseListener = function(data) {
var address = data["address"];
Expand Down Expand Up @@ -711,170 +581,4 @@ angular.module('emission.main.diary',['ui-leaflet', 'nvd3ChartDirectives',
notFoundFn(day, response);
});
};

$scope.nextSlide = function() {
console.log("next");
$ionicSlideBoxDelegate.next();
};

$scope.pickImage = function(item) {
if (item.predictedMode != null) {
var item_mode = item.predictedMode;
} else {
var item_mode = item.autoMode;
}

if (item_mode == 'walking') {
return 'img/walking.jpg';
}
if (item_mode == 'car') {
return 'img/car.jpg';
}
if (item_mode == 'cycling') {
return 'img/cycling.jpg';
}
if (item_mode == 'air') {
return 'img/air.jpg';
}
if (item_mode == 'bus') {
return 'img/bus.jpg';
}
if (item_mode == 'train') {
return 'img/train.jpg';
}
};

$scope.setupMap = function(item) {
console.log(JSON.stringify(item));
if ($scope.path) {
$scope.path.setMap(null)
}
if ($scope.startMarker) {
$scope.startMarker.setMap(null)
}
if ($scope.endMarker) {
$scope.endMarker.setMap(null)
}
var points = item["trackPoints"];
var latitude = points[0]["coordinate"][1];
var longitude = points[0]["coordinate"][0];
var endLat = points[points.length - 1]["coordinate"][1];
var endLng = points[points.length - 1]["coordinate"][0];
$scope.startMarker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
icon: 'img/maps-markera.png'
});
$scope.startMarker.setMap($scope.map);
$scope.endMarker = new google.maps.Marker({
position: new google.maps.LatLng(endLat, endLng),
icon: 'img/maps-markerb.png'
});
$scope.endMarker.setMap($scope.map);
$scope.map.setCenter({
lat: latitude,
lng: longitude
});
var coordinates = [];
for (var i = 0; i < points.length; i++) {
coordinates.push(new google.maps.LatLng(points[i]["coordinate"][1], points[i]["coordinate"][0]))
}
var path = new google.maps.Polyline({
path: coordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
$scope.path = path;
path.setMap($scope.map);
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < coordinates.length; i++) {
bounds.extend(coordinates[i]);
}
$scope.map.fitBounds(bounds);
};

//Change according to datatype in actual data object and the intervals set in the app.
// Intervals: Green - confidence > 80 ; Yellow: 80 > confidence > 70; Red: 70 > confidence
$scope.getConfidenceColor = function(item) {
if (item.userClassification != null && item.userClassification.length > 0) {
return "confidence-certain";
} else if (item.confidence >= 0.9) {
return "confidence-certain";
} else if (item.confidence >= 0.7) {
return "confidence-medium";
} else {
return "confidence-low";
}
};

$scope.getDisplayMode = function(item) {
var item_mode = "";
if (item.userClassification != null && item.userClassification.length > 0) {
item_mode = item.userClassification;
} else if (item.predictedMode != null) {
item_mode = item.predictedMode;
} else {
item_mode = item.autoMode;
}
if (item_mode == 'walking') {
return 'ion-android-walk'
}
if (item_mode == 'car') {
return 'ion-android-car';
}
if (item_mode == 'cycling') {
return 'ion-android-bicycle';
}
if (item_mode == 'air') {
return 'ion-android-plane';
}
if (item_mode == 'bus') {
return 'ion-android-bus';
}
if (item_mode == 'train') {
return 'ion-android-subway';
}
};

$scope.modes = [{
mode: "walking",
show: "Walk"
}, {
mode: "cycling",
show: "Bike"
}, {
mode: "car",
show: "Car"
}, {
mode: "air",
show: "Fly"
}, {
mode: "bus",
show: "Bus"
}, {
mode: "train",
show: "Train"
}];

$scope.modeUpdate = function(trip, newMode) {
console.log("selected new mode " + newMode + " with tripId " + trip.tripId);
var db = window.sqlitePlugin.openDatabase({
name: "TripSections.db",
location: 2,
createFromLocation: 1
});
db.transaction(function(tx) {
var mDate = new Date();
tx.executeSql("UPDATE currTrips SET userClassification = ? WHERE tripId = ?", [newMode, trip.tripId], function(tx, r) {
console.log("Your SQLite query was successful!");
}, function(tx, e) {
console.log("SQLite Error: " + e.message);
});
});
};

$scope.modeChange = function(newMode) {
$scope.modes[0].newMode;
};
});
4 changes: 2 additions & 2 deletions www/js/recent.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ angular.module('emission.main.recent', ['ngCordova'])
// $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);
window.Logger.log(window.Logger.LEVEL_DEBUG,
"currEntry.data = "+currEntry.data);
// 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');
Expand Down

0 comments on commit ca79150

Please sign in to comment.