From 51b44fbce5dfec42469aa4f010c82c97313a7e5b Mon Sep 17 00:00:00 2001 From: sunil07t Date: Mon, 25 Dec 2017 15:21:44 -0800 Subject: [PATCH 01/11] Choose mode feature in diary list --- www/css/style.css | 16 +++ www/js/diary/list.js | 179 +++++++++++++++++++++++--- www/templates/diary/list.html | 39 +++--- www/templates/diary/mode-popover.html | 10 ++ 4 files changed, 213 insertions(+), 31 deletions(-) create mode 100644 www/templates/diary/mode-popover.html diff --git a/www/css/style.css b/www/css/style.css index a4487ccab..699e51705 100644 --- a/www/css/style.css +++ b/www/css/style.css @@ -1001,6 +1001,7 @@ button.button.back-button.buttons.button-clear.header-item { font-size: 9px; position: absolute; left: 1%; + bottom:15px; top: 275px; line-height: 16px; } @@ -1890,3 +1891,18 @@ span.rz-bar-wrapper { -webkit-overflow-scrolling: touch !important; overflow: scroll !important; } + + +.popover { + height: 297px; + width: 230px; +} + +#diary-card{ + height: 335px; +} + +#diary-item { + padding: 0; + border-width: 0; +} diff --git a/www/js/diary/list.js b/www/js/diary/list.js index d1e3ccc05..aee19fede 100644 --- a/www/js/diary/list.js +++ b/www/js/diary/list.js @@ -14,8 +14,10 @@ angular.module('emission.main.diary.list',['ui-leaflet', $ionicActionSheet, ionicDatePicker, leafletData, Timeline, CommonGraph, DiaryHelper, - Config, PostTripManualMarker, nzTour, storage, Logger) { + Config, PostTripManualMarker, nzTour, storage, $ionicPopover) { console.log("controller DiaryListCtrl called"); + var MODE_CONFIRM_KEY = "manual/mode_confirm"; + // Add option // StatusBar.styleBlackOpaque() $scope.dark_theme = $rootScope.dark_theme; @@ -39,15 +41,6 @@ angular.module('emission.main.diary.list',['ui-leaflet', readAndUpdateForDay($rootScope.barDetailDate); $rootScope.barDetail = false; }; - if($rootScope.displayingIncident == true) { - if (angular.isDefined(Timeline.data.currDay)) { - // page was already loaded, reload it automatically - readAndUpdateForDay(Timeline.data.currDay); - } else { - Logger.log("currDay is not defined, load not complete"); - } - $rootScope.displayingIncident = false; - } }); readAndUpdateForDay(moment().startOf('day')); @@ -170,12 +163,73 @@ angular.module('emission.main.diary.list',['ui-leaflet', ionicDatePicker.openDatePicker($scope.datepickerObject); } + var getTripModes = function(trip) { + return $window.cordova.plugins.BEMUserCache.getAllMessages(MODE_CONFIRM_KEY, false).then(function(modes) { + Logger.log("Modes stored locally" + JSON.stringify(modes)); + var tripMode = {}; + if(modes.length > 0) { + modes.forEach(function(mode) { + if ((trip.properties.start_ts == mode.start_ts) && + (trip.properties.end_ts == mode.end_ts)) { + tripMode = mode; + Logger.log("trip" + JSON.stringify(trip)+ "mode" + JSON.stringify(tripMode)); + } + }); + } + return tripMode; + }); + } + + var addModeFeature = function(trip, mode) { + $scope.$apply(function() { + var modeFeature = mode; + modeFeature.feature_type = "mode"; + Logger.log("Created mode feature" + JSON.stringify(modeFeature) + "for" + JSON.stringify(trip)); + trip.features.push(modeFeature); + $scope.modeTripgj = angular.undefined; + }); + } + + var isNotEmpty = function(obj) { + for(var prop in obj) { + if(obj.hasOwnProperty(prop)) + return true; + } + return false; + }; + + var addUnpushedMode = function(trip) { + getTripModes(trip).then(function(mode) { + if(isNotEmpty(mode)){ + addModeFeature(trip, mode); + } + }); + } + + $scope.checkMode = function(trip) { + var hasMode = false; + trip.data.features.forEach(function(feature) { + if(feature.feature_type == "mode") { + $scope.modeOptions.forEach(function(mode) { + if(feature.label == mode.value) { + $scope.mode = mode.text; + } else { + $scope.mode = feature.label; + } + }); + hasMode = true; + } + }); + return hasMode; + } + $scope.$on(Timeline.UPDATE_DONE, function(event, args) { console.log("Got timeline update done event with args "+JSON.stringify(args)); $scope.$apply(function() { $scope.data = Timeline.data; $scope.datepickerObject.inputDate = Timeline.data.currDay.toDate(); $scope.data.currDayTrips.forEach(function(trip, index, array) { + addUnpushedMode(trip); PostTripManualMarker.addUnpushedIncidents(trip); }); $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( @@ -236,13 +290,24 @@ angular.module('emission.main.diary.list',['ui-leaflet', // readAndUpdateForDay($scope.data.currDay); }); */ + + + + // TEST CODE REMOVE BEFORE PUSH + var printModes = function() { + $window.cordova.plugins.BEMUserCache.getAllMessages(MODE_CONFIRM_KEY, false).then(function(modes) { + console.log("Modes list"); + console.log(modes); + }); + }; $scope.refresh = function() { if ($ionicScrollDelegate.getScrollPosition().top < 5) { readAndUpdateForDay(Timeline.data.currDay); $scope.$broadcast('invalidateSize'); } - } + printModes(); + }; /* For UI control */ $scope.groups = []; @@ -375,10 +440,96 @@ angular.module('emission.main.diary.list',['ui-leaflet', readAndUpdateForDay(nextDay); }; - $scope.toDetail = function() { - $state.go('root.main.detail'); + $scope.toDetail = function(param) { + $state.go('root.main.diary-detail', {tripId: param}); }; + $scope.showModes = DiaryHelper.showModes; + + $ionicPopover.fromTemplateUrl('templates/diary/mode-popover.html', { + scope: $scope + }).then(function(popover) { + $scope.modePopover = popover; + }); + + $scope.openModePopover = function($event, start_ts, end_ts, tripgj) { + $scope.draftMode = {"start_ts": start_ts, "end_ts": end_ts}; + $scope.modeTripgj = tripgj; + Logger.log("in openModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); + $scope.modePopover.show($event); + }; + + var closeModePopover = function($event, isOther) { + if(isOther == false) + $scope.draftMode = angular.undefined; + Logger.log("in closeModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); + $scope.modePopover.hide($event); + }; + + $scope.chosen = {mode:''}; + + var checkOtherOption = function(choice, isOther) { + if(choice == 'other_mode') { + var text = "mode"; + $ionicPopup.show({title: "Please fill in the " + text + " not listed.", + scope: $scope, + template: '', + buttons: [ + { text: 'Cancel' }, { + text: 'Save', + type: 'button-positive', + onTap: function(e) { + if (!$scope.chosen.other) { + e.preventDefault(); + } else { + Logger.log("in choose other, other = "+JSON.stringify($scope.chosen)); + if(choice == 'other_mode') { + $scope.storeMode($scope.chosen.other, isOther); + $scope.chosen.other = ''; + } + return $scope.chosen.other; + } + } + } + ] + }); + + } + }; + + $scope.chooseMode = function (){ + var isOther = false + if($scope.chosen.mode != "other_mode"){ + $scope.storeMode($scope.chosen.mode, isOther); + } else { + isOther = true + checkOtherOption($scope.chosen.mode, isOther); + } + closeModePopover(); + }; + + $scope.modeOptions = [ + {text:'Walk', value:'walk'}, + {text:'Bike',value:'bike'}, + {text:'Drove Alone',value:'drove_alone'}, + {text:'Shared Ride',value:'shared_ride'}, + {text:'Taxi/Uber/Lyft',value:'taxi'}, + {text:'Bus',value:'bus'}, + {text:'Train',value:'train'}, + {text:'Free Shuttle',value:'free_shuttle'}, + {text:'Other',value:'other_mode'}]; + + $scope.storeMode = function(mode_val, isOther) { + $scope.draftMode.label = mode_val; + Logger.log("in storeMode, after setting mode_val = "+mode_val+", draftMode = "+JSON.stringify($scope.draftMode)); + $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, $scope.draftMode).then(function() { + console.log($scope.modeTripgj); + addUnpushedMode($scope.modeTripgj.data); + }); + if(isOther == true) + $scope.draftMode = angular.undefined; + } + $scope.redirect = function(){ $state.go("root.main.current"); }; @@ -407,6 +558,4 @@ angular.module('emission.main.diary.list',['ui-leaflet', return in_trip; }; - $scope.showModes = DiaryHelper.showModes; - }); diff --git a/www/templates/diary/list.html b/www/templates/diary/list.html index 2f9f3a266..18149afba 100644 --- a/www/templates/diary/list.html +++ b/www/templates/diary/list.html @@ -15,16 +15,12 @@
- + -
-
Current Trip
-
-
- + -
+
{{localTimeString (tripgj.data.properties.start_local_dt)}}
- +
{{parseEarlierOrLater(getEarlierOrLater(tripgj.data.properties.start_ts, tripgj.data.id))}}
-
+
+
-

