From 75e5507d7969894054ca3266814015805a7eac29 Mon Sep 17 00:00:00 2001 From: Shankari Date: Mon, 9 May 2022 23:23:31 -0700 Subject: [PATCH] Pull out the code to extract the results from the promise response 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 https://github.com/e-mission/e-mission-docs/issues/727#issuecomment-1121933037 Let's revisit this later once we figure out how the answers should work --- www/js/diary/services.js | 14 +++----------- www/js/survey/enketo/enketo-trip-button.js | 4 +++- www/js/survey/multilabel/multi-label-ui.js | 2 ++ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/www/js/diary/services.js b/www/js/diary/services.js index 5500de1b4..be21a93c3 100644 --- a/www/js/diary/services.js +++ b/www/js/diary/services.js @@ -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) { @@ -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 @@ -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 }); diff --git a/www/js/survey/enketo/enketo-trip-button.js b/www/js/survey/enketo/enketo-trip-button.js index ff09b0657..0110efe5c 100644 --- a/www/js/survey/enketo/enketo-trip-button.js +++ b/www/js/survey/enketo/enketo-trip-button.js @@ -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 { @@ -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"; @@ -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) { diff --git a/www/js/survey/multilabel/multi-label-ui.js b/www/js/survey/multilabel/multi-label-ui.js index 9f6cbabf8..8a79af375 100644 --- a/www/js/survey/multilabel/multi-label-ui.js +++ b/www/js/survey/multilabel/multi-label-ui.js @@ -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) {