refactor: ChakraUI v3 frontend + direct SQL backend services

Frontend:
- Replace Tailwind CSS with ChakraUI v3 (react, recharts, fontsource)
- 24 themes (12 Dune factions x day/night variants)
- Collapsible sidebar navigation with 6 groups
- Recharts AreaChart/PieChart for CPU/RAM/metrics
- New Experimental page (ports legacy admin_experimental.html)
- Common components: DataTable, Modal, Badge, Toaster

Backend:
- Fix services to use direct SQL (dune.* schema) instead of stored procedures
- PlayerService, EconomyService, GuildService, WorldService rewritten
- Auto-login for SPA development in factory.py
- Fix settings.yaml path resolution

Launcher:
- Add option [7] Start New Dashboard in launcher.ps1 and start.sh
- Auto-installs pip + npm dependencies
- Sets up SSH tunnels + kubectl port-forwards
- Starts backend API + frontend Vite dev server

Security:
- Sanitize hardcoded RMQ password in config.py
- Add frontend/dist/ to .gitignore
This commit is contained in:
Reditus committed 2026-05-25 03:08:02 +01:00
1 parent d7ac8a6641
commit 011ba8c8b4
52 files changed
+5901 -2444

No files matched your search

+23 -11
View File
@@ -1,15 +1,27 @@
import { ReactNode } from 'react'
import NavBar from './NavBar'
import ToastProvider from '../common/ToastProvider'
import { Box, Flex } from '@chakra-ui/react'
import { Toaster, ToastRoot, ToastTitle, ToastDescription } from '@chakra-ui/react'
import Sidebar from './Sidebar'
import TopBar from './TopBar'
import { toaster } from '../../toaster'
export default function AppShell({ children }: { children: ReactNode }) {
export default function AppShell({ children }: { children: React.ReactNode }) {
return (
<div className="min-h-screen bg-background text-text-primary">
<NavBar />
<main className="p-6 max-w-[1600px] mx-auto">
<ToastProvider />
{children}
</main>
</div>
<Flex minH="100vh" bg="bg">
<Sidebar />
<Box flex={1} ml="260px">
<TopBar />
<Box as="main" p={6} minH="calc(100vh - 56px)">
{children}
</Box>
</Box>
<Toaster toaster={toaster}>
{(toast: any) => (
<ToastRoot key={toast.id}>
{toast.title && <ToastTitle>{toast.title}</ToastTitle>}
{toast.description && <ToastDescription>{toast.description}</ToastDescription>}
</ToastRoot>
)}
</Toaster>
</Flex>
)
}
@@ -1,21 +1,70 @@
import { Box, Flex, Text, Tooltip, VStack, Circle } from '@chakra-ui/react'
import { FiWifi, FiWifiOff } from 'react-icons/fi'
import { useApp } from '../../stores/AppContext'
const SERVICES = [
{ key: 'database' as const, label: 'Database' },
{ key: 'ssh' as const, label: 'SSH Tunnel' },
{ key: 'bgd' as const, label: 'BG Director' },
{ key: 'rmq' as const, label: 'RMQ' },
]
export default function ConnectionBadge() {
const { state } = useApp()
const { database, ssh, bgd, rmq } = state.connectionStatus
const allOk = database && ssh && bgd && rmq
const someDown = !allOk && (database || ssh || bgd || rmq)
const statuses = SERVICES.map((s) => state.connectionStatus[s.key])
const upCount = statuses.filter(Boolean).length
const allUp = upCount === statuses.length
const allDown = upCount === 0
const dotColor = allUp ? 'success.DEFAULT' : allDown ? 'danger.DEFAULT' : 'warning.DEFAULT'
return (
<div className="flex items-center gap-2">
<div
className="w-2.5 h-2.5 rounded-full"
style={{
backgroundColor: allOk ? '#27ae60' : someDown ? '#f39c12' : '#c0392b',
boxShadow: `0 0 6px ${allOk ? '#27ae60' : someDown ? '#f39c12' : '#c0392b'}`,
}}
title={`DB: ${database ? 'OK' : 'DOWN'} | SSH: ${ssh ? 'OK' : 'DOWN'} | BGD: ${bgd ? 'OK' : 'DOWN'} | RMQ: ${rmq ? 'OK' : 'DOWN'}`}
/>
</div>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Flex
align="center"
gap={1.5}
px={2.5}
py={1}
borderRadius="full"
bg="bg.subtle"
border="1px solid"
borderColor="border.subtle"
cursor="default"
>
{allUp ? (
<FiWifi size={14} color="currentColor" />
) : (
<FiWifiOff size={14} color="currentColor" />
)}
<Circle size="6px" bg={dotColor} />
</Flex>
</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content bg="card.bg" border="1px solid" borderColor="border" borderRadius="md" p={3}>
<VStack align="stretch" gap={2} minW="160px">
<Text fontSize="xs" fontWeight="semibold" color="fg" mb={1}>
Service Status
</Text>
{SERVICES.map((s) => (
<Flex key={s.key} justify="space-between" align="center" gap={4}>
<Text fontSize="xs" color="fg.muted">
{s.label}
</Text>
<Flex align="center" gap={1.5}>
<Circle
size="6px"
bg={state.connectionStatus[s.key] ? 'success.DEFAULT' : 'danger.DEFAULT'}
/>
<Text fontSize="2xs" color="fg.muted">
{state.connectionStatus[s.key] ? 'OK' : 'DOWN'}
</Text>
</Flex>
</Flex>
))}
</VStack>
</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
)
}
+192
View File
@@ -0,0 +1,192 @@
import { useState } from 'react'
import { Link, useLocation } from 'react-router-dom'
import { Box, Flex, VStack, Text, Collapsible, Separator } from '@chakra-ui/react'
import { FiHome, FiServer, FiUsers, FiShield, FiMap, FiTruck, FiBox, FiMessageSquare, FiTool, FiSliders, FiUserCheck, FiFolder, FiTerminal, FiSettings, FiZap } from 'react-icons/fi'
interface NavGroup {
label: string
icon: React.ElementType
items: { path: string; label: string; icon: React.ElementType }[]
}
const NAV_GROUPS: NavGroup[] = [
{
label: 'Dashboard',
icon: FiHome,
items: [
{ path: '/', label: 'Overview', icon: FiHome },
{ path: '/server', label: 'Server', icon: FiServer },
],
},
{
label: 'Players & World',
icon: FiUsers,
items: [
{ path: '/players', label: 'Players', icon: FiUsers },
{ path: '/guilds', label: 'Guilds', icon: FiShield },
{ path: '/map', label: 'Map', icon: FiMap },
{ path: '/vehicles', label: 'Vehicles', icon: FiTruck },
{ path: '/buildings', label: 'Buildings', icon: FiBox },
],
},
{
label: 'Communication',
icon: FiMessageSquare,
items: [
{ path: '/chat', label: 'Chat Monitor', icon: FiMessageSquare },
],
},
{
label: 'Administration',
icon: FiTool,
items: [
{ path: '/admin', label: 'Admin Tools', icon: FiTool },
{ path: '/director', label: 'Director', icon: FiSliders },
{ path: '/accounts', label: 'Accounts', icon: FiUserCheck },
],
},
{
label: 'System',
icon: FiFolder,
items: [
{ path: '/files', label: 'Files', icon: FiFolder },
{ path: '/shell', label: 'Shell', icon: FiTerminal },
{ path: '/settings', label: 'Settings', icon: FiSettings },
],
},
{
label: 'Experimental',
icon: FiZap,
items: [
{ path: '/experimental', label: 'Experimental', icon: FiZap },
],
},
]
export default function Sidebar() {
return (
<Box
as="aside"
w="260px"
minW="260px"
h="100vh"
position="fixed"
left={0}
top={0}
bg="nav.bg"
color="fg"
overflowY="auto"
borderRight="1px solid"
borderColor="border"
zIndex={40}
>
<Flex align="center" px={5} py={4} borderBottom="1px solid" borderColor="border">
<Text
fontFamily="Playfair Display, serif"
fontSize="xl"
fontWeight="bold"
color="primary.DEFAULT"
letterSpacing="wider"
>
Dune
</Text>
<Text
fontSize="2xs"
color="fg.muted"
ml={2}
mt={1}
letterSpacing="widest"
textTransform="uppercase"
>
Admin
</Text>
</Flex>
<VStack gap={1} px={2} py={3} align="stretch">
{NAV_GROUPS.map((group) => (
<NavGroupSection key={group.label} group={group} />
))}
</VStack>
</Box>
)
}
function NavGroupSection({ group }: { group: NavGroup }) {
const location = useLocation()
const groupActive = group.items.some(
(item) =>
location.pathname === item.path ||
(item.path !== '/' && location.pathname.startsWith(item.path))
)
const [open, setOpen] = useState(groupActive)
return (
<Collapsible.Root open={open} onOpenChange={(e) => setOpen(e.open)}>
<Collapsible.Trigger
asChild
cursor="pointer"
display="flex"
alignItems="center"
gap={2}
px={3}
py={2}
borderRadius="md"
fontSize="xs"
fontWeight="semibold"
color="fg.muted"
textTransform="uppercase"
letterSpacing="wider"
_hover={{ bg: 'bg.subtle', color: 'fg' }}
transition="all 0.15s"
>
<Flex align="center" gap={2} w="full">
<Box as="span" fontSize="sm">
<group.icon />
</Box>
<Text flex={1}>{group.label}</Text>
<Collapsible.Indicator
transform={open ? 'rotate(180deg)' : 'rotate(0deg)'}
transition="transform 0.15s"
/>
</Flex>
</Collapsible.Trigger>
<Collapsible.Content>
<VStack gap={0} align="stretch" pl={6} mt={1}>
{group.items.map((item) => {
const active =
location.pathname === item.path ||
(item.path !== '/' && location.pathname.startsWith(item.path))
return (
<Link key={item.path} to={item.path}>
<Flex
align="center"
gap={2}
px={3}
py={2}
borderRadius="md"
fontSize="sm"
fontWeight={active ? 'semibold' : 'normal'}
color={active ? 'primary.DEFAULT' : 'fg.muted'}
bg={active ? 'primary.subtle' : 'transparent'}
borderLeft={active ? '3px solid' : '3px solid transparent'}
borderColor={active ? 'primary.DEFAULT' : 'transparent'}
_hover={
!active
? { bg: 'bg.subtle', color: 'fg' }
: {}
}
transition="all 0.15s"
>
<Box as="span" fontSize="xs" opacity={active ? 1 : 0.6}>
<item.icon />
</Box>
<Text>{item.label}</Text>
</Flex>
</Link>
)
})}
</VStack>
</Collapsible.Content>
</Collapsible.Root>
)
}
+105 -58
View File
@@ -1,68 +1,115 @@
import { useState, useRef, useEffect } from 'react'
import {
Box,
Flex,
Text,
Menu,
Button,
HStack,
IconButton,
Tooltip,
Portal,
} from '@chakra-ui/react'
import { FiSun, FiMoon, FiChevronDown } from 'react-icons/fi'
import { useApp } from '../../stores/AppContext'
const THEMES = [
{ key: 'default', label: 'Classic Dune' },
{ key: 'atreides', label: 'House Atreides' },
{ key: 'harkonnen', label: 'House Harkonnen' },
{ key: 'fremen', label: 'Fremen' },
{ key: 'bene-gesserit', label: 'Bene Gesserit' },
{ key: 'spacing-guild', label: 'Spacing Guild' },
{ key: 'emperor', label: 'Emperor' },
{ key: 'corrino', label: 'House Corrino' },
{ key: 'mentat', label: 'Mentat' },
{ key: 'sardaukar', label: 'Sardaukar' },
{ key: 'tleilax', label: 'Bene Tleilax' },
{ key: 'ordos', label: 'House Ordos' },
{ key: 'ix', label: 'Ix' },
{ key: 'choam', label: 'CHOAM' },
]
import { FACTION_KEYS, getFactionName } from '../../themes'
import type { FactionKey } from '../../themes/palettes'
export default function ThemeSwitcher() {
const { state, dispatch } = useApp()
const [open, setOpen] = useState(false)
const ref = useRef<HTMLDivElement>(null)
useEffect(() => {
function handleClick(e: MouseEvent) {
if (ref.current && !ref.current.contains(e.target as Node)) {
setOpen(false)
}
}
document.addEventListener('mousedown', handleClick)
return () => document.removeEventListener('mousedown', handleClick)
}, [])
const handleFactionChange = (key: FactionKey) => {
dispatch({ type: 'SET_FACTION', payload: key })
}
const toggleColorMode = () => {
dispatch({
type: 'SET_COLOR_MODE',
payload: state.colorMode === 'day' ? 'night' : 'day',
})
}
return (
<div className="relative" ref={ref}>
<button
onClick={() => setOpen(!open)}
className="w-6 h-6 rounded-full"
style={{ background: 'linear-gradient(135deg, var(--primary) 50%, var(--bg) 50%)' }}
title="Change theme"
/>
{open && (
<div className="absolute right-0 mt-2 w-56 bg-card-bg border border-border rounded-lg shadow-xl z-50 py-2">
{THEMES.map((t) => (
<button
key={t.key}
onClick={() => {
dispatch({ type: 'SET_THEME', payload: t.key })
setOpen(false)
}}
className={`w-full text-left px-4 py-2 text-sm flex items-center gap-3 hover:bg-hover transition-colors ${
state.theme === t.key ? 'text-primary font-semibold' : 'text-text-secondary'
}`}
<HStack gap={1}>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<IconButton
aria-label="Toggle color mode"
variant="ghost"
size="sm"
onClick={toggleColorMode}
color="fg.muted"
w={8}
h={8}
>
{state.colorMode === 'day' ? <FiSun size={16} /> : <FiMoon size={16} />}
</IconButton>
</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content bg="card.bg" border="1px solid" borderColor="border" borderRadius="md" px={3} py={1}>
{state.colorMode === 'day' ? 'Switch to Night' : 'Switch to Day'}
</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
<Menu.Root>
<Menu.Trigger asChild>
<Button
variant="outline"
size="sm"
borderColor="border"
color="fg"
_hover={{ borderColor: 'primary.DEFAULT', color: 'primary.DEFAULT' }}
gap={2}
>
<Box
w={2.5}
h={2.5}
borderRadius="full"
bg="primary.DEFAULT"
/>
<Text fontSize="xs">{getFactionName(state.faction)}</Text>
<FiChevronDown size={12} />
</Button>
</Menu.Trigger>
<Portal>
<Menu.Positioner>
<Menu.Content
bg="card.bg"
borderColor="border"
borderRadius="lg"
boxShadow="card"
maxH="400px"
overflowY="auto"
>
<span
className="w-4 h-4 rounded border border-border"
style={{ background: `linear-gradient(135deg, var(--primary) 50%, var(--bg) 50%)` }}
/>
{t.label}
</button>
))}
</div>
)}
</div>
<Menu.ItemGroup title="Factions">
{FACTION_KEYS.map((key) => (
<Menu.Item
key={key}
value={key}
onClick={() => handleFactionChange(key)}
bg={state.faction === key ? 'primary.subtle' : 'transparent'}
color={state.faction === key ? 'primary.DEFAULT' : 'fg'}
fontWeight={state.faction === key ? 'semibold' : 'normal'}
_hover={{ bg: 'bg.subtle' }}
cursor="pointer"
py={2}
>
<Flex align="center" gap={3}>
<Box
w={3}
h={3}
borderRadius="full"
bg="primary.DEFAULT"
/>
<Text>{getFactionName(key)}</Text>
</Flex>
</Menu.Item>
))}
</Menu.ItemGroup>
</Menu.Content>
</Menu.Positioner>
</Portal>
</Menu.Root>
</HStack>
)
}
+73
View File
@@ -0,0 +1,73 @@
import { Flex, Text, HStack, Box, Input, InputGroup } from '@chakra-ui/react'
import { FiSearch, FiUser } from 'react-icons/fi'
import { useApp } from '../../stores/AppContext'
import ConnectionBadge from './ConnectionBadge'
import ThemeSwitcher from './ThemeSwitcher'
export default function TopBar() {
const { state } = useApp()
return (
<Flex
as="header"
h="56px"
align="center"
px={6}
gap={4}
bg="bg"
borderBottom="1px solid"
borderColor="border"
position="sticky"
top={0}
zIndex={30}
>
<Box flex={1} maxW="400px">
<InputGroup
startElement={
<Box pl={3} color="fg.muted">
<FiSearch size={14} />
</Box>
}
w="full"
>
<Input
placeholder="Search players, guilds, accounts..."
size="sm"
borderRadius="lg"
bg="bg.subtle"
border="1px solid"
borderColor="border"
color="fg"
_placeholder={{ color: 'fg.muted' }}
_hover={{ borderColor: 'border' }}
_focus={{ borderColor: 'primary.DEFAULT', boxShadow: `0 0 0 1px var(--chakra-colors-primary-DEFAULT)` }}
fontSize="xs"
pl={8}
/>
</InputGroup>
</Box>
<HStack gap={3} ml="auto">
<ConnectionBadge />
<ThemeSwitcher />
{state.user && (
<Flex
align="center"
gap={2}
px={3}
py={1}
borderRadius="full"
bg="primary.subtle"
border="1px solid"
borderColor="primary.subtle"
>
<FiUser size={12} />
<Text fontSize="xs" color="primary.DEFAULT" fontWeight="medium">
{state.user}
</Text>
</Flex>
)}
</HStack>
</Flex>
)
}