| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- <template>
- <AppShell class="layout-fixed-header">
- <template #header>
- <Header
- :title="pageTitle"
- :logo-url="logoUrl"
- :breadcrumbs="false"
- :sidebar-enabled="sidebarEnabled"
- :top-bar-enabled="topbarEnabled"
- :navigation="navigation"
- :top-bar-navigation="navigation"
- :username="headerUsername"
- :login-route="headerLoginRoute"
- @toggle-sidebar="toggleSidebar"
- @user-click="goToUserControlPanel"
- >
- <template #toolbar>
- <QuickSearch
- v-if="!loginRequired && headerSearchEnabled"
- :items="searchIndexItems"
- :auto-import-routes="false"
- :search-fields="['title', 'description', 'category']"
- :max-results="15"
- placeholder="Search actions, dashboards, entities…"
- />
- </template>
- </Header>
- </template>
- <template #sidebar>
- <Navigation ref="navigation">
- <Sidebar
- v-if="sidebarEnabled && showNavigation"
- id="mainnav"
- ref="sidebar"
- />
- </Navigation>
- </template>
- <template #banners>
- <NotificationBlock
- v-if="bannerMessage"
- id="banner"
- type="info"
- tabindex="0"
- :message="bannerMessage"
- :style="bannerCss"
- />
- <ConnectionBanner />
- </template>
- <router-view :key="routerViewKey" />
- <template
- v-if="showFooter"
- #footer
- >
- <p>
- <img
- title="application icon"
- :src="logoUrl"
- alt="OliveTin logo"
- style="height: 1em;"
- class="logo"
- >
- OliveTin <span v-if="showVersionNumber">{{ currentVersion }}</span>
- </p>
- <p>
- <span>
- <a
- href="https://docs.olivetin.app"
- target="_new"
- >{{ t('docs') }}</a>
- </span>
- <span>
- <a
- href="https://github.com/OliveTin/OliveTin/issues/new/choose"
- target="_new"
- >{{ t('raise-issue') }}</a>
- </span>
- <span>
- <a
- href="#"
- @click.prevent="openLanguageDialog"
- >{{ currentLanguageName }}</a>
- </span>
- <span v-if="availableThemes.length > 1">
- <a
- href="#"
- @click.prevent="openThemeDialog"
- >{{ currentThemeName }}</a>
- </span>
- </p>
- <p v-if="showVersionNumber">
- <a
- id="available-version"
- href="http://olivetin.app"
- target="_blank"
- hidden
- >?</a>
- </p>
- </template>
- </AppShell>
- <dialog
- ref="languageDialog"
- class="language-dialog"
- @click="handleLanguageDialogClick"
- >
- <div
- class="dialog-content"
- @click.stop
- >
- <h2>{{ t('language-dialog.title') }}</h2>
- <select
- v-model="selectedLanguage"
- class="language-select"
- @change="changeLanguage"
- >
- <option
- v-for="(name, code) in availableLanguages"
- :key="code"
- :value="code"
- >
- {{ code === 'auto' ? name : `${name} (${code})` }}
- </option>
- </select>
- <p class="browser-languages">
- {{ t('language-dialog.browser-languages') }}:
- <span v-if="browserLanguages.length > 0">{{ browserLanguages.join(', ') }}</span>
- <span v-else>{{ t('language-dialog.not-available') }}</span>
- </p>
- <div class="dialog-buttons">
- <button @click="closeLanguageDialog">
- {{ t('language-dialog.close') }}
- </button>
- </div>
- </div>
- </dialog>
- <dialog
- ref="themeDialog"
- class="theme-dialog"
- @click="handleThemeDialogClick"
- >
- <div
- class="dialog-content"
- @click.stop
- >
- <h2>{{ t('theme-dialog.title') }}</h2>
- <select
- v-model="selectedTheme"
- class="language-select"
- @change="changeTheme"
- >
- <option value="">
- {{ t('theme-dialog.default') }}
- </option>
- <option
- v-for="theme in availableThemes"
- :key="theme"
- :value="theme"
- >
- {{ theme }}
- </option>
- </select>
- <div class="dialog-buttons">
- <button @click="closeThemeDialog">
- {{ t('theme-dialog.close') }}
- </button>
- </div>
- </div>
- </dialog>
- </template>
- <script setup>
- import { ref, onMounted, computed } from 'vue'
- import { useRoute, useRouter } from 'vue-router'
- import Sidebar from 'picocrank/vue/components/Sidebar.vue'
- import Navigation from 'picocrank/vue/components/Navigation.vue'
- import Header from 'picocrank/vue/components/Header.vue'
- import AppShell from 'picocrank/vue/components/AppShell.vue'
- import NotificationBlock from 'picocrank/vue/components/NotificationBlock.vue'
- import QuickSearch from 'picocrank/vue/components/QuickSearch.vue'
- import ConnectionBanner from './components/ConnectionBanner.vue'
- import { connectEventStreamIfNeeded, stopEventStream } from '../../js/websocket.js'
- import { DashboardSquare01Icon } from '@hugeicons/core-free-icons'
- import logoUrl from '../../OliveTinLogo.png'
- import { useI18n } from 'vue-i18n'
- import { ensureLocaleMessages, resolveBrowserLocale } from './i18n.js'
- import { searchIndexItems, clearSearchIndex, indexSystemNavigation, indexSearchHints, indexRootDashboardEntries } from './stores/searchIndex.js'
- import { applyThemeStyles } from './utils/themeLoader.js'
- const { t } = useI18n()
- const router = useRouter()
- const route = useRoute()
- // Views that keep their own state in the query (e.g. the calendar month) opt out of remounting when only the query changes.
- const routerViewKey = computed(() => route.meta.keepOnQueryChange ? route.path : route.fullPath)
- const sidebar = ref(null)
- const navigation = ref(null)
- const username = ref('')
- const isLoggedIn = ref(false)
- const currentVersion = ref('?')
- const pageTitle = ref('OliveTin')
- const bannerMessage = ref('')
- const bannerCss = ref('')
- const showFooter = ref(true)
- const showNavigation = ref(true)
- const showLogs = ref(true)
- const showDiagnostics = ref(true)
- const showVersionNumber = ref(true)
- const showLoginLink = ref(true)
- const sectionNavigationStyle = ref('sidebar')
- const loginRequired = ref(false)
- const headerSearchEnabled = ref(false)
- const languageDialog = ref(null)
- const browserLanguages = ref([])
- const initialLanguagePreference = typeof window !== 'undefined' ? localStorage.getItem('olivetin-language') : null
- const languagePreference = ref(initialLanguagePreference || 'auto')
- const selectedLanguage = ref(languagePreference.value)
- let latestLanguageChange = 0
- const themeDialog = ref(null)
- const availableThemes = ref([])
- const initialThemePreference = typeof window !== 'undefined' ? localStorage.getItem('olivetin-theme') : null
- const themePreference = ref(initialThemePreference || '')
- const selectedTheme = ref(themePreference.value)
- // Available languages with display names
- const availableLanguages = {
- auto: 'Browser Language',
- en: 'English',
- 'de-DE': 'Deutsch',
- 'es-ES': 'Español',
- 'it-IT': 'Italiano',
- 'zh-Hans-CN': '简体中文',
- 'zh-Hant-TW': '繁體中文'
- }
- // Computed property to get current language display name
- const currentLanguageName = computed(() => {
- if (languagePreference.value === 'auto') {
- return availableLanguages.auto
- }
- return availableLanguages[languagePreference.value] || languagePreference.value
- })
- // Computed property to get current theme display name
- const currentThemeName = computed(() => {
- if (!themePreference.value || themePreference.value === '') {
- return t('theme-dialog.default')
- }
- return themePreference.value
- })
- // Computed properties for navigation style
- const topbarEnabled = computed(() => {
- return sectionNavigationStyle.value === 'topbar' && showNavigation.value
- })
- const sidebarEnabled = computed(() => {
- return sectionNavigationStyle.value !== 'topbar' && showNavigation.value
- })
- const headerUsername = computed(() => {
- return isLoggedIn.value ? username.value : ''
- })
- const headerLoginRoute = computed(() => {
- return showLoginLink.value ? { name: 'Login' } : null
- })
- function toggleSidebar () {
- if (sidebar.value && showNavigation.value) {
- sidebar.value.toggle()
- }
- }
- function goToUserControlPanel () {
- router.push({ name: 'UserInformation' })
- }
- async function updateHeaderFromInit () {
- if (!window.initResponse) {
- return
- }
- // Rebuild the in-memory search index from this Init; never persist it.
- clearSearchIndex()
- const authenticatedUser = window.initResponse.authenticatedUser
- loginRequired.value = !!window.initResponse.loginRequired
- headerSearchEnabled.value = !!window.initResponse.features?.headerSearch
- // The server filters stream events by the identity the stream connected with.
- if (username.value !== authenticatedUser) {
- stopEventStream()
- }
- username.value = authenticatedUser
- isLoggedIn.value = authenticatedUser !== '' && authenticatedUser !== 'guest'
- currentVersion.value = window.initResponse.currentVersion
- pageTitle.value = window.initResponse.pageTitle || 'OliveTin'
- bannerMessage.value = window.initResponse.bannerMessage || ''
- bannerCss.value = window.initResponse.bannerCss || ''
- showFooter.value = window.initResponse.showFooter
- showNavigation.value = !!window.initResponse.showNavigation && !loginRequired.value
- showLogs.value = window.initResponse.showLogList
- showDiagnostics.value = window.initResponse.showDiagnostics
- showVersionNumber.value = window.initResponse.effectivePolicy?.showVersionNumber ?? true
- sectionNavigationStyle.value = window.initResponse.sectionNavigationStyle || 'sidebar'
- availableThemes.value = window.initResponse.availableThemes || []
- if (!window.initResponse.authLocalLogin && window.initResponse.oAuth2Providers.length === 0) {
- showLoginLink.value = false
- }
- applyStyleMods()
- loadCustomJsIfEnabled()
- applyTheme().catch((err) => {
- console.warn('Failed to load theme CSS:', err)
- })
- if (loginRequired.value) {
- connectEventStreamIfNeeded()
- router.push('/login')
- return
- }
- renderNavigation()
- if (headerSearchEnabled.value) {
- indexSearchHints(window.initResponse.searchHints)
- indexRootDashboardEntries(getRootDashboardEntries())
- }
- connectEventStreamIfNeeded()
- }
- function getRootDashboardEntries () {
- const entries = window.initResponse?.rootDashboardEntries
- if (entries && entries.length > 0) {
- return entries.map((entry) => ({
- title: entry.title,
- category: entry.category || ''
- }))
- }
- return (window.initResponse?.rootDashboards || []).map((title) => ({
- title,
- category: ''
- }))
- }
- function addDashboardNavLink (title) {
- navigation.value.addNavigationLink({
- id: title,
- name: title,
- title,
- path: title === 'Actions' ? '/' : `/dashboards/${title}`,
- icon: DashboardSquare01Icon
- })
- }
- function addCategorizedDashboardLinks (entries) {
- const categoryOrder = []
- const byCategory = new Map()
- for (const entry of entries) {
- const category = entry.category.trim()
- if (!byCategory.has(category)) {
- byCategory.set(category, [])
- categoryOrder.push(category)
- }
- byCategory.get(category).push(entry.title)
- }
- for (const category of categoryOrder) {
- navigation.value.addSection(category)
- for (const title of byCategory.get(category)) {
- addDashboardNavLink(title)
- }
- }
- }
- function renderNavigation () {
- if (!navigation.value) {
- return
- }
- if (typeof navigation.value.clearNavigationLinks === 'function') {
- navigation.value.clearNavigationLinks()
- }
- const entries = getRootDashboardEntries()
- const uncategorized = entries.filter((entry) => !entry.category.trim())
- const categorized = entries.filter((entry) => entry.category.trim())
- for (const entry of uncategorized) {
- addDashboardNavLink(entry.title)
- }
- addCategorizedDashboardLinks(categorized)
- addSystemNavLinks()
- }
- function addSystemNavLinks () {
- const systemLinks = []
- systemLinks.push({
- routeName: 'Entities',
- title: t('nav.entities')
- })
- if (showLogs.value) {
- systemLinks.push({
- routeName: 'Logs',
- title: t('nav.logs')
- })
- }
- if (showDiagnostics.value) {
- const issueCount = window.initResponse?.configIssueCount || 0
- systemLinks.push({
- routeName: 'Diagnostics',
- title: t('nav.diagnostics'),
- options: { count: issueCount }
- })
- }
- if (!loginRequired.value && headerSearchEnabled.value) {
- indexRootDashboardEntries(getRootDashboardEntries())
- indexSystemNavigation({
- showLogs: showLogs.value,
- showDiagnostics: showDiagnostics.value,
- entitiesTitle: t('nav.entities'),
- logsTitle: t('nav.logs'),
- diagnosticsTitle: t('nav.diagnostics')
- })
- }
- if (systemLinks.length === 0) {
- return
- }
- navigation.value.addSection(t('nav.system'))
- for (const link of systemLinks) {
- addSystemRouterNavLink(link.routeName, link.title, link.options || {})
- }
- }
- function addSystemRouterNavLink (routeName, title, options = {}) {
- const foundRoute = router.getRoutes().find((candidate) => candidate.name === routeName)
- if (!foundRoute) {
- console.warn(`Route "${routeName}" not found`)
- return
- }
- const navLink = {
- name: routeName,
- title,
- path: foundRoute.path,
- to: foundRoute.path,
- icon: foundRoute.meta?.icon || DashboardSquare01Icon,
- type: 'route'
- }
- if (options.count != null && options.count > 0) {
- navLink.count = options.count
- }
- navigation.value.addNavigationLink(navLink)
- }
- function openLanguageDialog () {
- selectedLanguage.value = languagePreference.value
- if (typeof navigator !== 'undefined' && Array.isArray(navigator.languages)) {
- browserLanguages.value = navigator.languages
- } else {
- browserLanguages.value = []
- }
- if (languageDialog.value) {
- languageDialog.value.showModal()
- }
- }
- function closeLanguageDialog () {
- if (languageDialog.value) {
- languageDialog.value.close()
- }
- }
- async function changeLanguage () {
- if (!window.i18n || !selectedLanguage.value) {
- return
- }
- const languageChange = ++latestLanguageChange
- const requestedPreference = selectedLanguage.value
- const requestedLocale = requestedPreference === 'auto' ? resolveBrowserLocale() : requestedPreference
- await ensureLocaleMessages(window.i18n, requestedLocale)
- if (languageChange !== latestLanguageChange) {
- return
- }
- window.i18n.locale.value = requestedLocale
- if (requestedPreference === 'auto') {
- localStorage.removeItem('olivetin-language')
- languagePreference.value = 'auto'
- } else {
- localStorage.setItem('olivetin-language', requestedPreference)
- languagePreference.value = requestedPreference
- }
- // Update navigation with new translations
- if (navigation.value) {
- renderNavigation()
- }
- closeLanguageDialog()
- }
- function handleLanguageDialogClick (event) {
- // Close dialog when clicking on the backdrop
- if (event.target === languageDialog.value) {
- closeLanguageDialog()
- }
- }
- function openThemeDialog () {
- selectedTheme.value = themePreference.value || ''
- if (themeDialog.value) {
- themeDialog.value.showModal()
- }
- }
- function closeThemeDialog () {
- if (themeDialog.value) {
- themeDialog.value.close()
- }
- }
- async function changeTheme () {
- if (!selectedTheme.value || selectedTheme.value === '') {
- localStorage.removeItem('olivetin-theme')
- themePreference.value = ''
- } else {
- localStorage.setItem('olivetin-theme', selectedTheme.value)
- themePreference.value = selectedTheme.value
- }
- await applyTheme()
- closeThemeDialog()
- }
- async function applyTheme () {
- try {
- await applyThemeStyles(themePreference.value)
- } catch (err) {
- console.warn('Failed to load theme CSS:', err)
- localStorage.removeItem('olivetin-theme')
- themePreference.value = ''
- selectedTheme.value = ''
- try {
- await applyThemeStyles('')
- } catch (fallbackErr) {
- console.warn('Failed to load default theme CSS:', fallbackErr)
- const themeStyle = document.getElementById('theme-style')
- if (themeStyle) {
- themeStyle.textContent = ''
- }
- document.body.removeAttribute('loaded-theme')
- }
- }
- }
- function loadCustomJsIfEnabled () {
- if (!window.initResponse?.enableCustomJs || document.getElementById('olivetin-custom-js')) {
- return
- }
- const script = document.createElement('script')
- script.src = '/custom-webui/custom.js'
- script.async = true
- script.id = 'olivetin-custom-js'
- document.head.appendChild(script)
- }
- function applyStyleMods () {
- if (!window.initResponse || !window.initResponse.styleMods) {
- return
- }
- for (const styleMod of window.initResponse.styleMods) {
- if (styleMod) {
- document.body.classList.add(styleMod)
- }
- }
- }
- function handleThemeDialogClick (event) {
- if (event.target === themeDialog.value) {
- closeThemeDialog()
- }
- }
- window.updateHeaderFromInit = updateHeaderFromInit
- onMounted(async () => {
- await updateHeaderFromInit()
- // Initialize selected language from stored preference
- selectedLanguage.value = languagePreference.value
- // Initialize selected theme from stored preference
- selectedTheme.value = themePreference.value || ''
- if (typeof navigator !== 'undefined' && Array.isArray(navigator.languages)) {
- browserLanguages.value = navigator.languages
- }
- })
- </script>
- <style scoped>
- /* The banner area is sticky, so a long configured message must not fill a short viewport. */
- #banner {
- max-height: 25vh;
- overflow-y: auto;
- }
- .language-dialog,
- .theme-dialog {
- border: 1px solid var(--border-color, #ccc);
- border-radius: 0.5rem;
- padding: 0;
- max-width: 400px;
- width: 90%;
- }
- .language-dialog::backdrop,
- .theme-dialog::backdrop {
- background-color: rgba(0, 0, 0, 0.5);
- }
- .dialog-content {
- padding: 1.5rem;
- }
- .dialog-content h2 {
- margin-top: 0;
- margin-bottom: 1rem;
- }
- .language-select {
- width: 100%;
- padding: 0.5rem;
- margin-bottom: 1rem;
- font-size: 1rem;
- border: 1px solid var(--border-color, #ccc);
- border-radius: 0.25rem;
- }
- .dialog-buttons {
- display: flex;
- justify-content: flex-end;
- gap: 0.5rem;
- }
- .dialog-buttons button {
- padding: 0.5rem 1rem;
- cursor: pointer;
- }
- .browser-languages {
- font-size: 0.875rem;
- color: var(--fg2, #555);
- margin-bottom: 1rem;
- }
- </style>
|