From 9e939cafa1c66536e0e1620868b503a8fe01c7f6 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 22 May 2019 11:12:37 -0400 Subject: [PATCH] LP#1785061: move the filter value munging to the template service This allows the reporter app to stay a bit more focused on display concerns. Here's a test plan for the patch series --------------------------------------- [1] Create a reporter template that has a filter field and a filter operator of "In list", "Not in list", "Between", or "Not between" and hard-code a value for that filter in the template, separating values with a comma. [2] Try to create a report from that template; note that it fails with an error. [3] Apply the patch and repeat steps 1 and 2. This time, the report should succeed. Note that this fix applies only to hardcoding filter values in the template; it doesn't change any behavior when attempting to set a filter value for any of the four operators above at the point of creating a report. Signed-off-by: Galen Charlton Conflicts: Open-ILS/web/js/ui/default/staff/reporter/template/app.js Signed-off-by: Dan Wells --- .../staff/reporter/services/template.js | 24 ++++++++++++++++ .../ui/default/staff/reporter/template/app.js | 28 ++----------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/reporter/services/template.js b/Open-ILS/web/js/ui/default/staff/reporter/services/template.js index 1c3b4e027f..043dd47638 100644 --- a/Open-ILS/web/js/ui/default/staff/reporter/services/template.js +++ b/Open-ILS/web/js/ui/default/staff/reporter/services/template.js @@ -379,6 +379,30 @@ function($uibModal , $q , egCore , egConfirmDialog , egAlertDialog) { }); } + service.updateFilterValue = function(item, value) { + switch (item.operator.op) { + case 'between': + case 'not between': + case 'not in': + case 'in': + //if value isn't an array yet, split into an array for + // operators that need it + if (typeof value === 'string') { + value = value.split(/\s*,\s*/); + } + break; + + default: + //if value was split but shouldn't be, then convert back to + // comma-separated string + if (Array.isArray(value)) { + value = value.toString(); + } + } + + service.filter_fields[item.index].value = value; + } + service.removeField = function (type, field) { var new_list = []; while (service[type].length) { diff --git a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js index 6e3f9501d4..5dde15936f 100644 --- a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js +++ b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js @@ -513,7 +513,7 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , } else { egPromptDialog.open(egCore.strings.TEMPLATE_CONF_DEFAULT, item.value || '', {ok : function(value) { - if (value) _update_filter_value(item, value); + if (value) egReportTemplateSvc.updateFilterValue(item, value); }} ); } @@ -521,30 +521,6 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , fgrid.refresh(); } - _update_filter_value = function(item, value) { - switch (item.operator.op) { - case 'between': - case 'not between': - case 'not in': - case 'in': - //if value isn't an array yet, split into an array for - // operators that need it - if (typeof value === 'string') { - value = value.split(/\s*,\s*/); - } - break; - - default: - //if value was split but shouldn't be, then convert back to - // comma-separated string - if (Array.isArray(value)) { - value = value.toString(); - } - } - - egReportTemplateSvc.filter_fields[item.index].value = value; - } - $scope.changeTransform = function (items) { var f = items[0]; @@ -599,7 +575,7 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , //Update the filter value based on the new operator, because // different operators treat the value differently - _update_filter_value(item, egReportTemplateSvc.filter_fields[item.index].value); + egReportTemplateSvc.updateFilterValue(item, egReportTemplateSvc.filter_fields[item.index].value); } }} ); -- 2.43.2