| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196 |
- <!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 Bottom Panel -->
- <div id="logsPanel" class="fixed left-0 right-0 z-20 bg-white dark:bg-gray-800 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1)] flex flex-col transition-transform duration-300 ease-out" style="bottom: 0; height: 45vh; transform: translateY(100%);">
- <!-- Panel Header -->
- <div class="flex items-center justify-between px-4 py-2 border-b border-slate-200 dark:border-gray-600 shrink-0">
- <div class="flex items-center gap-2">
- <span class="material-icons text-lg text-slate-600 dark:text-gray-300">article</span>
- <h3 class="text-sm font-semibold text-slate-800 dark:text-gray-100">Logs</h3>
- <span id="logsConnectionStatus" class="text-xs px-2 py-0.5 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 border-slate-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 py-1 pl-2 pr-8">
- <option value="">All</option>
- <option value="DEBUG">Debug</option>
- <option value="INFO">Info</option>
- <option value="WARNING">Warn</option>
- <option value="ERROR">Error</option>
- <option value="CRITICAL">Critical</option>
- </select>
- <button
- onclick="clearLogs()"
- class="flex items-center justify-center rounded h-7 px-2 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"
- title="Clear logs"
- >
- <span class="material-icons text-sm">delete_sweep</span>
- </button>
- <label class="flex items-center gap-1 text-xs text-slate-600 dark:text-gray-300">
- <input type="checkbox" id="logsAutoScroll" checked class="rounded border-slate-300 dark:border-gray-600 w-3.5 h-3.5">
- Auto
- </label>
- <button
- onclick="closeLogsModal()"
- class="flex items-center justify-center rounded size-7 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400 transition-colors"
- title="Close logs"
- >
- <span class="material-icons text-lg">close</span>
- </button>
- </div>
- </div>
- <!-- Panel Body -->
- <div id="logsContainer" class="flex-1 overflow-y-auto p-2 font-mono text-xs bg-slate-50 dark:bg-gray-900">
- <div id="logsContent" class="space-y-0.5">
- <!-- Log entries will be inserted here -->
- </div>
- </div>
- <!-- Panel Footer -->
- <div class="px-4 py-1.5 border-t border-slate-200 dark:border-gray-600 flex items-center justify-between text-xs text-slate-500 dark:text-gray-400 shrink-0">
- <span id="logsCount">0 entries</span>
- <span id="logsInfo">Last 500 entries</span>
- </div>
- </div>
- <script>
- // ============================================================================
- // Application Logs Bottom Panel
- // ============================================================================
- let logsWebSocket = null;
- let logsEntries = [];
- let logsPanelOpen = false;
- const MAX_LOG_ENTRIES = 500;
- const LOGS_PANEL_HEIGHT = '45vh';
- 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(skipSave = false) {
- if (logsPanelOpen) return;
- logsPanelOpen = true;
- const panel = document.getElementById('logsPanel');
- const footer = document.querySelector('footer');
- const previewBtn = document.getElementById('toggle-preview-modal-btn');
- // Slide panel up
- panel.style.transform = 'translateY(0)';
- // Push footer up
- if (footer) {
- footer.style.transition = 'transform 0.3s ease-out';
- footer.style.transform = `translateY(-${LOGS_PANEL_HEIGHT})`;
- }
- // Push floating preview button up
- if (previewBtn) {
- previewBtn.style.transition = 'transform 0.3s ease-out';
- previewBtn.style.transform = `translateY(-${LOGS_PANEL_HEIGHT})`;
- }
- // Persist state across pages
- if (!skipSave) {
- localStorage.setItem('logsPanelOpen', 'true');
- }
- loadInitialLogs();
- connectLogsWebSocket();
- document.addEventListener('keydown', handleLogsEscapeKey);
- }
- function closeLogsModal() {
- if (!logsPanelOpen) return;
- logsPanelOpen = false;
- const panel = document.getElementById('logsPanel');
- const footer = document.querySelector('footer');
- const previewBtn = document.getElementById('toggle-preview-modal-btn');
- // Slide panel down
- panel.style.transform = 'translateY(100%)';
- // Reset footer position
- if (footer) {
- footer.style.transform = 'translateY(0)';
- }
- // Reset floating button position
- if (previewBtn) {
- previewBtn.style.transform = 'translateY(0)';
- }
- // Persist state across pages
- localStorage.removeItem('logsPanelOpen');
- if (logsWebSocket) {
- logsWebSocket.close();
- logsWebSocket = null;
- }
- document.removeEventListener('keydown', handleLogsEscapeKey);
- }
- function handleLogsEscapeKey(e) {
- if (e.key === 'Escape') closeLogsModal();
- }
- // Restore logs panel state on page load
- document.addEventListener('DOMContentLoaded', function() {
- if (localStorage.getItem('logsPanelOpen') === 'true') {
- // Small delay to ensure DOM is ready
- setTimeout(() => openLogsModal(true), 100);
- }
- });
- 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>
|