blob: 859a47f78ecea13bac2371902180b3053577aca5 [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',
Derick Montague602e98a2020-10-21 16:20:00 -0500220 (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) {
249 box-shadow: inset 0 0 0 3px $padding-color, inset 0 0 0 5px $outline-color;
250}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530251.app-header {
252 .link-skip-nav {
253 position: absolute;
254 top: -60px;
255 left: 0.5rem;
256 z-index: $zindex-popover;
257 transition: $duration--moderate-01 $exit-easing--expressive;
258 &:focus {
259 top: 0.5rem;
260 transition-timing-function: $entrance-easing--expressive;
261 }
Derick Montague75b48322019-12-06 01:24:41 -0600262 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530263 .navbar-text,
264 .nav-link,
265 .btn-link {
266 color: color('white') !important;
267 fill: currentColor;
268 padding: 0.68rem 1rem !important;
269
270 &:hover {
271 background-color: theme-color-level(light, 10);
272 }
273 &:active {
274 background-color: theme-color-level(light, 9);
275 }
276 &:focus {
Derick Montague7d4b53b2020-10-26 12:14:16 -0500277 @include focus-box-shadow;
278 outline: 0;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530279 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800280 }
281
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530282 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700283 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800284 }
285
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530286 .navbar {
287 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200288 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530289 @include media-breakpoint-up($responsive-layout-bp) {
290 height: $header-height;
291 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530292
SurenNeware057232b2020-06-08 20:53:26 +0530293 .helper-menu {
294 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700295 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530296 width: 100%;
297 justify-content: flex-end;
298
299 .nav-link,
300 .btn {
301 padding: $spacer / 1.125 $spacer / 2;
302 }
Derick Montague7d4b53b2020-10-26 12:14:16 -0500303
304 .nav-link:focus,
305 .btn:focus {
306 @include focus-box-shadow($gray-800);
307 }
SurenNeware057232b2020-06-08 20:53:26 +0530308 }
309
310 .responsive-text {
311 @include media-breakpoint-down(xs) {
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530312 @include sr-only;
SurenNeware057232b2020-06-08 20:53:26 +0530313 }
314 }
315 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530316 }
317
318 .navbar-nav {
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530319 @include media-breakpoint-up($responsive-layout-bp) {
320 padding: 0 $spacer;
321 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530322 align-items: center;
323
324 .navbar-brand,
325 .nav-link {
326 transition: $focus-transition;
327 }
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530328 .nav-tags {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530329 color: theme-color-level(light, 3);
Sukanya Pandey4dd7eab2021-08-16 18:59:14 +0530330 @include media-breakpoint-down(xs) {
331 @include sr-only;
332 }
333 .asset-tag {
334 @include media-breakpoint-down($responsive-layout-bp) {
335 @include sr-only;
336 }
337 }
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530338 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530339 }
340
341 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700342 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530343 width: $header-height;
344 height: $header-height;
345 transition: none;
SurenNeware1f8117f2020-09-22 19:28:56 +0530346 display: inline-flex;
347 flex: 0 0 20px;
348 align-items: center;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530349
350 svg {
351 margin: 0;
352 }
353
354 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700355 fill: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530356 background-color: theme-color-level(light, 10);
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530357 }
358
SurenNeware057232b2020-06-08 20:53:26 +0530359 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700360 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530361 }
362
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530363 @include media-breakpoint-up($responsive-layout-bp) {
364 display: none;
365 }
366 }
367
SurenNeware1f8117f2020-09-22 19:28:56 +0530368 .dropdown-menu {
369 margin-top: 0;
370
371 @include media-breakpoint-only(md) {
372 margin-top: 4px;
SurenNeware057232b2020-06-08 20:53:26 +0530373 }
374 }
375
376 .navbar-expand {
377 @include media-breakpoint-down(sm) {
378 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530379 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800380 }
381}
SurenNeware1f8117f2020-09-22 19:28:56 +0530382
383.navbar-brand {
384 padding: $spacer/2;
385 height: $header-height;
386 line-height: 1;
387 &:focus {
388 box-shadow: inset 0 0 0 3px $navbar-color, inset 0 0 0 5px color('white');
389 outline: 0;
390 }
391}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800392</style>