blob: 01ebf5a1ab2045cfa6218ac29cba76b6cc584d22 [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>
SurenNeware1f8117f2020-09-22 19:28:56 +053029 <b-navbar-brand to="/" data-test-id="appHeader-container-overview">
Dixsie Wolmers76ccbbc2020-08-24 21:25:57 -050030 <img
31 class="header-logo"
32 src="@/assets/images/logo-header.svg"
33 :alt="altLogo"
34 />
SurenNeware1f8117f2020-09-22 19:28:56 +053035 </b-navbar-brand>
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 >
Derick Montague602e98a2020-10-21 16:20:00 -050072 <template #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,
Derick Montague602e98a2020-10-21 16:20:00 -0500113 LoadingBar,
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700114 },
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,
Derick Montague602e98a2020-10-21 16:20:00 -0500119 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'];
Derick Montague602e98a2020-10-21 16:20:00 -0500159 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800160 },
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 }
Derick Montague602e98a2020-10-21 16:20:00 -0500169 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530170 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600171 created() {
Yoshie Muranakad624dae2020-09-21 14:35:58 -0700172 // Reset auth state to check if user is authenticated based
173 // on available browser cookies
174 this.$store.dispatch('authentication/resetStoreState');
Derick Montague09e45cd2020-01-23 15:45:57 -0600175 this.getHostInfo();
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800176 this.getEvents();
Derick Montague09e45cd2020-01-23 15:45:57 -0600177 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800178 mounted() {
179 this.$root.$on(
180 'change:isNavigationOpen',
Derick Montague602e98a2020-10-21 16:20:00 -0500181 (isNavigationOpen) => (this.isNavigationOpen = isNavigationOpen)
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800182 );
183 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800184 methods: {
185 getHostInfo() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600186 this.$store.dispatch('global/getHostStatus');
Derick Montaguee080a1a2019-12-04 16:30:08 -0600187 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800188 getEvents() {
189 this.$store.dispatch('eventLog/getEventLogData');
190 },
Yoshie Muranakaeb154bb2020-02-07 12:18:45 -0800191 refresh() {
192 this.$emit('refresh');
193 },
Derick Montaguee080a1a2019-12-04 16:30:08 -0600194 logout() {
Derick Montaguec031b692020-02-12 15:55:42 -0600195 this.$store.dispatch('authentication/logout');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800196 },
197 toggleNavigation() {
198 this.$root.$emit('toggle:navigation');
Derick Montague602e98a2020-10-21 16:20:00 -0500199 },
200 },
Derick Montaguea2988f42020-01-17 13:46:30 -0600201};
202</script>
203
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530204<style lang="scss">
Derick Montague7d4b53b2020-10-26 12:14:16 -0500205@mixin focus-box-shadow($padding-color: $navbar-color, $outline-color: $white) {
206 box-shadow: inset 0 0 0 3px $padding-color, inset 0 0 0 5px $outline-color;
207}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530208.app-header {
209 .link-skip-nav {
210 position: absolute;
211 top: -60px;
212 left: 0.5rem;
213 z-index: $zindex-popover;
214 transition: $duration--moderate-01 $exit-easing--expressive;
215 &:focus {
216 top: 0.5rem;
217 transition-timing-function: $entrance-easing--expressive;
218 }
Derick Montague75b48322019-12-06 01:24:41 -0600219 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530220 .navbar-text,
221 .nav-link,
222 .btn-link {
223 color: color('white') !important;
224 fill: currentColor;
225 padding: 0.68rem 1rem !important;
226
227 &:hover {
228 background-color: theme-color-level(light, 10);
229 }
230 &:active {
231 background-color: theme-color-level(light, 9);
232 }
233 &:focus {
Derick Montague7d4b53b2020-10-26 12:14:16 -0500234 @include focus-box-shadow;
235 outline: 0;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530236 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800237 }
238
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530239 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700240 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800241 }
242
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530243 .navbar {
244 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200245 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530246 @include media-breakpoint-up($responsive-layout-bp) {
247 height: $header-height;
248 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530249
SurenNeware057232b2020-06-08 20:53:26 +0530250 .helper-menu {
251 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700252 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530253 width: 100%;
254 justify-content: flex-end;
255
256 .nav-link,
257 .btn {
258 padding: $spacer / 1.125 $spacer / 2;
259 }
Derick Montague7d4b53b2020-10-26 12:14:16 -0500260
261 .nav-link:focus,
262 .btn:focus {
263 @include focus-box-shadow($gray-800);
264 }
SurenNeware057232b2020-06-08 20:53:26 +0530265 }
266
267 .responsive-text {
268 @include media-breakpoint-down(xs) {
269 display: none;
270 }
271 }
272 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530273 }
274
275 .navbar-nav {
276 padding: 0 $spacer;
SurenNeware1f8117f2020-09-22 19:28:56 +0530277 align-items: center;
278
279 .navbar-brand,
280 .nav-link {
281 transition: $focus-transition;
282 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530283 }
284
285 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700286 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530287 width: $header-height;
288 height: $header-height;
289 transition: none;
SurenNeware1f8117f2020-09-22 19:28:56 +0530290 display: inline-flex;
291 flex: 0 0 20px;
292 align-items: center;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530293
294 svg {
295 margin: 0;
296 }
297
298 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700299 fill: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530300 background-color: theme-color-level(light, 10);
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530301 }
302
SurenNeware057232b2020-06-08 20:53:26 +0530303 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700304 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530305 }
306
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530307 @include media-breakpoint-up($responsive-layout-bp) {
308 display: none;
309 }
310 }
311
SurenNeware1f8117f2020-09-22 19:28:56 +0530312 .dropdown-menu {
313 margin-top: 0;
314
315 @include media-breakpoint-only(md) {
316 margin-top: 4px;
SurenNeware057232b2020-06-08 20:53:26 +0530317 }
318 }
319
320 .navbar-expand {
321 @include media-breakpoint-down(sm) {
322 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530323 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800324 }
325}
SurenNeware1f8117f2020-09-22 19:28:56 +0530326
327.navbar-brand {
328 padding: $spacer/2;
329 height: $header-height;
330 line-height: 1;
331 &:focus {
332 box-shadow: inset 0 0 0 3px $navbar-color, inset 0 0 0 5px color('white');
333 outline: 0;
334 }
335}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800336</style>