blob: 4eba7522dbde949303fc81a7c782ce33ddb08d39 [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001<template>
2 <div>
Derick Montague75b48322019-12-06 01:24:41 -06003 <header id="page-header">
Derick Montague68592032020-04-04 14:02:34 -05004 <a role="link" class="link-skip-nav btn btn-light" href="#main-content">
5 {{ $t('appHeader.skipToContent') }}
6 </a>
7
Mateusz Gapski21d6de02020-07-29 14:28:23 +02008 <b-navbar type="dark" :aria-label="$t('appHeader.applicationHeader')">
Yoshie Muranakadc04feb2019-12-04 08:41:22 -08009 <!-- Left aligned nav items -->
Yoshie Muranaka74f86872020-02-10 12:28:37 -080010 <b-button
Derick Montague68592032020-04-04 14:02:34 -050011 id="app-header-trigger"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080012 class="nav-trigger"
13 aria-hidden="true"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080014 type="button"
15 variant="link"
SurenNeware057232b2020-06-08 20:53:26 +053016 :class="{ open: isNavigationOpen }"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080017 @click="toggleNavigation"
18 >
SurenNewarea5cbc442020-10-12 15:26:39 +053019 <icon-close
20 v-if="isNavigationOpen"
21 :title="$t('appHeader.titleHideNavigation')"
22 />
23 <icon-menu
24 v-if="!isNavigationOpen"
25 :title="$t('appHeader.titleShowNavigation')"
26 />
Yoshie Muranaka74f86872020-02-10 12:28:37 -080027 </b-button>
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080028 <b-navbar-nav>
Dixsie Wolmers76ccbbc2020-08-24 21:25:57 -050029 <b-nav-item to="/" data-test-id="appHeader-container-overview">
30 <img
31 class="header-logo"
32 src="@/assets/images/logo-header.svg"
33 :alt="altLogo"
34 />
35 </b-nav-item>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080036 </b-navbar-nav>
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080037 <!-- Right aligned nav items -->
SurenNeware057232b2020-06-08 20:53:26 +053038 <b-navbar-nav class="ml-auto helper-menu">
Derick Montague965cf672020-07-23 17:24:39 -050039 <b-nav-item
40 to="/health/event-logs"
41 data-test-id="appHeader-container-health"
42 >
Derick Montague68592032020-04-04 14:02:34 -050043 <status-icon :status="healthStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053044 {{ $t('appHeader.health') }}
Derick Montague68592032020-04-04 14:02:34 -050045 </b-nav-item>
Derick Montague965cf672020-07-23 17:24:39 -050046 <b-nav-item
47 to="/control/server-power-operations"
48 data-test-id="appHeader-container-power"
49 >
Derick Montague68592032020-04-04 14:02:34 -050050 <status-icon :status="hostStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053051 {{ $t('appHeader.power') }}
Derick Montague68592032020-04-04 14:02:34 -050052 </b-nav-item>
53 <!-- Using LI elements instead of b-nav-item to support semantic button elements -->
54 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050055 <b-button
56 id="app-header-refresh"
57 variant="link"
58 data-test-id="appHeader-button-refresh"
59 @click="refresh"
60 >
SurenNewarea5cbc442020-10-12 15:26:39 +053061 <icon-renew :title="$t('appHeader.titleRefresh')" />
SurenNeware057232b2020-06-08 20:53:26 +053062 <span class="responsive-text">{{ $t('appHeader.refresh') }}</span>
Derick Montague68592032020-04-04 14:02:34 -050063 </b-button>
64 </li>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053065 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050066 <b-dropdown
67 id="app-header-user"
68 variant="link"
69 right
70 data-test-id="appHeader-container-user"
71 >
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053072 <template v-slot:button-content>
SurenNewarea5cbc442020-10-12 15:26:39 +053073 <icon-avatar :title="$t('appHeader.titleProfile')" />
SurenNeware057232b2020-06-08 20:53:26 +053074 <span class="responsive-text">{{ username }}</span>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053075 </template>
Derick Montague965cf672020-07-23 17:24:39 -050076 <b-dropdown-item
77 to="/profile-settings"
78 data-test-id="appHeader-link-profile"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053079 >{{ $t('appHeader.profileSettings') }}
80 </b-dropdown-item>
Derick Montague965cf672020-07-23 17:24:39 -050081 <b-dropdown-item
82 data-test-id="appHeader-link-logout"
83 @click="logout"
84 >
85 {{ $t('appHeader.logOut') }}
86 </b-dropdown-item>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053087 </b-dropdown>
Derick Montague68592032020-04-04 14:02:34 -050088 </li>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080089 </b-navbar-nav>
Derick Montaguea2988f42020-01-17 13:46:30 -060090 </b-navbar>
91 </header>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -070092 <loading-bar />
Derick Montaguea2988f42020-01-17 13:46:30 -060093 </div>
94</template>
95
96<script>
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +053097import BVToastMixin from '@/components/Mixins/BVToastMixin';
Derick Montaguee2fd1562019-12-20 13:26:53 -060098import IconAvatar from '@carbon/icons-vue/es/user--avatar/20';
Yoshie Muranaka74f86872020-02-10 12:28:37 -080099import IconClose from '@carbon/icons-vue/es/close/20';
100import IconMenu from '@carbon/icons-vue/es/menu/20';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600101import IconRenew from '@carbon/icons-vue/es/renew/20';
SurenNeware61859092020-10-01 09:37:32 +0530102import StatusIcon from '@/components/Global/StatusIcon';
103import LoadingBar from '@/components/Global/LoadingBar';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800104
Derick Montaguea2988f42020-01-17 13:46:30 -0600105export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600106 name: 'AppHeader',
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700107 components: {
108 IconAvatar,
109 IconClose,
110 IconMenu,
111 IconRenew,
112 StatusIcon,
113 LoadingBar
114 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530115 mixins: [BVToastMixin],
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800116 data() {
117 return {
Mateusz Gapski03505912020-06-25 08:16:51 +0200118 isNavigationOpen: false,
119 altLogo: `${process.env.VUE_APP_COMPANY_NAME} logo`
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800120 };
121 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800122 computed: {
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530123 isAuthorized() {
124 return this.$store.getters['global/isAuthorized'];
125 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800126 hostStatus() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600127 return this.$store.getters['global/hostStatus'];
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800128 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800129 healthStatus() {
130 return this.$store.getters['eventLog/healthStatus'];
131 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800132 hostStatusIcon() {
133 switch (this.hostStatus) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600134 case 'on':
135 return 'success';
136 case 'error':
137 return 'danger';
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -0700138 case 'diagnosticMode':
139 return 'warning';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600140 case 'off':
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800141 default:
Derick Montaguee2fd1562019-12-20 13:26:53 -0600142 return 'secondary';
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800143 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800144 },
145 healthStatusIcon() {
146 switch (this.healthStatus) {
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700147 case 'OK':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800148 return 'success';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700149 case 'Warning':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800150 return 'warning';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700151 case 'Critical':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800152 return 'danger';
153 default:
154 return 'secondary';
155 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530156 },
157 username() {
158 return this.$store.getters['global/username'];
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800159 }
160 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530161 watch: {
162 isAuthorized(value) {
163 if (value === false) {
164 this.errorToast(
165 this.$t('global.toast.unAuthDescription'),
166 this.$t('global.toast.unAuthTitle')
167 );
168 }
169 }
170 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600171 created() {
172 this.getHostInfo();
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800173 this.getEvents();
Derick Montague09e45cd2020-01-23 15:45:57 -0600174 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800175 mounted() {
176 this.$root.$on(
177 'change:isNavigationOpen',
178 isNavigationOpen => (this.isNavigationOpen = isNavigationOpen)
179 );
180 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800181 methods: {
182 getHostInfo() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600183 this.$store.dispatch('global/getHostStatus');
Derick Montaguee080a1a2019-12-04 16:30:08 -0600184 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800185 getEvents() {
186 this.$store.dispatch('eventLog/getEventLogData');
187 },
Yoshie Muranakaeb154bb2020-02-07 12:18:45 -0800188 refresh() {
189 this.$emit('refresh');
190 },
Derick Montaguee080a1a2019-12-04 16:30:08 -0600191 logout() {
Derick Montaguec031b692020-02-12 15:55:42 -0600192 this.$store.dispatch('authentication/logout');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800193 },
194 toggleNavigation() {
195 this.$root.$emit('toggle:navigation');
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800196 }
Derick Montaguea2988f42020-01-17 13:46:30 -0600197 }
198};
199</script>
200
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530201<style lang="scss">
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530202.app-header {
203 .link-skip-nav {
204 position: absolute;
205 top: -60px;
206 left: 0.5rem;
207 z-index: $zindex-popover;
208 transition: $duration--moderate-01 $exit-easing--expressive;
209 &:focus {
210 top: 0.5rem;
211 transition-timing-function: $entrance-easing--expressive;
212 }
Derick Montague75b48322019-12-06 01:24:41 -0600213 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530214 .navbar-dark {
215 .navbar-text,
216 .nav-link,
217 .btn-link {
SurenNewarea5cbc442020-10-12 15:26:39 +0530218 color: theme-color('light') !important;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530219 fill: currentColor;
220 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800221 }
222
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530223 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700224 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800225 }
226
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530227 .navbar {
228 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200229 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530230 @include media-breakpoint-up($responsive-layout-bp) {
231 height: $header-height;
232 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530233
234 .btn-link {
235 padding: $spacer / 2;
236 }
SurenNeware057232b2020-06-08 20:53:26 +0530237
Mateusz Gapski03505912020-06-25 08:16:51 +0200238 .header-logo {
239 width: auto;
240 height: $header-height;
241 padding: $spacer/2 0;
242 }
243
SurenNeware057232b2020-06-08 20:53:26 +0530244 .helper-menu {
245 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700246 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530247 width: 100%;
248 justify-content: flex-end;
249
250 .nav-link,
251 .btn {
252 padding: $spacer / 1.125 $spacer / 2;
253 }
254 }
255
256 .responsive-text {
257 @include media-breakpoint-down(xs) {
258 display: none;
259 }
260 }
261 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530262 }
263
264 .navbar-nav {
265 padding: 0 $spacer;
266 }
267
268 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700269 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530270 width: $header-height;
271 height: $header-height;
272 transition: none;
273
274 svg {
275 margin: 0;
276 }
277
278 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700279 fill: theme-color('light');
280 background-color: theme-color('dark');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530281 }
282
SurenNeware057232b2020-06-08 20:53:26 +0530283 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700284 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530285 }
286
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530287 @include media-breakpoint-up($responsive-layout-bp) {
288 display: none;
289 }
290 }
291
292 .dropdown {
293 .dropdown-menu {
SurenNeware057232b2020-06-08 20:53:26 +0530294 margin-top: 0;
295 @include media-breakpoint-up(md) {
296 margin-top: 7px;
297 }
298 }
299 }
300
301 .navbar-expand {
302 @include media-breakpoint-down(sm) {
303 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530304 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800305 }
306}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800307</style>