Skip to content

Commit

Permalink
Pull out the code to extract the results from the promise response
Browse files Browse the repository at this point in the history
We do this as part of the promise response instead of folding it into the
`processManualInputs` function because enketo survey answers also returns a promise.
So we will have to set the `resultMap` asynchronously, which may run into timing issues
e-mission/e-mission-docs#727 (comment)

Let's revisit this later once we figure out how the answers should work
  • Loading branch information
shankari committed May 10, 2022
1 parent 97d748f commit 75e5507
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
14 changes: 3 additions & 11 deletions www/js/diary/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

angular.module('emission.main.diary.services', ['emission.plugin.logger',
'emission.services', 'emission.main.common.services',
'emission.incident.posttrip.manual', 'emission.survey.enketo.answer'])
'emission.incident.posttrip.manual'])
.factory('DiaryHelper', function(CommonGraph, PostTripManualMarker, $translate){
var dh = {};
// dh.expandEarlierOrLater = function(id) {
Expand Down Expand Up @@ -375,7 +375,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
return dh;
})
.factory('Timeline', function(CommHelper, ConfirmHelper, SurveyOptions, $http, $ionicLoading, $window,
$rootScope, CommonGraph, UnifiedDataLoader, Logger, $injector, EnketoSurveyAnswer, $translate) {
$rootScope, CommonGraph, UnifiedDataLoader, Logger, $injector, $translate) {
var timeline = {};
// corresponds to the old $scope.data. Contains all state for the current
// day, including the indication of the current day
Expand Down Expand Up @@ -1005,15 +1005,7 @@ angular.module('emission.main.diary.services', ['emission.plugin.logger',
var readTripsAndUnprocessedInputs = function(day, tripReadFn, completeStatus, tq) {
var manualPromises = ConfirmHelper.INPUTS.map(function(inp) {
return UnifiedDataLoader.getUnifiedMessagesForInterval(
ConfirmHelper.inputDetails[inp].key, tq).then(function(results) {
switch(ConfirmHelper.inputDetails[inp].key) {
// Post-process survey answers
case 'manual/survey_response':
return EnketoSurveyAnswer.filterByNameAndVersion('TripConfirmSurvey', results);
default:
return results;
}
});
ConfirmHelper.inputDetails[inp].key, tq).then(manualInputFactory.extractResult);
});
let tripsReadPromise = tripReadFn(day);
// var surveyAnswersPromise = EnketoSurvey.getAllSurveyAnswers("manual/confirm_survey", { populateLabels: true });
Expand Down
4 changes: 3 additions & 1 deletion www/js/survey/enketo/enketo-trip-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
angular.module('emission.survey.enketo.trip.button',
['emission.stats.clientstats',
'emission.survey.enketo.launch',
'emission.survey.enketo.answer',
'emission.survey.inputmatcher'])
.directive('enketoTripButton', function() {
return {
Expand Down Expand Up @@ -138,7 +139,7 @@ angular.module('emission.survey.enketo.trip.button',

$scope.init();
})
.factory("EnketoTripButtonService", function(InputMatcher, $timeout) {
.factory("EnketoTripButtonService", function(InputMatcher, EnketoSurveyAnswer, $timeout) {
var etbs = {};
console.log("Creating EnketoTripButtonService");
etbs.key = "manual/trip_user_input";
Expand All @@ -147,6 +148,7 @@ angular.module('emission.survey.enketo.trip.button',
/**
* Embed 'inputType' to the trip.
*/
etbs.extractResult = (results) => EnketoSurveyAnswer.filterByNameAndVersion('TripConfirmSurvey', results);

etbs.processManualInputs = function(manualResults, resultMap) {
if (manualResults.length > 1) {
Expand Down
2 changes: 2 additions & 0 deletions www/js/survey/multilabel/multi-label-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ angular.module('emission.survey.multilabel.buttons',
* Embed 'inputType' to the trip.
*/

mls.extractResult = (results) => results;

mls.processManualInputs = function(manualResults, resultMap) {
var mrString = 'unprocessed manual inputs '
+ manualResults.map(function(item, index) {
Expand Down

0 comments on commit 75e5507

Please sign in to comment.