All files / src/layouts AppLayout.vue

0% Statements 0/167
100% Branches 1/1
100% Functions 1/1
0% Lines 0/167

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
<script setup lang="ts">
import {
  LayoutDashboard,
  BarChart3,
  Layers,
  GraduationCap,
  HelpCircle,
  User,
  LogOut,
  ChevronDown,
  PanelLeftClose,
  PanelLeftOpen,
  ShieldCheck,
} from 'lucide-vue-next'
 
import { useI18n } from 'vue-i18n'
import { useAuthStore } from '@/stores/auth.store'
import { useAuth } from '@/composables/useAuth'
import { useRole } from '@/composables/useRole'
import { computed, ref, onMounted, onBeforeUnmount } from 'vue'
import { useRoute } from 'vue-router'
 
import logo from '@/assets/Six7-white-withoutBackground.png'
 
const { locale, t } = useI18n()
const authStore = useAuthStore()
const { logout } = useAuth()
const { isAdmin, isStaff } = useRole()
const route = useRoute()
 
const userName = computed(() => authStore.user?.username || 'User')
const userInitial = computed(() => (authStore.user?.username ?? 'U').charAt(0).toUpperCase())
 
const isMeshBgActive = computed(() => route.name === 'dashboard' || route.path === '/')
 
const sidebarCollapsed = ref(false)
const userMenuOpen = ref(false)
 
const closeUserMenu = (e: MouseEvent) => {
  const target = e.target as HTMLElement
  if (!target.closest('.user-menu-root')) userMenuOpen.value = false
}
onMounted(() => document.addEventListener('click', closeUserMenu))
onBeforeUnmount(() => document.removeEventListener('click', closeUserMenu))
 
const pageTitle = computed(() => {
  const name = route.name as string | undefined
  const path = route.path as string
 
  if (name === 'dashboard' || name === 'home' || path === '/') return t('nav.dashboard')
  if (name?.startsWith('deployments') || path.startsWith('/deployments')) return t('nav.deployments')
  if (name?.startsWith('apps') || path.startsWith('/apps')) return t('nav.apps')
  if (name === 'courses' || path === '/courses' || path.startsWith('/courses')) return t('nav.courses')
  if (name === 'help' || path === '/help') return t('nav.help')
  if (name === 'config') return t('nav.config')
  if (name === 'admin.apps') return t('nav.approvals')
  return ''
})
 
const changeLocale = (lang: string) => {
  locale.value = lang
  localStorage.setItem('locale', lang)
}
 
const navItems = computed(() => [
  { to: '/', label: 'nav.dashboard', icon: LayoutDashboard },
  { to: { name: 'deployments.list' }, label: 'nav.deployments', icon: BarChart3 },
  { to: '/apps', label: 'nav.apps', icon: Layers },
  { to: '/courses', label: 'nav.courses', icon: GraduationCap, visible: isStaff.value },
  { to: '/admin/apps', label: 'nav.approvals', icon: ShieldCheck, visible: isAdmin.value },
  { to: '/help', label: 'nav.help', icon: HelpCircle },
].filter(item => item.visible !== false))
</script>
 
