1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

[bug] statistics: select machines as default tab if subscriptions is disabled

This commit is contained in:
Sylvain 2021-03-09 12:39:25 +01:00
parent 3d5484918c
commit cd30e0d8d8
5 changed files with 46 additions and 6 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}
};
/**

View File

@ -102,7 +102,7 @@
</form>
<uib-tabset justified="true">
<uib-tab ng-repeat="stat in statistics" heading="{{stat.label}}" select="setActiveTab(stat)" ng-if="stat.graph && !(stat.es_type_key == 'subscription' && modules.plans)" class="row">
<uib-tab ng-repeat="(index, stat) in statistics" heading="{{stat.label}}" select="setActiveTab(stat, index)" ng-if="hiddenTab(stat)" index="index" class="row">
<div ng-if="stat.graph.chart_type == 'discreteBarChart'">
<div id="rankingFilters">

View File

@ -31,8 +31,8 @@
<div class="row">
<div class="col-md-12">
<uib-tabset justified="true">
<uib-tab ng-repeat="stat in statistics" heading="{{stat.label}}" select="setActiveTab(stat)" ng-hide="hiddenTab(stat)">
<uib-tabset justified="true" active="selectedTab">
<uib-tab ng-repeat="(index, stat) in statistics" heading="{{stat.label}}" select="setActiveTab(stat, index)" index="index" ng-hide="hiddenTab(stat)">
<form id="filters_form" name="filters_form" class="form-inline m-t-md m-b-lg" novalidate="novalidate">
<div id="agePickerPane" class="form-group datepicker-container" style="z-index:102;">
<button id="agePickerExpand" class="btn btn-default" type="button" ng-click="agePicker.show = !agePicker.show">