blob: 5f05406abb50fc61314addbbcb5199a8d44808a6 [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>
Dixsie Wolmers76ccbbc2020-08-24 21:25:57 -050029 <b-nav-item to="/" data-test-id="appHeader-container-overview">
30 <img
31 class="header-logo"
32 src="@/assets/images/logo-header.svg"
33 :alt="altLogo"
34 />
35 </b-nav-item>
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 >
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053072 <template v-slot: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,
113 LoadingBar
114 },
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,
119 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'];
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800159 }
160 },
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 }
169 }
170 },
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',
181 isNavigationOpen => (this.isNavigationOpen = isNavigationOpen)
182 );
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');
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800199 }
Derick Montaguea2988f42020-01-17 13:46:30 -0600200 }
201};
202</script>
203
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530204<style lang="scss">
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530205.app-header {
206 .link-skip-nav {
207 position: absolute;
208 top: -60px;
209 left: 0.5rem;
210 z-index: $zindex-popover;
211 transition: $duration--moderate-01 $exit-easing--expressive;
212 &:focus {
213 top: 0.5rem;
214 transition-timing-function: $entrance-easing--expressive;
215 }
Derick Montague75b48322019-12-06 01:24:41 -0600216 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530217 .navbar-dark {
218 .navbar-text,
219 .nav-link,
220 .btn-link {
SurenNewarea5cbc442020-10-12 15:26:39 +0530221 color: theme-color('light') !important;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530222 fill: currentColor;
223 }
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800224 }
225
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530226 .nav-item {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700227 fill: theme-color('light');
Yoshie Muranaka74f86872020-02-10 12:28:37 -0800228 }
229
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530230 .navbar {
231 padding: 0;
Mateusz Gapski21d6de02020-07-29 14:28:23 +0200232 background-color: $navbar-color;
SurenNeware057232b2020-06-08 20:53:26 +0530233 @include media-breakpoint-up($responsive-layout-bp) {
234 height: $header-height;
235 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530236
237 .btn-link {
238 padding: $spacer / 2;
239 }
SurenNeware057232b2020-06-08 20:53:26 +0530240
Mateusz Gapski03505912020-06-25 08:16:51 +0200241 .header-logo {
242 width: auto;
243 height: $header-height;
244 padding: $spacer/2 0;
245 }
246
SurenNeware057232b2020-06-08 20:53:26 +0530247 .helper-menu {
248 @include media-breakpoint-down(sm) {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700249 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530250 width: 100%;
251 justify-content: flex-end;
252
253 .nav-link,
254 .btn {
255 padding: $spacer / 1.125 $spacer / 2;
256 }
257 }
258
259 .responsive-text {
260 @include media-breakpoint-down(xs) {
261 display: none;
262 }
263 }
264 }
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530265 }
266
267 .navbar-nav {
268 padding: 0 $spacer;
269 }
270
271 .nav-trigger {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700272 fill: theme-color('light');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530273 width: $header-height;
274 height: $header-height;
275 transition: none;
276
277 svg {
278 margin: 0;
279 }
280
281 &:hover {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700282 fill: theme-color('light');
283 background-color: theme-color('dark');
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530284 }
285
SurenNeware057232b2020-06-08 20:53:26 +0530286 &.open {
Yoshie Muranaka01da8182020-07-08 15:46:43 -0700287 background-color: gray('800');
SurenNeware057232b2020-06-08 20:53:26 +0530288 }
289
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530290 @include media-breakpoint-up($responsive-layout-bp) {
291 display: none;
292 }
293 }
294
295 .dropdown {
296 .dropdown-menu {
SurenNeware057232b2020-06-08 20:53:26 +0530297 margin-top: 0;
298 @include media-breakpoint-up(md) {
299 margin-top: 7px;
300 }
301 }
302 }
303
304 .navbar-expand {
305 @include media-breakpoint-down(sm) {
306 flex-flow: wrap;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530307 }
Yoshie Muranakadc04feb2019-12-04 08:41:22 -0800308 }
309}
Yoshie Muranakab8b6f792019-12-03 14:47:32 -0800310</style>