blob: 5cda341e56afec3c6214e2f9208a0332bd34e7f0 [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 Montague80267972021-02-16 09:47:03 -06004 <a
5 class="link-skip-nav btn btn-light"
6 href="#main-content"
7 @click="setFocus"
8 >
Derick Montague68592032020-04-04 14:02:34 -05009 {{ $t('appHeader.skipToContent') }}
10 </a>
11
Mateusz Gapski21d6de02020-07-29 14:28:23 +020012 <b-navbar type="dark" :aria-label="$t('appHeader.applicationHeader')">
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080013 <!-- Left aligned nav items -->
Yoshie Muranaka74f86872020-02-10 12:28:37 -080014 <b-button
Derick Montague68592032020-04-04 14:02:34 -050015 id="app-header-trigger"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080016 class="nav-trigger"
17 aria-hidden="true"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080018 type="button"
19 variant="link"
SurenNeware057232b2020-06-08 20:53:26 +053020 :class="{ open: isNavigationOpen }"
Yoshie Muranaka74f86872020-02-10 12:28:37 -080021 @click="toggleNavigation"
22 >
SurenNewarea5cbc442020-10-12 15:26:39 +053023 <icon-close
24 v-if="isNavigationOpen"
25 :title="$t('appHeader.titleHideNavigation')"
26 />
27 <icon-menu
28 v-if="!isNavigationOpen"
29 :title="$t('appHeader.titleShowNavigation')"
30 />
Yoshie Muranaka74f86872020-02-10 12:28:37 -080031 </b-button>
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080032 <b-navbar-nav>
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053033 <b-navbar-brand
34 class="mr-0"
35 to="/"
36 data-test-id="appHeader-container-overview"
37 >
Dixsie Wolmers76ccbbc2020-08-24 21:25:57 -050038 <img
39 class="header-logo"
40 src="@/assets/images/logo-header.svg"
41 :alt="altLogo"
42 />
SurenNeware1f8117f2020-09-22 19:28:56 +053043 </b-navbar-brand>
kennyneedsmilky14172d72021-11-10 15:26:07 -060044 <div v-if="isNavTagPresent" :key="routerKey" class="pl-2 nav-tags">
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +053045 <span>|</span>
46 <span class="pl-3 asset-tag">{{ assetTag }}</span>
47 <span class="pl-3">{{ modelType }}</span>
48 <span class="pl-3">{{ serialNumber }}</span>
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053049 </div>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080050 </b-navbar-nav>
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080051 <!-- Right aligned nav items -->
SurenNeware057232b2020-06-08 20:53:26 +053052 <b-navbar-nav class="ml-auto helper-menu">
Derick Montague965cf672020-07-23 17:24:39 -050053 <b-nav-item
Derick Montague828dda92021-06-28 15:52:22 -050054 to="/logs/event-logs"
Derick Montague965cf672020-07-23 17:24:39 -050055 data-test-id="appHeader-container-health"
56 >
Derick Montague68592032020-04-04 14:02:34 -050057 <status-icon :status="healthStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053058 {{ $t('appHeader.health') }}
Derick Montague68592032020-04-04 14:02:34 -050059 </b-nav-item>
Derick Montague965cf672020-07-23 17:24:39 -050060 <b-nav-item
Sandeepa Singh68cbbe92021-07-14 16:02:22 +053061 to="/operations/server-power-operations"
Derick Montague965cf672020-07-23 17:24:39 -050062 data-test-id="appHeader-container-power"
63 >
Derick Montague71114fe2021-05-06 18:17:34 -050064 <status-icon :status="serverStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053065 {{ $t('appHeader.power') }}
Derick Montague68592032020-04-04 14:02:34 -050066 </b-nav-item>
67 <!-- Using LI elements instead of b-nav-item to support semantic button elements -->
68 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050069 <b-button
70 id="app-header-refresh"
71 variant="link"
72 data-test-id="appHeader-button-refresh"
73 @click="refresh"
74 >
SurenNewarea5cbc442020-10-12 15:26:39 +053075 <icon-renew :title="$t('appHeader.titleRefresh')" />
SurenNeware057232b2020-06-08 20:53:26 +053076 <span class="responsive-text">{{ $t('appHeader.refresh') }}</span>
Derick Montague68592032020-04-04 14:02:34 -050077 </b-button>
78 </li>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053079 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050080 <b-dropdown
81 id="app-header-user"
82 variant="link"
83 right
84 data-test-id="appHeader-container-user"
85 >
Derick Montague602e98a2020-10-21 16:20:00 -050086 <template #button-content>
SurenNewarea5cbc442020-10-12 15:26:39 +053087 <icon-avatar :title="$t('appHeader.titleProfile')" />
SurenNeware057232b2020-06-08 20:53:26 +053088 <span class="responsive-text">{{ username }}</span>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053089 </template>
Derick Montague965cf672020-07-23 17:24:39 -050090 <b-dropdown-item
91 to="/profile-settings"
92 data-test-id="appHeader-link-profile"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053093 >{{ $t('appHeader.profileSettings') }}
94 </b-dropdown-item>
Derick Montague965cf672020-07-23 17:24:39 -050095 <b-dropdown-item
96 data-test-id="appHeader-link-logout"
97 @click="logout"
98 >
99 {{ $t('appHeader.logOut') }}
100 </b-dropdown-item>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530101 </b-dropdown>
Derick Montague68592032020-04-04 14:02:34 -0500102 </li>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800103 </b-navbar-nav>
Derick Montaguea2988f42020-01-17 13:46:30 -0600104 </b-navbar>
105 </header>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700106 <loading-bar />
Derick Montaguea2988f42020-01-17 13:46:30 -0600107 </div>
108</template>
109
110<script>
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530111import BVToastMixin from '@/components/Mixins/BVToastMixin';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600112import IconAvatar from '@carbon/icons-vue/es/user--avatar/20';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800113import IconClose from '@carbon/icons-vue/es/close/20';
114import IconMenu from '@carbon/icons-vue/es/menu/20';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600115import IconRenew from '@carbon/icons-vue/es/renew/20';
SurenNeware61859092020-10-01 09:37:32 +0530116import StatusIcon from '@/components/Global/StatusIcon';
117import LoadingBar from '@/components/Global/LoadingBar';
Konstantinfb6c6de2023-06-14 17:23:14 +0300118import { mapState } from 'vuex';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800119
Derick Montaguea2988f42020-01-17 13:46:30 -0600120export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600121 name: 'AppHeader',
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700122 components: {
123 IconAvatar,
124 IconClose,
125 IconMenu,
126 IconRenew,
127 StatusIcon,
Derick Montague602e98a2020-10-21 16:20:00 -0500128 LoadingBar,
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700129 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530130 mixins: [BVToastMixin],
kennyneedsmilky14172d72021-11-10 15:26:07 -0600131 props: {
Kenneth Fullbright00cb42b2021-12-21 13:56:08 -0600132 routerKey: {
133 type: Number,
134 default: 0,
135 },
kennyneedsmilky14172d72021-11-10 15:26:07 -0600136 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800137 data() {
138 return {
Mateusz Gapski03505912020-06-25 08:16:51 +0200139 isNavigationOpen: false,
Derick Montague932aff92021-08-26 14:06:49 -0500140 altLogo: process.env.VUE_APP_COMPANY_NAME || 'Built on OpenBMC',
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800141 };
142 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800143 computed: {
Konstantinfb6c6de2023-06-14 17:23:14 +0300144 ...mapState('authentication', ['consoleWindow']),
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530145 isNavTagPresent() {
146 return this.assetTag || this.modelType || this.serialNumber;
147 },
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530148 assetTag() {
149 return this.$store.getters['global/assetTag'];
150 },
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530151 modelType() {
152 return this.$store.getters['global/modelType'];
153 },
154 serialNumber() {
155 return this.$store.getters['global/serialNumber'];
156 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530157 isAuthorized() {
158 return this.$store.getters['global/isAuthorized'];
159 },
Damian Celicoaeb19812022-11-24 02:00:53 +0100160 userPrivilege() {
161 return this.$store.getters['global/userPrivilege'];
162 },
Derick Montague71114fe2021-05-06 18:17:34 -0500163 serverStatus() {
164 return this.$store.getters['global/serverStatus'];
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800165 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800166 healthStatus() {
167 return this.$store.getters['eventLog/healthStatus'];
168 },
Derick Montague71114fe2021-05-06 18:17:34 -0500169 serverStatusIcon() {
170 switch (this.serverStatus) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600171 case 'on':
172 return 'success';
173 case 'error':
174 return 'danger';
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -0700175 case 'diagnosticMode':
176 return 'warning';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600177 case 'off':
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800178 default:
Derick Montaguee2fd1562019-12-20 13:26:53 -0600179 return 'secondary';
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800180 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800181 },
182 healthStatusIcon() {
183 switch (this.healthStatus) {
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700184 case 'OK':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800185 return 'success';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700186 case 'Warning':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800187 return 'warning';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700188 case 'Critical':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800189 return 'danger';
190 default:
191 return 'secondary';
192 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530193 },
194 username() {
195 return this.$store.getters['global/username'];
Derick Montague602e98a2020-10-21 16:20:00 -0500196 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800197 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530198 watch: {
Konstantinfb6c6de2023-06-14 17:23:14 +0300199 consoleWindow() {
200 if (this.consoleWindow === false) this.$eventBus.$consoleWindow.close();
201 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530202 isAuthorized(value) {
203 if (value === false) {
Yoshie Muranakaf92e2962021-02-09 12:41:53 -0800204 this.errorToast(this.$t('global.toast.unAuthDescription'), {
205 title: this.$t('global.toast.unAuthTitle'),
206 });
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530207 }
Derick Montague602e98a2020-10-21 16:20:00 -0500208 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530209 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600210 created() {
Yoshie Muranakad624dae2020-09-21 14:35:58 -0700211 // Reset auth state to check if user is authenticated based
212 // on available browser cookies
213 this.$store.dispatch('authentication/resetStoreState');
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530214 this.getSystemInfo();
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800215 this.getEvents();
Derick Montague09e45cd2020-01-23 15:45:57 -0600216 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800217 mounted() {
218 this.$root.$on(
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530219 'change-is-navigation-open',
Ed Tanous81323992024-02-27 11:26:24 -0800220 (isNavigationOpen) => (this.isNavigationOpen = isNavigationOpen),
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800221 );
222 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800223 methods: {
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530224 getSystemInfo() {
225 this.$store.dispatch('global/getSystemInfo');
Derick Montaguee080a1a2019-12-04 16:30:08 -0600226 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800227 getEvents() {
228 this.$store.dispatch('eventLog/getEventLogData');
229 },
Yoshie Muranakaeb154bb2020-02-07 12:18:45 -0800230 refresh() {
231 this.$emit('refresh');
232 },
Derick Montaguee080a1a2019-12-04 16:30:08 -0600233 logout() {
Derick Montaguec031b692020-02-12 15:55:42 -0600234 this.$store.dispatch('authentication/logout');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800235 },
236 toggleNavigation() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530237 this.$root.$emit('toggle-navigation');
Derick Montague602e98a2020-10-21 16:20:00 -0500238 },
Derick Montague80267972021-02-16 09:47:03 -0600239 setFocus(event) {
240 event.preventDefault();
241 this.$root.$emit('skip-navigation');
242 },
Derick Montague602e98a2020-10-21 16:20:00 -0500243 },
Derick Montaguea2988f42020-01-17 13:46:30 -0600244};
245</script>
246
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530247<style lang="scss">
Derick Montague7d4b53b2020-10-26 12:14:16 -0500248@mixin focus-box-shadow($padding-color: $navbar-color, $outline-color: $white) {
Ed Tanous81323992024-02-27 11:26:24 -0800249 box-shadow:
250 inset 0 0 0 3px $padding-color,
251 inset 0 0 0 5px $outline-color;
Derick Montague7d4b53b2020-10-26 12:14:16 -0500252}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530253.app-header {
254 .link-skip-nav {
255 position: absolute;
256 top: -60px;
257 left: 0.5rem;
258 z-index: $zindex-popover;
259 transition: $duration--moderate-01 $exit-easing--expressive;
260 &:focus {
261 top: 0.5rem;
262 transition-timing-function: $entrance-easing--expressive;
263 }
Derick Montague75b48322019-12-06 01:24:41 -0600264 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530265 .navbar-text,
266 .nav-link,
267 .btn-link {
268 color: color('white') !important;
269 fill: currentColor;
270 padding: 0.68rem 1rem !important;
271
272 &:hover {
273 background-color: theme-color-level(light, 10);
274 }
275 &:active {
276 background-color: theme-color-level(light, 9);
277 }
278 &:focus {
Derick Montague7d4b53b2020-10-26 12:14:16 -0500279 @include focus-box-shadow;
280 outline: 0;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530281 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800282 }
283
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530284 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700285 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800286 }
287
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530288 .navbar {
289 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200290 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530291 @include media-breakpoint-up($responsive-layout-bp) {
292 height: $header-height;
293 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530294
SurenNeware057232b2020-06-08 20:53:26 +0530295 .helper-menu {
296 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700297 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530298 width: 100%;
299 justify-content: flex-end;
300
301 .nav-link,
302 .btn {
303 padding: $spacer / 1.125 $spacer / 2;
304 }
Derick Montague7d4b53b2020-10-26 12:14:16 -0500305
306 .nav-link:focus,
307 .btn:focus {
308 @include focus-box-shadow($gray-800);
309 }
SurenNeware057232b2020-06-08 20:53:26 +0530310 }
311
312 .responsive-text {
313 @include media-breakpoint-down(xs) {
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530314 @include sr-only;
SurenNeware057232b2020-06-08 20:53:26 +0530315 }
316 }
317 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530318 }
319
320 .navbar-nav {
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530321 @include media-breakpoint-up($responsive-layout-bp) {
322 padding: 0 $spacer;
323 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530324 align-items: center;
325
326 .navbar-brand,
327 .nav-link {
328 transition: $focus-transition;
329 }
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530330 .nav-tags {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530331 color: theme-color-level(light, 3);
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530332 @include media-breakpoint-down(xs) {
333 @include sr-only;
334 }
335 .asset-tag {
336 @include media-breakpoint-down($responsive-layout-bp) {
337 @include sr-only;
338 }
339 }
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530340 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530341 }
342
343 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700344 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530345 width: $header-height;
346 height: $header-height;
347 transition: none;
SurenNeware1f8117f2020-09-22 19:28:56 +0530348 display: inline-flex;
349 flex: 0 0 20px;
350 align-items: center;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530351
352 svg {
353 margin: 0;
354 }
355
356 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700357 fill: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530358 background-color: theme-color-level(light, 10);
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530359 }
360
SurenNeware057232b2020-06-08 20:53:26 +0530361 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700362 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530363 }
364
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530365 @include media-breakpoint-up($responsive-layout-bp) {
366 display: none;
367 }
368 }
369
SurenNeware1f8117f2020-09-22 19:28:56 +0530370 .dropdown-menu {
371 margin-top: 0;
372
373 @include media-breakpoint-only(md) {
374 margin-top: 4px;
SurenNeware057232b2020-06-08 20:53:26 +0530375 }
376 }
377
378 .navbar-expand {
379 @include media-breakpoint-down(sm) {
380 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530381 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800382 }
383}
SurenNeware1f8117f2020-09-22 19:28:56 +0530384
385.navbar-brand {
386 padding: $spacer/2;
387 height: $header-height;
388 line-height: 1;
389 &:focus {
Ed Tanous81323992024-02-27 11:26:24 -0800390 box-shadow:
391 inset 0 0 0 3px $navbar-color,
392 inset 0 0 0 5px color('white');
SurenNeware1f8117f2020-09-22 19:28:56 +0530393 outline: 0;
394 }
395}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800396</style>