<template>
  <div class="h-screen flex bg-bgSoft overflow-x-visible">
 
    <!-- Sidebar -->
    <aside
      class="sidebar-bg flex flex-col h-full flex-shrink-0 transition-colors duration-200"
      :class="sidebarCollapsed ? 'w-16' : 'w-60'"
    >
 
      <!-- Logo area -->
      <div class="h-16 flex items-center border-b border-white/10 px-3" style="overflow: visible;">
        <RouterLink to="/" class="block" style="height: 48px; width: 100%; overflow: visible;">
          <img :src="logo" alt="SIX7 Click'n Deploy" style="position: relative; z-index: 30; height: 96px; margin-top: -24px; margin-left: -8px; max-width: none;" />
        </RouterLink>
      </div>
 
      <!-- Sidebar toggle inside navigation zone (shown only when collapsed) -->
      <div v-if="sidebarCollapsed" class="px-2 py-2 border-b border-white/5">
        <button
          @click="sidebarCollapsed = false"
          class="sidebar-toggle-btn"
          aria-label="Open sidebar"
        >
          <PanelLeftOpen :size="18" />
        </button>
      </div>
 
      <!-- Navigation -->
      <nav class="flex-1 px-2 py-4 space-y-0.5 overflow-y-auto">
        <RouterLink
          v-for="item in navItems"
          :key="item.label"
          :to="item.to"
          class="nav-link group"
          :class="sidebarCollapsed ? 'nav-link-collapsed' : ''"
          active-class="nav-link-active"
        >
          <span class="nav-indicator" />
          <component :is="item.icon" :size="21" class="flex-shrink-0 opacity-70 group-[.nav-link-active]:opacity-100" />
          <span
            v-if="!sidebarCollapsed"
            class="transition-opacity duration-150 whitespace-nowrap"
          >{{ $t(item.label) }}</span>
          <!-- Tooltip when collapsed -->
          <span v-if="sidebarCollapsed" class="nav-tooltip">{{ $t(item.label) }}</span>
        </RouterLink>
      </nav>
 
      <!--
        Placeholder for a future bottom-of-sidebar config link.
        Previously there was an empty ``<div class="px-2 py-3 border-t border-white/10">``
        here, which rendered as a stray horizontal line above empty
        space. Removed entirely until there's actual content to host.
      -->
 
    </aside>
 
    <!-- Main area -->
    <div class="flex-1 flex flex-col h-full min-w-0">
 
      <!-- Header -->
      <header class="h-16 header-bg flex items-center justify-between px-6 flex-shrink-0 border-b border-white/10 relative">
 
        <!-- Left: toggle (title centered separately) -->
        <div class="flex items-center gap-3">
          <button
            v-if="!sidebarCollapsed"
            @click="sidebarCollapsed = true"
            class="text-white/60 hover:text-white transition-colors p-1 rounded-md hover:bg-white/10"
            aria-label="Close sidebar"
          >
            <PanelLeftClose :size="20" />
          </button>
        </div>
 
        <!-- Centered title (always horizontally centered in viewport) -->
        <div class="header-title">
          <span class="text-white/90 text-sm font-medium tracking-wide">{{ pageTitle }}</span>
        </div>
 
        <!-- Right controls -->
        <div class="flex items-center gap-2">
 
          <!-- Language toggle -->
          <div class="flex rounded-md overflow-hidden border border-white/20 text-xs">
            <button
              @click="changeLocale('de')"
              :class="locale === 'de' ? 'bg-white/20 text-white' : 'text-white/50 hover:text-white/80'"
              class="px-2.5 py-1 transition-colors"
            >DE</button>
            <button
              @click="changeLocale('en')"
              :class="locale === 'en' ? 'bg-white/20 text-white' : 'text-white/50 hover:text-white/80'"
              class="px-2.5 py-1 transition-colors border-l border-white/20"
            >EN</button>
          </div>
 
          <!-- User menu -->
          <div class="relative user-menu-root">
            <button
              @click="userMenuOpen = !userMenuOpen"
              class="flex items-center gap-2 rounded-lg px-2.5 py-1.5 hover:bg-white/10 transition-colors text-white"
            >
              <div class="w-7 h-7 rounded-full bg-white/20 flex items-center justify-center text-xs font-semibold">
                {{ userInitial }}
              </div>
              <span class="text-sm text-white/90 max-w-24 truncate">{{ userName }}</span>
              <ChevronDown
                :size="14"
                class="text-white/50 transition-transform duration-150"
                :class="userMenuOpen ? 'rotate-180' : ''"
              />
            </button>
 
            <!-- Dropdown -->
            <Transition name="dropdown">
              <div
                v-if="userMenuOpen"
                class="absolute right-0 top-full mt-1.5 w-44 bg-white rounded-xl shadow-lg border border-slate-200 py-1 z-50"
              >
                <RouterLink
                  to="/user"
                  @click="userMenuOpen = false"
                  class="flex items-center gap-2.5 px-3.5 py-2 text-sm text-slate-700 hover:bg-slate-50 transition-colors"
                >
                  <User :size="15" class="text-slate-400" />
                  Profil
                </RouterLink>
                <div class="my-1 border-t border-slate-100" />
                <button
                  @click="logout(); userMenuOpen = false"
                  class="w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-red-600 hover:bg-red-50 transition-colors"
                >
                  <LogOut :size="15" />
                  Abmelden
                </button>
              </div>
            </Transition>
          </div>
 
        </div>
      </header>
 
      <!-- Main content -->
      <main
        class="flex-1 overflow-y-auto px-8 pt-6 pb-8"
        :class="isMeshBgActive ? 'mesh-gradient-bg' : 'bg-bgSoft'"
      >
        <slot />
      </main>
 
    </div>
  </div>
