Skip to content

Commit

Permalink
fix(reports): hack to refresh reportData
Browse files Browse the repository at this point in the history
This commit implements a $rootScope hack to refresh the $state's
reportData.

Closes #1821.
  • Loading branch information
jniles committed Jul 28, 2017
1 parent 5a04825 commit 5e7056b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions client/src/modules/reports/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ angular.module('bhima.controllers')
.controller('ReportsController', ReportsController);

ReportsController.$inject = [
'$state', 'reportData',
'$state', 'reportData', '$scope', 'BaseReportService'
];

function ReportsController($state, reportData) {
function ReportsController($state, reportData, $scope, SavedReports) {
var vm = this;
var archiveState = 'reportsBase.reportsArchive';

Expand All @@ -15,4 +15,20 @@ function ReportsController($state, reportData) {
function isArchive() {
return $state.current.name === archiveState;
}

function refreshReportData() {
SavedReports.requestKey($state.params.key)
.then(function (results) {
vm.report = results[0];
});
}

// FIXME(@jniles): this is a hack to get the state to refresh the top level data
// without changing the way states are defined. Since the top level state never
// changes, the only effective way to communicate between states is to either:
// 1) Have a service share the data (this would require changing a ton of files)
// 2) Have an event trigger the refresh (much easier, implemented here)
$scope.$on('$stateChangeSuccess', function () {
refreshReportData();
});
}
4 changes: 2 additions & 2 deletions client/src/modules/reports/reports.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('bhima.routes')
// a list of all supported reported and their respective keys, this allows
// the ui-view to be populated with the correct report configuration form
/* @const */
var SUPPORTED_REPORTS = [
var SUPPORTED_REPORTS = [
'cash_report',
'account_report',
'balance_sheet_report',
Expand Down Expand Up @@ -40,7 +40,7 @@ angular.module('bhima.routes')
url : '/'.concat(key),
controller : key.concat('Controller as ReportConfigCtrl'),
templateUrl : '/modules/reports/generate/'.concat(key, '/', key, '.html'),
params : { key : key },
params : { key : key }
});
});
}]);
Expand Down

0 comments on commit 5e7056b

Please sign in to comment.