Skip to content

Commit

Permalink
BAH-3049 | Refactor. rootScope.default method | [Riya/Sweety]
Browse files Browse the repository at this point in the history
  • Loading branch information
riyaTw committed Dec 6, 2023
1 parent b69232e commit dae233a
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions ui/app/reports/controllers/reportsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@ angular.module('bahmni.reports')
fileItem.report.reportTemplateLocation = response;
};

$rootScope.default = _.isUndefined($rootScope.default) ? {
$rootScope.default = $rootScope.default || {
reportsRequiringDateRange: {
responseType: format[1],
dateRangeType: dateRange[0],
startDate: dateRange[0],
stopDate: dateRange[0],
report: {
responseType: format[1]
}
report: { responseType: format[1] }
},
reportsNotRequiringDateRange: {}
} : $rootScope.default;
};

$scope.reportsDefined = true;
$scope.enableReportQueue = appService.getAppDescriptor().getConfigValue("enableReportQueue");

$scope.setDefault = function (item, header) {
var setToChange = header === 'reportsRequiringDateRange' ? $rootScope.reportsRequiringDateRange : $rootScope.reportsNotRequiringDateRange;
var isPreviousMonth = $rootScope.default[header][item] && $rootScope.default[header][item] === dateRange[2];
setToChange.forEach(function (report) {
if (item == 'dateRangeType') {
var setToChange = (header === 'reportsRequiringDateRange') ? $rootScope.reportsRequiringDateRange : $rootScope.reportsNotRequiringDateRange;
var isPreviousMonth = $rootScope.default[header][item] === dateRange[2];

angular.forEach(setToChange, function (report) {
if (item === 'dateRangeType') {
$rootScope.default.reportsRequiringDateRange.startDate = $rootScope.default[header][item];
$rootScope.default.reportsRequiringDateRange.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0];
report['startDate'] = $rootScope.default[header][item];
report['stopDate'] = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0];
} else if ($rootScope.default[header][item] === undefined) {
report.startDate = $rootScope.default[header][item];
report.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0];
} else if (_.isUndefined($rootScope.default[header][item])) {
$rootScope.default.reportsRequiringDateRange.startDate = dateRange[0];
$rootScope.reportsRequiringDateRange.forEach(function (report) {
angular.forEach($rootScope.reportsRequiringDateRange, function (report) {
report.startDate = dateRange[0];
report.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0];
report.responseType = format[1];
Expand All @@ -52,7 +53,7 @@ angular.module('bahmni.reports')
report[item] = $rootScope.default[header][item];
}
});
};
};

var getPreviousMonthEndDate = function () {
return new Date(new Date().getFullYear(), new Date().getMonth(), 0);
Expand All @@ -74,8 +75,8 @@ angular.module('bahmni.reports')
}
report.reportTemplateLocation = report.config.macroTemplatePath;
}
report.startDate = Bahmni.Common.Util.DateUtil.getDateWithoutTime(report.startDate);
report.stopDate = Bahmni.Common.Util.DateUtil.getDateWithoutTime(report.stopDate);
report.startDate = Bahmni.Common.Util.DateUtil.getDateWithoutTime(report.startDate);
report.stopDate = Bahmni.Common.Util.DateUtil.getDateWithoutTime(report.stopDate);
if (isDateRangeRequiredFor(report) && (!report.startDate || !report.stopDate)) {
var msg = [];
if (!report.startDate) {
Expand Down

0 comments on commit dae233a

Please sign in to comment.