diff --git a/CHANGELOG.md b/CHANGELOG.md index c3e5d15ce..cf4f1a0c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next release - Prevent showing error message when testing for old versions during upgrade - In the email notification, sent to admins on account creation, show the group of the user +- Fix a bug: subscriptions tab is selected by default in statistics, even if the module is disabled ## v4.7.5 2021 March 08 - Fix a bug: unable to compile the assets during the upgrade, if the env file has some whitespaces around the equal sign diff --git a/app/frontend/src/javascript/controllers/admin/graphs.js b/app/frontend/src/javascript/controllers/admin/graphs.js index 3883405e0..d92f76366 100644 --- a/app/frontend/src/javascript/controllers/admin/graphs.js +++ b/app/frontend/src/javascript/controllers/admin/graphs.js @@ -51,6 +51,9 @@ Application.Controllers.controller('GraphsController', ['$scope', '$state', '$ro // active tab will be set here $scope.selectedIndex = null; + // ui-bootstrap active tab index + $scope.selectedTab = 0; + // for palmares graphs, filters values are stored here $scope.ranking = { sortCriterion: 'ca', @@ -101,9 +104,11 @@ Application.Controllers.controller('GraphsController', ['$scope', '$state', '$ro * Callback called when the active tab is changed. * Recover the current tab and store its value in $scope.selectedIndex * @param tab {Object} elasticsearch statistic structure + * @param index {number} index of the tab in the $scope.statistics array */ - $scope.setActiveTab = function (tab) { + $scope.setActiveTab = function (tab, index) { $scope.selectedIndex = tab; + $scope.selectedTab = index; $scope.ranking.groupCriterion = 'subType'; if (tab.ca) { $scope.ranking.sortCriterion = 'ca'; @@ -113,6 +118,17 @@ Application.Controllers.controller('GraphsController', ['$scope', '$state', '$ro return refreshChart(); }; + /** + * Returns true if the provided tab must be hidden due to some global or local configuration + * @param tab {Object} elasticsearch statistic structure (from statistic_indices table) + */ + $scope.hiddenTab = function (tab) { + if (tab.graph) { + return !((tab.es_type_key === 'subscription') && !$rootScope.modules.plans); + } + return false; + }; + /** * Callback to close the date-picking popup and refresh the results */ @@ -137,11 +153,20 @@ Application.Controllers.controller('GraphsController', ['$scope', '$state', '$ro $scope.$watch(scope => scope.ranking.groupCriterion , (newValue, oldValue) => refreshChart()); return refreshChart(); + + // set the default tab to "machines" if "subscriptions" are disabled + if (!$rootScope.modules.plans) { + const idx = $scope.statistics.findIndex(s => s.es_type_key === 'machine'); + $scope.setActiveTab($scope.statistics[idx], idx); + } else { + const idx = $scope.statistics.findIndex(s => s.es_type_key === 'subscription'); + $scope.setActiveTab($scope.statistics[idx], idx); + } }); // workaround for angular-bootstrap::tabs behavior: on tab deletion, another tab will be selected // which will cause every tabs to reload, one by one, when the view is closed - return $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { + $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { if ((fromState.name === 'app.admin.stats_graphs') && (Object.keys(fromParams).length === 0)) { return $scope.preventRefresh = true; } diff --git a/app/frontend/src/javascript/controllers/admin/statistics.js b/app/frontend/src/javascript/controllers/admin/statistics.js index 679f55255..dd99e2d1f 100644 --- a/app/frontend/src/javascript/controllers/admin/statistics.js +++ b/app/frontend/src/javascript/controllers/admin/statistics.js @@ -76,6 +76,9 @@ Application.Controllers.controller('StatisticsController', ['$scope', '$state', // active tab will be set here $scope.selectedIndex = null; + // ui-bootstrap active tab index + $scope.selectedTab = 0; + // type filter binding $scope.type = { selected: null, @@ -159,9 +162,11 @@ Application.Controllers.controller('StatisticsController', ['$scope', '$state', * Callback called when the active tab is changed. * recover the current tab and store its value in $scope.selectedIndex * @param tab {Object} elasticsearch statistic structure (from statistic_indices table) + * @param index {number} index of the tab in the $scope.statistics array */ - $scope.setActiveTab = function (tab) { + $scope.setActiveTab = function (tab, index) { $scope.selectedIndex = tab; + $scope.selectedTab = index; $scope.type.selected = tab.types[0]; $scope.type.active = $scope.type.selected; $scope.customFilter.criterion = {}; @@ -406,6 +411,15 @@ Application.Controllers.controller('StatisticsController', ['$scope', '$state', return $scope.preventRefresh = true; } }); + + // set the default tab to "machines" if "subscriptions" are disabled + if (!$rootScope.modules.plans) { + const idx = $scope.statistics.findIndex(s => s.es_type_key === 'machine'); + $scope.setActiveTab($scope.statistics[idx], idx); + } else { + const idx = $scope.statistics.findIndex(s => s.es_type_key === 'subscription'); + $scope.setActiveTab($scope.statistics[idx], idx); + } }; /** diff --git a/app/frontend/templates/admin/statistics/graphs.html b/app/frontend/templates/admin/statistics/graphs.html index 69043bfbf..21ad2f331 100644 --- a/app/frontend/templates/admin/statistics/graphs.html +++ b/app/frontend/templates/admin/statistics/graphs.html @@ -102,7 +102,7 @@ - +
diff --git a/app/frontend/templates/admin/statistics/index.html b/app/frontend/templates/admin/statistics/index.html index c465058f9..0928da2d8 100644 --- a/app/frontend/templates/admin/statistics/index.html +++ b/app/frontend/templates/admin/statistics/index.html @@ -31,8 +31,8 @@
- - + +