</template>
 
<style scoped>
.sidebar-bg {
  background: linear-gradient(180deg, #317153 0%, #1e4a32 100%);
}
 
.header-bg {
  background: #317153;
}
 
/* Nav link base */
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 12px 13px 18px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.65);
  transition: background-color 150ms, color 150ms;
  text-decoration: none;
}
 
.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
}
 
.nav-link-active {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}
 
/* Collapsed: center icons */
.nav-link-collapsed {
  padding: 13px;
  justify-content: center;
}
 
/* Left indicator bar */
.nav-indicator {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 60%;
  background: #E48C2A;
  border-radius: 0 2px 2px 0;
  transition: transform 150ms ease;
}
 
.nav-link-active .nav-indicator {
  transform: translateY(-50%) scaleY(1);
}
 
/* Tooltip on collapsed state */
.nav-tooltip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #1e2d26;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 100ms ease;
  z-index: 100;
}
 
.nav-link:hover .nav-tooltip {
  opacity: 1;
}
 
/* Mesh background */
.mesh-gradient-bg {
  background-color: #f8faf9;
  background-image:
    radial-gradient(at top left, rgba(49, 113, 83, 0.18) 0px, transparent 50%),
    radial-gradient(at bottom right, rgba(49, 113, 83, 0.22) 0px, transparent 55%),
    radial-gradient(at top right, rgba(255, 255, 255, 0.6) 0px, transparent 45%),
    radial-gradient(at bottom left, rgba(16, 185, 129, 0.10) 0px, transparent 50%);
}
 
/* Logo text fade */
.fade-text-enter-active {
  transition: opacity 150ms ease 100ms, transform 150ms ease 100ms;
}
.fade-text-leave-active {
  transition: opacity 100ms ease, transform 100ms ease;
}
 
/* Logo sizes for expanded / collapsed sidebar */
.logo-full {
  height: 96px;
  margin-top: -24px;
  margin-left: -8px;
  max-width: none;
}
 
/* Sidebar toggle appearance */
.sidebar-toggle-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  transition: background-color 150ms;
}
.sidebar-toggle-btn:hover {
  background: rgba(255,255,255,0.04);
}
 
/* Header title centered in viewport */
.header-title {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  height: 4rem; /* matches h-16 */
  display: flex;
  align-items: center;
  z-index: 70;
  pointer-events: none;
}
.header-title span {
  pointer-events: none;
}
 
/* When collapsed, center the toggle so it doesn't overlap the first nav icon */
.w-16 > .px-2 > .sidebar-toggle-btn,
.w-16 > .px-2 > .sidebar-toggle-btn > * {
  margin-left: auto;
  margin-right: auto;
  display: block;
}
 
/* Hide native scrollbar when sidebar is collapsed (class w-16 applied on aside) */
.sidebar-bg.w-16 nav {
  /* Firefox */
  scrollbar-width: none;
  /* IE 10+ */
  -ms-overflow-style: none;
}
.sidebar-bg.w-16 nav::-webkit-scrollbar {
  width: 0;
  height: 0;
}
 
/* Sidebar scroll controls placed at bottom when expanded */
 
.fade-text-enter-from,
.fade-text-leave-to {
  opacity: 0;
  transform: translateX(-6px);
}
 
/* Dropdown transition */
.dropdown-enter-active,
.dropdown-leave-active {
  transition: opacity 120ms ease, transform 120ms ease;
}
.dropdown-enter-from,
.dropdown-leave-to {
  opacity: 0;
  transform: translateY(-4px);
}
</style>