| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <script>
- // Immediately set dark mode if needed, before page loads
- const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
- const savedTheme = localStorage.getItem('theme');
- if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
- document.documentElement.classList.add('dark');
- }
- </script>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <link crossorigin="" href="https://fonts.gstatic.com/" rel="preconnect" />
- <link
- as="style"
- href="https://fonts.googleapis.com/css2?display=swap&family=Noto+Sans%3Awght%40400%3B500%3B700%3B900&family=Plus+Jakarta+Sans%3Awght%40400%3B500%3B700%3B800"
- onload="this.rel='stylesheet'"
- rel="stylesheet"
- />
- <!-- Preload Material Icons fonts for faster loading -->
- <link rel="preload" href="/static/fonts/material-icons/MaterialIcons-Regular.woff2" as="font" type="font/woff2" crossorigin>
- <link rel="preload" href="/static/fonts/material-icons/MaterialIconsOutlined-Regular.woff2" as="font" type="font/woff2" crossorigin>
- <title>{% block title %}{{ app_name or 'Dune Weaver' }}{% endblock %}</title>
- {% if custom_logo %}
- {# Favicon is auto-generated from logo as favicon.ico #}
- <link rel="apple-touch-icon" sizes="180x180" href="/static/custom/{{ custom_logo }}">
- <link rel="icon" type="image/x-icon" href="/static/custom/favicon.ico">
- {% else %}
- <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
- <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
- <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
- {% endif %}
- <link rel="manifest" href="/static/site.webmanifest?v=2">
- <link rel="stylesheet" href="/static/css/tailwind.css">
- <link rel="stylesheet" href="/static/css/material-icons.css">
- <style>
- /* Mobile navigation styles */
- @media (max-width: 640px) {
- nav.flex {
- display: grid;
- grid-template-columns: repeat(5, 1fr);
- gap: 0;
- }
- nav.flex a {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- text-align: center;
- padding: 0.75rem 0;
- }
- nav.flex a .material-icons {
- margin-bottom: 0.25rem;
- }
- }
- /* Dark mode styles */
- .dark {
- color-scheme: dark;
- }
- .dark body {
- background-color: #1a1a1a;
- color: #e5e5e5;
- }
- .dark header {
- background-color: #262626;
- border-color: #404040;
- }
- .dark footer {
- background-color: #262626;
- border-color: #404040;
- }
- .dark .inactive-tab {
- color: #9ca3af;
- }
- .dark .inactive-tab:hover {
- color: #d1d5db;
- }
- .dark #player-status-bar-container {
- background-color: #262626;
- color: #e5e5e5;
- }
- .dark .bg-gray-100 {
- background-color: #262626;
- }
- .dark .bg-gray-200 {
- background-color: #404040;
- }
- .dark .bg-gray-300 {
- background-color: #525252;
- }
- .dark .text-gray-500 {
- color: #9ca3af;
- }
- .dark .text-gray-700 {
- color: #d1d5db;
- }
- .dark .text-gray-800 {
- color: #e5e5e5;
- }
- .dark .border-gray-200 {
- border-color: #404040;
- }
- .dark .hover\:bg-gray-200:hover {
- background-color: #404040;
- }
- .dark .hover\:bg-gray-300:hover {
- background-color: #525252;
- }
- .dark .hover\:border-gray-300:hover {
- border-color: #525252;
- }
- .dark .hover\:bg-gray-50:hover {
- background-color: #262626;
- }
- .dark .bg-white {
- background-color: #262626;
- }
- .dark #shutdown-button:hover {
- background-color: #404040;
- }
- .dark #restart-button:hover {
- background-color: #404040;
- }
- .dark #theme-toggle:hover {
- background-color: #404040;
- }
- .dark .bg-gray-50 {
- background-color: #1a1a1a;
- }
- .dark .text-gray-900 {
- color: #e5e5e5;
- }
- .dark .text-gray-400 {
- color: #9ca3af;
- }
- .dark .border-gray-300 {
- border-color: #404040;
- }
- .dark .focus\:ring-offset-2 {
- --tw-ring-offset-color: #262626;
- }
- .dark .shadow-sm {
- box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
- }
- .dark .shadow-lg {
- box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
- }
- .dark .shadow-xl {
- box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
- }
- /* Existing styles */
- .active-tab {
- color: #0c7ff2;
- border-color: #0c7ff2;
- }
- .active-tab .material-icons {
- color: #0c7ff2;
- }
- .inactive-tab {
- color: #6b7280;
- border-color: transparent;
- }
- .inactive-tab:hover {
- color: #374151;
- }
- #status-message {
- transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
- }
- /* Switch toggle styles */
- .switch {
- position: relative;
- display: inline-block;
- width: 40px;
- height: 20px;
- }
- .switch input {
- opacity: 0;
- width: 0;
- height: 0;
- }
- .slider {
- position: absolute;
- cursor: pointer;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: #ccc;
- transition: .4s;
- border-radius: 20px;
- }
- .slider:before {
- position: absolute;
- content: "";
- height: 16px;
- width: 16px;
- left: 2px;
- bottom: 2px;
- background-color: white;
- transition: .4s;
- border-radius: 50%;
- }
- input:checked + .slider {
- background-color: #0c7ff2;
- }
- input:checked + .slider:before {
- transform: translateX(20px);
- }
- /* Shadow for top of status bar */
- .shadow-lg-top {
- box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 -2px 4px -2px rgb(0 0 0 / 0.1);
- }
- /* Marquee animation for pattern name on small screens */
- @keyframes marquee {
- 0% { transform: translateX(0%); }
- 50% { transform: translateX(-50%); }
- }
- .pattern-marquee {
- display: inline-block;
- min-width: 100%;
- animation: marquee 8s linear infinite;
- }
- @media (min-width: 640px) { /* sm: and up, disable marquee */
- .pattern-marquee {
- animation: none !important;
- transform: none !important;
- }
- }
- {% block additional_styles %}{% endblock %}
- </style>
- {% block additional_head %}{% endblock %}
- </head>
- <body
- class="bg-gray-50"
- style="font-family: 'Plus Jakarta Sans', 'Noto Sans', sans-serif"
- >
- <div
- class="mt-2 w-full text-center px-4 z-50 pointer-events-none absolute"
- id="status-message-container"
- >
- <p
- class="text-base font-semibold opacity-0 transform -translate-y-2 transition-all duration-300 ease-in-out px-10 py-2 rounded-lg shadow-lg"
- id="status-message"
- ></p>
- </div>
- <div
- class="relative flex size-full min-h-screen flex-col group/design-root overflow-x-hidden"
- >
- <div class="layout-container flex min-h-full grow flex-col">
- <header
- class="fixed top-0 left-0 right-0 z-10 flex items-center justify-between whitespace-nowrap border-b border-solid border-b-gray-200 bg-white px-4 sm:px-6 md:px-10 py-3 sm:py-4 shadow-sm"
- >
- <div class="flex items-center gap-3 text-gray-800">
- <a href="/" class="flex items-center gap-3 text-gray-800 hover:opacity-80 transition-opacity">
- <div class="text-blue-600 w-9 h-9 rounded-full shadow overflow-hidden">
- <img src="{% if custom_logo %}/static/custom/{{ custom_logo }}{% else %}/static/apple-touch-icon.png{% endif %}" alt="{{ app_name or 'Dune Weaver' }} Logo" class="w-full h-full object-cover"/>
- </div>
- <h1
- class="text-gray-800 text-xl font-bold leading-tight tracking-tight flex items-center gap-2"
- >
- {{ app_name or 'Dune Weaver' }}
- <span
- id="connectionStatusDot"
- class="inline-block size-2 rounded-full bg-red-500 ml-2 align-middle"
- ></span>
- </h1>
- </a>
- </div>
- <div class="flex items-center gap-2">
- <!-- Update Available Indicator -->
- <button
- id="update-indicator"
- class="hidden p-1.5 flex rounded-lg hover:bg-green-100 dark:hover:bg-green-900 focus:outline-none focus:ring-2 focus:ring-green-500"
- aria-label="Update available"
- title="Software update available - Click to view"
- >
- <span class="material-icons text-green-600 dark:text-green-400 animate-pulse">system_update</span>
- </button>
- <button
- id="theme-toggle"
- class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- aria-label="Toggle dark mode"
- >
- <span class="material-icons" id="theme-toggle-icon">dark_mode</span>
- </button>
- <button
- id="view-logs-button"
- class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- aria-label="View logs"
- title="View Application Logs"
- onclick="openLogsModal()"
- >
- <span class="material-icons">article</span>
- </button>
- <button
- id="restart-button"
- class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-amber-500"
- aria-label="Restart system"
- title="Restart Docker Containers"
- >
- <span class="material-icons text-amber-600">restart_alt</span>
- </button>
- <button
- id="shutdown-button"
- class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-red-500"
- aria-label="Shutdown system"
- title="Shutdown System (Raspberry Pi only)"
- >
- <span class="material-icons text-red-600">power_settings_new</span>
- </button>
- </div>
- </header>
- <main class="flex flex-1 justify-center px-4 sm:px-6 lg:px-8 pt-16 sm:pt-20">
- {% block content %}{% endblock %}
- </main>
- <!-- Floating Preview Button -->
- <button
- id="toggle-preview-modal-btn"
- class="fixed bottom-24 right-4 z-30 bg-blue-600 hover:bg-blue-700 text-white rounded-full shadow-lg w-12 h-12 flex items-center justify-center transition-all focus:outline-none focus:ring-2 focus:ring-blue-500"
- title="Toggle Pattern Preview"
- >
- <span class="material-icons text-xl">preview</span>
- </button>
- <footer
- class="fixed bottom-0 left-0 right-0 z-10 bg-white border-t border-gray-200 shadow-t-sm"
- >
- <nav class="mx-auto flex max-w-5xl justify-around">
- <a
- class="{% if request.url.path == '/' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] {% if request.url.path != '/' %}border-transparent{% endif %} py-3 text-xs font-medium sm:text-sm"
- href="/"
- >
- <span class="material-icons">search</span> Browse
- </a>
- <a
- class="{% if request.url.path == '/playlists' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/playlists"
- >
- <span class="material-icons">list_alt</span> Playlists
- </a>
- <a
- class="{% if request.url.path == '/table_control' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/table_control"
- >
- <span class="material-icons">table_chart</span> Table Control
- </a>
- <a
- class="{% if request.url.path == '/led' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/led"
- >
- <span class="material-icons">lightbulb</span> <span id="led-nav-label">LED</span>
- </a>
- <a
- class="{% if request.url.path == '/settings' %}active-tab{% else %}inactive-tab{% endif %} flex flex-1 flex-col items-center justify-center gap-1 border-b-[3px] py-3 text-xs font-medium sm:text-sm"
- href="/settings"
- >
- <span class="material-icons">settings</span> Settings
- </a>
- </nav>
- </footer>
- </div>
- </div>
- {% block scripts %}{% endblock %}
- <script src="/static/js/base.js"></script>
- <!-- Cache Progress Modal -->
- <div id="cacheProgressModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
- <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
- <div class="p-6">
- <div class="text-center">
- <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Initializing Pattern Cache</h2>
- <p class="text-gray-600 dark:text-gray-400 mb-4">Preparing your pattern previews...</p>
-
- <div class="mb-4">
- <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
- <div id="cacheProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
- </div>
- <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
- <span id="cacheProgressText">Starting...</span>
- <span id="cacheProgressPercentage">0%</span>
- </div>
- </div>
-
- <div class="text-sm text-gray-500 dark:text-gray-400">
- <p id="cacheCurrentStage">Preparing...</p>
- <p id="cacheCurrentFile" class="mt-1 truncate"></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- Player Preview Modal -->
- <div id="playerPreviewModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-40 hidden p-4">
- <div class="bg-white rounded-lg shadow-xl w-full max-w-5xl max-h-[95vh] flex flex-col">
- <div class="flex items-center justify-between p-4 border-b border-gray-200 flex-shrink-0">
- <h2 id="playerPreviewTitle" class="text-xl font-semibold text-gray-800">Pattern Preview</h2>
- <button id="closePlayerPreview" class="text-gray-400 hover:text-gray-600 transition-colors">
- <span class="material-icons text-2xl">close</span>
- </button>
- </div>
- <!-- Canvas Area -->
- <div class="flex-1 p-4 flex justify-center items-center overflow-hidden">
- <div class="relative flex items-center justify-center w-full h-full">
- <div class="relative max-w-[min(800px,90vw)] max-h-[min(600px,80vh)] aspect-square">
- <canvas id="playerPreviewCanvas" width="800" height="800" class="w-full h-full rounded-full border border-gray-300 dark:invert"></canvas>
- </div>
- </div>
- </div>
- <!-- Pattern Info and Controls -->
- <div class="flex-shrink-0 p-4 border-b border-gray-200 flex items-center gap-4 flex-wrap">
- <!-- Pattern Preview Image -->
- <div class="flex-shrink-0">
- <img id="modal-pattern-preview-img"
- class="w-[126px] h-[126px] rounded-full border border-gray-300 object-cover dark:invert" src="">
- </div>
- <div class="flex-grow w-auto">
- <div class="flex items-center justify-between mb-2">
- <div class="min-w-0 max-w-[50%]">
- <div class="overflow-hidden relative">
- <p class="text-lg font-semibold whitespace-nowrap" id="modal-pattern-name">
- No pattern playing
- </p>
- </div>
- <p class="text-base text-gray-500" id="modal-eta">
- ETA: --:--
- </p>
- </div>
- <div class="flex items-center gap-2 flex-shrink-0">
- <button
- aria-label="Next"
- class="w-12 aspect-square rounded-full flex items-center justify-center hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- id="modal-skip-button"
- >
- <span class="material-icons text-gray-700">skip_next</span>
- </button>
- <button
- aria-label="Pause"
- class="w-12 aspect-square rounded-full flex items-center justify-center hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- id="modal-pause-button"
- >
- <span class="material-icons text-gray-700">pause</span>
- </button>
- <button
- aria-label="Stop"
- class="w-12 aspect-square rounded-full flex items-center justify-center hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
- id="modal-stop-button"
- >
- <span class="material-icons text-gray-700">stop</span>
- </button>
- </div>
- </div>
- <div class="w-full bg-gray-300 rounded-full h-2.5 mb-2">
- <div
- class="bg-blue-600 h-2.5 rounded-full"
- id="modal-progress-bar"
- style="width: 0%"
- ></div>
- </div>
- <div class="flex items-center justify-between">
- <div class="text-base text-gray-500">
- Next:
- <span class="text-gray-700 font-medium" id="modal-next-pattern">None</span>
- </div>
- <div class="flex items-center gap-3 text-sm">
- <span class="text-gray-500">Speed:</span>
- <div class="flex items-center gap-2">
- <div class="relative min-w-[4ch] text-center cursor-pointer inline-flex items-center" id="modal-speed-container">
- <span class="inline-block px-2 py-1 text-gray-700 font-medium border border-transparent rounded hover:border-gray-300 hover:bg-gray-50 transition-colors" id="modal-speed-display" title="Click to edit speed">--</span>
- <input type="number" min="1" max="5000" step="1" class="w-16 sm:w-20 px-2 py-1 text-sm border border-blue-500 rounded focus:border-blue-500 focus:ring-1 focus:ring-blue-500 text-center hidden" id="modal-speed-input" />
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- // Function to show status message
- function showStatusMessage(message, type = "success") {
- const statusContainer = document.getElementById(
- "status-message-container"
- );
- const statusMessage = document.getElementById("status-message");
- if (!statusContainer || !statusMessage) return;
- // Set message and color based on type
- statusMessage.textContent = message;
- statusMessage.className = `text-base font-semibold opacity-0 transform -translate-y-2 transition-all duration-300 ease-in-out px-4 py-2 rounded-lg shadow-lg ${
- type === "success"
- ? "bg-green-50 text-green-700 border border-green-200"
- : type === "error"
- ? "bg-red-50 text-red-700 border border-red-200"
- : type === "warning"
- ? "bg-yellow-50 text-yellow-700 border border-yellow-200"
- : "bg-blue-50 text-blue-700 border border-blue-200"
- }`;
- // Show message with animation
- requestAnimationFrame(() => {
- statusMessage.classList.remove("opacity-0", "-translate-y-2");
- statusMessage.classList.add("opacity-100", "translate-y-0");
- });
- // Hide message after 5 seconds
- setTimeout(() => {
- statusMessage.classList.remove("opacity-100", "translate-y-0");
- statusMessage.classList.add("opacity-0", "-translate-y-2");
- }, 5000);
- }
- // Initial connection status check
- async function checkInitialConnectionStatus() {
- try {
- const response = await fetch("/serial_status");
- if (response.ok) {
- const data = await response.json();
- const statusDot = document.getElementById("connectionStatusDot");
- if (statusDot) {
- statusDot.className = `inline-block size-2 rounded-full ml-2 align-middle ${
- data.connected ? "bg-green-500" : "bg-red-500"
- }`;
- }
- }
- } catch (error) {
- console.error("Error checking initial connection status:", error);
- }
- }
- // Check initial status on page load
- document.addEventListener("DOMContentLoaded", checkInitialConnectionStatus);
- // Player bar toggle logic will be handled by base.js
- </script>
-
- <script>
- // Cache progress modal functionality
- let cacheProgressSocket = null;
- let cacheProgressCheckInterval = null;
-
- function initCacheProgressModal() {
- const modal = document.getElementById('cacheProgressModal');
- const progressBar = document.getElementById('cacheProgressBar');
- const progressText = document.getElementById('cacheProgressText');
- const progressPercentage = document.getElementById('cacheProgressPercentage');
- const currentStage = document.getElementById('cacheCurrentStage');
- const currentFile = document.getElementById('cacheCurrentFile');
-
- // Check if cache generation is needed on page load
- fetch('/cache-progress')
- .then(response => response.json())
- .then(data => {
- if (data.is_running) {
- showCacheProgressModal();
- }
- })
- .catch(error => {
- console.error('Error checking initial cache progress:', error);
- });
-
- function showCacheProgressModal() {
- modal.classList.remove('hidden');
-
- // Connect to WebSocket for real-time updates
- const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
- const wsUrl = `${protocol}//${window.location.host}/ws/cache-progress`;
-
- cacheProgressSocket = new WebSocket(wsUrl);
-
- cacheProgressSocket.onmessage = function(event) {
- const data = JSON.parse(event.data);
- if (data.type === 'cache_progress') {
- updateCacheProgress(data.data);
- }
- };
-
- cacheProgressSocket.onclose = function() {
- // Fallback to polling if WebSocket fails
- startProgressPolling();
- };
-
- cacheProgressSocket.onerror = function() {
- // Fallback to polling if WebSocket fails
- startProgressPolling();
- };
- }
-
- function startProgressPolling() {
- if (cacheProgressCheckInterval) {
- clearInterval(cacheProgressCheckInterval);
- }
-
- cacheProgressCheckInterval = setInterval(() => {
- fetch('/cache-progress')
- .then(response => response.json())
- .then(data => updateCacheProgress(data))
- .catch(error => console.error('Error fetching cache progress:', error));
- }, 1000);
- }
-
- function updateCacheProgress(data) {
- if (!data.is_running && data.stage === 'complete') {
- console.log('Initial cache generation completed');
- hideCacheProgressModal();
- // Trigger cache all prompt after initial cache generation completes
- if (typeof onInitialCacheComplete === 'function') {
- console.log('Calling onInitialCacheComplete()');
- onInitialCacheComplete();
- } else {
- console.log('onInitialCacheComplete function not found');
- }
- return;
- }
-
- if (!data.is_running && data.stage === 'error') {
- progressText.textContent = 'Error occurred';
- currentStage.textContent = data.error || 'Unknown error';
- currentFile.textContent = '';
- return;
- }
-
- if (!data.is_running) {
- hideCacheProgressModal();
- return;
- }
-
- // Calculate progress percentage
- const percentage = data.total_files > 0 ? Math.round((data.processed_files / data.total_files) * 100) : 0;
-
- // Update progress bar
- progressBar.style.width = `${percentage}%`;
- progressPercentage.textContent = `${percentage}%`;
-
- // Update text based on stage
- let stageText = '';
- let progressTextContent = '';
-
- switch (data.stage) {
- case 'starting':
- stageText = 'Initializing...';
- progressTextContent = 'Getting ready...';
- break;
- case 'metadata':
- stageText = 'Processing pattern metadata';
- progressTextContent = `${data.processed_files} of ${data.total_files} patterns`;
- break;
- case 'images':
- stageText = 'Generating pattern previews';
- progressTextContent = `${data.processed_files} of ${data.total_files} previews`;
- break;
- default:
- stageText = 'Processing...';
- progressTextContent = `${data.processed_files} of ${data.total_files} files`;
- }
-
- currentStage.textContent = stageText;
- progressText.textContent = progressTextContent;
-
- // Update current file
- if (data.current_file) {
- currentFile.textContent = `Current: ${data.current_file}`;
- } else {
- currentFile.textContent = '';
- }
- }
-
- function hideCacheProgressModal() {
- modal.classList.add('hidden');
-
- if (cacheProgressSocket) {
- cacheProgressSocket.close();
- cacheProgressSocket = null;
- }
-
- if (cacheProgressCheckInterval) {
- clearInterval(cacheProgressCheckInterval);
- cacheProgressCheckInterval = null;
- }
- }
-
- // Expose functions globally for potential external use
- window.showCacheProgressModal = showCacheProgressModal;
- window.hideCacheProgressModal = hideCacheProgressModal;
- }
-
- // Initialize when DOM is loaded
- document.addEventListener('DOMContentLoaded', initCacheProgressModal);
- </script>
- <script>
- // Theme switching functionality
- document.addEventListener('DOMContentLoaded', function() {
- const themeToggle = document.getElementById('theme-toggle');
- const themeToggleIcon = document.getElementById('theme-toggle-icon');
- // Update icon based on current theme
- function updateThemeIcon() {
- const isDark = document.documentElement.classList.contains('dark');
- themeToggleIcon.textContent = isDark ? 'light_mode' : 'dark_mode';
- }
- // Initial icon update
- updateThemeIcon();
- // Theme toggle click handler
- themeToggle.addEventListener('click', () => {
- const isDark = document.documentElement.classList.toggle('dark');
- localStorage.setItem('theme', isDark ? 'dark' : 'light');
- updateThemeIcon();
- });
- });
- // Shutdown button functionality
- document.addEventListener('DOMContentLoaded', function() {
- const shutdownButton = document.getElementById('shutdown-button');
- // Shutdown button click handler
- shutdownButton.addEventListener('click', async () => {
- const confirmed = confirm('Are you sure you want to shutdown the system?\n\nNote: This only works on Raspberry Pi.\n\nThis will:\n1. Stop Docker containers\n2. Shut down the system\n\nYou will need physical access to restart it.');
- if (!confirmed) return;
- try {
- showStatusMessage('Initiating shutdown...', 'warning');
- const response = await fetch('/api/system/shutdown', { method: 'POST' });
- const data = await response.json();
- if (data.success) {
- showStatusMessage('System is shutting down...', 'success');
- } else {
- showStatusMessage('Shutdown failed: ' + data.message, 'error');
- }
- } catch (error) {
- showStatusMessage('Failed to shutdown: ' + error.message, 'error');
- }
- });
- });
- // Restart button functionality
- document.addEventListener('DOMContentLoaded', function() {
- const restartButton = document.getElementById('restart-button');
- // Restart button click handler
- restartButton.addEventListener('click', async () => {
- const confirmed = confirm('Are you sure you want to restart the application?\n\nThis will restart the Docker containers.\nThe page will reload automatically when the service is back online.');
- if (!confirmed) return;
- try {
- showStatusMessage('Initiating restart...', 'warning');
- const response = await fetch('/api/system/restart', { method: 'POST' });
- const data = await response.json();
- if (data.success) {
- showStatusMessage('System is restarting... Page will reload when ready.', 'success');
- // Start checking if the server is back online
- setTimeout(() => {
- checkServerAndReload();
- }, 3000);
- } else {
- showStatusMessage('Restart failed: ' + data.message, 'error');
- }
- } catch (error) {
- showStatusMessage('Failed to restart: ' + error.message, 'error');
- }
- });
- // Function to check if server is back online and reload
- function checkServerAndReload() {
- const checkInterval = setInterval(async () => {
- try {
- const response = await fetch('/api/version', { method: 'GET' });
- if (response.ok) {
- clearInterval(checkInterval);
- showStatusMessage('Server is back online. Reloading...', 'success');
- setTimeout(() => {
- window.location.reload();
- }, 1000);
- }
- } catch (error) {
- // Server not ready yet, keep checking
- console.log('Server not ready yet, retrying...');
- }
- }, 2000);
- // Stop checking after 60 seconds
- setTimeout(() => {
- clearInterval(checkInterval);
- }, 60000);
- }
- });
- // Update indicator functionality
- document.addEventListener('DOMContentLoaded', async function() {
- const updateIndicator = document.getElementById('update-indicator');
- if (!updateIndicator) return;
- // Check for updates
- async function checkForUpdates() {
- try {
- const response = await fetch('/api/version');
- const data = await response.json();
- // Show indicator if update is available
- if (data.update_available) {
- updateIndicator.classList.remove('hidden');
- } else {
- updateIndicator.classList.add('hidden');
- }
- } catch (error) {
- console.error('Failed to check for updates:', error);
- }
- }
- // Initial check
- await checkForUpdates();
- // Check every hour
- setInterval(checkForUpdates, 3600000);
- // Click handler - navigate to settings and scroll to update section
- updateIndicator.addEventListener('click', () => {
- // Navigate to settings page
- window.location.href = '/settings#software-version-section';
- });
- });
- </script>
- <!-- Cache All Previews Prompt Modal -->
- <div id="cacheAllPromptModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
- <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
- <div class="p-6">
- <div class="text-center">
- <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Cache All Pattern Previews?</h2>
- <p class="text-gray-600 dark:text-gray-400 mb-4 max-w-md mx-auto">
- Would you like to cache all pattern previews for faster browsing? This will download and store preview images in your browser for instant loading.
- </p>
-
- <div class="bg-amber-50 dark:bg-amber-900 p-3 rounded-lg mb-4 text-sm">
- <p class="text-amber-700 dark:text-amber-300">
- <strong>Note:</strong> This cache is browser-specific. You'll need to repeat this process for each browser you use.
- </p>
- </div>
-
- <!-- Progress section (hidden initially) -->
- <div id="cacheAllProgress" class="mb-4 hidden">
- <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
- <div id="cacheAllProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
- </div>
- <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
- <span id="cacheAllProgressText">Starting...</span>
- <span id="cacheAllProgressPercentage">0%</span>
- </div>
- </div>
-
- <!-- Buttons -->
- <div id="cacheAllButtons" class="flex gap-3 justify-center">
- <button id="skipCacheAllBtn" class="px-4 py-2 text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 transition-colors">
- Skip for now
- </button>
- <button id="startCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
- Cache All Previews
- </button>
- </div>
-
- <!-- Completion message (hidden initially) -->
- <div id="cacheAllComplete" class="hidden">
- <p class="text-green-600 dark:text-green-400 mb-4">✓ All previews cached successfully!</p>
- <button id="closeCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
- Done
- </button>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- Logs Modal -->
- <div id="logsModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
- <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-5xl max-h-[90vh] flex flex-col">
- <!-- Modal Header -->
- <div class="flex items-center justify-between px-6 py-4 border-b border-slate-200 dark:border-gray-600">
- <div class="flex items-center gap-3">
- <span class="material-icons text-2xl text-slate-600 dark:text-gray-300">article</span>
- <h3 class="text-lg font-semibold text-slate-800 dark:text-gray-100">Application Logs</h3>
- <span id="logsConnectionStatus" class="text-xs px-2 py-1 rounded-full bg-gray-200 dark:bg-gray-600 text-gray-600 dark:text-gray-300">Connecting...</span>
- </div>
- <div class="flex items-center gap-2">
- <select id="logLevelFilter" onchange="filterLogs()" class="form-select text-xs rounded-lg border-slate-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 py-2 pl-3 pr-10">
- <option value="">All Levels</option>
- <option value="DEBUG">Debug</option>
- <option value="INFO">Info</option>
- <option value="WARNING">Warning</option>
- <option value="ERROR">Error</option>
- <option value="CRITICAL">Critical</option>
- </select>
- <button
- onclick="clearLogs()"
- class="flex items-center justify-center gap-1 rounded-lg h-8 px-3 bg-gray-200 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-500 text-gray-700 dark:text-gray-200 text-xs font-medium transition-colors"
- >
- <span class="material-icons text-sm">delete_sweep</span>
- Clear
- </button>
- <label class="flex items-center gap-1.5 text-sm text-slate-600 dark:text-gray-300">
- <input type="checkbox" id="logsAutoScroll" checked class="rounded border-slate-300 dark:border-gray-600">
- Auto-scroll
- </label>
- <button
- onclick="closeLogsModal()"
- class="flex items-center justify-center rounded-lg size-8 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400 transition-colors"
- >
- <span class="material-icons">close</span>
- </button>
- </div>
- </div>
- <!-- Modal Body -->
- <div id="logsContainer" class="flex-1 overflow-y-auto p-4 font-mono text-xs bg-slate-50 dark:bg-gray-900">
- <div id="logsContent" class="space-y-1">
- <!-- Log entries will be inserted here -->
- </div>
- </div>
- <!-- Modal Footer -->
- <div class="px-6 py-3 border-t border-slate-200 dark:border-gray-600 flex items-center justify-between text-xs text-slate-500 dark:text-gray-400">
- <span id="logsCount">0 entries</span>
- <span id="logsInfo">Showing last 500 log entries</span>
- </div>
- </div>
- </div>
- <script>
- // ============================================================================
- // Application Logs Modal
- // ============================================================================
- let logsWebSocket = null;
- let logsEntries = [];
- const MAX_LOG_ENTRIES = 500;
- const LOG_LEVEL_COLORS = {
- DEBUG: 'text-gray-500 dark:text-gray-400',
- INFO: 'text-blue-600 dark:text-blue-400',
- WARNING: 'text-amber-600 dark:text-amber-400',
- ERROR: 'text-red-600 dark:text-red-400',
- CRITICAL: 'text-red-700 dark:text-red-300 font-bold'
- };
- const LOG_LEVEL_BG = {
- DEBUG: 'bg-gray-100 dark:bg-gray-700',
- INFO: 'bg-blue-50 dark:bg-blue-900/30',
- WARNING: 'bg-amber-50 dark:bg-amber-900/30',
- ERROR: 'bg-red-50 dark:bg-red-900/30',
- CRITICAL: 'bg-red-100 dark:bg-red-900/50'
- };
- function openLogsModal() {
- const modal = document.getElementById('logsModal');
- modal.classList.remove('hidden');
- loadInitialLogs();
- connectLogsWebSocket();
- modal.addEventListener('click', (e) => {
- if (e.target === modal) closeLogsModal();
- });
- document.addEventListener('keydown', handleLogsEscapeKey);
- }
- function closeLogsModal() {
- const modal = document.getElementById('logsModal');
- modal.classList.add('hidden');
- if (logsWebSocket) {
- logsWebSocket.close();
- logsWebSocket = null;
- }
- document.removeEventListener('keydown', handleLogsEscapeKey);
- }
- function handleLogsEscapeKey(e) {
- if (e.key === 'Escape') closeLogsModal();
- }
- async function loadInitialLogs() {
- const logsContent = document.getElementById('logsContent');
- logsContent.innerHTML = '<div class="text-gray-500 dark:text-gray-400">Loading logs...</div>';
- try {
- const response = await fetch('/api/logs?limit=500');
- const data = await response.json();
- logsEntries = data.logs || [];
- renderLogs();
- updateLogsCount();
- const container = document.getElementById('logsContainer');
- container.scrollTop = container.scrollHeight;
- } catch (error) {
- console.error('Failed to load logs:', error);
- logsContent.innerHTML = '<div class="text-red-500">Failed to load logs</div>';
- }
- }
- function connectLogsWebSocket() {
- const statusEl = document.getElementById('logsConnectionStatus');
- const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
- const wsUrl = `${protocol}//${window.location.host}/ws/logs`;
- try {
- logsWebSocket = new WebSocket(wsUrl);
- logsWebSocket.onopen = () => {
- statusEl.textContent = 'Live';
- statusEl.className = 'text-xs px-2 py-1 rounded-full bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300';
- };
- logsWebSocket.onmessage = (event) => {
- const message = JSON.parse(event.data);
- if (message.type === 'log_entry') addLogEntry(message.data);
- };
- logsWebSocket.onclose = () => {
- statusEl.textContent = 'Disconnected';
- statusEl.className = 'text-xs px-2 py-1 rounded-full bg-gray-200 dark:bg-gray-600 text-gray-600 dark:text-gray-300';
- };
- logsWebSocket.onerror = (error) => {
- console.error('Logs WebSocket error:', error);
- statusEl.textContent = 'Error';
- statusEl.className = 'text-xs px-2 py-1 rounded-full bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300';
- };
- } catch (error) {
- console.error('Failed to connect to logs WebSocket:', error);
- statusEl.textContent = 'Failed';
- statusEl.className = 'text-xs px-2 py-1 rounded-full bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300';
- }
- }
- function addLogEntry(entry) {
- logsEntries.unshift(entry);
- if (logsEntries.length > MAX_LOG_ENTRIES) logsEntries.pop();
- const logsContent = document.getElementById('logsContent');
- const entryEl = createLogEntryElement(entry);
- logsContent.appendChild(entryEl);
- const autoScroll = document.getElementById('logsAutoScroll').checked;
- if (autoScroll) {
- const container = document.getElementById('logsContainer');
- container.scrollTop = container.scrollHeight;
- }
- const levelFilter = document.getElementById('logLevelFilter').value;
- if (levelFilter && entry.level !== levelFilter) entryEl.classList.add('hidden');
- updateLogsCount();
- }
- function createLogEntryElement(entry) {
- const div = document.createElement('div');
- div.className = `log-entry flex gap-2 py-1 px-2 rounded ${LOG_LEVEL_BG[entry.level] || 'bg-gray-50 dark:bg-gray-800'}`;
- div.dataset.level = entry.level;
- const timestamp = new Date(entry.timestamp);
- const timeStr = timestamp.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
- const msStr = timestamp.getMilliseconds().toString().padStart(3, '0');
- div.innerHTML = `
- <span class="text-gray-400 dark:text-gray-500 shrink-0">${timeStr}.${msStr}</span>
- <span class="${LOG_LEVEL_COLORS[entry.level] || 'text-gray-600'} shrink-0 w-16">${entry.level}</span>
- <span class="text-purple-600 dark:text-purple-400 shrink-0 truncate max-w-32" title="${entry.logger}:${entry.line}">${entry.module}:${entry.line}</span>
- <span class="text-slate-700 dark:text-gray-200 break-all">${escapeHtmlLogs(entry.message)}</span>
- `;
- return div;
- }
- function escapeHtmlLogs(text) {
- const div = document.createElement('div');
- div.textContent = text;
- return div.innerHTML;
- }
- function renderLogs() {
- const logsContent = document.getElementById('logsContent');
- logsContent.innerHTML = '';
- const reversedLogs = [...logsEntries].reverse();
- const levelFilter = document.getElementById('logLevelFilter').value;
- for (const entry of reversedLogs) {
- const entryEl = createLogEntryElement(entry);
- if (levelFilter && entry.level !== levelFilter) entryEl.classList.add('hidden');
- logsContent.appendChild(entryEl);
- }
- }
- function filterLogs() {
- const levelFilter = document.getElementById('logLevelFilter').value;
- const entries = document.querySelectorAll('#logsContent .log-entry');
- let visibleCount = 0;
- entries.forEach(entry => {
- if (!levelFilter || entry.dataset.level === levelFilter) {
- entry.classList.remove('hidden');
- visibleCount++;
- } else {
- entry.classList.add('hidden');
- }
- });
- const countEl = document.getElementById('logsCount');
- if (levelFilter) {
- countEl.textContent = `${visibleCount} of ${logsEntries.length} entries (filtered)`;
- } else {
- countEl.textContent = `${logsEntries.length} entries`;
- }
- }
- function updateLogsCount() {
- const countEl = document.getElementById('logsCount');
- const levelFilter = document.getElementById('logLevelFilter').value;
- if (levelFilter) {
- const filteredCount = logsEntries.filter(e => e.level === levelFilter).length;
- countEl.textContent = `${filteredCount} of ${logsEntries.length} entries (filtered)`;
- } else {
- countEl.textContent = `${logsEntries.length} entries`;
- }
- }
- async function clearLogs() {
- try {
- await fetch('/api/logs', { method: 'DELETE' });
- logsEntries = [];
- document.getElementById('logsContent').innerHTML = '<div class="text-gray-500 dark:text-gray-400 text-center py-4">Logs cleared</div>';
- updateLogsCount();
- } catch (error) {
- console.error('Failed to clear logs:', error);
- }
- }
- </script>
- </body>
- </html>
|