Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the changes to the UI after user chooses mode/purpose on list screen #307

Open
wants to merge 6 commits into
base: cci-berkeley
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 155 additions & 7 deletions www/js/diary/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,132 @@ 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 getTripPurpose = function(trip) {
return $window.cordova.plugins.BEMUserCache.getAllMessages(PURPOSE_CONFIRM_KEY, false).then(function(purposeList) {
Logger.log("Purpose stored locally" + JSON.stringify(purposeList));
var tripPurpose = {};
if(purposeList.length > 0) {
purposeList.forEach(function(purpose) {
if ((trip.properties.start_ts == purpose.start_ts) &&
(trip.properties.end_ts == purpose.end_ts)) {
tripPurpose = purpose;
Logger.log("trip" + JSON.stringify(trip) + "purpose" + JSON.stringify(tripPurpose));
}
});
}
return tripPurpose;
});
}

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 addPurposeFeature = function(trip, purpose) {
$scope.$apply(function() {
var purposeFeature = purpose;
purposeFeature.feature_type = "purpose";
Logger.log("Created purpose feature" + JSON.stringify(purposeFeature) + "for" + JSON.stringify(trip));
trip.features.push(purposeFeature);
$scope.purposeTripgj = 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);
}
});
}

var addUnpushedPurpose = function(trip) {
getTripPurpose(trip).then(function(purpose) {
if(isNotEmpty(purpose)) {
addPurposeFeature(trip, purpose);
}
});
}

$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.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;
}

$scope.checkPurpose = function(trip) {
var hasPurpose = false;
trip.data.features.forEach(function(feature) {
if(feature.feature_type == "purpose") {
var purposes = $scope.purposeOptions.map(a => a.value);
if(purposes.indexOf(feature.label) > -1) {
$scope.purposeOptions.forEach(function(purpose) {
if(feature.label == purpose.value) {
$scope.purpose = purpose.text;
}
});
} else {
$scope.purpose = feature.label;
}
hasPurpose = true;
}
});
return hasPurpose;
}

$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);
addUnpushedPurpose(trip);
PostTripManualMarker.addUnpushedIncidents(trip);
});
$scope.data.currDayTripWrappers = Timeline.data.currDayTrips.map(
Expand Down Expand Up @@ -230,13 +350,32 @@ angular.module('emission.main.diary.list',['ui-leaflet',
// readAndUpdateForDay($scope.data.currDay);
});
*/



// TEST CODE REMOVE BEFORE PUSH
var printPurposes = function() {
$window.cordova.plugins.BEMUserCache.getAllMessages(PURPOSE_CONFIRM_KEY, false).then(function(purposeList) {
console.log("Purpose list");
console.log(purposeList);
});
};

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');
}
}
printPurposes();
printModes();
};

/* For UI control */
$scope.groups = [];
Expand Down Expand Up @@ -381,8 +520,9 @@ angular.module('emission.main.diary.list',['ui-leaflet',
$scope.modePopover = popover;
});

$scope.openModePopover = function($event, start_ts, end_ts) {
$scope.draftMode = {"start_ts": start_ts, "end_ts": end_ts}
$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);
};
Expand All @@ -400,8 +540,9 @@ angular.module('emission.main.diary.list',['ui-leaflet',
$scope.purposePopover = popover;
});

$scope.openPurposePopover = function($event, start_ts, end_ts) {
$scope.draftPurpose = {"start_ts": start_ts, "end_ts": end_ts}
$scope.openPurposePopover = function($event, start_ts, end_ts, tripgj) {
$scope.draftPurpose = {"start_ts": start_ts, "end_ts": end_ts};
$scope.purposeTripgj = tripgj;
Logger.log("in openPurposePopover, setting draftPurpose = "+JSON.stringify($scope.draftPurpose));
$scope.purposePopover.show($event);
};
Expand Down Expand Up @@ -497,15 +638,21 @@ angular.module('emission.main.diary.list',['ui-leaflet',
$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);
$window.cordova.plugins.BEMUserCache.putMessage(MODE_CONFIRM_KEY, $scope.draftMode).then(function() {
console.log($scope.modeTripgj);
addUnpushedMode($scope.modeTripgj.data);
});
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);
$window.cordova.plugins.BEMUserCache.putMessage(PURPOSE_CONFIRM_KEY, $scope.draftPurpose).then(function() {
console.log($scope.purposeTripgj);
addUnpushedPurpose($scope.purposeTripgj.data);
});
if(isOther == true)
$scope.draftPurpose = angular.undefined;
}
Expand Down Expand Up @@ -537,4 +684,5 @@ angular.module('emission.main.diary.list',['ui-leaflet',
$scope.checkTripState();
return in_trip;
};

});
20 changes: 17 additions & 3 deletions www/templates/diary/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,26 @@
</div>
</div>
</div>
<div class="row" style="padding-left: 5px;padding-right: 5px;">
<div class="row" style="padding-left: 5px;padding-right: 5px;">
<div class="col-50" style="text-align: center;font-size: 14px;font-weight: 600;" ng-if="checkMode(tripgj)">
Mode
</div>
<div class="col-50" style="text-align: center;font-size: 14px;font-weight: 600;" ng-if="checkPurpose(tripgj)">
Purpose
</div>
</div>
<div class="row" style="padding-left: 5px;padding-right: 5px;">
<div class="col-50" style="text-align: center;">
<button ng-click ="openModePopover($event, tripgj.data.properties.start_ts, tripgj.data.properties.end_ts)" class="button" style="line-height: 30px;min-height: 30px;font-size: 0.8em;color: #333;background-color: #ddd;width: 115px;padding: 0;">Choose Mode</button>
<div ng-if="checkMode(tripgj)" style="font-size: 14px; margin-top: 5px">
{{mode}}
</div>
<button ng-if="!checkMode(tripgj)" ng-click ="openModePopover($event, tripgj.data.properties.start_ts, tripgj.data.properties.end_ts, tripgj)" class="button" style="line-height: 30px;min-height: 30px;font-size: 0.8em;color: #333;background-color: #ddd;width: 115px;padding: 0;">Choose Mode</button>
</div>
<div class="col-50" style="text-align: center;">
<button ng-click="openPurposePopover($event, tripgj.data.properties.start_ts, tripgj.data.properties.end_ts)" class="button" style="line-height: 30px;min-height: 30px;font-size: 0.8em;color: #333;background-color: #ddd;width: 115px;padding: 0;">Choose Purpose</button>
<div ng-if="checkPurpose(tripgj)" style="font-size: 14px; margin-top: 5px">
{{purpose}}
</div>
<button ng-if="!checkPurpose(tripgj)" ng-click="openPurposePopover($event, tripgj.data.properties.start_ts, tripgj.data.properties.end_ts, tripgj)" class="button" style="line-height: 30px;min-height: 30px;font-size: 0.8em;color: #333;background-color: #ddd;width: 115px;padding: 0;">Choose Purpose</button>
</div>
</div>
</div>
Expand Down