Skip to content

Commit

Permalink
fix(bhRendererDropdown): send filters server
Browse files Browse the repository at this point in the history
This commit fixes the `bhRendererDropdown` to ensure it sends the report
filter parameters to the server for rendering.

Closes https://github.com/Vanga-Hospital/bhima-2.X/issues/221.
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 8, 2017
1 parent c0b4874 commit 221d8a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions client/src/js/components/bhRendererDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ angular.module('bhima.components')
controller : bhRendererController
});

bhRendererController.$inject = [ 'appcache' ];
bhRendererController.$inject = [ 'appcache', '$httpParamSerializer' ];

function bhRendererController(AppCache) {
function bhRendererController(AppCache, $httpParamSerializer) {
var $ctrl = this;

var cache = new AppCache('bhRendererComponent');

// delay between GET request completion and loading indication, this is used
// to compensate for the delay in browsers opening the print dialog
// @todo - make this work!
var loadingIndicatorDelay = 1000;

$ctrl.$onInit = function () {
Expand All @@ -27,20 +28,42 @@ function bhRendererController(AppCache) {

$ctrl.selection = cache.selection || $ctrl.options[0];

$ctrl.reportOptions = $ctrl.reportOptions || {};

$ctrl.$loading = false;

combineAndSerializeParameters();
};

$ctrl.select = function (option) {
$ctrl.selection = cache.selection = option;
};

/*
// watch for changes on the component's border and behave appropriately
$ctrl.$onChanges = function (changes) {
console.log('changes:', changes);
var hasParameterChanges = (changes && changes.reportOptions);

// if there are changes to the report options, serialize them
if (hasParameterChanges) {
combineAndSerializeParameters();
}
};
*/

/**
* @method combineAndSerializeParameters
*
* @description
* This method combines the renderers parameter and the reportOptions into
* a url to be passed to ngHref.
*/
function combineAndSerializeParameters() {
var rendererParams = $ctrl.selection && $ctrl.selection.parameters || {};
var reportParams = $ctrl.reportOptions || {};

// combine the parameters into one
var combined = angular.merge(rendererParams, reportParams);

// serialize the parameters with the $http parameter serializer
$ctrl.params = $httpParamSerializer(combined);
}

/**
* @method toggleLoading
Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/templates/bhRendererDropdown.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="btn-group" uib-dropdown>
<a class="btn btn-default" ng-href="{{::$ctrl.reportUrl}}?renderer={{::$ctrl.selection.parameters.renderer}}" download>
<a class="btn btn-default" ng-href="{{::$ctrl.reportUrl}}?{{$ctrl.params}}" download>
<span ng-show="$ctrl.loading">
<i class="fa fa-circle-notch-o"></i> <span translate>FORM.INFO.LOAING</span>
</span>
Expand Down

0 comments on commit 221d8a6

Please sign in to comment.