blob: 5b36cf85583008fad913fefd9c1fa084c7621f99 [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>
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053029 <b-navbar-brand
30 class="mr-0"
31 to="/"
32 data-test-id="appHeader-container-overview"
33 >
Dixsie Wolmers76ccbbc2020-08-24 21:25:57 -050034 <img
35 class="header-logo"
36 src="@/assets/images/logo-header.svg"
37 :alt="altLogo"
38 />
SurenNeware1f8117f2020-09-22 19:28:56 +053039 </b-navbar-brand>
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053040 <div v-if="assetTag" class="asset-tag">
41 <span class="pr-2">|</span>
42 <span>{{ assetTag }}</span>
43 </div>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080044 </b-navbar-nav>
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080045 <!-- Right aligned nav items -->
SurenNeware057232b2020-06-08 20:53:26 +053046 <b-navbar-nav class="ml-auto helper-menu">
Derick Montague965cf672020-07-23 17:24:39 -050047 <b-nav-item
48 to="/health/event-logs"
49 data-test-id="appHeader-container-health"
50 >
Derick Montague68592032020-04-04 14:02:34 -050051 <status-icon :status="healthStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053052 {{ $t('appHeader.health') }}
Derick Montague68592032020-04-04 14:02:34 -050053 </b-nav-item>
Derick Montague965cf672020-07-23 17:24:39 -050054 <b-nav-item
55 to="/control/server-power-operations"
56 data-test-id="appHeader-container-power"
57 >
Derick Montague68592032020-04-04 14:02:34 -050058 <status-icon :status="hostStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053059 {{ $t('appHeader.power') }}
Derick Montague68592032020-04-04 14:02:34 -050060 </b-nav-item>
61 <!-- Using LI elements instead of b-nav-item to support semantic button elements -->
62 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050063 <b-button
64 id="app-header-refresh"
65 variant="link"
66 data-test-id="appHeader-button-refresh"
67 @click="refresh"
68 >
SurenNewarea5cbc442020-10-12 15:26:39 +053069 <icon-renew :title="$t('appHeader.titleRefresh')" />
SurenNeware057232b2020-06-08 20:53:26 +053070 <span class="responsive-text">{{ $t('appHeader.refresh') }}</span>
Derick Montague68592032020-04-04 14:02:34 -050071 </b-button>
72 </li>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053073 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050074 <b-dropdown
75 id="app-header-user"
76 variant="link"
77 right
78 data-test-id="appHeader-container-user"
79 >
Derick Montague602e98a2020-10-21 16:20:00 -050080 <template #button-content>
SurenNewarea5cbc442020-10-12 15:26:39 +053081 <icon-avatar :title="$t('appHeader.titleProfile')" />
SurenNeware057232b2020-06-08 20:53:26 +053082 <span class="responsive-text">{{ username }}</span>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053083 </template>
Derick Montague965cf672020-07-23 17:24:39 -050084 <b-dropdown-item
85 to="/profile-settings"
86 data-test-id="appHeader-link-profile"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053087 >{{ $t('appHeader.profileSettings') }}
88 </b-dropdown-item>
Derick Montague965cf672020-07-23 17:24:39 -050089 <b-dropdown-item
90 data-test-id="appHeader-link-logout"
91 @click="logout"
92 >
93 {{ $t('appHeader.logOut') }}
94 </b-dropdown-item>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053095 </b-dropdown>
Derick Montague68592032020-04-04 14:02:34 -050096 </li>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080097 </b-navbar-nav>
Derick Montaguea2988f42020-01-17 13:46:30 -060098 </b-navbar>
99 </header>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700100 <loading-bar />
Derick Montaguea2988f42020-01-17 13:46:30 -0600101 </div>
102</template>
103
104<script>
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530105import BVToastMixin from '@/components/Mixins/BVToastMixin';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600106import IconAvatar from '@carbon/icons-vue/es/user--avatar/20';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800107import IconClose from '@carbon/icons-vue/es/close/20';
108import IconMenu from '@carbon/icons-vue/es/menu/20';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600109import IconRenew from '@carbon/icons-vue/es/renew/20';
SurenNeware61859092020-10-01 09:37:32 +0530110import StatusIcon from '@/components/Global/StatusIcon';
111import LoadingBar from '@/components/Global/LoadingBar';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800112
Derick Montaguea2988f42020-01-17 13:46:30 -0600113export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600114 name: 'AppHeader',
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700115 components: {
116 IconAvatar,
117 IconClose,
118 IconMenu,
119 IconRenew,
120 StatusIcon,
Derick Montague602e98a2020-10-21 16:20:00 -0500121 LoadingBar,
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700122 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530123 mixins: [BVToastMixin],
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800124 data() {
125 return {
Mateusz Gapski03505912020-06-25 08:16:51 +0200126 isNavigationOpen: false,
Derick Montague602e98a2020-10-21 16:20:00 -0500127 altLogo: `${process.env.VUE_APP_COMPANY_NAME} logo`,
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800128 };
129 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800130 computed: {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530131 assetTag() {
132 return this.$store.getters['global/assetTag'];
133 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530134 isAuthorized() {
135 return this.$store.getters['global/isAuthorized'];
136 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800137 hostStatus() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600138 return this.$store.getters['global/hostStatus'];
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800139 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800140 healthStatus() {
141 return this.$store.getters['eventLog/healthStatus'];
142 },
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800143 hostStatusIcon() {
144 switch (this.hostStatus) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600145 case 'on':
146 return 'success';
147 case 'error':
148 return 'danger';
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -0700149 case 'diagnosticMode':
150 return 'warning';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600151 case 'off':
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800152 default:
Derick Montaguee2fd1562019-12-20 13:26:53 -0600153 return 'secondary';
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800154 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800155 },
156 healthStatusIcon() {
157 switch (this.healthStatus) {
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700158 case 'OK':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800159 return 'success';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700160 case 'Warning':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800161 return 'warning';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700162 case 'Critical':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800163 return 'danger';
164 default:
165 return 'secondary';
166 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530167 },
168 username() {
169 return this.$store.getters['global/username'];
Derick Montague602e98a2020-10-21 16:20:00 -0500170 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800171 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530172 watch: {
173 isAuthorized(value) {
174 if (value === false) {
175 this.errorToast(
176 this.$t('global.toast.unAuthDescription'),
177 this.$t('global.toast.unAuthTitle')
178 );
179 }
Derick Montague602e98a2020-10-21 16:20:00 -0500180 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530181 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600182 created() {
Yoshie Muranakad624dae2020-09-21 14:35:58 -0700183 // Reset auth state to check if user is authenticated based
184 // on available browser cookies
185 this.$store.dispatch('authentication/resetStoreState');
Derick Montague09e45cd2020-01-23 15:45:57 -0600186 this.getHostInfo();
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800187 this.getEvents();
Derick Montague09e45cd2020-01-23 15:45:57 -0600188 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800189 mounted() {
190 this.$root.$on(
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530191 'change-is-navigation-open',
Derick Montague602e98a2020-10-21 16:20:00 -0500192 (isNavigationOpen) => (this.isNavigationOpen = isNavigationOpen)
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800193 );
194 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800195 methods: {
196 getHostInfo() {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600197 this.$store.dispatch('global/getHostStatus');
Derick Montaguee080a1a2019-12-04 16:30:08 -0600198 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800199 getEvents() {
200 this.$store.dispatch('eventLog/getEventLogData');
201 },
Yoshie Muranakaeb154bb2020-02-07 12:18:45 -0800202 refresh() {
203 this.$emit('refresh');
204 },
Derick Montaguee080a1a2019-12-04 16:30:08 -0600205 logout() {
Derick Montaguec031b692020-02-12 15:55:42 -0600206 this.$store.dispatch('authentication/logout');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800207 },
208 toggleNavigation() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530209 this.$root.$emit('toggle-navigation');
Derick Montague602e98a2020-10-21 16:20:00 -0500210 },
211 },
Derick Montaguea2988f42020-01-17 13:46:30 -0600212};
213</script>
214
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530215<style lang="scss">
Derick Montague7d4b53b2020-10-26 12:14:16 -0500216@mixin focus-box-shadow($padding-color: $navbar-color, $outline-color: $white) {
217 box-shadow: inset 0 0 0 3px $padding-color, inset 0 0 0 5px $outline-color;
218}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530219.app-header {
220 .link-skip-nav {
221 position: absolute;
222 top: -60px;
223 left: 0.5rem;
224 z-index: $zindex-popover;
225 transition: $duration--moderate-01 $exit-easing--expressive;
226 &:focus {
227 top: 0.5rem;
228 transition-timing-function: $entrance-easing--expressive;
229 }
Derick Montague75b48322019-12-06 01:24:41 -0600230 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530231 .navbar-text,
232 .nav-link,
233 .btn-link {
234 color: color('white') !important;
235 fill: currentColor;
236 padding: 0.68rem 1rem !important;
237
238 &:hover {
239 background-color: theme-color-level(light, 10);
240 }
241 &:active {
242 background-color: theme-color-level(light, 9);
243 }
244 &:focus {
Derick Montague7d4b53b2020-10-26 12:14:16 -0500245 @include focus-box-shadow;
246 outline: 0;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530247 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800248 }
249
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530250 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700251 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800252 }
253
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530254 .navbar {
255 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200256 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530257 @include media-breakpoint-up($responsive-layout-bp) {
258 height: $header-height;
259 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530260
SurenNeware057232b2020-06-08 20:53:26 +0530261 .helper-menu {
262 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700263 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530264 width: 100%;
265 justify-content: flex-end;
266
267 .nav-link,
268 .btn {
269 padding: $spacer / 1.125 $spacer / 2;
270 }
Derick Montague7d4b53b2020-10-26 12:14:16 -0500271
272 .nav-link:focus,
273 .btn:focus {
274 @include focus-box-shadow($gray-800);
275 }
SurenNeware057232b2020-06-08 20:53:26 +0530276 }
277
278 .responsive-text {
279 @include media-breakpoint-down(xs) {
280 display: none;
281 }
282 }
283 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530284 }
285
286 .navbar-nav {
287 padding: 0 $spacer;
SurenNeware1f8117f2020-09-22 19:28:56 +0530288 align-items: center;
289
290 .navbar-brand,
291 .nav-link {
292 transition: $focus-transition;
293 }
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530294 .asset-tag {
295 color: theme-color-level(light, 3);
296 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530297 }
298
299 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700300 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530301 width: $header-height;
302 height: $header-height;
303 transition: none;
SurenNeware1f8117f2020-09-22 19:28:56 +0530304 display: inline-flex;
305 flex: 0 0 20px;
306 align-items: center;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530307
308 svg {
309 margin: 0;
310 }
311
312 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700313 fill: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530314 background-color: theme-color-level(light, 10);
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530315 }
316
SurenNeware057232b2020-06-08 20:53:26 +0530317 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700318 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530319 }
320
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530321 @include media-breakpoint-up($responsive-layout-bp) {
322 display: none;
323 }
324 }
325
SurenNeware1f8117f2020-09-22 19:28:56 +0530326 .dropdown-menu {
327 margin-top: 0;
328
329 @include media-breakpoint-only(md) {
330 margin-top: 4px;
SurenNeware057232b2020-06-08 20:53:26 +0530331 }
332 }
333
334 .navbar-expand {
335 @include media-breakpoint-down(sm) {
336 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530337 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800338 }
339}
SurenNeware1f8117f2020-09-22 19:28:56 +0530340
341.navbar-brand {
342 padding: $spacer/2;
343 height: $header-height;
344 line-height: 1;
345 &:focus {
346 box-shadow: inset 0 0 0 3px $navbar-color, inset 0 0 0 5px color('white');
347 outline: 0;
348 }
349}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800350</style>