From 5e5329aaf55f8a67e4ee2b88c5f8c222459fa75a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 30 Oct 2017 11:36:29 -0400 Subject: [PATCH] LP#1728122 Webstaff survey display avoids deep fleshing Avoid collecting survey/question/answer data via deep pcrud fleshing. Opt instead to organize the data locally using the values fleshed directly on the response object. Additional fixes included: 1. Avoid displaying survey responses for out-of-scope surveys. 2. Format survey response dates using the configured date format instead of display a bare ISO date. Signed-off-by: Bill Erickson Signed-off-by: Chris Sharp Signed-off-by: Galen Charlton --- .../templates/staff/circ/patron/t_surveys.tt2 | 29 ++++++---- .../js/ui/default/staff/circ/patron/app.js | 57 ++++++++++++++----- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/Open-ILS/src/templates/staff/circ/patron/t_surveys.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_surveys.tt2 index bd059b8f3f..3f5e7d8cc8 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_surveys.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_surveys.tt2 @@ -1,27 +1,34 @@
[% l('Surveys') %]
-
+
-
[% l('Survey') %] #{{survey.id()}}
-
{{survey.description()}}
+
+ [% l('Survey') %] #{{collection.survey.id()}} +
+
{{collection.survey.description()}}
- [% l('Required') %] - [% l('OPAC Visible') %] + [% l('Required') %] + [% l('OPAC Visible') %]
    -
  1. {{question.question()}} -
    - [% l('Last Answered on: ') %]{{response.answer_date() | date}} - [% l('Answer: ') %] {{response.answer().answer()}} -
    +
  2. + {{response.question().question()}} + [% l('Answer: ') %] + {{response.answer().answer()}} + + [% l('Last Answered on: ') %] + {{response.answer_date() | date:$root.egDateFormat}} +
-
\ No newline at end of file +
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 748cbfcf7d..f92eac1096 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -1172,25 +1172,54 @@ function($scope, $routeParams , $location , egCore , patronSvc) { $scope.initTab('other', $routeParams.id); var usr_id = $routeParams.id; var org_ids = egCore.org.fullPath(egCore.auth.user().ws_ou(), true); + $scope.surveys = []; - // fetch the surveys + var svr_responses = {}; + + // fetch all survey responses for this user. egCore.pcrud.search('asvr', {usr : usr_id}, - {flesh : 4, flesh_fields : { - asvr : ['question', 'survey', 'answer'], - asv : ['responses', 'questions'], - asvq : ['responses', 'question'] - }}, - {authoritative : true}) - .then(null, null, function(survey) { - var sameSurveyId = false; - if (survey.survey().id() && $scope.surveys.length > 0) { - for (sid = 0; sid < $scope.surveys.length; sid++) { - if (survey.survey().id() == $scope.surveys[sid].id()) sameSurveyId = true; + {flesh : 2, flesh_fields : {asvr : ['survey','question','answer']}} + ).then( + function() { + // All responses collected and deduplicated. + // Create one collection of responses per survey. + + angular.forEach(svr_responses, function(questions, survey_id) { + var collection = {responses : []}; + angular.forEach(questions, function(response) { + collection.survey = response.survey(); // same for one. + collection.responses.push(response); + }); + $scope.surveys.push(collection); + }); + }, + null, + function(response) { + + // Discard responses for out-of-scope surveys. + if (org_ids.indexOf(response.survey().owner()) < 0) + return; + + // survey_id => question_id => response + var svr_id = response.survey().id(); + var qst_id = response.question().id(); + + if (!svr_responses[svr_id]) + svr_responses[svr_id] = []; + + if (!svr_responses[svr_id][qst_id]) { + svr_responses[svr_id][qst_id] = response; + + } else { + // We have multiple responses for the same question. + // For this UI we only care about the most recent response. + if (response.effective_date() > + svr_responses[svr_id][qst_id].effective_date()) + svr_responses[svr_id][qst_id] = response; } } - if (!sameSurveyId) $scope.surveys.push(survey.survey()); - }); + ); }]) .controller('PatronFetchLastCtrl', -- 2.43.2