{{getFormattedDistance(tripgj.data.properties.distance)}} km in {{getFormattedTimeRange(tripgj.data.properties.start_ts, +

{{getFormattedDistance(tripgj.data.properties.distance)}} mi in {{getFormattedTimeRange(tripgj.data.properties.start_ts, tripgj.data.properties.end_ts)}}

{{ getLongerOrShorter(tripgj.data, tripgj.data.id)[1] }} @@ -88,18 +85,28 @@
- - - - +
+
+
+ Mode +
+
+
+
+
+ {{mode}} +
+ +
+
{{localTimeString (tripgj.data.properties.end_local_dt)}}
- - + + diff --git a/www/templates/diary/mode-popover.html b/www/templates/diary/mode-popover.html new file mode 100644 index 000000000..933826e57 --- /dev/null +++ b/www/templates/diary/mode-popover.html @@ -0,0 +1,10 @@ + + +

How did you get here?

+
+ + + {{mode.text}} + + +
\ No newline at end of file From 569f455cc8fdd77a3ae3f8858d82203b378f4ad2 Mon Sep 17 00:00:00 2001 From: sunil07t Date: Tue, 26 Dec 2017 17:58:43 -0800 Subject: [PATCH 02/11] added edit mode button to deatil screen, edit mode screen and different onEachFeature for maps --- www/index.html | 1 + www/js/diary.js | 13 +++++- www/js/diary/detail.js | 10 ++++- www/js/diary/edit-mode.js | 66 +++++++++++++++++++++++++++++ www/js/diary/list.js | 12 +++--- www/js/diary/services.js | 54 +++++++++++++++++++++-- www/js/incident/post-trip-manual.js | 8 ++-- www/templates/diary/detail.html | 7 ++- www/templates/diary/edit-mode.html | 12 ++++++ 9 files changed, 165 insertions(+), 18 deletions(-) create mode 100644 www/js/diary/edit-mode.js create mode 100644 www/templates/diary/edit-mode.html diff --git a/www/index.html b/www/index.html index 50a760566..f2965f470 100644 --- a/www/index.html +++ b/www/index.html @@ -87,6 +87,7 @@ + diff --git a/www/js/diary.js b/www/js/diary.js index 76974dd02..a0931eb2e 100644 --- a/www/js/diary.js +++ b/www/js/diary.js @@ -1,7 +1,8 @@ angular.module('emission.main.diary',['emission.main.diary.list', 'emission.main.diary.detail', 'emission.main.diary.services', - 'emission.main.diary.current',]) + 'emission.main.diary.current', + 'emission.main.diary.editMode',]) .config(function($stateProvider, $ionicConfigProvider) { $stateProvider @@ -34,5 +35,15 @@ angular.module('emission.main.diary',['emission.main.diary.list', }, } + }) + + .state('root.main.diary-edit-mode', { + url: '/diary/:tripId/:tripId2', + views: { + 'main-diary': { + templateUrl: 'templates/diary/edit-mode.html', + controller: 'EditModeCtrl' + } + } }); }); diff --git a/www/js/diary/detail.js b/www/js/diary/detail.js index 85e8ebda4..3b4e2e192 100644 --- a/www/js/diary/detail.js +++ b/www/js/diary/detail.js @@ -7,7 +7,7 @@ angular.module('emission.main.diary.detail',['ui-leaflet', 'ng-walkthrough', .controller("DiaryDetailCtrl", function($scope, $rootScope, $window, $stateParams, $ionicActionSheet, leafletData, leafletMapEvents, nzTour, storage, Logger, Timeline, DiaryHelper, Config, - CommHelper, PostTripManualMarker) { + CommHelper, PostTripManualMarker, $state) { console.log("controller DiaryDetailCtrl called with params = "+ JSON.stringify($stateParams)); @@ -64,7 +64,9 @@ angular.module('emission.main.diary.detail',['ui-leaflet', 'ng-walkthrough', $scope.getFormattedTimeRange = DiaryHelper.getFormattedTimeRange; $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; $scope.getTripDetails = DiaryHelper.getTripDetails - $scope.tripgj = DiaryHelper.directiveForTrip($scope.trip); + $scope.tripgj = DiaryHelper.directiveForTrip($scope.trip, false); + console.log($scope.tripgj); + console.log($scope.trip); $scope.getTripBackground = function() { var ret_val = DiaryHelper.getTripBackground($rootScope.dark_theme, $scope.tripgj); @@ -159,6 +161,10 @@ angular.module('emission.main.diary.detail',['ui-leaflet', 'ng-walkthrough', startWalkthrough(); } + $scope.editMode = function(param) { + $state.go('root.main.diary-edit-mode', {tripId: param}); + } + $scope.$on('$ionicView.afterEnter', function(ev) { // Workaround from // https://github.com/driftyco/ionic/issues/3433#issuecomment-195775629 diff --git a/www/js/diary/edit-mode.js b/www/js/diary/edit-mode.js new file mode 100644 index 000000000..0ac277164 --- /dev/null +++ b/www/js/diary/edit-mode.js @@ -0,0 +1,66 @@ +'use strict'; +angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', + 'ionic-datepicker', 'nvd3', 'angularLocalStorage', + 'emission.services', 'emission.plugin.logger', + 'emission.incident.posttrip.manual']) + +.controller("EditModeCtrl", function($scope, $rootScope, $window, $stateParams, $ionicActionSheet, + leafletData, leafletMapEvents, nzTour, storage, + Logger, Timeline, DiaryHelper, Config, + CommHelper, PostTripManualMarker) { + console.log("controller editMode called with params = "+ + JSON.stringify($stateParams)); + + $scope.mapCtrl = {}; + angular.extend($scope.mapCtrl, { + defaults : { + } + }); + + angular.extend($scope.mapCtrl.defaults, Config.getMapTiles()) + + $scope.$on('leafletDirectiveMap.detail.resize', function(event, data) { + console.log("diary/editMode received resize event, invalidating map size"); + data.leafletObject.invalidateSize(); + }); + + $scope.refreshTiles = function() { + $scope.$broadcast('invalidateSize'); + }; + + $scope.getFormattedDate = DiaryHelper.getFormattedDate; + $scope.arrowColor = DiaryHelper.arrowColor; + $scope.parseEarlierOrLater = DiaryHelper.parseEarlierOrLater; + $scope.getEarlierOrLater = DiaryHelper.getEarlierOrLater; + $scope.getLongerOrShorter = DiaryHelper.getLongerOrShorter; + $scope.getIcon = DiaryHelper.getIcon; + $scope.getHumanReadable = DiaryHelper.getHumanReadable; + $scope.getPercentages = DiaryHelper.getPercentages; + $scope.allModes = DiaryHelper.allModes; + $scope.trip = Timeline.getTrip($stateParams.tripId); + $scope.getKmph = DiaryHelper.getKmph; + $scope.getFormattedDistance = DiaryHelper.getFormattedDistance; + $scope.getSectionDetails = DiaryHelper.getSectionDetails; + $scope.getFormattedTime = DiaryHelper.getFormattedTime; + $scope.getFormattedTimeRange = DiaryHelper.getFormattedTimeRange; + $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; + $scope.getTripDetails = DiaryHelper.getTripDetails + $scope.tripgj = DiaryHelper.directiveForTrip($scope.trip, true); + console.log($scope.tripgj); + console.log($scope.trip); + + $scope.getTripBackground = function() { + var ret_val = DiaryHelper.getTripBackground($rootScope.dark_theme, $scope.tripgj); + return ret_val; + } + + console.log("trip.start_place = " + JSON.stringify($scope.trip.start_place)); + + leafletData.getMap('detail').then(function(map) { + map.on('click', PostTripManualMarker.startAddingIncidentToTrip($scope.trip, map)); + }); + + $scope.editMode = function(param) { + $state.go('root.main.diary-edit-mode', {tripId: param}); + } +}) diff --git a/www/js/diary/list.js b/www/js/diary/list.js index aee19fede..0a91704a9 100644 --- a/www/js/diary/list.js +++ b/www/js/diary/list.js @@ -232,8 +232,8 @@ angular.module('emission.main.diary.list',['ui-leaflet', addUnpushedMode(trip); PostTripManualMarker.addUnpushedIncidents(trip); }); - $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( - DiaryHelper.directiveForTrip); + $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( + function(trip) { return DiaryHelper.directiveForTrip(trip, false);}); $ionicScrollDelegate.scrollTop(true); }); }); @@ -498,12 +498,14 @@ angular.module('emission.main.diary.list',['ui-leaflet', }; $scope.chooseMode = function (){ + var modeChosen = $scope.chosen.mode + $scope.chosen.mode = '' var isOther = false - if($scope.chosen.mode != "other_mode"){ - $scope.storeMode($scope.chosen.mode, isOther); + if(modeChosen != "other_mode"){ + $scope.storeMode(modeChosen, isOther); } else { isOther = true - checkOtherOption($scope.chosen.mode, isOther); + checkOtherOption(modeChosen, isOther); } closeModePopover(); }; diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 4babf1066..673b73fc7 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -3,7 +3,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', 'emission.services', 'emission.main.common.services', 'emission.incident.posttrip.manual']) -.factory('DiaryHelper', function(Timeline, CommonGraph, PostTripManualMarker){ +.factory('DiaryHelper', function(Timeline, CommonGraph, PostTripManualMarker, $ionicActionSheet){ var dh = {}; // dh.expandEarlierOrLater = function(id) { // document.querySelector('#hidden-' + id.toString()).setAttribute('style', 'display: block;'); @@ -276,11 +276,14 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', tripWrapper.common_count = cTrip.trips.length; } }; - dh.directiveForTrip = function(trip) { + dh.directiveForTrip = function(trip, editMode) { var retVal = {}; retVal.data = trip; retVal.style = style_feature; - retVal.onEachFeature = onEachFeature; + if(editMode) + retVal.onEachFeature = onEachFeatureForEditMode; + else + retVal.onEachFeature = onEachFeature; retVal.pointToLayer = dh.pointFormat; retVal.start_place = trip.start_place; retVal.end_place = trip.end_place; @@ -346,7 +349,18 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', PostTripManualMarker.startAddingIncidentToSection(feature, layer)); break; case "incident": PostTripManualMarker.displayIncident(feature, layer); break; } -}; + }; + + var onEachFeatureForEditMode = function(feature, layer) { + // console.log("onEachFeature called with "+JSON.stringify(feature)); + switch(feature.properties.feature_type) { + case "stop": layer.bindPopup(""+feature.properties.duration); break; + case "start_place": layer.bindPopup(""+feature.properties.displayName); break; + case "end_place": layer.bindPopup(""+feature.properties.displayName); break; + case "section": layer.on('click', () => {editMode(feature, layer)}); break; + case "incident": PostTripManualMarker.displayIncident(feature, layer); break; + } + }; dh.pointFormat = function(feature, latlng) { switch(feature.properties.feature_type) { @@ -389,6 +403,38 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } }; + var editMode = function(feature, layer) { + layer.bindPopup(""+dh.getHumanReadable(feature.properties.sensed_mode)); + console.log("EDIT MODE SHEET!!!") + } + + /*var incidentOrModeSheet = function(feature, layer) { + Logger.log("About to show sheet to choose incident or edit trip"); + var incident_or_mode = [{text: "Incident"}, + {text: "Mode"}, + {text: "Cancel"}] + + Logger.log("About to call ionicActionSheet.show"); + $ionicActionSheet.show({titleText: "Edit Mode or Incident", + cancel: function() { + Logger.log("Canceled incident or edit trip"); + }, + buttons: incident_or_mode, + buttonClicked: function(index, button) { + Logger.log("Clicked button "+button.text+" at index "+index); + if (button.text != "Cancel") { + Logger.log("Editing" + button.text); + if(button.text == "Incident") { + PostTripManualMarker.startAddingIncidentToSection(feature, layer) + } else { + editMode(feature, layer) + } + } + return true; + } + }); + };*/ + return dh; }) diff --git a/www/js/incident/post-trip-manual.js b/www/js/incident/post-trip-manual.js index 076650040..26db76773 100644 --- a/www/js/incident/post-trip-manual.js +++ b/www/js/incident/post-trip-manual.js @@ -20,7 +20,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', // BEGIN: Adding incidents /* - * INTERNAL FUNCTION, not part of factory + * EXTERNAL FUNCTION * * Returns objects of the form: { * loc: geojson representation, @@ -29,7 +29,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', * } */ - var getSectionPoints = function(section) { + ptmm.getSectionPoints = function(section) { Logger.log("Called getSection points with list of size "+section.geometry.coordinates.length); var mappedPoints = section.geometry.coordinates.map(function(currCoords, index) { if (index % 100 == 0) { @@ -279,7 +279,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', Logger.log("section "+feature.properties.start_fmt_time + " -> "+feature.properties.end_fmt_time + " bound incident addition "); - var allPoints = getSectionPoints(feature); + var allPoints = ptmm.getSectionPoints(feature); var trip = Timeline.getTrip(feature.properties.trip_id.$oid); var featureArray = trip.features; return ptmm.startAddingIncidentToPoints(layer, allPoints, featureArray); @@ -288,7 +288,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', var getAllPointsForTrip = function(trip) { var allPoints = []; trip.sections.forEach(function(s) { - Array.prototype.push.apply(allPoints, getSectionPoints(s)); + Array.prototype.push.apply(allPoints, ptmm.getSectionPoints(s)); }); return allPoints; } diff --git a/www/templates/diary/detail.html b/www/templates/diary/detail.html index ea281054a..030ad3990 100644 --- a/www/templates/diary/detail.html +++ b/www/templates/diary/detail.html @@ -6,14 +6,14 @@
-
+
{{getFormattedTime(tripgj.data.properties.start_ts)}}
{{parseEarlierOrLater(getEarlierOrLater(tripgj.data.properties.start_ts, tripgj.data.id))}}
{{getFormattedTime(tripgj.data.properties.end_ts)}}
-
+
@@ -25,6 +25,9 @@ {{tripgj.end_place.properties.displayName.split(',')[0]}}
+
+ +
+ {{ getFormattedDate(tripgj.data.properties.start_ts) }} + + + + +
+ + +
+ From 3678008126a6d9d529fcd62b9659014ee840aeee Mon Sep 17 00:00:00 2001 From: sunil07t Date: Wed, 27 Dec 2017 20:21:42 -0800 Subject: [PATCH 03/11] Added feature that allows users to change mode of the section of the trip v1 --- www/js/diary/edit-mode.js | 7 +- www/js/diary/services.js | 161 +++++++++++++++++++++++++++----------- 2 files changed, 122 insertions(+), 46 deletions(-) diff --git a/www/js/diary/edit-mode.js b/www/js/diary/edit-mode.js index 0ac277164..475f45357 100644 --- a/www/js/diary/edit-mode.js +++ b/www/js/diary/edit-mode.js @@ -7,7 +7,7 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', .controller("EditModeCtrl", function($scope, $rootScope, $window, $stateParams, $ionicActionSheet, leafletData, leafletMapEvents, nzTour, storage, Logger, Timeline, DiaryHelper, Config, - CommHelper, PostTripManualMarker) { + CommHelper, PostTripManualMarker, EditModeFactory) { console.log("controller editMode called with params = "+ JSON.stringify($stateParams)); @@ -46,6 +46,7 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; $scope.getTripDetails = DiaryHelper.getTripDetails $scope.tripgj = DiaryHelper.directiveForTrip($scope.trip, true); + $scope.editModeObj = EditModeFactory.chosenModeAndSection console.log($scope.tripgj); console.log($scope.trip); @@ -60,6 +61,10 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', map.on('click', PostTripManualMarker.startAddingIncidentToTrip($scope.trip, map)); }); + $scope.$watch(function() { + $scope.editModeObj; + }); + $scope.editMode = function(param) { $state.go('root.main.diary-edit-mode', {tripId: param}); } diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 673b73fc7..0452d19b1 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -3,7 +3,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', 'emission.services', 'emission.main.common.services', 'emission.incident.posttrip.manual']) -.factory('DiaryHelper', function(Timeline, CommonGraph, PostTripManualMarker, $ionicActionSheet){ +.factory('DiaryHelper', function(Timeline, CommonGraph, PostTripManualMarker, $ionicActionSheet, EditModeFactory){ var dh = {}; // dh.expandEarlierOrLater = function(id) { // document.querySelector('#hidden-' + id.toString()).setAttribute('style', 'display: block;'); @@ -357,7 +357,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', case "stop": layer.bindPopup(""+feature.properties.duration); break; case "start_place": layer.bindPopup(""+feature.properties.displayName); break; case "end_place": layer.bindPopup(""+feature.properties.displayName); break; - case "section": layer.on('click', () => {editMode(feature, layer)}); break; + case "section": layer.on('click', EditModeFactory.editMode(feature, layer)); break; case "incident": PostTripManualMarker.displayIncident(feature, layer); break; } }; @@ -390,50 +390,34 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', weight: 5, opacity: 1, }; - var mode_string = dh.getHumanReadable(feature.properties.sensed_mode); - switch(mode_string) { - case "WALKING": return getColoredStyle(baseDict, 'brown'); - case "RUNNING": return getColoredStyle(baseDict, 'brown'); - case "BICYCLING": return getColoredStyle(baseDict, 'green'); - case "IN_VEHICLE": return getColoredStyle(baseDict, 'purple'); - case "UNKNOWN": return getColoredStyle(baseDict, 'orange'); - case "UNPROCESSED": return getColoredStyle(baseDict, 'orange'); - case "AIR_OR_HSR": return getColoredStyle(baseDict, 'red'); - default: return getColoredStyle(baseDict, 'black'); + if('mode_confirm' in feature.properties) { + var mode_string = feature.properties.mode_confirm.value; + switch(mode_string) { + case "walk": return getColoredStyle(baseDict, 'brown'); + case "bike": return getColoredStyle(baseDict, 'green'); + case "drove_alone": return getColoredStyle(baseDict, 'purple'); + case "shared_ride": return getColoredStyle(baseDict, 'purple'); + case "taxi": return getColoredStyle(baseDict, 'purple'); + case "bus": return getColoredStyle(baseDict, 'purple'); + case "train": return getColoredStyle(baseDict, 'purple'); + case "free_shuttle": return getColoredStyle(baseDict, 'purple'); + case "other_mode": return getColoredStyle(baseDict, 'orange'); + default: return getColoredStyle(baseDict, 'black'); + } + } else { + var mode_string = dh.getHumanReadable(feature.properties.sensed_mode); + switch(mode_string) { + case "WALKING": return getColoredStyle(baseDict, 'brown'); + case "RUNNING": return getColoredStyle(baseDict, 'brown'); + case "BICYCLING": return getColoredStyle(baseDict, 'green'); + case "IN_VEHICLE": return getColoredStyle(baseDict, 'purple'); + case "UNKNOWN": return getColoredStyle(baseDict, 'orange'); + case "UNPROCESSED": return getColoredStyle(baseDict, 'orange'); + case "AIR_OR_HSR": return getColoredStyle(baseDict, 'red'); + default: return getColoredStyle(baseDict, 'black'); + } } - }; - - var editMode = function(feature, layer) { - layer.bindPopup(""+dh.getHumanReadable(feature.properties.sensed_mode)); - console.log("EDIT MODE SHEET!!!") - } - - /*var incidentOrModeSheet = function(feature, layer) { - Logger.log("About to show sheet to choose incident or edit trip"); - var incident_or_mode = [{text: "Incident"}, - {text: "Mode"}, - {text: "Cancel"}] - - Logger.log("About to call ionicActionSheet.show"); - $ionicActionSheet.show({titleText: "Edit Mode or Incident", - cancel: function() { - Logger.log("Canceled incident or edit trip"); - }, - buttons: incident_or_mode, - buttonClicked: function(index, button) { - Logger.log("Clicked button "+button.text+" at index "+index); - if (button.text != "Cancel") { - Logger.log("Editing" + button.text); - if(button.text == "Incident") { - PostTripManualMarker.startAddingIncidentToSection(feature, layer) - } else { - editMode(feature, layer) - } - } - return true; - } - }); - };*/ + }; return dh; @@ -1111,4 +1095,91 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', return timeline; }) +.factory('EditModeFactory', function($window, $state, $ionicActionSheet, + Logger, Timeline, PostTripManualMarker) { + + var edm = {} + edm.chosenModeAndSection = [] + var MODE_CONFIRM_KEY = "manual/mode_confirm"; + + var addModeToSectionDisplay = function(modeObj, section, layer) { + //Get trip from cache here? + //feature.properties.mode_confirm = modeObj; + var trip = Timeline.getTrip(section.properties.trip_id.$oid); + trip.features.forEach(function(feature) { + if(feature.type == "FeatureCollection") { + if(feature.features[0].id == section.id) feature.features[0].properties.mode_confirm = modeObj; + } + }) + console.log(trip); + } + + var modeOptions = [ + {text:'Walk', value:'walk'}, + {text:'Bike',value:'bike'}, + {text:'Drove Alone',value:'drove_alone'}, + {text:'Shared Ride',value:'shared_ride'}, + {text:'Taxi/Uber/Lyft',value:'taxi'}, + {text:'Bus',value:'bus'}, + {text:'Train',value:'train'}, + {text:'Free Shuttle',value:'free_shuttle'}, + {text:'Other',value:'other_mode'}]; + + var toModeTextArray = function(modeOptions) { + var modeTextArray = modeOptions.map(function(item) { return {text: item["text"]} }); + modeTextArray.push( {text:"Cancel"}); + return modeTextArray; + } + + var modeTextToValue = function(modeText, feature) { + var modeObjReturn = {} + var trip = Timeline.getTrip(feature.properties.trip_id.$oid); + modeOptions.forEach(function (modeObj) { + if(modeText == "Other") modeObjReturn = {text:'Other',value:'other_mode'} //Change this to have users own mode value + else if(modeObj.text == modeText) modeObjReturn = modeObj; + }); + modeObjReturn.tripId = feature.properties.trip_id.$oid; + modeObjReturn.id = feature.id; + modeObjReturn.ts = new Date().getTime(); + return modeObjReturn; + } + + var addModeToSection = function(modeText, feature, layer) { + var modeObj = modeTextToValue(modeText, feature); + $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, modeObj).then(function() { + console.log(modeObj); + addModeToSectionDisplay(modeObj, feature, layer); + }); + } + + edm.editMode = function(feature, layer) { + //layer.bindPopup(""+dh.getHumanReadable(feature.properties.sensed_mode)); + return function(e) { + console.log("Edit mode sheet") + incidentOrModeSheet(feature, layer) + } + } + + var incidentOrModeSheet = function(feature, layer) { + Logger.log("About to show sheet to edit section mode"); + var modesText = toModeTextArray(modeOptions) + + Logger.log("About to call ionicActionSheet.show"); + $ionicActionSheet.show({titleText: "Edit Mode", + cancel: function() { + Logger.log("Canceled incident or edit trip"); + }, + buttons: modesText, + buttonClicked: function(index, button) { + Logger.log("Clicked button "+button.text+" at index "+index); + if (button.text != "Cancel") { + Logger.log("Choose " + button.text); + addModeToSection(button.text, feature, layer) + } + return true; + } + }) + }; + return edm; +}) From 6a7f8f439534bfe751183f7564ec83bfa36f683a Mon Sep 17 00:00:00 2001 From: sunil07t Date: Wed, 27 Dec 2017 21:59:19 -0800 Subject: [PATCH 04/11] Get edited mode from cache to show on UI --- www/js/diary/list.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/www/js/diary/list.js b/www/js/diary/list.js index 0a91704a9..9bc73ca2e 100644 --- a/www/js/diary/list.js +++ b/www/js/diary/list.js @@ -14,7 +14,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', $ionicActionSheet, ionicDatePicker, leafletData, Timeline, CommonGraph, DiaryHelper, - Config, PostTripManualMarker, nzTour, storage, $ionicPopover) { + Config, PostTripManualMarker, nzTour, storage, $ionicPopover, EditModeFactory) { console.log("controller DiaryListCtrl called"); var MODE_CONFIRM_KEY = "manual/mode_confirm"; @@ -169,8 +169,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', var tripMode = {}; if(modes.length > 0) { modes.forEach(function(mode) { - if ((trip.properties.start_ts == mode.start_ts) && - (trip.properties.end_ts == mode.end_ts)) { + if (trip.id == mode.tripId && mode.trip_mode == true) { tripMode = mode; Logger.log("trip" + JSON.stringify(trip)+ "mode" + JSON.stringify(tripMode)); } @@ -211,10 +210,10 @@ angular.module('emission.main.diary.list',['ui-leaflet', trip.data.features.forEach(function(feature) { if(feature.feature_type == "mode") { $scope.modeOptions.forEach(function(mode) { - if(feature.label == mode.value) { + if(feature.value == mode.value) { $scope.mode = mode.text; } else { - $scope.mode = feature.label; + $scope.mode = feature.value; } }); hasMode = true; @@ -231,6 +230,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', $scope.data.currDayTrips.forEach(function(trip, index, array) { addUnpushedMode(trip); PostTripManualMarker.addUnpushedIncidents(trip); + EditModeFactory.addUnpushedSectionMode(trip); }); $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( function(trip) { return DiaryHelper.directiveForTrip(trip, false);}); @@ -453,7 +453,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', }); $scope.openModePopover = function($event, start_ts, end_ts, tripgj) { - $scope.draftMode = {"start_ts": start_ts, "end_ts": end_ts}; + $scope.draftMode = {"tripId": tripgj.data.id, "trip_mode": true}; $scope.modeTripgj = tripgj; Logger.log("in openModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); $scope.modePopover.show($event); @@ -522,7 +522,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', {text:'Other',value:'other_mode'}]; $scope.storeMode = function(mode_val, isOther) { - $scope.draftMode.label = mode_val; + $scope.draftMode.value = mode_val; Logger.log("in storeMode, after setting mode_val = "+mode_val+", draftMode = "+JSON.stringify($scope.draftMode)); $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, $scope.draftMode).then(function() { console.log($scope.modeTripgj); From c21fa641256f3cadbda05c8ae302ddc33520777f Mon Sep 17 00:00:00 2001 From: sunil07t Date: Wed, 27 Dec 2017 22:00:15 -0800 Subject: [PATCH 05/11] Get edited mode from cache to show on UI service --- www/js/diary/services.js | 47 +++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 0452d19b1..f219b6d5f 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -1102,16 +1102,16 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', edm.chosenModeAndSection = [] var MODE_CONFIRM_KEY = "manual/mode_confirm"; - var addModeToSectionDisplay = function(modeObj, section, layer) { + var addModeToSectionDisplay = function(modeObj, trip) { //Get trip from cache here? //feature.properties.mode_confirm = modeObj; - var trip = Timeline.getTrip(section.properties.trip_id.$oid); - trip.features.forEach(function(feature) { + var tripReturn = trip; + tripReturn.features.forEach(function(feature) { if(feature.type == "FeatureCollection") { - if(feature.features[0].id == section.id) feature.features[0].properties.mode_confirm = modeObj; + if(feature.features[0].id == modeObj.id) feature.features[0].properties.mode_confirm = modeObj; } }) - console.log(trip); + console.log(tripReturn); } var modeOptions = [ @@ -1141,14 +1141,16 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', modeObjReturn.tripId = feature.properties.trip_id.$oid; modeObjReturn.id = feature.id; modeObjReturn.ts = new Date().getTime(); + modeObjReturn.trip_mode = false return modeObjReturn; } var addModeToSection = function(modeText, feature, layer) { + var trip = Timeline.getTrip(feature.properties.trip_id.$oid); var modeObj = modeTextToValue(modeText, feature); $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, modeObj).then(function() { console.log(modeObj); - addModeToSectionDisplay(modeObj, feature, layer); + addModeToSectionDisplay(modeObj, trip); }); } @@ -1180,6 +1182,39 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } }) }; + + var getTripMode = function(trip) { + return $window.cordova.plugins.BEMUserCache.getAllMessages(MODE_CONFIRM_KEY, false).then(function(modes) { + Logger.log("Modes stored locally" + JSON.stringify(modes)); + var tripMode = {}; + if(modes.length > 0) { + modes.forEach(function(mode) { + if (mode.trip_mode == false && mode.tripId == trip.id) { + tripMode = mode; + Logger.log("trip" + JSON.stringify(trip)+ "mode" + JSON.stringify(tripMode)); + } + }); + } + return tripMode; + }); + } + + var isNotEmpty = function(obj) { + for(var prop in obj) { + if(obj.hasOwnProperty(prop)) + return true; + } + return false; + }; + + edm.addUnpushedSectionMode = function(trip) { + getTripMode(trip).then(function(mode) { + if(isNotEmpty(mode)){ + addModeToSectionDisplay(mode, trip); + } + }); + } + return edm; }) From 108cd3f1efb6db97649f1ecd267f52cc123ebacd Mon Sep 17 00:00:00 2001 From: sunil07t Date: Thu, 28 Dec 2017 00:16:45 -0800 Subject: [PATCH 06/11] minor changes to not show choose mode button on cards with more than 1 modes --- www/js/diary/list.js | 23 ++++++++++++++++------- www/js/diary/services.js | 9 ++++++++- www/templates/diary/list.html | 13 +++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/www/js/diary/list.js b/www/js/diary/list.js index 9bc73ca2e..769b73938 100644 --- a/www/js/diary/list.js +++ b/www/js/diary/list.js @@ -209,19 +209,28 @@ angular.module('emission.main.diary.list',['ui-leaflet', var hasMode = false; trip.data.features.forEach(function(feature) { if(feature.feature_type == "mode") { - $scope.modeOptions.forEach(function(mode) { - if(feature.value == mode.value) { - $scope.mode = mode.text; - } else { - $scope.mode = feature.value; - } - }); + var modes = $scope.modeOptions.map(a => a.value); + if(modes.indexOf(feature.value) > -1) { + $scope.modeOptions.forEach(function(mode) { + if(feature.value == mode.value) { + $scope.mode = mode.text; + } + }); + } else { + $scope.mode = feature.value; + } hasMode = true; } }); return hasMode; } + $scope.isSingleModeTrip = function(trip) { + var singleModeTrip = false; + if(trip.sections.length == 1) singleModeTrip = true + return singleModeTrip; + } + $scope.$on(Timeline.UPDATE_DONE, function(event, args) { console.log("Got timeline update done event with args "+JSON.stringify(args)); $scope.$apply(function() { diff --git a/www/js/diary/services.js b/www/js/diary/services.js index f219b6d5f..7a2ff8d4f 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -1187,13 +1187,20 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', return $window.cordova.plugins.BEMUserCache.getAllMessages(MODE_CONFIRM_KEY, false).then(function(modes) { Logger.log("Modes stored locally" + JSON.stringify(modes)); var tripMode = {}; + var modeHistory = [] if(modes.length > 0) { modes.forEach(function(mode) { if (mode.trip_mode == false && mode.tripId == trip.id) { - tripMode = mode; + modeHistory.push(mode) Logger.log("trip" + JSON.stringify(trip)+ "mode" + JSON.stringify(tripMode)); } }); + } + if(modeHistory.length > 0) { + modeHistory.sort(function(x, y){ + return x.ts - y.ts; + }) + tripMode = modeHistory[modeHistory.length-1] } return tripMode; }); diff --git a/www/templates/diary/list.html b/www/templates/diary/list.html index 18149afba..285fef70d 100644 --- a/www/templates/diary/list.html +++ b/www/templates/diary/list.html @@ -86,12 +86,17 @@
-
-
- Mode +
+
+ Mode +
+
+
+ Multiple modes +
-
+
{{mode}} From d5315bfab1bcb0e07a134609fee84d04cc72998f Mon Sep 17 00:00:00 2001 From: sunil07t Date: Mon, 1 Jan 2018 14:44:37 -0800 Subject: [PATCH 07/11] changes with adding section to trip and restrictive split --- www/js/diary/list.js | 34 +- www/js/diary/oldList.js | 540 ++++++++++++++++++++++++++++ www/js/diary/services.js | 370 ++++++++++++++++--- www/js/incident/post-trip-manual.js | 30 +- www/templates/diary/list.html | 2 +- 5 files changed, 891 insertions(+), 85 deletions(-) create mode 100644 www/js/diary/oldList.js diff --git a/www/js/diary/list.js b/www/js/diary/list.js index 769b73938..676966abb 100644 --- a/www/js/diary/list.js +++ b/www/js/diary/list.js @@ -169,7 +169,8 @@ angular.module('emission.main.diary.list',['ui-leaflet', var tripMode = {}; if(modes.length > 0) { modes.forEach(function(mode) { - if (trip.id == mode.tripId && mode.trip_mode == true) { + if ((trip.properties.start_ts == mode.start_ts && + trip.properties.end_ts == mode.end_ts) && mode.trip_mode == true) { tripMode = mode; Logger.log("trip" + JSON.stringify(trip)+ "mode" + JSON.stringify(tripMode)); } @@ -182,7 +183,6 @@ angular.module('emission.main.diary.list',['ui-leaflet', var addModeFeature = function(trip, mode) { $scope.$apply(function() { var modeFeature = mode; - modeFeature.feature_type = "mode"; Logger.log("Created mode feature" + JSON.stringify(modeFeature) + "for" + JSON.stringify(trip)); trip.features.push(modeFeature); $scope.modeTripgj = angular.undefined; @@ -208,18 +208,20 @@ angular.module('emission.main.diary.list',['ui-leaflet', $scope.checkMode = function(trip) { var hasMode = false; trip.data.features.forEach(function(feature) { - if(feature.feature_type == "mode") { - var modes = $scope.modeOptions.map(a => a.value); - if(modes.indexOf(feature.value) > -1) { - $scope.modeOptions.forEach(function(mode) { - if(feature.value == mode.value) { - $scope.mode = mode.text; - } - }); - } else { - $scope.mode = feature.value; - } - hasMode = true; + if(feature.hasOwnProperty('label')) { + if(feature.trip_mode == true) { + var modes = $scope.modeOptions.map(a => a.value); + if(modes.indexOf(feature.label) > -1) { + $scope.modeOptions.forEach(function(mode) { + if(feature.label == mode.value) { + $scope.mode = mode.text; + } + }); + } else { + $scope.mode = feature.label; + } + hasMode = true; + } } }); return hasMode; @@ -462,7 +464,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', }); $scope.openModePopover = function($event, start_ts, end_ts, tripgj) { - $scope.draftMode = {"tripId": tripgj.data.id, "trip_mode": true}; + $scope.draftMode = {"start_ts": start_ts, "end_ts": end_ts, "trip_mode": true}; $scope.modeTripgj = tripgj; Logger.log("in openModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); $scope.modePopover.show($event); @@ -531,7 +533,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', {text:'Other',value:'other_mode'}]; $scope.storeMode = function(mode_val, isOther) { - $scope.draftMode.value = mode_val; + $scope.draftMode.label = mode_val; Logger.log("in storeMode, after setting mode_val = "+mode_val+", draftMode = "+JSON.stringify($scope.draftMode)); $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, $scope.draftMode).then(function() { console.log($scope.modeTripgj); diff --git a/www/js/diary/oldList.js b/www/js/diary/oldList.js new file mode 100644 index 000000000..3147c315a --- /dev/null +++ b/www/js/diary/oldList.js @@ -0,0 +1,540 @@ +'use strict'; + +angular.module('emission.main.diary.list',['ui-leaflet', + 'ionic-datepicker', + 'emission.main.common.services', + 'emission.incident.posttrip.manual', + 'emission.services', + 'ng-walkthrough', 'nzTour', 'angularLocalStorage', + 'emission.plugin.logger']) + +.controller("DiaryListCtrl", function($window, $scope, $rootScope, $ionicPlatform, $state, + $ionicScrollDelegate, $ionicPopup, + $ionicLoading, + $ionicActionSheet, + ionicDatePicker, + leafletData, Timeline, CommonGraph, DiaryHelper, + Config, PostTripManualMarker, nzTour, storage, $ionicPopover) { + console.log("controller DiaryListCtrl called"); + var MODE_CONFIRM_KEY = "manual/mode_confirm"; + var PURPOSE_CONFIRM_KEY = "manual/purpose_confirm"; + + // Add option + // StatusBar.styleBlackOpaque() + $scope.dark_theme = $rootScope.dark_theme; + + $scope.$on('leafletDirectiveMap.resize', function(event, data) { + console.log("diary/list received resize event, invalidating map size"); + data.leafletObject.invalidateSize(); + }); + + 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. + // TODO: Convert the usercache calls into promises so that we don't have to + // do this juggling + Timeline.updateForDay(day); + // CommonGraph.updateCurrent(); + }; + + $scope.$on('$ionicView.afterEnter', function() { + if($rootScope.barDetail){ + readAndUpdateForDay($rootScope.barDetailDate); + $rootScope.barDetail = false; + }; + }); + + readAndUpdateForDay(moment().startOf('day')); + + angular.extend($scope, { + defaults: { + zoomControl: false, + dragging: false, + zoomAnimation: true, + touchZoom: false, + scrollWheelZoom: false, + doubleClickZoom: false, + boxZoom: false, + } + }); + + angular.extend($scope.defaults, Config.getMapTiles()) + + moment.locale('en', { + relativeTime : { + future: "in %s", + past: "%s ago", + s: "secs", + m: "a min", + mm: "%d m", + h: "an hr", + hh: "%d h", + d: "a day", + dd: "%d days", + M: "a month", + MM: "%d months", + y: "a year", + yy: "%d years" + } +}); + + /* + * While working with dates, note that the datepicker needs a javascript date because it uses + * setHours here, while the currDay is a moment, since we use it to perform + * +date and -date operations. + */ + $scope.listExpandClass = function () { + return ($scope.dark_theme)? "earlier-later-expand-dark" : "earlier-later-expand"; + } + $scope.listLocationClass = function() { + return ($scope.dark_theme)? "item item-icon-left list-location-dark" : "item item-icon-left list-location"; + } + $scope.listTextClass = function() { + return ($scope.dark_theme)? "list-text-dark" : "list-text"; + } + $scope.ionViewBackgroundClass = function() { + return ($scope.dark_theme)? "ion-view-background-dark" : "ion-view-background"; + } + $scope.datePickerClass = function() { + } + $scope.listCardClass = function(tripgj) { + var background = DiaryHelper.getTripBackground($scope.dark_theme, tripgj); + if ($window.screen.width <= 320) { + return "list card list-card "+ background +" list-card-sm"; + } else if ($window.screen.width <= 375) { + return "list card list-card "+ background +" list-card-md"; + } else { + return "list card list-card "+background+" list-card-lg"; + } + + } + $scope.listColLeftClass = function(margin) { + if (margin == 0) { + return ($scope.dark_theme)? "col-50 list-col-left-dark" : "col-50 list-col-left"; + } else { + return ($scope.dark_theme)? "col-50 list-col-left-margin-dark" : "col-50 list-col-left-margin"; + } + } + $scope.listColRightClass = function() { + return ($scope.dark_theme)? "col-50 list-col-right-dark" : "col-50 list-col-right"; + } + $scope.differentCommon = function(tripgj) { + return ($scope.isCommon(tripgj.id))? ((DiaryHelper.getEarlierOrLater(tripgj.data.properties.start_ts, tripgj.data.id) == '')? false : true) : false; + } + $scope.stopTimeTagClass = function(tripgj) { + return ($scope.differentCommon(tripgj))? "stop-time-tag-lower" : "stop-time-tag"; + } + $scope.setCurrDay = function(val) { + if (typeof(val) === 'undefined') { + window.Logger.log(window.Logger.LEVEL_INFO, 'No date selected'); + } else { + window.Logger.log(window.Logger.LEVEL_INFO, 'Selected date is :' + val); + readAndUpdateForDay(moment(val)); + } + } + $scope.localTimeString = function(dt) { + var hr = ((dt.hour > 12))? dt.hour - 12 : dt.hour; + var post = ((dt.hour >= 12))? " pm" : " am"; + var min = (dt.minute.toString().length == 1)? "0" + dt.minute.toString() : dt.minute.toString(); + return hr + ":" + min + post; + } + + $scope.datepickerObject = { + + todayLabel: 'Today', //Optional + closeLabel: 'Close', //Optional + setLabel: 'Set', //Optional + setButtonType : 'button-positive', //Optional + todayButtonType : 'button-stable', //Optional + closeButtonType : 'button-stable', //Optional + inputDate: new Date(), //Optional + from: new Date(2015, 1, 1), + to: new Date(), + mondayFirst: true, //Optional + templateType: 'popup', //Optional + showTodayButton: 'true', //Optional + modalHeaderColor: 'bar-positive', //Optional + modalFooterColor: 'bar-positive', //Optional + callback: $scope.setCurrDay, //Mandatory + dateFormat: 'dd MMM yyyy', //Optional + closeOnSelect: true //Optional + }; + + $scope.pickDay = function() { + ionicDatePicker.openDatePicker($scope.datepickerObject); + } + + $scope.$on(Timeline.UPDATE_DONE, function(event, args) { + console.log("Got timeline update done event with args "+JSON.stringify(args)); + $scope.$apply(function() { + $scope.data = Timeline.data; + $scope.datepickerObject.inputDate = Timeline.data.currDay.toDate(); + $scope.data.currDayTrips.forEach(function(trip, index, array) { + PostTripManualMarker.addUnpushedIncidents(trip); + }); + $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( + DiaryHelper.directiveForTrip); + $ionicScrollDelegate.scrollTop(true); + }); + }); + + $scope.$on(CommonGraph.UPDATE_DONE, function(event, args) { + console.log("Got common graph update done event with args "+JSON.stringify(args)); + $scope.$apply(function() { + // If we don't have the trip wrappers yet, then we can just bail because + // 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) && !angular.isUndefined($scope.data.currDayTripWrappers)) { + $scope.data.currDayTripWrappers.forEach(function(tripWrapper, index, array) { + DiaryHelper.fillCommonTripCount(tripWrapper); + }); + }; + }); + }); + + $scope.setColor = function(mode) { + var colors = {"icon ion-android-bicycle":'green', + "icon ion-android-walk":'brown', + "icon ion-speedometer":'red',}; + return { color: colors[mode] }; + } + + var showNoTripsAlert = function() { + var buttons = [ + {text: 'New', type: 'button-balanced', onTap: function(e) { $state.go('root.main.recent.log'); }}, + {text: 'Force', type: 'button-balanced', onTap: function(e) { $state.go('root.main.control'); }}, + {text: 'OK', type: 'button-balanced', onTap: function(e) { return; }}, + ]; + console.log("No trips found for day "); + var alertPopup = $ionicPopup.show({ + title: 'No trips found!', + template: "This is probably because you didn't go anywhere. You can also check", + buttons: buttons + }); + return alertPopup; + } + + /* + * Disabling the reload of the page on background sync because it doesn't + * work correctly. on iOS, plugins are not loaded if backgroundFetch or + * remote push are invoked, since they don't initialize the app. On + * android, it looks like the thread ends before the maps are fully loaded, + * so we have half displayed, frozen maps. We should really check the + * status, reload here if active and reload everything on resume. + * For now, we just add a refresh button to avoid maintaining state. + window.broadcaster.addEventListener( "edu.berkeley.eecs.emission.sync.NEW_DATA", function( e ) { + window.Logger.log(window.Logger.LEVEL_INFO, + "new data received! reload data for the current day"+$scope.data.currDay); + $window.location.reload(); + // readAndUpdateForDay($scope.data.currDay); + }); + */ + + $scope.refresh = function() { + if ($ionicScrollDelegate.getScrollPosition().top < 5) { + readAndUpdateForDay(Timeline.data.currDay); + $scope.$broadcast('invalidateSize'); + } + } + + /* For UI control */ + $scope.groups = []; + for (var i=0; i<10; i++) { + $scope.groups[i] = { + name: i, + items: ["good1", "good2", "good3"] + }; + for (var j=0; j<3; j++) { + $scope.groups[i].items.push(i + '-' + j); + } + } + $scope.toggleGroup = function(group) { + if ($scope.isGroupShown(group)) { + $scope.shownGroup = null; + } else { + $scope.shownGroup = group; + } + }; + $scope.isGroupShown = function(group) { + return $scope.shownGroup === group; + }; + $scope.getEarlierOrLater = DiaryHelper.getEarlierOrLater; + $scope.getLongerOrShorter = DiaryHelper.getLongerOrShorter; + $scope.getHumanReadable = DiaryHelper.getHumanReadable; + $scope.allModes = DiaryHelper.allModes; + $scope.getKmph = DiaryHelper.getKmph; + $scope.getPercentages = DiaryHelper.getPercentages; + $scope.getFormattedDistance = DiaryHelper.getFormattedDistance; + $scope.getSectionDetails = DiaryHelper.getSectionDetails; + $scope.getFormattedTime = DiaryHelper.getFormattedTime; + $scope.getFormattedTimeRange = DiaryHelper.getFormattedTimeRange; + $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; + $scope.getTripDetails = DiaryHelper.getTripDetails; + $scope.starColor = DiaryHelper.starColor; + $scope.arrowColor = DiaryHelper.arrowColor; + $scope.getArrowClass = DiaryHelper.getArrowClass; + $scope.isCommon = DiaryHelper.isCommon; + $scope.isDraft = DiaryHelper.isDraft; + // $scope.expandEarlierOrLater = DiaryHelper.expandEarlierOrLater; + // $scope.increaseRestElementsTranslate3d = DiaryHelper.increaseRestElementsTranslate3d; + + $scope.makeCurrent = function() { + $ionicPopup.alert({template: "Coming soon, after Shankari's quals in early March!"}); + } + + $scope.userModes = [ + "walk", "bicycle", "car", "bus", "train", "unicorn" + ]; + $scope.parseEarlierOrLater = DiaryHelper.parseEarlierOrLater; + + $scope.getTimeSplit = function(tripList) { + var retVal = {}; + var tripTimes = tripList.map(function(dt) { + return dt.data.properties.duration; + }); + + }; + + // Tour steps + var tour = { + config: { + mask: { + visibleOnNoTarget: true, + clickExit: true + } + }, + steps: [{ + target: '#date-picker-button', + content: 'Use this to select the day you want to see.' + }, + { + target: '.diary-entry', + content: 'Click on the map to see more details about each trip.' + }, + { + target: '#map-fix-button', + content: 'Use this to fix the map tiles if they have not loaded properly.' + }] + }; + + var startWalkthrough = function () { + nzTour.start(tour).then(function(result) { + Logger.log("list walkthrough start completed, no error"); + }).catch(function(err) { + Logger.log("list walkthrough start errored" + err); + }); + }; + + $scope.refreshTiles = function() { + $scope.$broadcast('invalidateSize'); + }; + + /* + * Checks if it is the first time the user has loaded the diary tab. If it is then + * show a walkthrough and store the info that the user has seen the tutorial. + */ + var checkDiaryTutorialDone = function () { + var DIARY_DONE_KEY = 'diary_tutorial_done'; + var diaryTutorialDone = storage.get(DIARY_DONE_KEY); + if (!diaryTutorialDone) { + startWalkthrough(); + storage.set(DIARY_DONE_KEY, true); + } + }; + + $scope.startWalkthrough = function () { + startWalkthrough(); + } + + $scope.$on('$ionicView.enter', function(ev) { + // Workaround from + // https://github.com/driftyco/ionic/issues/3433#issuecomment-195775629 + if(ev.targetScope !== $scope) + return; + checkDiaryTutorialDone(); + }); + + $scope.prevDay = function() { + console.log("Called prevDay when currDay = "+Timeline.data.currDay.format('YYYY-MM-DD')); + var prevDay = moment(Timeline.data.currDay).subtract(1, 'days'); + console.log("prevDay = "+prevDay.format('YYYY-MM-DD')); + readAndUpdateForDay(prevDay); + }; + + $scope.nextDay = function() { + console.log("Called nextDay when currDay = "+Timeline.data.currDay.format('YYYY-MM-DD')); + var nextDay = moment(Timeline.data.currDay).add(1, 'days'); + console.log("nextDay = "+nextDay); + readAndUpdateForDay(nextDay); + }; + + $scope.toDetail = function(param) { + $state.go('root.main.diary-detail', {tripId: param}); + }; + + $scope.showModes = DiaryHelper.showModes; + + $ionicPopover.fromTemplateUrl('templates/diary/mode-popover.html', { + scope: $scope + }).then(function(popover) { + $scope.modePopover = popover; + }); + + $scope.openModePopover = function($event, start_ts, end_ts) { + $scope.draftMode = {"start_ts": start_ts, "end_ts": end_ts} + Logger.log("in openModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); + $scope.modePopover.show($event); + }; + + var closeModePopover = function($event, isOther) { + if(isOther == false) + $scope.draftMode = angular.undefined; + Logger.log("in closeModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); + $scope.modePopover.hide($event); + }; + + $ionicPopover.fromTemplateUrl('templates/diary/purpose-popover.html', { + scope: $scope + }).then(function(popover) { + $scope.purposePopover = popover; + }); + + $scope.openPurposePopover = function($event, start_ts, end_ts) { + $scope.draftPurpose = {"start_ts": start_ts, "end_ts": end_ts} + Logger.log("in openPurposePopover, setting draftPurpose = "+JSON.stringify($scope.draftPurpose)); + $scope.purposePopover.show($event); + }; + + var closePurposePopover = function($event, isOther) { + if(isOther == false) + $scope.draftPurpose = angular.undefined; + Logger.log("in closePurposePopover, setting draftPurpose = "+JSON.stringify($scope.draftPurpose)); + $scope.purposePopover.hide($event); + }; + + $scope.chosen = {mode:'',purpose:''}; + + var checkOtherOption = function(choice, isOther) { + if(choice == 'other_mode' || choice == 'other_purpose') { + var text = choice == 'other_mode' ? "mode" : "purpose"; + $ionicPopup.show({title: "Please fill in the " + text + " not listed.", + scope: $scope, + template: '', + buttons: [ + { text: 'Cancel' }, { + text: 'Save', + type: 'button-positive', + onTap: function(e) { + if (!$scope.chosen.other) { + e.preventDefault(); + } else { + Logger.log("in choose other, other = "+JSON.stringify($scope.chosen)); + if(choice == 'other_mode') { + $scope.storeMode($scope.chosen.other, isOther); + $scope.chosen.other = ''; + } else { + $scope.storePurpose($scope.chosen.other, isOther); + $scope.chosen.other = ''; + } + return $scope.chosen.other; + } + } + } + ] + }); + + } + }; + + $scope.choosePurpose = function() { + var isOther = false + if($scope.chosen.purpose != "other_purpose"){ + $scope.storePurpose($scope.chosen.purpose, isOther); + } else { + isOther = true + checkOtherOption($scope.chosen.purpose, isOther); + } + closePurposePopover(); + }; + + $scope.chooseMode = function (){ + var isOther = false + if($scope.chosen.mode != "other_mode"){ + $scope.storeMode($scope.chosen.mode, isOther); + } else { + isOther = true + checkOtherOption($scope.chosen.mode, isOther); + } + closeModePopover(); + }; + + $scope.modeOptions = [ + {text:'Walk', value:'walk'}, + {text:'Bike',value:'bike'}, + {text:'Drove Alone',value:'drove_alone'}, + {text:'Shared Ride',value:'shared_ride'}, + {text:'Taxi/Uber/Lyft',value:'taxi'}, + {text:'Bus',value:'bus'}, + {text:'Train',value:'train'}, + {text:'Free Shuttle',value:'free_shuttle'}, + {text:'Other',value:'other_mode'}]; + + $scope.purposeOptions = [ + {text:'Home', value:'home'}, + {text:'Work',value:'work'}, + {text:'School',value:'school'}, + {text:'Transit transfer', value:'transit_transfer'}, + {text:'Shopping',value:'shopping'}, + {text:'Meal',value:'meal'}, + {text:'Pick-up/Drop off',value:'pick_drop'}, + {text:'Personal/Medical',value:'personal_med'}, + {text:'Recreation/Exercise',value:'exercise'}, + {text:'Entertainment/Social',value:'entertainment'}, + {text:'Religious', value:'religious'}, + {text:'Other',value:'other_purpose'}]; + + $scope.storeMode = function(mode_val, isOther) { + $scope.draftMode.label = mode_val; + Logger.log("in storeMode, after setting mode_val = "+mode_val+", draftMode = "+JSON.stringify($scope.draftMode)); + $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, $scope.draftMode); + if(isOther = true) + $scope.draftPurpose = angular.undefined; + } + + $scope.storePurpose = function(purpose_val, isOther) { + $scope.draftPurpose.label = purpose_val; + Logger.log("in storePurpose, after setting purpose_val = "+purpose_val+", draftPurpose = "+JSON.stringify($scope.draftPurpose)); + $window.cordova.plugins.BEMUserCache.putMessage(PURPOSE_CONFIRM_KEY, $scope.draftPurpose); + if(isOther = true) + $scope.draftPurpose = angular.undefined; + } + + $scope.redirect = function(){ + $state.go("root.main.current"); + }; + + var in_trip; + $scope.checkTripState = function() { + window.cordova.plugins.BEMDataCollection.getState().then(function(result) { + Logger.log("Current trip state" + JSON.stringify(result)); + if(JSON.stringify(result) == "\"STATE_ONGOING_TRIP\"" || + JSON.stringify(result) == "\"local.state.ongoing_trip\"") { + in_trip = true; + } else { + in_trip = false; + } + }); + }; + + // storing boolean to in_trip and return it in inTrip function + // work because ng-show is watching the inTrip function. + // Returning a promise to ng-show did not work. + // Changing in_trip = bool value; in checkTripState function + // to return bool value and using checkTripState function in ng-show + // did not work. + $scope.inTrip = function() { + $scope.checkTripState(); + return in_trip; + }; +}); \ No newline at end of file diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 7a2ff8d4f..328cabd8e 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -279,7 +279,22 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', dh.directiveForTrip = function(trip, editMode) { var retVal = {}; retVal.data = trip; - retVal.style = style_feature; + var sectionsSource = trip.features.map(function(section){ + var aSectionsSource; + if(section.type == "FeatureCollection"){ + aSectionsSource = section.features[0].properties.source; + } + return aSectionsSource; + }) + if(sectionsSource.indexOf('user') > -1) { + retVal.style = style_feature; + console.log("Found user edited mode"); + } else { + if(editMode) + retVal.style = style_featureEditMode; + else + retVal.style = style_feature; + } if(editMode) retVal.onEachFeature = onEachFeatureForEditMode; else @@ -335,6 +350,14 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } }; + var style_featureEditMode = function(feature) { + switch(feature.properties.feature_type) { + case "section": return style_sectionEditMode(feature); + case "stop": return style_stop(feature); + default: return {} + } + }; + var showClickTime = function(feature, layer) { return layer.bindPopup("click: "+dh.getFormattedTime(feature.properties.ts)); }; @@ -345,8 +368,8 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', case "stop": layer.bindPopup(""+feature.properties.duration); break; case "start_place": layer.bindPopup(""+feature.properties.displayName); break; case "end_place": layer.bindPopup(""+feature.properties.displayName); break; - case "section": layer.on('click', - PostTripManualMarker.startAddingIncidentToSection(feature, layer)); break; + // case "section": layer.on('click', + //PostTripManualMarker.startAddingIncidentToSection(feature, layer)); break; case "incident": PostTripManualMarker.displayIncident(feature, layer); break; } }; @@ -357,7 +380,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', case "stop": layer.bindPopup(""+feature.properties.duration); break; case "start_place": layer.bindPopup(""+feature.properties.displayName); break; case "end_place": layer.bindPopup(""+feature.properties.displayName); break; - case "section": layer.on('click', EditModeFactory.editMode(feature, layer)); break; + case "section": layer.on('click', EditModeFactory.splitTrip(feature, layer)); break; case "incident": PostTripManualMarker.displayIncident(feature, layer); break; } }; @@ -390,22 +413,22 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', weight: 5, opacity: 1, }; - if('mode_confirm' in feature.properties) { - var mode_string = feature.properties.mode_confirm.value; + var mode_string = dh.getHumanReadable(feature.properties.sensed_mode); + if(mode_string == 'Edited') { + mode_string = feature.properties.user_edited_mode; switch(mode_string) { - case "walk": return getColoredStyle(baseDict, 'brown'); + case "walk": return getColoredStyle(baseDict, 'brown'); //ADD MORE COLORS case "bike": return getColoredStyle(baseDict, 'green'); - case "drove_alone": return getColoredStyle(baseDict, 'purple'); - case "shared_ride": return getColoredStyle(baseDict, 'purple'); - case "taxi": return getColoredStyle(baseDict, 'purple'); - case "bus": return getColoredStyle(baseDict, 'purple'); - case "train": return getColoredStyle(baseDict, 'purple'); + case "drove_alone": return getColoredStyle(baseDict, 'red'); + case "shared_ride": return getColoredStyle(baseDict, 'aqua'); + case "taxi": return getColoredStyle(baseDict, 'yellow'); + case "bus": return getColoredStyle(baseDict, 'lime'); + case "train": return getColoredStyle(baseDict, 'aqua'); case "free_shuttle": return getColoredStyle(baseDict, 'purple'); case "other_mode": return getColoredStyle(baseDict, 'orange'); default: return getColoredStyle(baseDict, 'black'); } } else { - var mode_string = dh.getHumanReadable(feature.properties.sensed_mode); switch(mode_string) { case "WALKING": return getColoredStyle(baseDict, 'brown'); case "RUNNING": return getColoredStyle(baseDict, 'brown'); @@ -419,6 +442,14 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } }; + var style_sectionEditMode = function(feature) { + var baseDict = { + weight: 5, + opacity: 1, + }; + return getColoredStyle(baseDict, 'white'); + }; + return dh; }) @@ -642,13 +673,23 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', return place_gj; } - var points2Geojson = function(trip, locationPoints) { + timeline.points2Geojson = function(locationPoints, unporcessedData, mode, tripId) { var startPoint = locationPoints[0]; var endPoint = locationPoints[locationPoints.length - 1]; - var tripAndSectionId = "unprocessed_"+startPoint.data.ts+"_"+endPoint.data.ts; - var startMoment = moment.unix(startPoint.data.ts).tz(startPoint.metadata.time_zone); - var endMoment = moment.unix(endPoint.data.ts).tz(endPoint.metadata.time_zone); - + var tripAndSectionId; + var startMoment; + var endMoment; + if (unporcessedData) { + tripAndSectionId = "unprocessed_"+startPoint.data.ts+"_"+endPoint.data.ts; + startMoment = moment.unix(startPoint.data.ts).tz(startPoint.metadata.time_zone); ///CHANGE THIS FOR FINAL VERSION + endMoment = moment.unix(endPoint.data.ts).tz(endPoint.metadata.time_zone); + } + else { + tripAndSectionId = "edited_"+startPoint.data.ts+"_"+endPoint.data.ts; + startMoment = moment.unix(startPoint.data.ts).tz("America/Los_Angeles"); ///CHANGE THIS FOR FINAL VERSION + endMoment = moment.unix(endPoint.data.ts).tz("America/Los_Angeles"); + } + var sectionCoordinates = locationPoints.map(function(point) { return [point.data.longitude, point.data.latitude]; }); @@ -697,16 +738,23 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', end_local_dt: moment2localdate(endMoment), end_ts: endPoint.data.ts, feature_type: "section", - sensed_mode: "MotionTypes.UNPROCESSED", - source: "unprocessed", speeds: speeds, start_fmt_time: startMoment.format(), start_local_dt: moment2localdate(startMoment), start_ts: startPoint.data.ts, - times: times, - trip_id: {$oid: tripAndSectionId} + times: times } } + if (unporcessedData) { + section_gj.properties.sensed_mode = "MotionTypes."+mode; + section_gj.properties.source = "unprocessed"; + section_gj.properties.trip_id = {$oid: tripAndSectionId}; + } else { + section_gj.properties.sensed_mode = "MotionTypes.Edited"; + section_gj.properties.user_edited_mode = mode; + section_gj.properties.source = "user"; + section_gj.properties.trip_id = {$oid: tripId} + } return { type: "FeatureCollection", features: [section_gj] @@ -739,7 +787,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', var features = [ place2Geojson(trip, tripStartPoint, startPlacePropertyFiller), place2Geojson(trip, tripEndPoint, endPlacePropertyFiller), - points2Geojson(trip, sortedLocationList) + timeline.points2Geojson(sortedLocationList, true, 'UNPROCESSED', '') ]; var section_gj = features[2]; var trip_gj = { @@ -965,7 +1013,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', }); timeline.data.currDayTrips.forEach(function(trip, index, array) { - var tc = getTripComponents(trip); + var tc = timeline.getTripComponents(trip); trip.start_place = tc[0]; trip.end_place = tc[1]; trip.stops = tc[2]; @@ -1056,7 +1104,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', timeline.data.currDaySummary.distance = 0; }; - var getTripComponents = function(trip) { + timeline.getTripComponents = function(trip) { console.log("getSections("+trip+") called"); var startPlace = null; var endPlace = null; @@ -1102,16 +1150,39 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', edm.chosenModeAndSection = [] var MODE_CONFIRM_KEY = "manual/mode_confirm"; + + var tripPointsData = function(trip) { + var tripPoints = []; + trip.sections.forEach(function(section, index1){ + section.geometry.coordinates.forEach(function(point, index2) { + tripPoints.push({'data': { + 'longitude': point[0], + 'latitude': point[1], + 'ts': trip.sections[index1].properties.times[index2]}}) + }) + }); + return tripPoints; + } + var addModeToSectionDisplay = function(modeObj, trip) { - //Get trip from cache here? - //feature.properties.mode_confirm = modeObj; var tripReturn = trip; - tripReturn.features.forEach(function(feature) { - if(feature.type == "FeatureCollection") { - if(feature.features[0].id == modeObj.id) feature.features[0].properties.mode_confirm = modeObj; + console.log(modeObj); + var tripPoints = tripPointsData(trip); + var sectionPoints = []; + tripPoints.forEach(function(point) { + if(modeObj.start_ts <= point.data.ts && point.data.ts <= modeObj.end_ts) { + sectionPoints.push(point); } }) - console.log(tripReturn); + console.log(tripPoints); + if(sectionPoints.length > 0) { + console.log(sectionPoints); + var section = Timeline.points2Geojson(sectionPoints, false, modeObj.label, trip.id) + console.log(section) + tripReturn.features.push(section) + tripReturn.features.push(modeObj) + console.log(tripReturn); + } } var modeOptions = [ @@ -1131,38 +1202,190 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', return modeTextArray; } - var modeTextToValue = function(modeText, feature) { + var modeTextToValue = function(modeText, ts, feature, lastSection) { var modeObjReturn = {} var trip = Timeline.getTrip(feature.properties.trip_id.$oid); + var tripPoints = tripPointsData(trip); + tripPoints.sort(function(x, y){return x.data.ts - y.data.ts;}); + var sectionsAddedSoFar = [] modeOptions.forEach(function (modeObj) { - if(modeText == "Other") modeObjReturn = {text:'Other',value:'other_mode'} //Change this to have users own mode value - else if(modeObj.text == modeText) modeObjReturn = modeObj; + if(modeText == "Other") modeObjReturn.label = 'other_mode'; //Change this to have users own mode value + else if(modeObj.text == modeText) modeObjReturn.label = modeObj.value; }); - modeObjReturn.tripId = feature.properties.trip_id.$oid; - modeObjReturn.id = feature.id; + trip.features.forEach(function(feature) { + if(feature.hasOwnProperty('label')) { + if(feature.trip_mode == false) { + sectionsAddedSoFar.push(feature) + } + } + }) + if(lastSection) { + //var index = tripPoints.findIndex(x => x.data.ts == ts); + modeObjReturn.start_ts = sectionsAddedSoFar[sectionsAddedSoFar.length-1].end_ts; + modeObjReturn.end_ts = trip.properties.end_ts; + } else { + if(sectionsAddedSoFar.length > 0) { + sectionsAddedSoFar.sort(function(x, y){return x.start_ts - y.start_ts;}); + modeObjReturn.start_ts = sectionsAddedSoFar[sectionsAddedSoFar.length-1].start_ts; + } else { + modeObjReturn.start_ts = trip.properties.start_ts; + } + if(ts != modeObjReturn.start_ts) { + modeObjReturn.end_ts = ts; + } else { + var index = tripPoints.findIndex(x => x.data.ts == modeObjReturn.start_ts); + modeObjReturn.end_ts = tripPoints[index+2].data.ts; + } + } + //modeObjReturn.tripId = feature.properties.trip_id.$oid; + //modeObjReturn.id = feature.id; modeObjReturn.ts = new Date().getTime(); - modeObjReturn.trip_mode = false + modeObjReturn.trip_mode = false; return modeObjReturn; } - var addModeToSection = function(modeText, feature, layer) { + var addModeToSection = function(modeText, ts, feature, layer) { var trip = Timeline.getTrip(feature.properties.trip_id.$oid); - var modeObj = modeTextToValue(modeText, feature); + var modeObj = modeTextToValue(modeText, ts, feature, false); $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, modeObj).then(function() { - console.log(modeObj); + //console.log(modeObj); addModeToSectionDisplay(modeObj, trip); + Logger.log("About to show sheet to edit section mode"); + var modesText = toModeTextArray(modeOptions) + + Logger.log("About to call ionicActionSheet.show"); + $ionicActionSheet.show({titleText: "Edit Mode", + cancel: function() { + Logger.log("Canceled incident or edit trip"); + }, + buttons: modesText, + buttonClicked: function(index, button) { + Logger.log("Clicked button "+button.text+" at index "+index); + if (button.text != "Cancel") { + Logger.log("Choose " + button.text); + //addModeToSection(button.text, ts, feature, layer) + var modeObj2 = modeTextToValue(button.text, ts, feature, true); + $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, modeObj2).then(function() { + addModeToSectionDisplay(modeObj2, trip); + }).then(function(res) { + var sectionsSource = trip.features.map(function(section){ + var aSectionsSource; + if(section.type == "FeatureCollection"){ + aSectionsSource = section.features[0].properties.source; + } + return aSectionsSource; + }) + var removeSensedSections = [] + if(sectionsSource.indexOf('user') > -1) { + trip.features.forEach(function(section, index) { + if(section.type == "FeatureCollection" && + section.features[0].properties.source != 'user') { + removeSensedSections.push(index) + } + }); + removeSensedSections.forEach(function(index){ + trip.features.splice(index, 1); + }) + }; + var tc = Timeline.getTripComponents(trip) + trip.sections = tc[3] + }); + return true; + } + } + }); }); } - edm.editMode = function(feature, layer) { + edm.editMode = function(latlng, ts, feature, layer) { //layer.bindPopup(""+dh.getHumanReadable(feature.properties.sensed_mode)); + //return function(e) { + console.log("Edit mode sheet") + modeSheet(latlng, ts, feature, layer) + //} + } + + edm.splitTrip = function(feature, layer) { return function(e) { - console.log("Edit mode sheet") - incidentOrModeSheet(feature, layer) + var trip = Timeline.getTrip(feature.properties.trip_id.$oid); + if(feature.properties.source == 'user' && (feature.properties.end_ts != trip.properties.end_ts)) { + Logger.log("skipping trip split because clicked edited section") + } else { + console.log("Split trip") + var latlng = e.latlng + var marker = L.circleMarker(latlng) + var sectionsPoints = PostTripManualMarker.getSectionPoints(feature) + var sortedPoints = PostTripManualMarker.getClosestPoints(marker.toGeoJSON(), sectionsPoints); + if (sortedPoints[0].selDistance > PostTripManualMarker.DISTANCE_THRESHOLD()) { + Logger.log("skipping trip split because closest distance " + + sortedPoints[0].selDistance + " > DISTANCE_THRESHOLD " + PostTripManualMarker.DISTANCE_THRESHOLD()); + return; + }; + var closestPoints = sortedPoints.slice(0,10); + Logger.log("Closest 10 points are "+ closestPoints.map(JSON.stringify)); + + var timeBins = PostTripManualMarker.getTimeBins(closestPoints); + Logger.log("number of bins = " + timeBins.length); + + + if (timeBins.length == 1) { + // Common case: find the first item in the first time bin, no need to + // prompt + Logger.log("About to retrieve ts from first bin of "+timeBins); + var ts = timeBins[0][0].ts; + splitSheet(latlng, ts, feature, layer) + } else { + Logger.log("About to retrieve first ts from each bin of "+timeBins); + var tsOptions = timeBins.map(function(bin) { + return bin[0].ts; + }); + Logger.log("tsOptions = " + tsOptions); + var timeSelActions = tsOptions.map(function(ts) { + return {text: PostTripManualMarker.getFormattedTime(ts), + selValue: ts}; + }); + $ionicActionSheet.show({titleText: "Choose split time", + buttons: timeSelActions, + buttonClicked: function(index, button) { + var ts = button.selValue; + splitSheet(latlng, ts, feature, layer); + return true; + } + }); + } + } } } - var incidentOrModeSheet = function(feature, layer) { + var splitTripAt = function(latlng, ts, feature, layer) { + console.log(latlng) + console.log(ts) + edm.editMode(latlng, ts, feature, layer) + } + + var splitSheet = function(latlng, ts, feature, layer) { + Logger.log("About to show sheet to split trip"); + var modesText = [{text:'Split'}, + {text:'Cancel'}] + + Logger.log("About to call ionicActionSheet.show"); + $ionicActionSheet.show({titleText: "Split Trip", + cancel: function() { + Logger.log("Canceled split trip"); + }, + buttons: modesText, + buttonClicked: function(index, button) { + Logger.log("Clicked button "+button.text+" at index "+index); + if (button.text != "Cancel") { + Logger.log("Choose " + button.text); + splitTripAt(latlng, ts, feature, layer) + } + return true; + } + }) + }; + + var modeSheet = function(latlng, ts, feature, layer) { Logger.log("About to show sheet to edit section mode"); var modesText = toModeTextArray(modeOptions) @@ -1176,13 +1399,26 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', Logger.log("Clicked button "+button.text+" at index "+index); if (button.text != "Cancel") { Logger.log("Choose " + button.text); - addModeToSection(button.text, feature, layer) + addModeToSection(button.text, ts, feature, layer) } return true; } }) }; + var filterOutOldModes = function(modesList) { + var list = []; + var nonDupTs = []; + var modeListDraft = modesList.sort(function(x, y){return x.ts - y.ts}); + modeListDraft.forEach(function(mode) { + if(nonDupTs.indexOf(mode.start_ts) == -1) { + list.push(mode) + nonDupTs.push(mode.start_ts) + } + }) + return list; + } + var getTripMode = function(trip) { return $window.cordova.plugins.BEMUserCache.getAllMessages(MODE_CONFIRM_KEY, false).then(function(modes) { Logger.log("Modes stored locally" + JSON.stringify(modes)); @@ -1190,19 +1426,21 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', var modeHistory = [] if(modes.length > 0) { modes.forEach(function(mode) { - if (mode.trip_mode == false && mode.tripId == trip.id) { + if (mode.trip_mode == false && trip.properties.start_ts <= mode.start_ts + && mode.end_ts <= trip.properties.end_ts) { modeHistory.push(mode) Logger.log("trip" + JSON.stringify(trip)+ "mode" + JSON.stringify(tripMode)); } }); } - if(modeHistory.length > 0) { + /*if(modeHistory.length > 0) { modeHistory.sort(function(x, y){ return x.ts - y.ts; }) tripMode = modeHistory[modeHistory.length-1] - } - return tripMode; + }*/ + var modeHistoryReturn = filterOutOldModes(modeHistory) + return modeHistory; }); } @@ -1215,10 +1453,36 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', }; edm.addUnpushedSectionMode = function(trip) { - getTripMode(trip).then(function(mode) { - if(isNotEmpty(mode)){ - addModeToSectionDisplay(mode, trip); - } + getTripMode(trip).then(function(modes) { + modes.forEach(function(mode) { + if(isNotEmpty(modes)){ + addModeToSectionDisplay(mode, trip); + } + }); + //console.log(trip); + return trip; + }).then(function(trip) { + var sectionsSource = trip.features.map(function(section){ + var aSectionsSource; + if(section.type == "FeatureCollection"){ + aSectionsSource = section.features[0].properties.source; + } + return aSectionsSource; + }) + var removeSensedSections = [] + if(sectionsSource.indexOf('user') > -1) { + trip.features.forEach(function(section, index) { + if(section.type == "FeatureCollection" && + section.features[0].properties.source != 'user') { + removeSensedSections.push(index) + } + }); + removeSensedSections.forEach(function(index){ + trip.features.splice(index, 1); + }) + }; + var tc = Timeline.getTripComponents(trip) + trip.sections = tc[3] }); } diff --git a/www/js/incident/post-trip-manual.js b/www/js/incident/post-trip-manual.js index 26db76773..71bcd2975 100644 --- a/www/js/incident/post-trip-manual.js +++ b/www/js/incident/post-trip-manual.js @@ -9,7 +9,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', var MULTI_PASS_THRESHOLD = 90; var MANUAL_INCIDENT = "manual/incident"; var theFeatureArray =[]; - var DISTANCE_THRESHOLD = function() { + ptmm.DISTANCE_THRESHOLD = function() { if ($ionicPlatform.is("android")) { return 200; } else { @@ -90,7 +90,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', * Uses sortPointsByDistance. */ - var getClosestPoints = function(selPoint, allPoints) { + ptmm.getClosestPoints = function(selPoint, allPoints) { var selPointLatLng = L.GeoJSON.coordsToLatLng(selPoint.geometry.coordinates); // Add distance to the selected point to the properties var sortedPoints = angular.copy(allPoints); @@ -119,7 +119,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', * This uses sortPointsByTime */ - var getTimeBins = function(closestPoints) { + ptmm.getTimeBins = function(closestPoints) { var sortedTsList = angular.copy(closestPoints).sort(sortPointsByTime); sortedTsList.forEach(function(currItem, i) { if (i == 0) { @@ -240,7 +240,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', Logger.log("About to call ionicActionSheet.show"); $ionicActionSheet.show({titleText: "lat: "+latlng.lat.toFixed(6) +", lng: " + latlng.lng.toFixed(6) - + " at " + getFormattedTime(ts), + + " at " + ptmm.getFormattedTime(ts), // cancelText: 'Cancel', cancel: function() { cancelTempEntry(latlng, ts, marker, map); @@ -266,7 +266,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', }); }; - var getFormattedTime = function(ts_sec) { + ptmm.getFormattedTime = function(ts_sec) { return moment(ts_sec * 1000).format('LT'); } @@ -329,13 +329,13 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', */ ptmm.startAddingIncidentToPoints = function(layer, allPoints, geojsonFeatureArray) { - Logger.log("points "+getFormattedTime(allPoints[0].ts) - + " -> "+getFormattedTime(allPoints[allPoints.length -1].ts) + Logger.log("points "+ptmm.getFormattedTime(allPoints[0].ts) + + " -> "+ptmm.getFormattedTime(allPoints[allPoints.length -1].ts) + " bound incident addition "); return function(e) { - Logger.log("points "+getFormattedTime(allPoints[0].ts) - + " -> "+getFormattedTime(allPoints[allPoints.length -1].ts) + Logger.log("points "+ptmm.getFormattedTime(allPoints[0].ts) + + " -> "+ptmm.getFormattedTime(allPoints[allPoints.length -1].ts) + " received click event, adding stress popup at " + e.latlng); if ($state.$current == "root.main.diary") { @@ -349,17 +349,17 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', var latlng = e.latlng; var marker = L.circleMarker(latlng).addTo(map); - var sortedPoints = getClosestPoints(marker.toGeoJSON(), allPoints); - if (sortedPoints[0].selDistance > DISTANCE_THRESHOLD()) { + var sortedPoints = ptmm.getClosestPoints(marker.toGeoJSON(), allPoints); + if (sortedPoints[0].selDistance > ptmm.DISTANCE_THRESHOLD()) { Logger.log("skipping incident addition because closest distance " - + sortedPoints[0].selDistance + " > DISTANCE_THRESHOLD " + DISTANCE_THRESHOLD()); + + sortedPoints[0].selDistance + " > DISTANCE_THRESHOLD " + ptmm.DISTANCE_THRESHOLD()); cancelTempEntry(latlng, ts, marker, map); return; }; var closestPoints = sortedPoints.slice(0,10); Logger.log("Closest 10 points are "+ closestPoints.map(JSON.stringify)); - var timeBins = getTimeBins(closestPoints); + var timeBins = ptmm.getTimeBins(closestPoints); Logger.log("number of bins = " + timeBins.length); @@ -387,7 +387,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', }); Logger.log("tsOptions = " + tsOptions); var timeSelActions = tsOptions.map(function(ts) { - return {text: getFormattedTime(ts), + return {text: ptmm.getFormattedTime(ts), selValue: ts}; }); $ionicActionSheet.show({titleText: "Choose incident time", @@ -472,7 +472,7 @@ angular.module('emission.incident.posttrip.manual', ['emission.plugin.logger', */ ptmm.displayIncident = function(feature, layer) { - return layer.bindPopup(""+getFormattedTime(feature.properties.ts)); + return layer.bindPopup(""+ptmm.getFormattedTime(feature.properties.ts)); }; /* diff --git a/www/templates/diary/list.html b/www/templates/diary/list.html index 285fef70d..eea250572 100644 --- a/www/templates/diary/list.html +++ b/www/templates/diary/list.html @@ -92,7 +92,7 @@
-
+
Multiple modes
From ab9bdb3596cf19491d5ecd2fc16b6a648319bdd6 Mon Sep 17 00:00:00 2001 From: sunil07t Date: Mon, 1 Jan 2018 14:46:29 -0800 Subject: [PATCH 08/11] removed dup life --- www/js/diary/oldList.js | 540 ---------------------------------------- 1 file changed, 540 deletions(-) delete mode 100644 www/js/diary/oldList.js diff --git a/www/js/diary/oldList.js b/www/js/diary/oldList.js deleted file mode 100644 index 3147c315a..000000000 --- a/www/js/diary/oldList.js +++ /dev/null @@ -1,540 +0,0 @@ -'use strict'; - -angular.module('emission.main.diary.list',['ui-leaflet', - 'ionic-datepicker', - 'emission.main.common.services', - 'emission.incident.posttrip.manual', - 'emission.services', - 'ng-walkthrough', 'nzTour', 'angularLocalStorage', - 'emission.plugin.logger']) - -.controller("DiaryListCtrl", function($window, $scope, $rootScope, $ionicPlatform, $state, - $ionicScrollDelegate, $ionicPopup, - $ionicLoading, - $ionicActionSheet, - ionicDatePicker, - leafletData, Timeline, CommonGraph, DiaryHelper, - Config, PostTripManualMarker, nzTour, storage, $ionicPopover) { - console.log("controller DiaryListCtrl called"); - var MODE_CONFIRM_KEY = "manual/mode_confirm"; - var PURPOSE_CONFIRM_KEY = "manual/purpose_confirm"; - - // Add option - // StatusBar.styleBlackOpaque() - $scope.dark_theme = $rootScope.dark_theme; - - $scope.$on('leafletDirectiveMap.resize', function(event, data) { - console.log("diary/list received resize event, invalidating map size"); - data.leafletObject.invalidateSize(); - }); - - 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. - // TODO: Convert the usercache calls into promises so that we don't have to - // do this juggling - Timeline.updateForDay(day); - // CommonGraph.updateCurrent(); - }; - - $scope.$on('$ionicView.afterEnter', function() { - if($rootScope.barDetail){ - readAndUpdateForDay($rootScope.barDetailDate); - $rootScope.barDetail = false; - }; - }); - - readAndUpdateForDay(moment().startOf('day')); - - angular.extend($scope, { - defaults: { - zoomControl: false, - dragging: false, - zoomAnimation: true, - touchZoom: false, - scrollWheelZoom: false, - doubleClickZoom: false, - boxZoom: false, - } - }); - - angular.extend($scope.defaults, Config.getMapTiles()) - - moment.locale('en', { - relativeTime : { - future: "in %s", - past: "%s ago", - s: "secs", - m: "a min", - mm: "%d m", - h: "an hr", - hh: "%d h", - d: "a day", - dd: "%d days", - M: "a month", - MM: "%d months", - y: "a year", - yy: "%d years" - } -}); - - /* - * While working with dates, note that the datepicker needs a javascript date because it uses - * setHours here, while the currDay is a moment, since we use it to perform - * +date and -date operations. - */ - $scope.listExpandClass = function () { - return ($scope.dark_theme)? "earlier-later-expand-dark" : "earlier-later-expand"; - } - $scope.listLocationClass = function() { - return ($scope.dark_theme)? "item item-icon-left list-location-dark" : "item item-icon-left list-location"; - } - $scope.listTextClass = function() { - return ($scope.dark_theme)? "list-text-dark" : "list-text"; - } - $scope.ionViewBackgroundClass = function() { - return ($scope.dark_theme)? "ion-view-background-dark" : "ion-view-background"; - } - $scope.datePickerClass = function() { - } - $scope.listCardClass = function(tripgj) { - var background = DiaryHelper.getTripBackground($scope.dark_theme, tripgj); - if ($window.screen.width <= 320) { - return "list card list-card "+ background +" list-card-sm"; - } else if ($window.screen.width <= 375) { - return "list card list-card "+ background +" list-card-md"; - } else { - return "list card list-card "+background+" list-card-lg"; - } - - } - $scope.listColLeftClass = function(margin) { - if (margin == 0) { - return ($scope.dark_theme)? "col-50 list-col-left-dark" : "col-50 list-col-left"; - } else { - return ($scope.dark_theme)? "col-50 list-col-left-margin-dark" : "col-50 list-col-left-margin"; - } - } - $scope.listColRightClass = function() { - return ($scope.dark_theme)? "col-50 list-col-right-dark" : "col-50 list-col-right"; - } - $scope.differentCommon = function(tripgj) { - return ($scope.isCommon(tripgj.id))? ((DiaryHelper.getEarlierOrLater(tripgj.data.properties.start_ts, tripgj.data.id) == '')? false : true) : false; - } - $scope.stopTimeTagClass = function(tripgj) { - return ($scope.differentCommon(tripgj))? "stop-time-tag-lower" : "stop-time-tag"; - } - $scope.setCurrDay = function(val) { - if (typeof(val) === 'undefined') { - window.Logger.log(window.Logger.LEVEL_INFO, 'No date selected'); - } else { - window.Logger.log(window.Logger.LEVEL_INFO, 'Selected date is :' + val); - readAndUpdateForDay(moment(val)); - } - } - $scope.localTimeString = function(dt) { - var hr = ((dt.hour > 12))? dt.hour - 12 : dt.hour; - var post = ((dt.hour >= 12))? " pm" : " am"; - var min = (dt.minute.toString().length == 1)? "0" + dt.minute.toString() : dt.minute.toString(); - return hr + ":" + min + post; - } - - $scope.datepickerObject = { - - todayLabel: 'Today', //Optional - closeLabel: 'Close', //Optional - setLabel: 'Set', //Optional - setButtonType : 'button-positive', //Optional - todayButtonType : 'button-stable', //Optional - closeButtonType : 'button-stable', //Optional - inputDate: new Date(), //Optional - from: new Date(2015, 1, 1), - to: new Date(), - mondayFirst: true, //Optional - templateType: 'popup', //Optional - showTodayButton: 'true', //Optional - modalHeaderColor: 'bar-positive', //Optional - modalFooterColor: 'bar-positive', //Optional - callback: $scope.setCurrDay, //Mandatory - dateFormat: 'dd MMM yyyy', //Optional - closeOnSelect: true //Optional - }; - - $scope.pickDay = function() { - ionicDatePicker.openDatePicker($scope.datepickerObject); - } - - $scope.$on(Timeline.UPDATE_DONE, function(event, args) { - console.log("Got timeline update done event with args "+JSON.stringify(args)); - $scope.$apply(function() { - $scope.data = Timeline.data; - $scope.datepickerObject.inputDate = Timeline.data.currDay.toDate(); - $scope.data.currDayTrips.forEach(function(trip, index, array) { - PostTripManualMarker.addUnpushedIncidents(trip); - }); - $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( - DiaryHelper.directiveForTrip); - $ionicScrollDelegate.scrollTop(true); - }); - }); - - $scope.$on(CommonGraph.UPDATE_DONE, function(event, args) { - console.log("Got common graph update done event with args "+JSON.stringify(args)); - $scope.$apply(function() { - // If we don't have the trip wrappers yet, then we can just bail because - // 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) && !angular.isUndefined($scope.data.currDayTripWrappers)) { - $scope.data.currDayTripWrappers.forEach(function(tripWrapper, index, array) { - DiaryHelper.fillCommonTripCount(tripWrapper); - }); - }; - }); - }); - - $scope.setColor = function(mode) { - var colors = {"icon ion-android-bicycle":'green', - "icon ion-android-walk":'brown', - "icon ion-speedometer":'red',}; - return { color: colors[mode] }; - } - - var showNoTripsAlert = function() { - var buttons = [ - {text: 'New', type: 'button-balanced', onTap: function(e) { $state.go('root.main.recent.log'); }}, - {text: 'Force', type: 'button-balanced', onTap: function(e) { $state.go('root.main.control'); }}, - {text: 'OK', type: 'button-balanced', onTap: function(e) { return; }}, - ]; - console.log("No trips found for day "); - var alertPopup = $ionicPopup.show({ - title: 'No trips found!', - template: "This is probably because you didn't go anywhere. You can also check", - buttons: buttons - }); - return alertPopup; - } - - /* - * Disabling the reload of the page on background sync because it doesn't - * work correctly. on iOS, plugins are not loaded if backgroundFetch or - * remote push are invoked, since they don't initialize the app. On - * android, it looks like the thread ends before the maps are fully loaded, - * so we have half displayed, frozen maps. We should really check the - * status, reload here if active and reload everything on resume. - * For now, we just add a refresh button to avoid maintaining state. - window.broadcaster.addEventListener( "edu.berkeley.eecs.emission.sync.NEW_DATA", function( e ) { - window.Logger.log(window.Logger.LEVEL_INFO, - "new data received! reload data for the current day"+$scope.data.currDay); - $window.location.reload(); - // readAndUpdateForDay($scope.data.currDay); - }); - */ - - $scope.refresh = function() { - if ($ionicScrollDelegate.getScrollPosition().top < 5) { - readAndUpdateForDay(Timeline.data.currDay); - $scope.$broadcast('invalidateSize'); - } - } - - /* For UI control */ - $scope.groups = []; - for (var i=0; i<10; i++) { - $scope.groups[i] = { - name: i, - items: ["good1", "good2", "good3"] - }; - for (var j=0; j<3; j++) { - $scope.groups[i].items.push(i + '-' + j); - } - } - $scope.toggleGroup = function(group) { - if ($scope.isGroupShown(group)) { - $scope.shownGroup = null; - } else { - $scope.shownGroup = group; - } - }; - $scope.isGroupShown = function(group) { - return $scope.shownGroup === group; - }; - $scope.getEarlierOrLater = DiaryHelper.getEarlierOrLater; - $scope.getLongerOrShorter = DiaryHelper.getLongerOrShorter; - $scope.getHumanReadable = DiaryHelper.getHumanReadable; - $scope.allModes = DiaryHelper.allModes; - $scope.getKmph = DiaryHelper.getKmph; - $scope.getPercentages = DiaryHelper.getPercentages; - $scope.getFormattedDistance = DiaryHelper.getFormattedDistance; - $scope.getSectionDetails = DiaryHelper.getSectionDetails; - $scope.getFormattedTime = DiaryHelper.getFormattedTime; - $scope.getFormattedTimeRange = DiaryHelper.getFormattedTimeRange; - $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; - $scope.getTripDetails = DiaryHelper.getTripDetails; - $scope.starColor = DiaryHelper.starColor; - $scope.arrowColor = DiaryHelper.arrowColor; - $scope.getArrowClass = DiaryHelper.getArrowClass; - $scope.isCommon = DiaryHelper.isCommon; - $scope.isDraft = DiaryHelper.isDraft; - // $scope.expandEarlierOrLater = DiaryHelper.expandEarlierOrLater; - // $scope.increaseRestElementsTranslate3d = DiaryHelper.increaseRestElementsTranslate3d; - - $scope.makeCurrent = function() { - $ionicPopup.alert({template: "Coming soon, after Shankari's quals in early March!"}); - } - - $scope.userModes = [ - "walk", "bicycle", "car", "bus", "train", "unicorn" - ]; - $scope.parseEarlierOrLater = DiaryHelper.parseEarlierOrLater; - - $scope.getTimeSplit = function(tripList) { - var retVal = {}; - var tripTimes = tripList.map(function(dt) { - return dt.data.properties.duration; - }); - - }; - - // Tour steps - var tour = { - config: { - mask: { - visibleOnNoTarget: true, - clickExit: true - } - }, - steps: [{ - target: '#date-picker-button', - content: 'Use this to select the day you want to see.' - }, - { - target: '.diary-entry', - content: 'Click on the map to see more details about each trip.' - }, - { - target: '#map-fix-button', - content: 'Use this to fix the map tiles if they have not loaded properly.' - }] - }; - - var startWalkthrough = function () { - nzTour.start(tour).then(function(result) { - Logger.log("list walkthrough start completed, no error"); - }).catch(function(err) { - Logger.log("list walkthrough start errored" + err); - }); - }; - - $scope.refreshTiles = function() { - $scope.$broadcast('invalidateSize'); - }; - - /* - * Checks if it is the first time the user has loaded the diary tab. If it is then - * show a walkthrough and store the info that the user has seen the tutorial. - */ - var checkDiaryTutorialDone = function () { - var DIARY_DONE_KEY = 'diary_tutorial_done'; - var diaryTutorialDone = storage.get(DIARY_DONE_KEY); - if (!diaryTutorialDone) { - startWalkthrough(); - storage.set(DIARY_DONE_KEY, true); - } - }; - - $scope.startWalkthrough = function () { - startWalkthrough(); - } - - $scope.$on('$ionicView.enter', function(ev) { - // Workaround from - // https://github.com/driftyco/ionic/issues/3433#issuecomment-195775629 - if(ev.targetScope !== $scope) - return; - checkDiaryTutorialDone(); - }); - - $scope.prevDay = function() { - console.log("Called prevDay when currDay = "+Timeline.data.currDay.format('YYYY-MM-DD')); - var prevDay = moment(Timeline.data.currDay).subtract(1, 'days'); - console.log("prevDay = "+prevDay.format('YYYY-MM-DD')); - readAndUpdateForDay(prevDay); - }; - - $scope.nextDay = function() { - console.log("Called nextDay when currDay = "+Timeline.data.currDay.format('YYYY-MM-DD')); - var nextDay = moment(Timeline.data.currDay).add(1, 'days'); - console.log("nextDay = "+nextDay); - readAndUpdateForDay(nextDay); - }; - - $scope.toDetail = function(param) { - $state.go('root.main.diary-detail', {tripId: param}); - }; - - $scope.showModes = DiaryHelper.showModes; - - $ionicPopover.fromTemplateUrl('templates/diary/mode-popover.html', { - scope: $scope - }).then(function(popover) { - $scope.modePopover = popover; - }); - - $scope.openModePopover = function($event, start_ts, end_ts) { - $scope.draftMode = {"start_ts": start_ts, "end_ts": end_ts} - Logger.log("in openModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); - $scope.modePopover.show($event); - }; - - var closeModePopover = function($event, isOther) { - if(isOther == false) - $scope.draftMode = angular.undefined; - Logger.log("in closeModePopover, setting draftMode = "+JSON.stringify($scope.draftMode)); - $scope.modePopover.hide($event); - }; - - $ionicPopover.fromTemplateUrl('templates/diary/purpose-popover.html', { - scope: $scope - }).then(function(popover) { - $scope.purposePopover = popover; - }); - - $scope.openPurposePopover = function($event, start_ts, end_ts) { - $scope.draftPurpose = {"start_ts": start_ts, "end_ts": end_ts} - Logger.log("in openPurposePopover, setting draftPurpose = "+JSON.stringify($scope.draftPurpose)); - $scope.purposePopover.show($event); - }; - - var closePurposePopover = function($event, isOther) { - if(isOther == false) - $scope.draftPurpose = angular.undefined; - Logger.log("in closePurposePopover, setting draftPurpose = "+JSON.stringify($scope.draftPurpose)); - $scope.purposePopover.hide($event); - }; - - $scope.chosen = {mode:'',purpose:''}; - - var checkOtherOption = function(choice, isOther) { - if(choice == 'other_mode' || choice == 'other_purpose') { - var text = choice == 'other_mode' ? "mode" : "purpose"; - $ionicPopup.show({title: "Please fill in the " + text + " not listed.", - scope: $scope, - template: '', - buttons: [ - { text: 'Cancel' }, { - text: 'Save', - type: 'button-positive', - onTap: function(e) { - if (!$scope.chosen.other) { - e.preventDefault(); - } else { - Logger.log("in choose other, other = "+JSON.stringify($scope.chosen)); - if(choice == 'other_mode') { - $scope.storeMode($scope.chosen.other, isOther); - $scope.chosen.other = ''; - } else { - $scope.storePurpose($scope.chosen.other, isOther); - $scope.chosen.other = ''; - } - return $scope.chosen.other; - } - } - } - ] - }); - - } - }; - - $scope.choosePurpose = function() { - var isOther = false - if($scope.chosen.purpose != "other_purpose"){ - $scope.storePurpose($scope.chosen.purpose, isOther); - } else { - isOther = true - checkOtherOption($scope.chosen.purpose, isOther); - } - closePurposePopover(); - }; - - $scope.chooseMode = function (){ - var isOther = false - if($scope.chosen.mode != "other_mode"){ - $scope.storeMode($scope.chosen.mode, isOther); - } else { - isOther = true - checkOtherOption($scope.chosen.mode, isOther); - } - closeModePopover(); - }; - - $scope.modeOptions = [ - {text:'Walk', value:'walk'}, - {text:'Bike',value:'bike'}, - {text:'Drove Alone',value:'drove_alone'}, - {text:'Shared Ride',value:'shared_ride'}, - {text:'Taxi/Uber/Lyft',value:'taxi'}, - {text:'Bus',value:'bus'}, - {text:'Train',value:'train'}, - {text:'Free Shuttle',value:'free_shuttle'}, - {text:'Other',value:'other_mode'}]; - - $scope.purposeOptions = [ - {text:'Home', value:'home'}, - {text:'Work',value:'work'}, - {text:'School',value:'school'}, - {text:'Transit transfer', value:'transit_transfer'}, - {text:'Shopping',value:'shopping'}, - {text:'Meal',value:'meal'}, - {text:'Pick-up/Drop off',value:'pick_drop'}, - {text:'Personal/Medical',value:'personal_med'}, - {text:'Recreation/Exercise',value:'exercise'}, - {text:'Entertainment/Social',value:'entertainment'}, - {text:'Religious', value:'religious'}, - {text:'Other',value:'other_purpose'}]; - - $scope.storeMode = function(mode_val, isOther) { - $scope.draftMode.label = mode_val; - Logger.log("in storeMode, after setting mode_val = "+mode_val+", draftMode = "+JSON.stringify($scope.draftMode)); - $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, $scope.draftMode); - if(isOther = true) - $scope.draftPurpose = angular.undefined; - } - - $scope.storePurpose = function(purpose_val, isOther) { - $scope.draftPurpose.label = purpose_val; - Logger.log("in storePurpose, after setting purpose_val = "+purpose_val+", draftPurpose = "+JSON.stringify($scope.draftPurpose)); - $window.cordova.plugins.BEMUserCache.putMessage(PURPOSE_CONFIRM_KEY, $scope.draftPurpose); - if(isOther = true) - $scope.draftPurpose = angular.undefined; - } - - $scope.redirect = function(){ - $state.go("root.main.current"); - }; - - var in_trip; - $scope.checkTripState = function() { - window.cordova.plugins.BEMDataCollection.getState().then(function(result) { - Logger.log("Current trip state" + JSON.stringify(result)); - if(JSON.stringify(result) == "\"STATE_ONGOING_TRIP\"" || - JSON.stringify(result) == "\"local.state.ongoing_trip\"") { - in_trip = true; - } else { - in_trip = false; - } - }); - }; - - // storing boolean to in_trip and return it in inTrip function - // work because ng-show is watching the inTrip function. - // Returning a promise to ng-show did not work. - // Changing in_trip = bool value; in checkTripState function - // to return bool value and using checkTripState function in ng-show - // did not work. - $scope.inTrip = function() { - $scope.checkTripState(); - return in_trip; - }; -}); \ No newline at end of file From d8753cb91ef937bf55d133a73b1ec4775435e92e Mon Sep 17 00:00:00 2001 From: sunil07t Date: Tue, 23 Jan 2018 13:12:29 -0800 Subject: [PATCH 09/11] Splitting trip works with list of modes and save button --- www/js/diary/detail.js | 2 + www/js/diary/edit-mode.js | 12 ++- www/js/diary/services.js | 128 ++++++++++++++++++++++++++--- www/templates/diary/edit-mode.html | 7 +- 4 files changed, 134 insertions(+), 15 deletions(-) diff --git a/www/js/diary/detail.js b/www/js/diary/detail.js index 3b4e2e192..d4148ea96 100644 --- a/www/js/diary/detail.js +++ b/www/js/diary/detail.js @@ -11,6 +11,8 @@ angular.module('emission.main.diary.detail',['ui-leaflet', 'ng-walkthrough', console.log("controller DiaryDetailCtrl called with params = "+ JSON.stringify($stateParams)); + + $scope.mapCtrl = {}; angular.extend($scope.mapCtrl, { defaults : { diff --git a/www/js/diary/edit-mode.js b/www/js/diary/edit-mode.js index 475f45357..b9e328701 100644 --- a/www/js/diary/edit-mode.js +++ b/www/js/diary/edit-mode.js @@ -7,7 +7,7 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', .controller("EditModeCtrl", function($scope, $rootScope, $window, $stateParams, $ionicActionSheet, leafletData, leafletMapEvents, nzTour, storage, Logger, Timeline, DiaryHelper, Config, - CommHelper, PostTripManualMarker, EditModeFactory) { + CommHelper, PostTripManualMarker, EditModeFactory, $ionicHistory) { console.log("controller editMode called with params = "+ JSON.stringify($stateParams)); @@ -50,6 +50,16 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', console.log($scope.tripgj); console.log($scope.trip); + $scope.save = function() { + EditModeFactory.save($scope.trip) + $ionicHistory.goBack() + } + + $scope.cancel = function() { + EditModeFactory.clear() + $ionicHistory.goBack() + } + $scope.getTripBackground = function() { var ret_val = DiaryHelper.getTripBackground($rootScope.dark_theme, $scope.tripgj); return ret_val; diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 328cabd8e..05dbdeb3e 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -1149,6 +1149,8 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', var edm = {} edm.chosenModeAndSection = [] var MODE_CONFIRM_KEY = "manual/mode_confirm"; + var modeSoFarList = []; + var splitCount = 0; var tripPointsData = function(trip) { @@ -1207,29 +1209,32 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', var trip = Timeline.getTrip(feature.properties.trip_id.$oid); var tripPoints = tripPointsData(trip); tripPoints.sort(function(x, y){return x.data.ts - y.data.ts;}); - var sectionsAddedSoFar = [] + //var sectionsAddedSoFar = [] modeOptions.forEach(function (modeObj) { if(modeText == "Other") modeObjReturn.label = 'other_mode'; //Change this to have users own mode value else if(modeObj.text == modeText) modeObjReturn.label = modeObj.value; }); - trip.features.forEach(function(feature) { + /*trip.features.forEach(function(feature) { if(feature.hasOwnProperty('label')) { if(feature.trip_mode == false) { sectionsAddedSoFar.push(feature) } } - }) + })*/ if(lastSection) { //var index = tripPoints.findIndex(x => x.data.ts == ts); - modeObjReturn.start_ts = sectionsAddedSoFar[sectionsAddedSoFar.length-1].end_ts; + if(splitCount != 0) { + modeSoFarList[modeSoFarList.length-1].end_ts = ts + } + modeObjReturn.start_ts = modeSoFarList[modeSoFarList.length-1].end_ts; modeObjReturn.end_ts = trip.properties.end_ts; } else { - if(sectionsAddedSoFar.length > 0) { - sectionsAddedSoFar.sort(function(x, y){return x.start_ts - y.start_ts;}); - modeObjReturn.start_ts = sectionsAddedSoFar[sectionsAddedSoFar.length-1].start_ts; - } else { - modeObjReturn.start_ts = trip.properties.start_ts; - } + /*if(modeSoFarList.length > 0) { + modeSoFarList.sort(function(x, y){return x.start_ts - y.start_ts;}); + modeObjReturn.start_ts = modeSoFarList[modeSoFarList.length-1].start_ts; + } else {*/ + modeObjReturn.start_ts = trip.properties.start_ts; + //} if(ts != modeObjReturn.start_ts) { modeObjReturn.end_ts = ts; } else { @@ -1239,11 +1244,109 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } //modeObjReturn.tripId = feature.properties.trip_id.$oid; //modeObjReturn.id = feature.id; - modeObjReturn.ts = new Date().getTime(); + //modeObjReturn.ts = new Date().getTime(); modeObjReturn.trip_mode = false; return modeObjReturn; } + edm.save = function(trip) { + if(modeSoFarList.length > 0) { + modeSoFarList.forEach(function(mode) { + $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, mode).then(function() { + addModeToSectionDisplay(mode, trip); + }).then(function(trip) { + var sectionsSource = trip.features.map(function(section){ + var aSectionsSource; + if(section.type == "FeatureCollection"){ + aSectionsSource = section.features[0].properties.source; + } + return aSectionsSource; + }) + var removeSensedSections = [] + if(sectionsSource.indexOf('user') > -1) { + trip.features.forEach(function(section, index) { + if(section.type == "FeatureCollection" && + section.features[0].properties.source != 'user') { + removeSensedSections.push(index) + } + }); + removeSensedSections.forEach(function(index){ + trip.features.splice(index, 1); + }) + }; + var tc = Timeline.getTripComponents(trip) + trip.sections = tc[3] + }); + }) + } + edm.clear() + } + + edm.clear = function() { + modeSoFarList.length = 0 + splitCount = 0 + } + + var addToModesSoFarList = function(modeText, ts, feature, layer) { + var trip = Timeline.getTrip(feature.properties.trip_id.$oid); + var modeObj = {} + if(splitCount == 0) { + modeObj = modeTextToValue(modeText, ts, feature, false); + } else { + modeObj = modeTextToValue(modeText, ts, feature, true); + } + modeSoFarList.push(modeObj); + console.log(modeSoFarList); + //addModeToSectionDisplay(modeObj, trip) + if(splitCount == 0) { + Logger.log("About to show sheet to edit section mode again for second half"); + var modesText = toModeTextArray(modeOptions) + + Logger.log("About to call ionicActionSheet.show"); + $ionicActionSheet.show({titleText: "Edit Mode", + cancel: function() { + Logger.log("Canceled incident or edit trip"); + }, + buttons: modesText, + buttonClicked: function(index, button) { + Logger.log("Clicked button "+button.text+" at index "+index); + if (button.text != "Cancel") { + Logger.log("Choose " + button.text); + //addModeToSection(button.text, ts, feature, layer) + var modeObj2 = modeTextToValue(button.text, ts, feature, true); + modeSoFarList.push(modeObj2); + //addModeToSectionDisplay(modeObj2, trip) + console.log(modeSoFarList); + + /*var sectionsSource = trip.features.map(function(section){ + var aSectionsSource; + if(section.type == "FeatureCollection"){ + aSectionsSource = section.features[0].properties.source; + } + return aSectionsSource; + }) + var removeSensedSections = [] + if(sectionsSource.indexOf('user') > -1) { + trip.features.forEach(function(section, index) { + if(section.type == "FeatureCollection" && + section.features[0].properties.source != 'user') { + removeSensedSections.push(index) + } + }); + removeSensedSections.forEach(function(index){ + trip.features.splice(index, 1); + }) + }; + var tc = Timeline.getTripComponents(trip) + trip.sections = tc[3]*/ + return true; + } + } + }); + } + splitCount += 1; + } + var addModeToSection = function(modeText, ts, feature, layer) { var trip = Timeline.getTrip(feature.properties.trip_id.$oid); var modeObj = modeTextToValue(modeText, ts, feature, false); @@ -1399,7 +1502,8 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', Logger.log("Clicked button "+button.text+" at index "+index); if (button.text != "Cancel") { Logger.log("Choose " + button.text); - addModeToSection(button.text, ts, feature, layer) + //addModeToSection(button.text, ts, feature, layer) + addToModesSoFarList(button.text, ts, feature, layer) } return true; } diff --git a/www/templates/diary/edit-mode.html b/www/templates/diary/edit-mode.html index faa577c2c..c94c241aa 100644 --- a/www/templates/diary/edit-mode.html +++ b/www/templates/diary/edit-mode.html @@ -1,7 +1,10 @@ - + {{ getFormattedDate(tripgj.data.properties.start_ts) }} - + + + +
From 00dfa8d954200694d3f58c65cc3eb522eef53870 Mon Sep 17 00:00:00 2001 From: sunil07t Date: Tue, 23 Jan 2018 17:04:51 -0800 Subject: [PATCH 10/11] removed unnecessary code --- www/js/diary/detail.js | 1 - www/js/diary/services.js | 108 --------------------------------------- 2 files changed, 109 deletions(-) diff --git a/www/js/diary/detail.js b/www/js/diary/detail.js index d4148ea96..6e40401bc 100644 --- a/www/js/diary/detail.js +++ b/www/js/diary/detail.js @@ -67,7 +67,6 @@ angular.module('emission.main.diary.detail',['ui-leaflet', 'ng-walkthrough', $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; $scope.getTripDetails = DiaryHelper.getTripDetails $scope.tripgj = DiaryHelper.directiveForTrip($scope.trip, false); - console.log($scope.tripgj); console.log($scope.trip); $scope.getTripBackground = function() { diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 05dbdeb3e..b6646252b 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -1209,32 +1209,18 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', var trip = Timeline.getTrip(feature.properties.trip_id.$oid); var tripPoints = tripPointsData(trip); tripPoints.sort(function(x, y){return x.data.ts - y.data.ts;}); - //var sectionsAddedSoFar = [] modeOptions.forEach(function (modeObj) { if(modeText == "Other") modeObjReturn.label = 'other_mode'; //Change this to have users own mode value else if(modeObj.text == modeText) modeObjReturn.label = modeObj.value; }); - /*trip.features.forEach(function(feature) { - if(feature.hasOwnProperty('label')) { - if(feature.trip_mode == false) { - sectionsAddedSoFar.push(feature) - } - } - })*/ if(lastSection) { - //var index = tripPoints.findIndex(x => x.data.ts == ts); if(splitCount != 0) { modeSoFarList[modeSoFarList.length-1].end_ts = ts } modeObjReturn.start_ts = modeSoFarList[modeSoFarList.length-1].end_ts; modeObjReturn.end_ts = trip.properties.end_ts; } else { - /*if(modeSoFarList.length > 0) { - modeSoFarList.sort(function(x, y){return x.start_ts - y.start_ts;}); - modeObjReturn.start_ts = modeSoFarList[modeSoFarList.length-1].start_ts; - } else {*/ modeObjReturn.start_ts = trip.properties.start_ts; - //} if(ts != modeObjReturn.start_ts) { modeObjReturn.end_ts = ts; } else { @@ -1242,9 +1228,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', modeObjReturn.end_ts = tripPoints[index+2].data.ts; } } - //modeObjReturn.tripId = feature.properties.trip_id.$oid; - //modeObjReturn.id = feature.id; - //modeObjReturn.ts = new Date().getTime(); modeObjReturn.trip_mode = false; return modeObjReturn; } @@ -1297,7 +1280,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } modeSoFarList.push(modeObj); console.log(modeSoFarList); - //addModeToSectionDisplay(modeObj, trip) if(splitCount == 0) { Logger.log("About to show sheet to edit section mode again for second half"); var modesText = toModeTextArray(modeOptions) @@ -1312,33 +1294,9 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', Logger.log("Clicked button "+button.text+" at index "+index); if (button.text != "Cancel") { Logger.log("Choose " + button.text); - //addModeToSection(button.text, ts, feature, layer) var modeObj2 = modeTextToValue(button.text, ts, feature, true); modeSoFarList.push(modeObj2); - //addModeToSectionDisplay(modeObj2, trip) console.log(modeSoFarList); - - /*var sectionsSource = trip.features.map(function(section){ - var aSectionsSource; - if(section.type == "FeatureCollection"){ - aSectionsSource = section.features[0].properties.source; - } - return aSectionsSource; - }) - var removeSensedSections = [] - if(sectionsSource.indexOf('user') > -1) { - trip.features.forEach(function(section, index) { - if(section.type == "FeatureCollection" && - section.features[0].properties.source != 'user') { - removeSensedSections.push(index) - } - }); - removeSensedSections.forEach(function(index){ - trip.features.splice(index, 1); - }) - }; - var tc = Timeline.getTripComponents(trip) - trip.sections = tc[3]*/ return true; } } @@ -1347,65 +1305,9 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', splitCount += 1; } - var addModeToSection = function(modeText, ts, feature, layer) { - var trip = Timeline.getTrip(feature.properties.trip_id.$oid); - var modeObj = modeTextToValue(modeText, ts, feature, false); - $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, modeObj).then(function() { - //console.log(modeObj); - addModeToSectionDisplay(modeObj, trip); - Logger.log("About to show sheet to edit section mode"); - var modesText = toModeTextArray(modeOptions) - - Logger.log("About to call ionicActionSheet.show"); - $ionicActionSheet.show({titleText: "Edit Mode", - cancel: function() { - Logger.log("Canceled incident or edit trip"); - }, - buttons: modesText, - buttonClicked: function(index, button) { - Logger.log("Clicked button "+button.text+" at index "+index); - if (button.text != "Cancel") { - Logger.log("Choose " + button.text); - //addModeToSection(button.text, ts, feature, layer) - var modeObj2 = modeTextToValue(button.text, ts, feature, true); - $window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, modeObj2).then(function() { - addModeToSectionDisplay(modeObj2, trip); - }).then(function(res) { - var sectionsSource = trip.features.map(function(section){ - var aSectionsSource; - if(section.type == "FeatureCollection"){ - aSectionsSource = section.features[0].properties.source; - } - return aSectionsSource; - }) - var removeSensedSections = [] - if(sectionsSource.indexOf('user') > -1) { - trip.features.forEach(function(section, index) { - if(section.type == "FeatureCollection" && - section.features[0].properties.source != 'user') { - removeSensedSections.push(index) - } - }); - removeSensedSections.forEach(function(index){ - trip.features.splice(index, 1); - }) - }; - var tc = Timeline.getTripComponents(trip) - trip.sections = tc[3] - }); - return true; - } - } - }); - }); - } - edm.editMode = function(latlng, ts, feature, layer) { - //layer.bindPopup(""+dh.getHumanReadable(feature.properties.sensed_mode)); - //return function(e) { console.log("Edit mode sheet") modeSheet(latlng, ts, feature, layer) - //} } edm.splitTrip = function(feature, layer) { @@ -1432,8 +1334,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', if (timeBins.length == 1) { - // Common case: find the first item in the first time bin, no need to - // prompt Logger.log("About to retrieve ts from first bin of "+timeBins); var ts = timeBins[0][0].ts; splitSheet(latlng, ts, feature, layer) @@ -1502,7 +1402,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', Logger.log("Clicked button "+button.text+" at index "+index); if (button.text != "Cancel") { Logger.log("Choose " + button.text); - //addModeToSection(button.text, ts, feature, layer) addToModesSoFarList(button.text, ts, feature, layer) } return true; @@ -1537,12 +1436,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } }); } - /*if(modeHistory.length > 0) { - modeHistory.sort(function(x, y){ - return x.ts - y.ts; - }) - tripMode = modeHistory[modeHistory.length-1] - }*/ var modeHistoryReturn = filterOutOldModes(modeHistory) return modeHistory; }); @@ -1563,7 +1456,6 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', addModeToSectionDisplay(mode, trip); } }); - //console.log(trip); return trip; }).then(function(trip) { var sectionsSource = trip.features.map(function(section){ From 43faeca2d3425b4282bc98295b295f4f6dd5e2c3 Mon Sep 17 00:00:00 2001 From: sunil07t Date: Tue, 23 Jan 2018 20:18:28 -0800 Subject: [PATCH 11/11] minor UI changes so not show edit button and show icons for different modes --- www/js/diary/detail.js | 10 +++++ www/js/diary/edit-mode.js | 4 -- www/js/diary/list.js | 5 +-- www/js/diary/services.js | 67 ++++++++++++++++++++++++--------- www/templates/diary/detail.html | 5 ++- www/templates/diary/list.html | 23 +++++++---- 6 files changed, 81 insertions(+), 33 deletions(-) diff --git a/www/js/diary/detail.js b/www/js/diary/detail.js index 6e40401bc..5b8df3179 100644 --- a/www/js/diary/detail.js +++ b/www/js/diary/detail.js @@ -74,6 +74,16 @@ angular.module('emission.main.diary.detail',['ui-leaflet', 'ng-walkthrough', return ret_val; } + $scope.userEdit = function(trip) { + var edited = false + trip.sections.forEach(function(section) { + if(section.id.split('_')[0] == 'edited') { + edited = true + } + }) + return edited + } + console.log("trip.start_place = " + JSON.stringify($scope.trip.start_place)); leafletData.getMap('detail').then(function(map) { diff --git a/www/js/diary/edit-mode.js b/www/js/diary/edit-mode.js index b9e328701..10f8f52fa 100644 --- a/www/js/diary/edit-mode.js +++ b/www/js/diary/edit-mode.js @@ -46,7 +46,6 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', $scope.getFormattedDuration = DiaryHelper.getFormattedDuration; $scope.getTripDetails = DiaryHelper.getTripDetails $scope.tripgj = DiaryHelper.directiveForTrip($scope.trip, true); - $scope.editModeObj = EditModeFactory.chosenModeAndSection console.log($scope.tripgj); console.log($scope.trip); @@ -71,9 +70,6 @@ angular.module('emission.main.diary.editMode',['ui-leaflet', 'ng-walkthrough', map.on('click', PostTripManualMarker.startAddingIncidentToTrip($scope.trip, map)); }); - $scope.$watch(function() { - $scope.editModeObj; - }); $scope.editMode = function(param) { $state.go('root.main.diary-edit-mode', {tripId: param}); diff --git a/www/js/diary/list.js b/www/js/diary/list.js index 676966abb..0d02a193a 100644 --- a/www/js/diary/list.js +++ b/www/js/diary/list.js @@ -241,7 +241,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', $scope.data.currDayTrips.forEach(function(trip, index, array) { addUnpushedMode(trip); PostTripManualMarker.addUnpushedIncidents(trip); - EditModeFactory.addUnpushedSectionMode(trip); + EditModeFactory.addUnpushedSectionMode(trip) }); $scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map( function(trip) { return DiaryHelper.directiveForTrip(trip, false);}); @@ -264,6 +264,7 @@ angular.module('emission.main.diary.list',['ui-leaflet', }); }); + $scope.setColor = function(mode) { var colors = {"icon ion-android-bicycle":'green', "icon ion-android-walk":'brown', @@ -303,8 +304,6 @@ angular.module('emission.main.diary.list',['ui-leaflet', */ - - // TEST CODE REMOVE BEFORE PUSH var printModes = function() { $window.cordova.plugins.BEMUserCache.getAllMessages(MODE_CONFIRM_KEY, false).then(function(modes) { console.log("Modes list"); diff --git a/www/js/diary/services.js b/www/js/diary/services.js index b6646252b..dccfaa87c 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -40,8 +40,21 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', "IN_VEHICLE":"ion-speedometer", "UNKNOWN": "ion-ios-help", "UNPROCESSED": "ion-ios-help", - "AIR_OR_HSR": "ion-plane"} - return icons[dh.getHumanReadable(section.properties.sensed_mode)]; + "AIR_OR_HSR": "ion-plane", + "bike":"ion-android-bicycle", + "walk":"ion-android-walk", + "bus":"ion-android-bus", + "drove_alone":"ion-speedometer", + "shared_ride":"ion-ios-people", + "train":"ion-android-train", + "taxi":"ion-android-car", + "free_shuttle":"ion-android-bus", + "other_mode":"ion-ios-help"} + var mode = dh.getHumanReadable(section.properties.sensed_mode) + if(mode == 'Edited') { + mode = section.properties.user_edited_mode + } + return icons[mode]; } dh.getHumanReadable = function(sensed_mode) { var ret_string = sensed_mode.split('.')[1]; @@ -63,8 +76,17 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', var rtn0 = []; // icons var rtn1 = []; //percentages - var icons = {"BICYCLING":"ion-android-bicycle", + var icons = {"bike":"ion-android-bicycle", + "BICYCLING":"ion-android-bicycle", "WALKING":"ion-android-walk", + "walk":"ion-android-walk", + "bus":"ion-android-bus", + "drove_alone":"ion-speedometer", + "shared_ride":"ion-ios-people", + "train":"ion-android-train", + "taxi":"ion-android-car", + "free_shuttle":"ion-android-bus", + "other_mode":"ion-ios-help", // "RUNNING":" ion-android-walk", // RUNNING has been filtered in function above "IN_VEHICLE":"ion-speedometer", @@ -73,12 +95,16 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', "AIR_OR_HSR": "ion-plane"} var total = 0; for (var i=0; i PostTripManualMarker.DISTANCE_THRESHOLD()) { Logger.log("skipping trip split because closest distance " + sortedPoints[0].selDistance + " > DISTANCE_THRESHOLD " + PostTripManualMarker.DISTANCE_THRESHOLD()); return; - }; + } else { + marker.addTo(map); + } var closestPoints = sortedPoints.slice(0,10); Logger.log("Closest 10 points are "+ closestPoints.map(JSON.stringify)); @@ -1336,7 +1367,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', if (timeBins.length == 1) { Logger.log("About to retrieve ts from first bin of "+timeBins); var ts = timeBins[0][0].ts; - splitSheet(latlng, ts, feature, layer) + splitSheet(latlng, ts, feature, map, marker) } else { Logger.log("About to retrieve first ts from each bin of "+timeBins); var tsOptions = timeBins.map(function(bin) { @@ -1351,7 +1382,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', buttons: timeSelActions, buttonClicked: function(index, button) { var ts = button.selValue; - splitSheet(latlng, ts, feature, layer); + splitSheet(latlng, ts, feature, map, marker); return true; } }); @@ -1360,13 +1391,13 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', } } - var splitTripAt = function(latlng, ts, feature, layer) { + var splitTripAt = function(latlng, ts, feature, map) { console.log(latlng) console.log(ts) - edm.editMode(latlng, ts, feature, layer) + edm.editMode(latlng, ts, feature, map) } - var splitSheet = function(latlng, ts, feature, layer) { + var splitSheet = function(latlng, ts, feature, map, marker) { Logger.log("About to show sheet to split trip"); var modesText = [{text:'Split'}, {text:'Cancel'}] @@ -1381,14 +1412,16 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', Logger.log("Clicked button "+button.text+" at index "+index); if (button.text != "Cancel") { Logger.log("Choose " + button.text); - splitTripAt(latlng, ts, feature, layer) + splitTripAt(latlng, ts, feature, map) + } else { + map.removeLayer(marker); } return true; } }) }; - var modeSheet = function(latlng, ts, feature, layer) { + var modeSheet = function(latlng, ts, feature, map) { Logger.log("About to show sheet to edit section mode"); var modesText = toModeTextArray(modeOptions) @@ -1402,7 +1435,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger', Logger.log("Clicked button "+button.text+" at index "+index); if (button.text != "Cancel") { Logger.log("Choose " + button.text); - addToModesSoFarList(button.text, ts, feature, layer) + addToModesSoFarList(button.text, ts, feature, map) } return true; } diff --git a/www/templates/diary/detail.html b/www/templates/diary/detail.html index 030ad3990..8be080992 100644 --- a/www/templates/diary/detail.html +++ b/www/templates/diary/detail.html @@ -25,9 +25,12 @@ {{tripgj.end_place.properties.displayName.split(',')[0]}}
-
+
+
+ Edited +
-
- -
(draft) - + +
+ +
(draft) + +
-
- + + +