forked from georchestra/header
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.ce.vue
More file actions
282 lines (262 loc) · 8.14 KB
/
header.ce.vue
File metadata and controls
282 lines (262 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { getUserDetails } from './auth'
import { getI18n, t } from '@/i18n'
import { state, replaceUrlsVariables } from '@/shared'
import { allNodes } from '@/utils'
import Menu from '@/ui/Menu.vue'
import AccountItem from '@/ui/AccountItem.vue'
import Logo from '@/ui/Logo.vue'
import BurgerIcon from '@/ui/icons/BurgerIcon.vue'
const props = defineProps<{
activeApp?: string
configFile?: string
stylesheet?: string
height?: number
legacyHeader?: string
legacyUrl?: string
logoUrl?: string
customNonce?: string
}>()
const navigation = computed(() => state.navigation)
const isAnonymous = computed(() => !state.user || state.user.anonymous)
const isWarned = computed(() => state.user?.warned)
const remainingDays = computed(() => state.user?.remainingDays)
const loginUrl = computed(() => {
const href = new URL(replaceUrlsVariables(state.config.login.url))
for (const param of state.config.login.params || []) {
const key = Object.keys(param)[0]
href.searchParams.set(key, replaceUrlsVariables(param[key]))
}
return href.toString()
})
const logoutUrl = computed(() =>
replaceUrlsVariables(
state.user?.isExternalAuth && state.config.logoutExternalUrl
? state.config.logoutExternalUrl
: state.config.logoutUrl
)
)
function determineActiveApp(): void {
const navigationSource =
(state.navigation?.menus?.length ?? 0) > 0 ? state.navigation : state.menu
const allLinks = allNodes(navigationSource, 'activeAppUrl')
const computedUrl = window.location.href.substring(
window.location.origin.length,
window.location.href.length
)
let matched: boolean
for (const link of allLinks) {
matched = false
const activeAppUrlSplitted = link.split(':')
const base =
activeAppUrlSplitted.length > 1 ? activeAppUrlSplitted[0] : 'start'
const url = replaceUrlsVariables(
activeAppUrlSplitted.length > 1
? activeAppUrlSplitted[1]
: activeAppUrlSplitted[0]
)
switch (base) {
case 'end':
matched = computedUrl.endsWith(url)
break
case 'includes':
matched = computedUrl.includes(url)
break
case 'exact':
matched = computedUrl === url
break
default:
matched = computedUrl.startsWith(url)
break
}
state.matchedRouteScore =
matched && link.length > state.matchedRouteScore
? link.length
: state.matchedRouteScore
if (matched && state.matchedRouteScore === link?.length) {
state.activeAppUrl = link
}
}
}
function setI18nAndActiveApp(i18n?: any) {
state.lang3 = getI18n(
i18n || {},
state.config.lang || navigator.language.substring(0, 2) || 'en'
)
state.config.logoutExternalUrl ??= state.config.logoutUrl
determineActiveApp()
state.loaded = true
}
onMounted(() => {
if (props.legacyHeader !== 'true') {
getUserDetails().then(user => {
state.user = user
state.config.stylesheet ??= props.stylesheet
if (props.configFile)
fetch(props.configFile)
.then(res => res.json())
.then(json => {
state.config = Object.assign({}, state.config, json.config)
const incomingNavigation = json.navigation
if (incomingNavigation?.menus?.length) {
state.navigation = Object.assign(
{},
state.navigation,
incomingNavigation
)
} else if (json.menu) {
state.navigation = Object.assign({}, state.navigation, {
menus: [json.menu],
})
} else if (incomingNavigation) {
state.navigation = Object.assign(
{},
state.navigation,
incomingNavigation
)
}
if (json.menu) {
state.menu = json.menu
}
setI18nAndActiveApp(json.i18n)
})
else setI18nAndActiveApp()
})
}
})
</script>
<template>
<div v-if="props.legacyHeader === 'true'">
<iframe
class="w-full"
v-bind:src="`${props.legacyUrl}${
props.activeApp ? `?active=${props.activeApp}` : ''
}`"
:style="`height:${props.height}px;width:100%;border:0;`"
></iframe>
</div>
<header
v-else-if="state.loaded"
class="host h-[80px] text-base"
:class="{ 'has-custom-stylesheet': state.config.stylesheet }"
:style="`height:${props.height}px`"
>
<link
rel="stylesheet"
:href="state.config.stylesheet"
v-if="state.config.stylesheet"
:nonce="props.customNonce"
/>
<link
rel="stylesheet"
:href="state.config.iconsUrl"
v-if="state.config.iconsUrl"
:nonce="props.customNonce"
/>
<div
class="justify-between text-slate-600 lg:flex hidden h-full bg-white lg:text-sm"
>
<div class="flex header-left flex-1 min-w-0">
<Logo :logoUrl="props.logoUrl || state.config.logoUrl" />
<nav
:class="[
'flex items-center font-semibold header-nav grow',
navigation.class || 'justify-start',
]"
>
<Menu :items="navigation?.menus ?? []" />
<span class="text-gray-400 text-xs" v-if="isWarned">
<a href="/console/account/changePassword">
{{ t('remaining_days_msg_part1') }} {{ remainingDays }}
{{ t('remaining_days_msg_part2') }}
{{ t('remaining_days_msg_part3') }}</a
></span
>
</nav>
</div>
<AccountItem
:is-anonymous="isAnonymous"
:login-url="loginUrl"
:logout-url="logoutUrl"
/>
</div>
<div class="flex-col lg:hidden w-full h-full">
<div
class="h-full flex items-center justify-between px-4 py-1 shrink-0 w-full bg-primary/10"
>
<div class="h-full flex">
<BurgerIcon class="mr-3" />
<Logo :logoUrl="props.logoUrl || state.config.logoUrl" />
</div>
<AccountItem
:is-anonymous="isAnonymous"
:login-url="loginUrl"
:logout-url="logoutUrl"
/>
</div>
<div
class="absolute z-[1000] bg-white w-full duration-300 transition-opacity ease-in-out"
>
<nav class="flex flex-col font-semibold" v-if="state.mobileMenuOpen">
<Menu :items="navigation?.menus ?? []" />
</nav>
</div>
</div>
</header>
</template>
<style>
@tailwind base;
@tailwind components;
@tailwind utilities;
.host {
-webkit-text-size-adjust: 100%;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif,
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
font-feature-settings: normal;
}
@layer components {
@layer colors {
header:not(.has-custom-stylesheet) {
--georchestra-header-primary: #85127e;
--georchestra-header-primary-light: #85127e1a;
}
}
.nav-item-mobile {
@apply text-xl block text-center py-3 w-full border-b border-b-slate-300 first-letter:capitalize;
display: flex;
justify-content: center;
}
.nav-item {
@apply relative w-fit block after:hover:scale-x-100 xl:mx-3 md:mx-2 hover:text-black first-letter:capitalize text-base;
}
.nav-item:after {
@apply block content-[''] absolute h-[3px] bg-primary w-full scale-x-0 transition duration-300 origin-left;
}
.nav-item.active {
@apply after:scale-x-100 after:bg-primary after:bg-none text-gray-900;
}
.btn {
@apply px-4 py-2 mx-2 text-slate-100 bg-primary rounded hover:bg-slate-700 transition-colors first-letter:capitalize;
}
.link-btn {
@apply text-primary hover:text-slate-700 hover:underline underline-offset-8 decoration-2 decoration-slate-700 flex flex-col items-center;
}
.dropdown > li {
@apply block text-center hover:bg-primary-light text-gray-700 hover:text-black capitalize;
}
.dropdown > li > a {
@apply block w-full h-full py-3;
}
.dropdown > li.active {
@apply bg-primary-light;
}
.disabled {
@apply cursor-pointer pointer-events-none;
}
* {
-webkit-tap-highlight-color: transparent;
}
}
</style>