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

Rk unsw #615

Open
wants to merge 22 commits into
base: rk-unsw
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5363d83
fix: Invalid date for processed trips
atton16 Jan 1, 2020
fd66aff
patch: limit datepicker to the date the user signed up
atton16 Jan 1, 2020
84422ee
patch: disable summary slide on intro page
atton16 Mar 11, 2020
4cb6f3d
feat: add repo branch to user data
atton16 Mar 11, 2020
fa189e7
patch: rename repo branch name
atton16 Mar 11, 2020
8814ec5
Merge pull request #619 from atton16/rk-unsw-branchId
shankari Mar 11, 2020
31fe33a
Merge pull request #620 from atton16/rciti1
shankari Mar 11, 2020
ea2327d
Update index.html
atton16 Mar 12, 2020
2ddfbb7
Merge pull request #625 from atton16/rciti1
shankari Mar 12, 2020
6877432
patch(Settings): remove medium accuracy button
atton16 Mar 12, 2020
c902571
patch(Settings): remove tracking button
atton16 Mar 12, 2020
e140fc5
patch(Settings): rename My Profile button
atton16 Mar 12, 2020
78e9661
feat: add end-survey
atton16 Mar 12, 2020
bac9d5c
patch(Settings): remove logout button
atton16 Mar 12, 2020
f1945f0
patch(UI): minor UI changes
atton16 Mar 12, 2020
286ffaf
patch(EndSurvey): refactor
atton16 Mar 12, 2020
f5ccdf2
Merge pull request #629 from atton16/rk-unsw-end-survey-inapp-browser
shankari Mar 12, 2020
3c064f2
Merge branch 'rk-unsw-end-survey-inapp-browser' into rciti1
atton16 Mar 13, 2020
5f1965c
Merge pull request #630 from atton16/rciti1
shankari Mar 13, 2020
5667c3e
patch: update survey version
atton16 Apr 20, 2020
d335c82
Merge branch 'rciti1' into rk-unsw
atton16 Apr 20, 2020
f5ec2d2
Merge branch 'rk-unsw' of github.com:atton16/e-mission-phone into rk-…
atton16 Apr 20, 2020
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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions survey-resources/data-json/20200420-01-user-profile.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions survey-resources/data-xml/20200420-01-trip-end-survey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0"?><h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><h:head><h:title>20200420-01-trip-end-survey</h:title><model odk:xforms-version="1.0.0"><instance><data id="20200420-01-trip-end-survey" version="vDLb2u3LWnnoJMf6mXjhyt"><start/><end/><group_vs9ga59><d_purpose_main>go_home</d_purpose_main></group_vs9ga59><group_ee9rk21><travel_mode_main>vehicle_driver</travel_mode_main><Total_people_in_trip_party>1</Total_people_in_trip_party><Non_household_member_s_on_trip>0</Non_household_member_s_on_trip><Transit_fees_AUD/><Taxi_fees/></group_ee9rk21><group_bn3jd79><Vehicle_trip_Parking_location>1</Vehicle_trip_Parking_location><Parking_cost/><Total_toll_charges_p_ng_the_trip_AUD/></group_bn3jd79><__version__/><meta><instanceID/></meta></data></instance><bind jr:preload="timestamp" jr:preloadParams="start" nodeset="/data/start" type="dateTime"/><bind jr:preload="timestamp" jr:preloadParams="end" nodeset="/data/end" type="dateTime"/><bind nodeset="/data/group_vs9ga59" required="false()"/><bind nodeset="/data/group_vs9ga59/d_purpose_main" required="true()" type="string"/><bind nodeset="/data/group_ee9rk21" required="false()"/><bind nodeset="/data/group_ee9rk21/travel_mode_main" required="true()" type="string"/><bind nodeset="/data/group_ee9rk21/Total_people_in_trip_party" required="true()" type="string"/><bind nodeset="/data/group_ee9rk21/Non_household_member_s_on_trip" relevant=" /data/group_ee9rk21/Total_people_in_trip_party != '1'" required="true()" type="string"/><bind nodeset="/data/group_ee9rk21/Transit_fees_AUD" relevant=" /data/group_ee9rk21/travel_mode_main = 'bus' or /data/group_ee9rk21/travel_mode_main = 'train' or /data/group_ee9rk21/travel_mode_main = 'ferry'" required="true()" type="decimal"/><bind nodeset="/data/group_ee9rk21/Taxi_fees" relevant=" /data/group_ee9rk21/travel_mode_main = 'taxi_and_ride_'" required="true()" type="decimal"/><bind nodeset="/data/group_bn3jd79" required="false()"/><bind nodeset="/data/group_bn3jd79/Vehicle_trip_Parking_location" relevant=" /data/group_ee9rk21/travel_mode_main = 'vehicle_driver'" required="true()" type="string"/><bind nodeset="/data/group_bn3jd79/Parking_cost" relevant=" /data/group_bn3jd79/Vehicle_trip_Parking_location = '4' or /data/group_bn3jd79/Vehicle_trip_Parking_location = '3' or /data/group_bn3jd79/Vehicle_trip_Parking_location = '5' or /data/group_bn3jd79/Vehicle_trip_Parking_location = '997'" required="false()" type="decimal"/><bind nodeset="/data/group_bn3jd79/Total_toll_charges_p_ng_the_trip_AUD" relevant=" /data/group_ee9rk21/travel_mode_main = 'vehicle_driver'" required="false()" type="decimal"/><bind calculate="'vDLb2u3LWnnoJMf6mXjhyt'" nodeset="/data/__version__" type="string"/><bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/></model></h:head><h:body class="pages"><group ref="/data/group_vs9ga59"><label>Trip purpose</label><select1 ref="/data/group_vs9ga59/d_purpose_main"><label>What is the purpose of this trip?</label><item><label>Go home</label><value>go_home</value></item><item><label>Work</label><value>work</value></item><item><label>Work related</label><value>work_related</value></item><item><label>Education</label><value>education</value></item><item><label>Shopping</label><value>shopping</value></item><item><label>Social/recreation</label><value>social_recreation</value></item><item><label>Personal business/services</label><value>personal_business_services</value></item><item><label>Serve passenger (e.g. drop-off, taxi or Uber)</label><value>AUTOMATIC</value></item><item><label>Other</label><value>other</value></item></select1></group><group ref="/data/group_ee9rk21"><label>Mode choice</label><select1 ref="/data/group_ee9rk21/travel_mode_main"><label>What is your main mode of travel for this trip?</label><hint>Choose one that covers the longest distance</hint><item><label>Vehicle driver</label><value>vehicle_driver</value></item><item><label>Vehicle passenger</label><value>vehicle_passenger</value></item><item><label>Walk</label><value>walk</value></item><item><label>Bus</label><value>bus</value></item><item><label>Train or Tram</label><value>train</value></item><item><label>Ferry</label><value>ferry</value></item><item><label>Taxi and ride-sharing services (e.g. Uber)</label><value>taxi_and_ride_</value></item><item><label>Other</label><value>AUTOMATIC</value></item></select1><select1 ref="/data/group_ee9rk21/Total_people_in_trip_party"><label>Total people in trip party</label><hint>Including yourself</hint><item><label>Just me</label><value>1</value></item><item><label>2 Travelers</label><value>2</value></item><item><label>3 Travelers</label><value>3</value></item><item><label>4 Travelers</label><value>4</value></item><item><label>5 Travelers</label><value>5</value></item><item><label>6 Travelers</label><value>6</value></item><item><label>7 Travelers</label><value>7</value></item><item><label>8+ Travelers</label><value>8</value></item></select1><select1 ref="/data/group_ee9rk21/Non_household_member_s_on_trip"><label>Non-household member(s) on trip</label><item><label>Nobody (0 people)</label><value>0</value></item><item><label>1 person</label><value>1</value></item><item><label>2 people</label><value>2</value></item><item><label>3 people</label><value>3</value></item><item><label>4 people</label><value>4</value></item><item><label>5 or more people</label><value>5</value></item></select1><input ref="/data/group_ee9rk21/Transit_fees_AUD"><label>Transit fees ($AUD)</label><hint>Only for yourself</hint></input><input ref="/data/group_ee9rk21/Taxi_fees"><label>Taxi fees ($AUD)</label></input></group><group ref="/data/group_bn3jd79"><label>Vehicle</label><select1 ref="/data/group_bn3jd79/Vehicle_trip_Parking_location"><label>Vehicle trip: Parking location</label><item><label>Own driveway/garage</label><value>1</value></item><item><label>Someone else's driveway</label><value>2</value></item><item><label>Parking lot/garage</label><value>3</value></item><item><label>On street parking</label><value>4</value></item><item><label>Park &amp; ride lot</label><value>5</value></item><item><label>Didn't park (waited, drop-off, drive-thru)</label><value>6</value></item><item><label>Other</label><value>997</value></item></select1><input ref="/data/group_bn3jd79/Parking_cost"><label>Parking cost ($AUD)</label><hint>(If none, put 0 or leave blank )</hint></input><input ref="/data/group_bn3jd79/Total_toll_charges_p_ng_the_trip_AUD"><label>Total toll charges paid during the trip? ($AUD)</label><hint>(If none, put 0 or leave blank )</hint></input></group></h:body></h:html>
1 change: 1 addition & 0 deletions survey-resources/data-xml/20200420-01-user-profile.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions www/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ background-image: none !important; }
.control-icon-user-profile {
background-color: rgb(201, 217, 236);
}
.control-icon-end-survey {
/* background-color: rgb(169, 226, 186); */
background-color: #E0A1A1 !important;
}


