Skip to content

Commit 9993661

Browse files
author
Amineta Lo
committed
fix(pfCard): Add loading state for pfCard
1 parent db1b797 commit 9993661

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/card/basic/card.component.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @param {boolean=} showTopBorder Show/Hide the blue top border. True shows top border, false (default) hides top border
99
* @param {boolean=} showTitlesSeparator Show/Hide the grey line between the title and sub-title.
1010
* True (default) shows the line, false hides the line
11+
* @param {boolean=} showSpinner Show/Hide the spinner for loading state. True shows the spinner, false (default) hides the spinner
1112
* @param {object=} footer footer configuration properties:<br/>
1213
* <ul style='list-style-type: none'>
1314
* <li>.iconClass - (optional) the icon to show on the bottom left of the footer panel
@@ -91,6 +92,7 @@ angular.module('patternfly.card').component('pfCard', {
9192
subTitle: '@?',
9293
showTopBorder: '@?',
9394
showTitlesSeparator: '@?',
95+
showSpinner: '<?',
9496
footer: '=?',
9597
filter: '=?'
9698
},
@@ -104,11 +106,9 @@ angular.module('patternfly.card').component('pfCard', {
104106
ctrl.currentFilter = ctrl.filter.filters[0];
105107
}
106108
}
107-
108109
ctrl.footerCallBackFn = function () {
109110
ctrl.footerCallBackResult = ctrl.footer.callBackFn();
110111
};
111-
112112
ctrl.filterCallBackFn = function (f) {
113113
ctrl.currentFilter = f;
114114
if (ctrl.filter.callBackFn) {
@@ -130,6 +130,7 @@ angular.module('patternfly.card').component('pfCard', {
130130

131131
ctrl.$onInit = function () {
132132
ctrl.shouldShowTitlesSeparator = (!ctrl.showTitlesSeparator || ctrl.showTitlesSeparator === 'true');
133+
ctrl.showSpinner = ctrl.showSpinner === true;
133134
};
134135
}
135136
});

src/card/basic/card.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div ng-class="$ctrl.showTopBorder === 'true' ? 'card-pf card-pf-accented' : 'card-pf'">
22
<div ng-if="$ctrl.showHeader()" ng-class="$ctrl.shouldShowTitlesSeparator ? 'card-pf-heading' : 'card-pf-heading-no-bottom'">
3-
<div ng-if="$ctrl.showFilterInHeader()" ng-include="'card/basic/card-filter.html'"></div>
3+
<div ng-if="$ctrl.showFilterInHeader() && !$ctrl.showSpinner " ng-include="'card/basic/card-filter.html'"></div>
44
<h2 class="card-pf-title">{{$ctrl.headTitle}}</h2>
55
</div>
6-
7-
<span ng-if="$ctrl.subTitle" class="card-pf-subtitle">{{$ctrl.subTitle}}</span>
6+
<span ng-if="$ctrl.subTitle && !$ctrl.showSpinner" class="card-pf-subtitle">{{$ctrl.subTitle}}</span>
87

98
<div class="card-pf-body">
10-
<div ng-transclude></div>
9+
<div ng-if="$ctrl.showSpinner" class="spinner spinner-lg"></div>
10+
<div ng-show="!$ctrl.showSpinner" ng-transclude></div>
1111
</div>
12-
<div ng-if="$ctrl.footer" class="card-pf-footer">
12+
<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>
1414
<p>
1515
<a ng-if="$ctrl.footer.href" href="{{$ctrl.footer.href}}" ng-class="{'card-pf-link-with-icon':$ctrl.footer.iconClass,'card-pf-link':!$ctrl.footer.iconClass}">

src/card/examples/card-timeframe.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @param {boolean=} showTopBorder Show/Hide the blue top border. True shows top border, false (default) hides top border
99
* @param {boolean=} showTitlesSeparator Show/Hide the grey line between the title and sub-title.
1010
* True (default) shows the line, false hides the line
11+
* @param {boolean=} showSpinner Show/Hide the spinner for loading state. True shows the spinner, false (default) hides the spinner
1112
* @param {object=} footer footer configuration properties:<br/>
1213
* <ul style='list-style-type: none'>
1314
* <li>.iconClass - (optional) the icon to show on the bottom left of the footer panel
@@ -45,10 +46,20 @@
4546
footer="footerConfig" filter="filterConfig" style="width: 50%">
4647
Card Contents
4748
</pf-card>
49+
<label class="label-title">Loading State</label>
50+
<pf-card show-spinner="dataLoading" head-title="Card Title" sub-title="Card Subtitle" show-top-border="true" filter="filterConfigHeader" style="width: 50%">
51+
Card Contents
52+
</pf-card>
4853
</div>
4954
</file>
5055
<file name="script.js">
51-
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope ) {
56+
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope, $timeout ) {
57+
58+
$scope.dataLoading = true;
59+
60+
$timeout(function () {
61+
$scope.dataLoading = false;
62+
}, 3000 );
5263
5364
$scope.footerConfig = {
5465
'iconClass' : 'fa fa-flag',

test/card/basic/card.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ describe('Component: pfCard', function() {
8585

8686
});
8787

88+
// REWORKING
89+
// it("should show and hide the spinner", function() {
90+
//
91+
// // by default, spinner should be hidden
92+
// element = compileCard('<pf-card head-title="My card title" sub-title="My card subtitle title" show-top-border="false">Inner content goes here</pf-card>', $scope);
93+
// cardClass = angular.element(element).find('.spinner-lg');
94+
// expect(cardClass.length).toBe(0);
95+
//
96+
// // setting to true should show spinner
97+
// element = compileCard('<pf-card head-title="My card title" show-spinner="true" sub-title="My card subtitle title" show-top-border="false">Inner content goes here</pf-card>', $scope);
98+
// cardClass = angular.element(element).find('.spinner-lg');
99+
// expect(cardClass.length).toBe(1);
100+
// });
101+
88102
it("should hide the action bar footer by default", function() {
89103

90104
// by default, if footer not defined, footer should not be shown

0 commit comments

Comments
 (0)