Skip to content

Commit

Permalink
SELV3-782: added fixes for report dashboard editing
Browse files Browse the repository at this point in the history
  • Loading branch information
saleksandra committed Jan 9, 2025
1 parent d1a70ca commit ea40612
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 42 deletions.
49 changes: 30 additions & 19 deletions src/admin-report-edit/admin-report-edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

ReportEditController.$inject = ['reportDashboardService', 'loadingModalService', '$state', 'dashboardReport',
'categories', 'notificationService', 'REPORT_TYPES', 'messageService', 'confirmService',
'stateTrackerService'];
'stateTrackerService', 'reportsList'];

function ReportEditController(reportDashboardService, loadingModalService, $state, dashboardReport,
categories, notificationService, REPORT_TYPES, messageService, confirmService,
stateTrackerService) {
stateTrackerService, reportsList) {
var vm = this;

vm.$onInit = onInit;
Expand Down Expand Up @@ -94,9 +94,10 @@
*/
vm.editMode = undefined;

vm.reportsList = reportsList;

function onInit() {
vm.editMode = !!dashboardReport;

categories.map(function(category) {
if (vm.report && category.id === vm.report.category.id) {
vm.report.category = category;
Expand All @@ -105,29 +106,39 @@
vm.types = REPORT_TYPES.getTypes();
}

function getActualHomePageReportName() {
var homePageReport = reportsList.filter(function(item) {
if (item.showOnHomePage) {
return item.name;
}
});

return homePageReport[0] ? homePageReport[0].name : undefined;
}

function confirmEdit() {
if (vm.report.showOnHomePage === true && dashboardReport && dashboardReport.showOnHomePage !== true) {
reportDashboardService.getHomePageReport()
.then(function(actualHomePageReport) {
if (actualHomePageReport) {
var confirmMessage = messageService.get('adminReportEdit.confirmChangeOfHomePageReport', {
newReport: vm.report.name,
actualReport: actualHomePageReport.name
});

confirmService.confirm(confirmMessage,
'adminReportEdit.save',
'adminReportEdit.cancel')
.then(function() {
edit();
});
}
if (checkConditionToConfirmMessage()) {
var confirmMessage = messageService.get('adminReportEdit.confirmChangeOfHomePageReport', {
newReport: vm.report.name,
actualReport: getActualHomePageReportName()
});

confirmService.confirm(confirmMessage,
'adminReportEdit.save',
'adminReportEdit.cancel')
.then(function() {
edit();
});
} else {
edit();
}
}

function checkConditionToConfirmMessage() {
return vm.report.showOnHomePage === true && (!dashboardReport || (dashboardReport &&
dashboardReport.showOnHomePage !== true && getActualHomePageReportName() !== undefined));
}

function edit() {
loadingModalService.open();

Expand Down
22 changes: 13 additions & 9 deletions src/admin-report-edit/admin-report-edit.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@
accessRights: [ADMINISTRATION_RIGHTS.REPORTS_MANAGE],
resolve: {
dashboardReport: function($stateParams, reportDashboardService) {
return reportDashboardService.get($stateParams.id)
.then(function(response) {
return response;
})
.catch(function(error) {
throw new Error('Error while getting dashboard report', error);
});
if ($stateParams.id) {
return reportDashboardService.get($stateParams.id)
.then(function(response) {
return response;
})
.catch(function(error) {
throw new Error('Error while getting dashboard report', error);
});
}
return undefined;
},
categories: function(reportCategoryService) {
return reportCategoryService.getAll().then(function(categories) {
return categories;
return categories.content;
});
}
}
},
parentResolves: ['reportsList']
});
}
})();
3 changes: 1 addition & 2 deletions src/report-category/report-category.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
},
getAll: {
method: 'GET',
url: openlmisUrlFactory('/api/reports/reportCategories'),
isArray: true
url: openlmisUrlFactory('/api/reports/reportCategories')
},
get: {
method: 'GET',
Expand Down
10 changes: 6 additions & 4 deletions src/report-category/report-category.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ describe('reportCategoryService', function() {
this.reportCategory1 = new this.ReportCategoryDataBuilder().build();
this.reportCategory2 = new this.ReportCategoryDataBuilder().build();

this.reportCategories = [
this.reportCategory1,
this.reportCategory2
];
this.reportCategories = {
content: [
this.reportCategory1,
this.reportCategory2
]
};
});

it('should create report category', function() {
Expand Down
6 changes: 2 additions & 4 deletions src/report/report-dashboard.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@
},
getAll: {
method: 'GET',
url: openlmisUrlFactory('/api/reports/dashboardReports'),
isArray: true
url: openlmisUrlFactory('/api/reports/dashboardReports')
},
getAllForUser: {
method: 'GET',
url: openlmisUrlFactory('/api/reports/dashboardReports/availableReports'),
isArray: true
url: openlmisUrlFactory('/api/reports/dashboardReports/availableReports')
},
getHomePageReport: {
method: 'GET',
Expand Down
10 changes: 6 additions & 4 deletions src/report/report-dashboard.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ describe('reportDashboardService', function() {
this.reportDashboard = new this.ReportDashboardDataBuilder().build();
this.reportDashboard2 = new this.ReportDashboardDataBuilder().build();

this.reportDashboards = [
this.reportDashboard,
this.reportDashboard2
];
this.reportDashboards = {
content: [
this.reportDashboard,
this.reportDashboard2
]
};

});

Expand Down

0 comments on commit ea40612

Please sign in to comment.