#switch-user.control-icon-button{
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<script src="manual_lib/enketo/enketo-bundle.js"></script>
<!-- Manually installed javascript for libraries that are not published through bower -->
<!-- cordova script (this will be a 404 in the browser) -->
<script type="text/javascript" src="cordova.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
Expand Down
10 changes: 10 additions & 0 deletions www/js/control/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ angular.module('emission.main.control',['emission.services',
$ionicPlatform,
$state, $ionicPopup, $ionicActionSheet, $ionicPopover,
$rootScope, KVStore, ionicDatePicker,
$cordovaInAppBrowser,
StartPrefs, ControlHelper, EmailHelper,
ControlCollectionHelper, ControlSyncHelper,
ControlTransitionNotifyHelper,
Expand Down Expand Up @@ -415,6 +416,15 @@ angular.module('emission.main.control',['emission.services',
EnketoSurveyLaunch.launch($scope, 'UserProfile');
};

$scope.launchEndSurvey = function() {
CommHelper.getUser().then(function(profile) {
const uuid = profile && profile.user_id && profile.user_id['$uuid'] ? profile.user_id['$uuid'] : 'undefined';
const fieldPath = '/aDHunALXzzHXAUMrvkvRT9/_user_id';
const returnURL = 'https://reward.amarin.dev';
$cordovaInAppBrowser.open(`https://ee.kobotoolbox.org/single/::T9bEosso?d[${fieldPath}]=${uuid}&returnURL=${returnURL}`, '_blank');
});
}

$scope.userStartStopTracking = function() {
if ($scope.settings.collect.trackingOn){
return ControlCollectionHelper.forceTransition('STOP_TRACKING');
Expand Down
30 changes: 26 additions & 4 deletions www/js/diary/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ angular.module('emission.main.diary.list',['ui-leaflet',
'emission.tripconfirm.services',
'emission.services',
'emission.survey.enketo.launch',
'emission.enketo-survey.service',
'ng-walkthrough', 'nzTour', 'emission.plugin.kvstore',
'emission.plugin.logger'
])
Expand All @@ -25,7 +26,7 @@ angular.module('emission.main.diary.list',['ui-leaflet',
$ionicActionSheet,
ionicDatePicker,
leafletData, Timeline, CommonGraph, DiaryHelper,
Config, PostTripManualMarker, ConfirmHelper, nzTour, KVStore, Logger, UnifiedDataLoader, $ionicPopover, $ionicModal, EnketoSurveyLaunch, $translate) {
Config, PostTripManualMarker, ConfirmHelper, nzTour, KVStore, Logger, UnifiedDataLoader, $ionicPopover, $ionicModal, EnketoSurvey, EnketoSurveyLaunch, CommHelper, $translate) {
console.log("controller DiaryListCtrl called");
var MODE_CONFIRM_KEY = "manual/mode_confirm";
var PURPOSE_CONFIRM_KEY = "manual/purpose_confirm";
Expand Down Expand Up @@ -214,12 +215,19 @@ angular.module('emission.main.diary.list',['ui-leaflet',
}

$scope.populateBasicClasses = function(tripgj) {
tripgj.display_start_time = DiaryHelper.getLocalTimeString(tripgj.data.properties.start_local_dt);
tripgj.display_end_time = DiaryHelper.getLocalTimeString(tripgj.data.properties.end_local_dt);
const start_dt = Object.assign({}, tripgj.data.properties.start_local_dt);
const end_dt = Object.assign({}, tripgj.data.properties.end_local_dt);
tripgj.isDraft = $scope.isDraft(tripgj);
// Fix "Invalid date" for processed trips
if (!tripgj.isDraft) {
start_dt.month = start_dt.month - 1;
Copy link
Contributor

@shankari shankari Jan 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tripgj.data.properties.start_local_dt and tripgj.data.properties.end_local_dt use a 1-12 month value while moment needs 0-11 month value. The test was done on December which translated to value 12. Hence moment throw Invalid date

Are you sure this is the problem? Because if this were the case, then the month would always be off by one (e.g. January would be 1 in the local_dt, converted to February by moment and displayed as such in the UI), and somebody would have noticed before this. Note that getLocalTimeString is used in the master branch as well.

Based on the screenshots, I believe that this fixes the immediate issue that you found, but I am concerned that if it is not based on a well-formed understanding of the underlying bug, it may lead to other regressions.

I would like to see screenshots showing that:

before I approve the change.

end_dt.month = end_dt.month - 1;
}
tripgj.display_start_time = DiaryHelper.getLocalTimeString(start_dt);
tripgj.display_end_time = DiaryHelper.getLocalTimeString(end_dt);
tripgj.display_distance = $scope.getFormattedDistance(tripgj.data.properties.distance);
tripgj.display_time = $scope.getFormattedTimeRange(tripgj.data.properties.start_ts,
tripgj.data.properties.end_ts);
tripgj.isDraft = $scope.isDraft(tripgj);
tripgj.background = DiaryHelper.getTripBackground(tripgj);
tripgj.listCardClass = $scope.listCardClass(tripgj);
tripgj.percentages = $scope.getPercentages(tripgj)
Expand Down Expand Up @@ -700,6 +708,20 @@ angular.module('emission.main.diary.list',['ui-leaflet',
});
});

$scope.$on('$ionicView.afterEnter', function() {
CommHelper.getUser().then(function(user) {
const uuid = user.user_id['$uuid'];
return EnketoSurvey.getAllSurveyAnswers('manual/user_profile_survey'
).then(function(answers){
return EnketoSurvey.getFirstUserProfile({ uuid }, answers);
}).then(function(userProfile){
if (userProfile && userProfile.data.timestamp) {
$scope.datepickerObject.from = moment(userProfile.data.timestamp).startOf('day').toDate();
}
});
});
})

$scope.storeMode = function (mode, isOther) {
if(isOther) {
// Let's make the value for user entered modes look consistent with our
Expand Down
6 changes: 4 additions & 2 deletions www/js/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ angular.module('emission.intro', ['emission.splash.startprefs',
$scope.userEmail = userEmail;
CommHelper.registerUser(function(successResult) {
const uuid = successResult.uuid;
return EnketoSurvey.getAllSurveyAnswers('manual/user_profile_survey'
).then(function(answers){
return CommHelper.updateUser({branch: 'rk-unsw'}
).then(function() {
return EnketoSurvey.getAllSurveyAnswers('manual/user_profile_survey');
}).then(function(answers){
return EnketoSurvey.getUserProfile({ uuid }, answers);
}).then(function(userProfile){
if (userProfile) {
Expand Down
10 changes: 10 additions & 0 deletions www/js/survey/enketo-survey-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ angular.module('emission.enketo-survey.service', [
null;
}

function getFirstUserProfile(user_properties, answers) {
const potentialCandidates = answers.filter(function(answer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to do this? you should not be able to retrieve profiles for other users anyway. You can argue that it doesn't hurt anything, but extra code = extra computation = slower response time.

return answer.data.user_uuid = user_properties.uuid;
});
return potentialCandidates.length ?
potentialCandidates[potentialCandidates.length - 1] :
null;
}

function _restoreAnswer(answers) {
let answer = null;
if (__trip) {
Expand Down Expand Up @@ -170,6 +179,7 @@ angular.module('emission.enketo-survey.service', [
getAllSurveyAnswers: getAllSurveyAnswers,
getState: getState,
getUserProfile: getUserProfile,
getFirstUserProfile: getFirstUserProfile,
populateLabels: populateLabels,
makeAnswerFromAnswerData: makeAnswerFromAnswerData,
};
Expand Down
4 changes: 2 additions & 2 deletions www/js/survey/enketo-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ angular.module('emission.survey.enketo.launch', [

function initConfirmSurvey(opts) {
return initSurvey({
form_location: 'json/trip-end-survey_v9.json',
form_location: 'json/20200420-01-trip-end-survey.json',
opts: {
session: {
data_key: 'manual/confirm_survey',
Expand All @@ -123,7 +123,7 @@ angular.module('emission.survey.enketo.launch', [
}
return promise.then(function(uuid) {
return initSurvey({
form_location: 'json/user-profile_v4.json',
form_location: 'json/20200420-01-user-profile.json',
opts: {
session: {
data_key: 'manual/user_profile_survey',
Expand Down
1 change: 1 addition & 0 deletions www/json/20200420-01-trip-end-survey.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions www/json/20200420-01-user-profile.json

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions www/templates/control/main-control.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
<ion-view view-title="{{'control.profile' | translate}}" ng-class="ion-view-background" translate-namespace="control">
<ion-content>
<div class="control-list-item">
<div class="control-list-text">{{settings.auth.email}}</div>
<div ng-click="returnToIntro()" id ="switch-user" class="control-icon-button"><i class="icon ion-log-out"></i></div>
<div class="control-list-text">Logged in as: {{settings.auth.email}}</div>
<!-- <div ng-click="returnToIntro()" id ="switch-user" class="control-icon-button"><i class="icon ion-log-out"></i></div> -->
</div>
<div class="control-list-item">
<div class="control-list-text">My Profile</div>
<div class="control-list-text">Edit User Profile</div>
<div ng-click="editUserProfile()" class="control-icon-button control-icon-user-profile">
<i class="ion-person"></i>
</div>
</div>
<div class="control-list-item">
<div class="control-list-text">End Survey</div>
<div ng-click="launchEndSurvey()" class="control-icon-button control-icon-end-survey">
<i class="ion-document-text"></i>
</div>
</div>
<!-- <div class="control-list-item">
<div class="control-list-text" translate>{{'.tracking'}}</div>
<label ng-click="userStartStopTracking()" class="toggle control-list-toggle toggle-color">
<input type="checkbox" ng-checked="settings.collect.trackingOn">
<div class="track">
<div class="handle"></div>
</div>
</label>
</div>
<div class="control-list-item">
</div> -->
<!-- <div class="control-list-item">
<div class="control-list-text" translate>{{'.medium-accuracy'}}</div>
<label ng-click="toggleLowAccuracy()" class="toggle control-list-toggle toggle-color">
<input type="checkbox" ng-checked="getLowAccuracy()">
<div class="track">
<div class="handle"></div>
</div>
</label>
</div>
</div> -->
<!-- <div class="control-list-item">
<div class="control-list-text" translate>{{'.dark-theme'}}</div>
<label ng-click="toggleDarkTheme()" class="toggle control-list-toggle toggle-color">
Expand Down
4 changes: 2 additions & 2 deletions www/templates/intro/intro.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-view hide-nav-bar="true" class="intro-view">
<ion-slide-box delegate-handle="intro-box" on-slide-changed="slideChanged(index)" show-pager="false">
<ion-slide>
<!-- <ion-slide>
<ng-include src="'templates/intro/summary.html'"></ng-include>
</ion-slide>
</ion-slide> -->
<ion-slide>
<ng-include src="consentFile"></ng-include>
</ion-slide>
Expand Down