Skip to content

Commit e712c0c

Browse files
authored
Merge pull request #2 from jeff-phillips-18/amarie401-card-loading-state
Fixes for maintaining card sizing
2 parents 5f8039a + 3bbd24b commit e712c0c

File tree

4 files changed

+57
-26
lines changed

4 files changed

+57
-26
lines changed

src/card/basic/card.component.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<file name="index.html">
3737
<div ng-controller="ChartCtrl">
3838
<label class="label-title">Card With Multiple Utilization Bars</label>
39-
<pf-card head-title="System Resources" show-top-border="true" style="width: 65%">
39+
<pf-card head-title="System Resources" show-spinner="dataLoading" show-top-border="true">
4040
<pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInline units=units2 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
4141
<pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInline units=units3 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
4242
<pf-utilization-bar-chart chart-data=data4 chart-title=title4 layout=layoutInline units=units4 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
@@ -45,37 +45,44 @@
4545
</div>
4646
</file>
4747
<file name="script.js">
48-
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope ) {
48+
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope, $timeout ) {
49+
50+
$scope.dataLoading = true;
4951
5052
$scope.title2 = 'Memory';
5153
$scope.units2 = 'GB';
5254
53-
$scope.data2 = {
54-
'used': '25',
55-
'total': '100'
56-
};
57-
5855
$scope.title3 = 'CPU Usage';
5956
$scope.units3 = 'MHz';
6057
61-
$scope.data3 = {
62-
'used': '420',
63-
'total': '500'
64-
};
65-
6658
$scope.title4 = 'Disk Usage';
6759
$scope.units4 = 'TB';
68-
$scope.data4 = {
69-
'used': '350',
70-
'total': '500'
71-
};
7260
7361
$scope.title5 = 'Disk I/O';
74-
$scope.units5 = 'I/Ops';
75-
$scope.data5 = {
76-
'used': '450',
77-
'total': '500'
78-
};
62+
$scope.units5 = 'I/Ops';
63+
64+
$timeout(function () {
65+
$scope.dataLoading = false;
66+
67+
$scope.data2 = {
68+
'used': '25',
69+
'total': '100'
70+
};
71+
72+
$scope.data3 = {
73+
'used': '420',
74+
'total': '500'
75+
};
76+
77+
$scope.data4 = {
78+
'used': '350',
79+
'total': '500'
80+
};
81+
$scope.data5 = {
82+
'used': '450',
83+
'total': '500'
84+
};
85+
}, 3000 );
7986
8087
$scope.layoutInline = {
8188
'type': 'inline'

src/card/basic/card.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ <h2 class="card-pf-title">{{$ctrl.headTitle}}</h2>
55
</div>
66
<span ng-if="$ctrl.subTitle && !$ctrl.showSpinner" class="card-pf-subtitle">{{$ctrl.subTitle}}</span>
77

8-
<div class="card-pf-body">
8+
<div class="card-pf-body" ng-class="{'show-spinner': $ctrl.showSpinner}">
99
<div ng-if="$ctrl.showSpinner" class="spinner spinner-lg"></div>
10-
<div ng-show="!$ctrl.showSpinner" ng-transclude></div>
10+
<div ng-class="{'hide-body': $ctrl.showSpinner}" ng-transclude></div>
1111
</div>
1212
<div ng-if="$ctrl.footer && !$ctrl.showSpinner" class="card-pf-footer">
1313
<div ng-if="$ctrl.showFilterInFooter()" ng-include="'card/basic/card-filter.html'"></div>

src/card/card.less

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
.card-pf-body {
2+
&.show-spinner {
3+
position: relative;
4+
}
5+
.spinner.spinner-lg {
6+
position: absolute;
7+
left: 50%;
8+
top: 50%;
9+
margin-left: -15px; /* -1 * image width / 2 */
10+
margin-top: -35px; /* -1 * image height / 2 - body margin */
11+
}
12+
.hide-body {
13+
opacity: 0;
14+
}
15+
}
16+
117
.card-pf-aggregate-status-alt {
218
.card-pf-body {
319
padding-bottom: 20px;

src/charts/utilization-bar/utilization-bar-chart.component.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,16 @@ angular.module('patternfly.charts').component('pfUtilizationBarChart', {
172172
prevChartData = angular.copy(ctrl.chartData);
173173
prevLayout = angular.copy(ctrl.layout);
174174

175+
if (!ctrl.chartData) {
176+
return;
177+
}
178+
175179
//Calculate the percentage used
176-
ctrl.chartData.percentageUsed = Math.round(100 * (ctrl.chartData.used / ctrl.chartData.total));
180+
if (!isNaN(ctrl.chartData.used) && !isNaN(ctrl.chartData.total) && (ctrl.chartData.total > 0)) {
181+
ctrl.chartData.percentageUsed = Math.round(100 * (ctrl.chartData.used / ctrl.chartData.total));
182+
} else {
183+
ctrl.chartData.percentageUsed = 0;
184+
}
177185

178186
if (ctrl.thresholdError || ctrl.thresholdWarning) {
179187
ctrl.isError = (ctrl.chartData.percentageUsed >= ctrl.thresholdError);
@@ -201,11 +209,11 @@ angular.module('patternfly.charts').component('pfUtilizationBarChart', {
201209
};
202210

203211
ctrl.usedTooltipMessage = function () {
204-
return ctrl.usedTooltipFunction ? ctrl.usedTooltipFunction() : ctrl.chartData.percentageUsed + '% Used';
212+
return ctrl.usedTooltipFunction ? ctrl.usedTooltipFunction() : _.get(ctrl.chartData, 'percentageUsed', 'N/A') + '% Used';
205213
};
206214

207215
ctrl.availableTooltipMessage = function () {
208-
return ctrl.availableTooltipFunction ? ctrl.availableTooltipFunction() : (100 - ctrl.chartData.percentageUsed) + '% Available';
216+
return ctrl.availableTooltipFunction ? ctrl.availableTooltipFunction() : (100 - _.get(ctrl.chartData, 'percentageUsed', 0)) + '% Available';
209217
};
210218
}
211219
});

0 commit comments

Comments
 (0)