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 2 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
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
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