Skip to content

Commit dd3a1db

Browse files
yoshiemuranakarfrandse
authored andcommitted
Create LoadingBar component
Create loading bar component to indicate when page data is 'loading'. Not every component view will need to show the loading bar (eg Reboot BMC). The LoadingBarMixin can be imported per component as needed. Signed-off-by: Yoshie Muranaka <[email protected]> Change-Id: I6735be37bc0a81f5bb2b7c93fb31a0e0ef9b40d1
1 parent 7a6a93e commit dd3a1db

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

src/components/AppHeader/AppHeader.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
</b-navbar-nav>
5353
</b-navbar>
5454
</header>
55+
<loading-bar />
5556
</div>
5657
</template>
5758

@@ -61,10 +62,18 @@ import IconClose from '@carbon/icons-vue/es/close/20';
6162
import IconMenu from '@carbon/icons-vue/es/menu/20';
6263
import IconRenew from '@carbon/icons-vue/es/renew/20';
6364
import StatusIcon from '../Global/StatusIcon';
65+
import LoadingBar from '../Global/LoadingBar';
6466
6567
export default {
6668
name: 'AppHeader',
67-
components: { IconAvatar, IconClose, IconMenu, IconRenew, StatusIcon },
69+
components: {
70+
IconAvatar,
71+
IconClose,
72+
IconMenu,
73+
IconRenew,
74+
StatusIcon,
75+
LoadingBar
76+
},
6877
data() {
6978
return {
7079
isNavigationOpen: false

src/components/Global/LoadingBar.vue

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<template>
2+
<transition name="fade">
3+
<b-progress
4+
v-if="!isLoadingComplete"
5+
:value="loadingIndicatorValue"
6+
height="0.4rem"
7+
/>
8+
</transition>
9+
</template>
10+
11+
<script>
12+
export default {
13+
data() {
14+
return {
15+
loadingIndicatorValue: 0,
16+
isLoadingComplete: false,
17+
loadingIntervalId: null,
18+
timeoutId: null
19+
};
20+
},
21+
created() {
22+
this.$root.$on('loader::start', () => {
23+
this.startLoadingInterval();
24+
});
25+
this.$root.$on('loader::end', () => {
26+
this.endLoadingInterval();
27+
});
28+
this.$root.$on('loader::hide', () => {
29+
this.hideLoadingBar();
30+
});
31+
},
32+
methods: {
33+
startLoadingInterval() {
34+
this.clearLoadingInterval();
35+
this.clearTimeout();
36+
this.loadingIndicatorValue = 0;
37+
this.isLoadingComplete = false;
38+
this.loadingIntervalId = setInterval(() => {
39+
this.loadingIndicatorValue += 1;
40+
if (this.loadingIndicatorValue > 100) this.clearLoadingInterval();
41+
}, 100);
42+
},
43+
endLoadingInterval() {
44+
this.clearLoadingInterval();
45+
this.clearTimeout();
46+
this.loadingIndicatorValue = 100;
47+
this.timeoutId = setTimeout(() => {
48+
// Let animation complete before hiding
49+
// the loading bar
50+
this.isLoadingComplete = true;
51+
}, 1000);
52+
},
53+
hideLoadingBar() {
54+
this.clearLoadingInterval();
55+
this.clearTimeout();
56+
this.loadingIndicatorValue = 0;
57+
this.isLoadingComplete = true;
58+
},
59+
clearLoadingInterval() {
60+
if (this.loadingIntervalId) clearInterval(this.loadingIntervalId);
61+
this.loadingIntervalId = null;
62+
},
63+
clearTimeout() {
64+
if (this.timeoutId) clearTimeout(this.timeoutId);
65+
this.timeoutId = null;
66+
}
67+
}
68+
};
69+
</script>
70+
71+
<style lang="scss" scoped>
72+
.progress {
73+
position: absolute;
74+
left: 0;
75+
right: 0;
76+
bottom: -0.4rem;
77+
opacity: 1;
78+
transition: opacity $duration--moderate-01 $standard-easing--productive;
79+
80+
&.fade-enter,
81+
&.fade-leave-to {
82+
opacity: 0;
83+
}
84+
}
85+
</style>
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const LoadingBarMixin = {
2+
methods: {
3+
startLoader() {
4+
this.$root.$emit('loader::start');
5+
},
6+
endLoader() {
7+
this.$root.$emit('loader::end');
8+
},
9+
hideLoader() {
10+
this.$root.$emit('loader::hide');
11+
}
12+
}
13+
};
14+
15+
export default LoadingBarMixin;

src/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ModalPlugin,
2525
NavbarPlugin,
2626
NavPlugin,
27+
ProgressPlugin,
2728
TablePlugin,
2829
ToastPlugin,
2930
TooltipPlugin
@@ -91,6 +92,7 @@ Vue.use(ListGroupPlugin);
9192
Vue.use(ModalPlugin);
9293
Vue.use(NavbarPlugin);
9394
Vue.use(NavPlugin);
95+
Vue.use(ProgressPlugin);
9496
Vue.use(TablePlugin);
9597
Vue.use(ToastPlugin);
9698
Vue.use(TooltipPlugin);

0 commit comments

Comments
 (0)