blob: f7989d2ee08577e183fe3762970ed237d422b3cf [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>
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +053044 <div v-if="assetTag" class="asset-tag">
45 <span class="pr-2">|</span>
46 <span>{{ assetTag }}</span>
47 </div>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -080048 </b-navbar-nav>
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080049 <!-- Right aligned nav items -->
SurenNeware057232b2020-06-08 20:53:26 +053050 <b-navbar-nav class="ml-auto helper-menu">
Derick Montague965cf672020-07-23 17:24:39 -050051 <b-nav-item
52 to="/health/event-logs"
53 data-test-id="appHeader-container-health"
54 >
Derick Montague68592032020-04-04 14:02:34 -050055 <status-icon :status="healthStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053056 {{ $t('appHeader.health') }}
Derick Montague68592032020-04-04 14:02:34 -050057 </b-nav-item>
Derick Montague965cf672020-07-23 17:24:39 -050058 <b-nav-item
59 to="/control/server-power-operations"
60 data-test-id="appHeader-container-power"
61 >
Derick Montague71114fe2021-05-06 18:17:34 -050062 <status-icon :status="serverStatusIcon" />
SurenNeware057232b2020-06-08 20:53:26 +053063 {{ $t('appHeader.power') }}
Derick Montague68592032020-04-04 14:02:34 -050064 </b-nav-item>
65 <!-- Using LI elements instead of b-nav-item to support semantic button elements -->
66 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050067 <b-button
68 id="app-header-refresh"
69 variant="link"
70 data-test-id="appHeader-button-refresh"
71 @click="refresh"
72 >
SurenNewarea5cbc442020-10-12 15:26:39 +053073 <icon-renew :title="$t('appHeader.titleRefresh')" />
SurenNeware057232b2020-06-08 20:53:26 +053074 <span class="responsive-text">{{ $t('appHeader.refresh') }}</span>
Derick Montague68592032020-04-04 14:02:34 -050075 </b-button>
76 </li>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053077 <li class="nav-item">
Derick Montague965cf672020-07-23 17:24:39 -050078 <b-dropdown
79 id="app-header-user"
80 variant="link"
81 right
82 data-test-id="appHeader-container-user"
83 >
Derick Montague602e98a2020-10-21 16:20:00 -050084 <template #button-content>
SurenNewarea5cbc442020-10-12 15:26:39 +053085 <icon-avatar :title="$t('appHeader.titleProfile')" />
SurenNeware057232b2020-06-08 20:53:26 +053086 <span class="responsive-text">{{ username }}</span>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053087 </template>
Derick Montague965cf672020-07-23 17:24:39 -050088 <b-dropdown-item
89 to="/profile-settings"
90 data-test-id="appHeader-link-profile"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053091 >{{ $t('appHeader.profileSettings') }}
92 </b-dropdown-item>
Derick Montague965cf672020-07-23 17:24:39 -050093 <b-dropdown-item
94 data-test-id="appHeader-link-logout"
95 @click="logout"
96 >
97 {{ $t('appHeader.logOut') }}
98 </b-dropdown-item>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053099 </b-dropdown>
Derick Montague68592032020-04-04 14:02:34 -0500100 </li>
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800101 </b-navbar-nav>
Derick Montaguea2988f42020-01-17 13:46:30 -0600102 </b-navbar>
103 </header>
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700104 <loading-bar />
Derick Montaguea2988f42020-01-17 13:46:30 -0600105 </div>
106</template>
107
108<script>
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530109import BVToastMixin from '@/components/Mixins/BVToastMixin';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600110import IconAvatar from '@carbon/icons-vue/es/user--avatar/20';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800111import IconClose from '@carbon/icons-vue/es/close/20';
112import IconMenu from '@carbon/icons-vue/es/menu/20';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600113import IconRenew from '@carbon/icons-vue/es/renew/20';
SurenNeware61859092020-10-01 09:37:32 +0530114import StatusIcon from '@/components/Global/StatusIcon';
115import LoadingBar from '@/components/Global/LoadingBar';
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800116
Derick Montaguea2988f42020-01-17 13:46:30 -0600117export default {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600118 name: 'AppHeader',
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700119 components: {
120 IconAvatar,
121 IconClose,
122 IconMenu,
123 IconRenew,
124 StatusIcon,
Derick Montague602e98a2020-10-21 16:20:00 -0500125 LoadingBar,
Yoshie Muranaka3be801a2020-04-21 11:34:56 -0700126 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530127 mixins: [BVToastMixin],
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800128 data() {
129 return {
Mateusz Gapski03505912020-06-25 08:16:51 +0200130 isNavigationOpen: false,
Derick Montague602e98a2020-10-21 16:20:00 -0500131 altLogo: `${process.env.VUE_APP_COMPANY_NAME} logo`,
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800132 };
133 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800134 computed: {
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530135 assetTag() {
136 return this.$store.getters['global/assetTag'];
137 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530138 isAuthorized() {
139 return this.$store.getters['global/isAuthorized'];
140 },
Derick Montague71114fe2021-05-06 18:17:34 -0500141 serverStatus() {
142 return this.$store.getters['global/serverStatus'];
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800143 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800144 healthStatus() {
145 return this.$store.getters['eventLog/healthStatus'];
146 },
Derick Montague71114fe2021-05-06 18:17:34 -0500147 serverStatusIcon() {
148 switch (this.serverStatus) {
Derick Montaguee2fd1562019-12-20 13:26:53 -0600149 case 'on':
150 return 'success';
151 case 'error':
152 return 'danger';
Yoshie Muranakaa3cbc652020-05-13 12:55:48 -0700153 case 'diagnosticMode':
154 return 'warning';
Derick Montaguee2fd1562019-12-20 13:26:53 -0600155 case 'off':
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800156 default:
Derick Montaguee2fd1562019-12-20 13:26:53 -0600157 return 'secondary';
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800158 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800159 },
160 healthStatusIcon() {
161 switch (this.healthStatus) {
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700162 case 'OK':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800163 return 'success';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700164 case 'Warning':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800165 return 'warning';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -0700166 case 'Critical':
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800167 return 'danger';
168 default:
169 return 'secondary';
170 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530171 },
172 username() {
173 return this.$store.getters['global/username'];
Derick Montague602e98a2020-10-21 16:20:00 -0500174 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800175 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530176 watch: {
177 isAuthorized(value) {
178 if (value === false) {
Yoshie Muranakaf92e2962021-02-09 12:41:53 -0800179 this.errorToast(this.$t('global.toast.unAuthDescription'), {
180 title: this.$t('global.toast.unAuthTitle'),
181 });
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530182 }
Derick Montague602e98a2020-10-21 16:20:00 -0500183 },
Sukanya Pandeydd6aa0a2020-10-08 20:47:39 +0530184 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600185 created() {
Yoshie Muranakad624dae2020-09-21 14:35:58 -0700186 // Reset auth state to check if user is authenticated based
187 // on available browser cookies
188 this.$store.dispatch('authentication/resetStoreState');
Derick Montague71114fe2021-05-06 18:17:34 -0500189 this.getServerInfo();
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800190 this.getEvents();
Derick Montague09e45cd2020-01-23 15:45:57 -0600191 },
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800192 mounted() {
193 this.$root.$on(
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530194 'change-is-navigation-open',
Derick Montague602e98a2020-10-21 16:20:00 -0500195 (isNavigationOpen) => (this.isNavigationOpen = isNavigationOpen)
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800196 );
197 },
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800198 methods: {
Derick Montague71114fe2021-05-06 18:17:34 -0500199 getServerInfo() {
200 this.$store.dispatch('global/getServerStatus');
Derick Montaguee080a1a2019-12-04 16:30:08 -0600201 },
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800202 getEvents() {
203 this.$store.dispatch('eventLog/getEventLogData');
204 },
Yoshie Muranakaeb154bb2020-02-07 12:18:45 -0800205 refresh() {
206 this.$emit('refresh');
207 },
Derick Montaguee080a1a2019-12-04 16:30:08 -0600208 logout() {
Derick Montaguec031b692020-02-12 15:55:42 -0600209 this.$store.dispatch('authentication/logout');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800210 },
211 toggleNavigation() {
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530212 this.$root.$emit('toggle-navigation');
Derick Montague602e98a2020-10-21 16:20:00 -0500213 },
Derick Montague80267972021-02-16 09:47:03 -0600214 setFocus(event) {
215 event.preventDefault();
216 this.$root.$emit('skip-navigation');
217 },
Derick Montague602e98a2020-10-21 16:20:00 -0500218 },
Derick Montaguea2988f42020-01-17 13:46:30 -0600219};
220</script>
221
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530222<style lang="scss">
Derick Montague7d4b53b2020-10-26 12:14:16 -0500223@mixin focus-box-shadow($padding-color: $navbar-color, $outline-color: $white) {
224 box-shadow: inset 0 0 0 3px $padding-color, inset 0 0 0 5px $outline-color;
225}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530226.app-header {
227 .link-skip-nav {
228 position: absolute;
229 top: -60px;
230 left: 0.5rem;
231 z-index: $zindex-popover;
232 transition: $duration--moderate-01 $exit-easing--expressive;
233 &:focus {
234 top: 0.5rem;
235 transition-timing-function: $entrance-easing--expressive;
236 }
Derick Montague75b48322019-12-06 01:24:41 -0600237 }
SurenNeware1f8117f2020-09-22 19:28:56 +0530238 .navbar-text,
239 .nav-link,
240 .btn-link {
241 color: color('white') !important;
242 fill: currentColor;
243 padding: 0.68rem 1rem !important;
244
245 &:hover {
246 background-color: theme-color-level(light, 10);
247 }
248 &:active {
249 background-color: theme-color-level(light, 9);
250 }
251 &:focus {
Derick Montague7d4b53b2020-10-26 12:14:16 -0500252 @include focus-box-shadow;
253 outline: 0;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530254 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800255 }
256
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530257 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700258 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800259 }
260
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530261 .navbar {
262 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200263 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530264 @include media-breakpoint-up($responsive-layout-bp) {
265 height: $header-height;
266 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530267
SurenNeware057232b2020-06-08 20:53:26 +0530268 .helper-menu {
269 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700270 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530271 width: 100%;
272 justify-content: flex-end;
273
274 .nav-link,
275 .btn {
276 padding: $spacer / 1.125 $spacer / 2;
277 }
Derick Montague7d4b53b2020-10-26 12:14:16 -0500278
279 .nav-link:focus,
280 .btn:focus {
281 @include focus-box-shadow($gray-800);
282 }
SurenNeware057232b2020-06-08 20:53:26 +0530283 }
284
285 .responsive-text {
286 @include media-breakpoint-down(xs) {
287 display: none;
288 }
289 }
290 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530291 }
292
293 .navbar-nav {
294 padding: 0 $spacer;
SurenNeware1f8117f2020-09-22 19:28:56 +0530295 align-items: center;
296
297 .navbar-brand,
298 .nav-link {
299 transition: $focus-transition;
300 }
Sukanya Pandeyc5c2ae92020-12-09 16:14:19 +0530301 .asset-tag {
302 color: theme-color-level(light, 3);
303 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530304 }
305
306 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700307 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530308 width: $header-height;
309 height: $header-height;
310 transition: none;
SurenNeware1f8117f2020-09-22 19:28:56 +0530311 display: inline-flex;
312 flex: 0 0 20px;
313 align-items: center;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530314
315 svg {
316 margin: 0;
317 }
318
319 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700320 fill: theme-color('light');
SurenNeware1f8117f2020-09-22 19:28:56 +0530321 background-color: theme-color-level(light, 10);
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530322 }
323
SurenNeware057232b2020-06-08 20:53:26 +0530324 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700325 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530326 }
327
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530328 @include media-breakpoint-up($responsive-layout-bp) {
329 display: none;
330 }
331 }
332
SurenNeware1f8117f2020-09-22 19:28:56 +0530333 .dropdown-menu {
334 margin-top: 0;
335
336 @include media-breakpoint-only(md) {
337 margin-top: 4px;
SurenNeware057232b2020-06-08 20:53:26 +0530338 }
339 }
340
341 .navbar-expand {
342 @include media-breakpoint-down(sm) {
343 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530344 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800345 }
346}
SurenNeware1f8117f2020-09-22 19:28:56 +0530347
348.navbar-brand {
349 padding: $spacer/2;
350 height: $header-height;
351 line-height: 1;
352 &:focus {
353 box-shadow: inset 0 0 0 3px $navbar-color, inset 0 0 0 5px color('white');
354 outline: 0;
355 }
356}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800357</style>