From 35a16e5570f473072e4fe9012f206972989a5a8a Mon Sep 17 00:00:00 2001 From: saleksandra Date: Thu, 9 Jan 2025 07:41:40 +0100 Subject: [PATCH] SELV3-784: Added Home Page Report Component to home page --- CHANGELOG.md | 1 + .../_home-page-report.scss | 3 + .../home-page-report.component.js | 34 ++++++ .../home-page-report.controller.js | 113 ++++++++++++++++++ .../home-page-report.html | 11 ++ .../home-page-report.module.js | 30 +++++ src/openlmis-home/home.html | 1 + src/openlmis-home/openlmis-home.module.js | 3 +- 8 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 src/openlmis-home-page-report/_home-page-report.scss create mode 100644 src/openlmis-home-page-report/home-page-report.component.js create mode 100644 src/openlmis-home-page-report/home-page-report.controller.js create mode 100644 src/openlmis-home-page-report/home-page-report.html create mode 100644 src/openlmis-home-page-report/home-page-report.module.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 442ac8fd..fea26447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ================== New functionality: * [SELV3-782](https://openlmis.atlassian.net/browse/SELV3-782): Added Reports Management Page in Administration +* [SELV3-784](https://openlmis.atlassian.net/browse/SELV3-784): Added Home Page Report Component to home page 5.6.14 / 2024-12-17 ================== diff --git a/src/openlmis-home-page-report/_home-page-report.scss b/src/openlmis-home-page-report/_home-page-report.scss new file mode 100644 index 00000000..951b836c --- /dev/null +++ b/src/openlmis-home-page-report/_home-page-report.scss @@ -0,0 +1,3 @@ +.home-page-report-panel { + margin-top: 4rem; +} \ No newline at end of file diff --git a/src/openlmis-home-page-report/home-page-report.component.js b/src/openlmis-home-page-report/home-page-report.component.js new file mode 100644 index 00000000..1b5ce0f1 --- /dev/null +++ b/src/openlmis-home-page-report/home-page-report.component.js @@ -0,0 +1,34 @@ +/* + * This program is part of the OpenLMIS logistics management information system platform software. + * Copyright © 2017 VillageReach + * + * This program is free software: you can redistribute it and/or modify it under the terms + * of the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + *   + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  + * See the GNU Affero General Public License for more details. You should have received a copy of + * the GNU Affero General Public License along with this program. If not, see + * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  + */ + +(function() { + + 'use strict'; + + /** + * @ngdoc component + * @name openlmis-home-page-report.component:openlmisHomePageReport + * + * @description + * Component responsible for displaying home page report + */ + angular + .module('openlmis-home-page-report') + .component('openlmisHomePageReport', { + templateUrl: 'openlmis-home-page-report/home-page-report.html', + controller: 'OpenlmisHomePageReportController', + controllerAs: 'vm' + }); +})(); diff --git a/src/openlmis-home-page-report/home-page-report.controller.js b/src/openlmis-home-page-report/home-page-report.controller.js new file mode 100644 index 00000000..4ae71509 --- /dev/null +++ b/src/openlmis-home-page-report/home-page-report.controller.js @@ -0,0 +1,113 @@ +/* + * This program is part of the OpenLMIS logistics management information system platform software. + * Copyright © 2017 VillageReach + * + * This program is free software: you can redistribute it and/or modify it under the terms + * of the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + *   + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  + * See the GNU Affero General Public License for more details. You should have received a copy of + * the GNU Affero General Public License along with this program. If not, see + * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  + */ + +(function() { + + 'use strict'; + + /** + * @ngdoc controller + * @name openlmis-home-page-report.controller:OpenlmisHomePageReportController + * @description + * Manages the openlmis-home-page-report component + */ + angular + .module('openlmis-home-page-report') + .controller('OpenlmisHomePageReportController', OpenlmisHomePageReportController); + + OpenlmisHomePageReportController.$inject = ['reportDashboardService', 'offlineService', '$sce', + 'supersetOAuthService', '$rootScope', '$state', 'REPORT_TYPES']; + + function OpenlmisHomePageReportController(reportDashboardService, offlineService, $sce, supersetOAuthService, + $rootScope, $state, REPORT_TYPES) { + + var vm = this; + vm.$onInit = onInit; + + /** + * @ngdoc property + * @propertyOf openlmis-home-page-report.controller:OpenlmisHomePageReportController + * @type {Object} + * @name report + * + * @description + * Holds information about the home page report + */ + vm.report = undefined; + + /** + * @ngdoc property + * @propertyOf openlmis-home-page-report.controller:OpenlmisHomePageReportController + * @type {boolean} + * @name isOffline + * + * @description + * Indicates offline connection. + */ + vm.isOffline = undefined; + + /** + * @ngdoc property + * @propertyOf openlmis-home-page-report.controller:OpenlmisHomePageReportController + * @name isAuthorized + * @type {boolean} + * + * @description + * Indicates if the controller is ready for iframe. + */ + vm.isAuthorized = false; + + /** + * @ngdoc method + * @methodOf openlmis-home-page-report.controller:OpenlmisHomePageReportController + * @name $onInit + * + * @description + * Method that is executed on initiating HomeSystemNotificationsController. + */ + function onInit() { + vm.isOffline = offlineService.isOffline(); + + reportDashboardService.getHomePageReport().then(function(report) { + if (report.content[0]) { + vm.report = report.content[0]; + vm.report.url = $sce.trustAsResourceUrl(vm.report.url); + + if (vm.report.type !== REPORT_TYPES.SUPERSET) { + vm.isAuthorized = true; + } + + if (!vm.isOffline && vm.report.type === REPORT_TYPES.SUPERSET) { + checkAuthorizationInSuperset(); + } + } + }); + } + + $rootScope.$on('openlmis-auth.authorized-in-superset', function() { + $state.reload(); + }); + + function checkAuthorizationInSuperset() { + supersetOAuthService.checkAuthorizationInSuperset() + .then(function(data) { + vm.supersetOAuthState = data.state; + if (data.isAuthorized === true) { + vm.isAuthorized = true; + } + }); + } + } +})(); diff --git a/src/openlmis-home-page-report/home-page-report.html b/src/openlmis-home-page-report/home-page-report.html new file mode 100644 index 00000000..7323e973 --- /dev/null +++ b/src/openlmis-home-page-report/home-page-report.html @@ -0,0 +1,11 @@ +
+ +
diff --git a/src/openlmis-home-page-report/home-page-report.module.js b/src/openlmis-home-page-report/home-page-report.module.js new file mode 100644 index 00000000..064ddb0d --- /dev/null +++ b/src/openlmis-home-page-report/home-page-report.module.js @@ -0,0 +1,30 @@ +/* + * This program is part of the OpenLMIS logistics management information system platform software. + * Copyright © 2017 VillageReach + * + * This program is free software: you can redistribute it and/or modify it under the terms + * of the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + *   + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  + * See the GNU Affero General Public License for more details. You should have received a copy of + * the GNU Affero General Public License along with this program. If not, see + * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  + */ + +(function() { + + 'use strict'; + + /** + * @module openlmis-home-page-report + * + * @description + * Responsible for displaying dashboard home page report + */ + angular.module('openlmis-home-page-report', [ + 'report', + 'openlmis-superset' + ]); +})(); diff --git a/src/openlmis-home/home.html b/src/openlmis-home/home.html index 553cb78c..520c1480 100644 --- a/src/openlmis-home/home.html +++ b/src/openlmis-home/home.html @@ -18,4 +18,5 @@