base.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <script>
  5. // Immediately set dark mode if needed, before page loads
  6. const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
  7. const savedTheme = localStorage.getItem('theme');
  8. if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
  9. document.documentElement.classList.add('dark');
  10. }
  11. </script>
  12. <meta charset="utf-8" />
  13. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  14. <link crossorigin="" href="https://fonts.gstatic.com/" rel="preconnect" />
  15. <link
  16. as="style"
  17. href="https://fonts.googleapis.com/css2?display=swap&amp;family=Noto+Sans%3Awght%40400%3B500%3B700%3B900&amp;family=Plus+Jakarta+Sans%3Awght%40400%3B500%3B700%3B800"
  18. onload="this.rel='stylesheet'"
  19. rel="stylesheet"
  20. />
  21. <title>{% block title %}{{ app_name or 'Dune Weaver' }}{% endblock %}</title>
  22. <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
  23. <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
  24. <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
  25. <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
  26. <link rel="manifest" href="/static/site.webmanifest?v=2">
  27. <link rel="stylesheet" href="/static/css/tailwind.css">
  28. <link rel="stylesheet" href="/static/css/material-icons.css">
  29. <style>
  30. /* Mobile navigation styles */
  31. @media (max-width: 640px) {
  32. nav.flex {
  33. display: grid;
  34. grid-template-columns: repeat(5, 1fr);
  35. gap: 0;
  36. }
  37. nav.flex a {
  38. display: flex;
  39. flex-direction: column;
  40. align-items: center;
  41. justify-content: center;
  42. text-align: center;
  43. padding: 0.75rem 0;
  44. }
  45. nav.flex a .material-icons {
  46. margin-bottom: 0.25rem;
  47. }
  48. }
  49. /* Dark mode styles */
  50. .dark {
  51. color-scheme: dark;
  52. }
  53. .dark body {
  54. background-color: #1a1a1a;
  55. color: #e5e5e5;
  56. }
  57. .dark header {
  58. background-color: #262626;
  59. border-color: #404040;
  60. }
  61. .dark footer {
  62. background-color: #262626;
  63. border-color: #404040;
  64. }
  65. .dark .inactive-tab {
  66. color: #9ca3af;
  67. }
  68. .dark .inactive-tab:hover {
  69. color: #d1d5db;
  70. }
  71. .dark #player-status-bar-container {
  72. background-color: #262626;
  73. color: #e5e5e5;
  74. }
  75. .dark .bg-gray-100 {
  76. background-color: #262626;
  77. }
  78. .dark .bg-gray-200 {
  79. background-color: #404040;
  80. }
  81. .dark .bg-gray-300 {
  82. background-color: #525252;
  83. }
  84. .dark .text-gray-500 {
  85. color: #9ca3af;
  86. }
  87. .dark .text-gray-700 {
  88. color: #d1d5db;
  89. }
  90. .dark .text-gray-800 {
  91. color: #e5e5e5;
  92. }
  93. .dark .border-gray-200 {
  94. border-color: #404040;
  95. }
  96. .dark .hover\:bg-gray-200:hover {
  97. background-color: #404040;
  98. }
  99. .dark .hover\:bg-gray-300:hover {
  100. background-color: #525252;
  101. }
  102. .dark .hover\:border-gray-300:hover {
  103. border-color: #525252;
  104. }
  105. .dark .hover\:bg-gray-50:hover {
  106. background-color: #262626;
  107. }
  108. .dark .bg-white {
  109. background-color: #262626;
  110. }
  111. .dark #shutdown-button:hover {
  112. background-color: #404040;
  113. }
  114. .dark #theme-toggle:hover {
  115. background-color: #404040;
  116. }
  117. .dark .bg-gray-50 {
  118. background-color: #1a1a1a;
  119. }
  120. .dark .text-gray-900 {
  121. color: #e5e5e5;
  122. }
  123. .dark .text-gray-400 {
  124. color: #9ca3af;
  125. }
  126. .dark .border-gray-300 {
  127. border-color: #404040;
  128. }
  129. .dark .focus\:ring-offset-2 {
  130. --tw-ring-offset-color: #262626;
  131. }
  132. .dark .shadow-sm {
  133. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  134. }
  135. .dark .shadow-lg {
  136. box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  137. }
  138. .dark .shadow-xl {
  139. box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  140. }
  141. /* Existing styles */
  142. .active-tab {
  143. color: #0c7ff2;
  144. border-color: #0c7ff2;
  145. }
  146. .active-tab .material-icons {
  147. color: #0c7ff2;
  148. }
  149. .inactive-tab {
  150. color: #6b7280;
  151. border-color: transparent;
  152. }
  153. .inactive-tab:hover {
  154. color: #374151;
  155. }
  156. #status-message {
  157. transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
  158. }
  159. /* Switch toggle styles */
  160. .switch {
  161. position: relative;
  162. display: inline-block;
  163. width: 40px;
  164. height: 20px;
  165. }
  166. .switch input {
  167. opacity: 0;
  168. width: 0;
  169. height: 0;
  170. }
  171. .slider {
  172. position: absolute;
  173. cursor: pointer;
  174. top: 0;
  175. left: 0;
  176. right: 0;
  177. bottom: 0;
  178. background-color: #ccc;
  179. transition: .4s;
  180. border-radius: 20px;
  181. }
  182. .slider:before {
  183. position: absolute;
  184. content: "";
  185. height: 16px;
  186. width: 16px;
  187. left: 2px;
  188. bottom: 2px;
  189. background-color: white;
  190. transition: .4s;
  191. border-radius: 50%;
  192. }
  193. input:checked + .slider {
  194. background-color: #0c7ff2;
  195. }
  196. input:checked + .slider:before {
  197. transform: translateX(20px);
  198. }
  199. /* Shadow for top of status bar */
  200. .shadow-lg-top {
  201. box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 -2px 4px -2px rgb(0 0 0 / 0.1);
  202. }
  203. /* Marquee animation for pattern name on small screens */
  204. @keyframes marquee {
  205. 0% { transform: translateX(0%); }
  206. 50% { transform: translateX(-50%); }
  207. }
  208. .pattern-marquee {
  209. display: inline-block;
  210. min-width: 100%;
  211. animation: marquee 8s linear infinite;
  212. }
  213. @media (min-width: 640px) { /* sm: and up, disable marquee */
  214. .pattern-marquee {
  215. animation: none !important;
  216. transform: none !important;
  217. }
  218. }
  219. {% block additional_styles %}{% endblock %}
  220. </style>
  221. {% block additional_head %}{% endblock %}
  222. </head>
  223. <body
  224. class="bg-gray-50"
  225. style="font-family: 'Plus Jakarta Sans', 'Noto Sans', sans-serif"
  226. >
  227. <div
  228. class="mt-2 w-full text-center px-4 z-50 pointer-events-none absolute"
  229. id="status-message-container"
  230. >
  231. <p
  232. 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"
  233. id="status-message"
  234. ></p>
  235. </div>
  236. <div
  237. class="relative flex size-full min-h-screen flex-col group/design-root overflow-x-hidden"
  238. >
  239. <div class="layout-container flex min-h-full grow flex-col">
  240. <header
  241. 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"
  242. >
  243. <div class="flex items-center gap-3 text-gray-800">
  244. <a href="/" class="flex items-center gap-3 text-gray-800 hover:opacity-80 transition-opacity">
  245. <div class="text-blue-600 w-9 h-9 rounded-full shadow">
  246. <img src="/static/apple-touch-icon.png" alt="Dune Weaver Logo"/>
  247. </div>
  248. <h1
  249. class="text-gray-800 text-xl font-bold leading-tight tracking-tight flex items-center gap-2"
  250. >
  251. {{ app_name or 'Dune Weaver' }}
  252. <span
  253. id="connectionStatusDot"
  254. class="inline-block size-2 rounded-full bg-red-500 ml-2 align-middle"
  255. ></span>
  256. </h1>
  257. </a>
  258. </div>
  259. <div class="flex items-center gap-2">
  260. <button
  261. id="theme-toggle"
  262. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
  263. aria-label="Toggle dark mode"
  264. >
  265. <span class="material-icons" id="theme-toggle-icon">dark_mode</span>
  266. </button>
  267. <button
  268. id="shutdown-button"
  269. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-red-500"
  270. aria-label="Shutdown system"
  271. title="Shutdown System (Raspberry Pi only)"
  272. >
  273. <span class="material-icons text-red-600">power_settings_new</span>
  274. </button>
  275. </div>
  276. </header>
  277. <main class="flex flex-1 justify-center px-4 sm:px-6 lg:px-8 pt-16 sm:pt-20">
  278. {% block content %}{% endblock %}
  279. </main>
  280. <!-- Floating Preview Button -->
  281. <button
  282. id="toggle-preview-modal-btn"
  283. 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"
  284. title="Toggle Pattern Preview"
  285. >
  286. <span class="material-icons text-xl">preview</span>
  287. </button>
  288. <footer
  289. class="fixed bottom-0 left-0 right-0 z-10 bg-white border-t border-gray-200 shadow-t-sm"
  290. >
  291. <nav class="mx-auto flex max-w-5xl justify-around">
  292. <a
  293. 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"
  294. href="/"
  295. >
  296. <span class="material-icons">search</span> Browse
  297. </a>
  298. <a
  299. 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"
  300. href="/playlists"
  301. >
  302. <span class="material-icons">list_alt</span> Playlists
  303. </a>
  304. <a
  305. 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"
  306. href="/table_control"
  307. >
  308. <span class="material-icons">table_chart</span> Table Control
  309. </a>
  310. <a
  311. class="{% if request.url.path == '/wled' %}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"
  312. href="/wled"
  313. >
  314. <span class="material-icons">lightbulb</span> <span id="led-nav-label">LED</span>
  315. </a>
  316. <a
  317. 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"
  318. href="/settings"
  319. >
  320. <span class="material-icons">settings</span> Settings
  321. </a>
  322. </nav>
  323. </footer>
  324. </div>
  325. </div>
  326. {% block scripts %}{% endblock %}
  327. <script src="/static/js/base.js"></script>
  328. <!-- Cache Progress Modal -->
  329. <div id="cacheProgressModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  330. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
  331. <div class="p-6">
  332. <div class="text-center">
  333. <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Initializing Pattern Cache</h2>
  334. <p class="text-gray-600 dark:text-gray-400 mb-4">Preparing your pattern previews...</p>
  335. <div class="mb-4">
  336. <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
  337. <div id="cacheProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
  338. </div>
  339. <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
  340. <span id="cacheProgressText">Starting...</span>
  341. <span id="cacheProgressPercentage">0%</span>
  342. </div>
  343. </div>
  344. <div class="text-sm text-gray-500 dark:text-gray-400">
  345. <p id="cacheCurrentStage">Preparing...</p>
  346. <p id="cacheCurrentFile" class="mt-1 truncate"></p>
  347. </div>
  348. </div>
  349. </div>
  350. </div>
  351. </div>
  352. <!-- Player Preview Modal -->
  353. <div id="playerPreviewModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-40 hidden p-4">
  354. <div class="bg-white rounded-lg shadow-xl w-full max-w-5xl max-h-[95vh] flex flex-col">
  355. <div class="flex items-center justify-between p-4 border-b border-gray-200 flex-shrink-0">
  356. <h2 id="playerPreviewTitle" class="text-xl font-semibold text-gray-800">Pattern Preview</h2>
  357. <button id="closePlayerPreview" class="text-gray-400 hover:text-gray-600 transition-colors">
  358. <span class="material-icons text-2xl">close</span>
  359. </button>
  360. </div>
  361. <!-- Canvas Area -->
  362. <div class="flex-1 p-4 flex justify-center items-center overflow-hidden">
  363. <div class="relative flex items-center justify-center w-full h-full">
  364. <div class="relative max-w-[min(800px,90vw)] max-h-[min(600px,80vh)] aspect-square">
  365. <canvas id="playerPreviewCanvas" width="800" height="800" class="w-full h-full rounded-full border border-gray-300 dark:invert"></canvas>
  366. </div>
  367. </div>
  368. </div>
  369. <!-- Pattern Info and Controls -->
  370. <div class="flex-shrink-0 p-4 border-b border-gray-200 flex items-center gap-4 flex-wrap">
  371. <!-- Pattern Preview Image -->
  372. <div class="flex-shrink-0">
  373. <img id="modal-pattern-preview-img"
  374. class="w-[126px] h-[126px] rounded-full border border-gray-300 object-cover dark:invert" src="">
  375. </div>
  376. <div class="flex-grow w-auto">
  377. <div class="flex items-center justify-between mb-2">
  378. <div class="min-w-0 max-w-[50%]">
  379. <div class="overflow-hidden relative">
  380. <p class="text-lg font-semibold whitespace-nowrap" id="modal-pattern-name">
  381. No pattern playing
  382. </p>
  383. </div>
  384. <p class="text-base text-gray-500" id="modal-eta">
  385. ETA: --:--
  386. </p>
  387. </div>
  388. <div class="flex items-center gap-2 flex-shrink-0">
  389. <button
  390. aria-label="Next"
  391. 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"
  392. id="modal-skip-button"
  393. >
  394. <span class="material-icons text-gray-700">skip_next</span>
  395. </button>
  396. <button
  397. aria-label="Pause"
  398. 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"
  399. id="modal-pause-button"
  400. >
  401. <span class="material-icons text-gray-700">pause</span>
  402. </button>
  403. <button
  404. aria-label="Stop"
  405. 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"
  406. id="modal-stop-button"
  407. >
  408. <span class="material-icons text-gray-700">stop</span>
  409. </button>
  410. </div>
  411. </div>
  412. <div class="w-full bg-gray-300 rounded-full h-2.5 mb-2">
  413. <div
  414. class="bg-blue-600 h-2.5 rounded-full"
  415. id="modal-progress-bar"
  416. style="width: 0%"
  417. ></div>
  418. </div>
  419. <div class="flex items-center justify-between">
  420. <div class="text-base text-gray-500">
  421. Next:
  422. <span class="text-gray-700 font-medium" id="modal-next-pattern">None</span>
  423. </div>
  424. <div class="flex items-center gap-3 text-sm">
  425. <span class="text-gray-500">Speed:</span>
  426. <div class="flex items-center gap-2">
  427. <div class="relative min-w-[4ch] text-center cursor-pointer inline-flex items-center" id="modal-speed-container">
  428. <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>
  429. <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" />
  430. </div>
  431. </div>
  432. </div>
  433. </div>
  434. </div>
  435. </div>
  436. </div>
  437. </div>
  438. <script>
  439. // Function to show status message
  440. function showStatusMessage(message, type = "success") {
  441. const statusContainer = document.getElementById(
  442. "status-message-container"
  443. );
  444. const statusMessage = document.getElementById("status-message");
  445. if (!statusContainer || !statusMessage) return;
  446. // Set message and color based on type
  447. statusMessage.textContent = message;
  448. 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 ${
  449. type === "success"
  450. ? "bg-green-50 text-green-700 border border-green-200"
  451. : type === "error"
  452. ? "bg-red-50 text-red-700 border border-red-200"
  453. : type === "warning"
  454. ? "bg-yellow-50 text-yellow-700 border border-yellow-200"
  455. : "bg-blue-50 text-blue-700 border border-blue-200"
  456. }`;
  457. // Show message with animation
  458. requestAnimationFrame(() => {
  459. statusMessage.classList.remove("opacity-0", "-translate-y-2");
  460. statusMessage.classList.add("opacity-100", "translate-y-0");
  461. });
  462. // Hide message after 5 seconds
  463. setTimeout(() => {
  464. statusMessage.classList.remove("opacity-100", "translate-y-0");
  465. statusMessage.classList.add("opacity-0", "-translate-y-2");
  466. }, 5000);
  467. }
  468. // Initial connection status check
  469. async function checkInitialConnectionStatus() {
  470. try {
  471. const response = await fetch("/serial_status");
  472. if (response.ok) {
  473. const data = await response.json();
  474. const statusDot = document.getElementById("connectionStatusDot");
  475. if (statusDot) {
  476. statusDot.className = `inline-block size-2 rounded-full ml-2 align-middle ${
  477. data.connected ? "bg-green-500" : "bg-red-500"
  478. }`;
  479. }
  480. }
  481. } catch (error) {
  482. console.error("Error checking initial connection status:", error);
  483. }
  484. }
  485. // Check initial status on page load
  486. document.addEventListener("DOMContentLoaded", checkInitialConnectionStatus);
  487. // Player bar toggle logic will be handled by base.js
  488. </script>
  489. <script>
  490. // Cache progress modal functionality
  491. let cacheProgressSocket = null;
  492. let cacheProgressCheckInterval = null;
  493. function initCacheProgressModal() {
  494. const modal = document.getElementById('cacheProgressModal');
  495. const progressBar = document.getElementById('cacheProgressBar');
  496. const progressText = document.getElementById('cacheProgressText');
  497. const progressPercentage = document.getElementById('cacheProgressPercentage');
  498. const currentStage = document.getElementById('cacheCurrentStage');
  499. const currentFile = document.getElementById('cacheCurrentFile');
  500. // Check if cache generation is needed on page load
  501. fetch('/cache-progress')
  502. .then(response => response.json())
  503. .then(data => {
  504. if (data.is_running) {
  505. showCacheProgressModal();
  506. }
  507. })
  508. .catch(error => {
  509. console.error('Error checking initial cache progress:', error);
  510. });
  511. function showCacheProgressModal() {
  512. modal.classList.remove('hidden');
  513. // Connect to WebSocket for real-time updates
  514. const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
  515. const wsUrl = `${protocol}//${window.location.host}/ws/cache-progress`;
  516. cacheProgressSocket = new WebSocket(wsUrl);
  517. cacheProgressSocket.onmessage = function(event) {
  518. const data = JSON.parse(event.data);
  519. if (data.type === 'cache_progress') {
  520. updateCacheProgress(data.data);
  521. }
  522. };
  523. cacheProgressSocket.onclose = function() {
  524. // Fallback to polling if WebSocket fails
  525. startProgressPolling();
  526. };
  527. cacheProgressSocket.onerror = function() {
  528. // Fallback to polling if WebSocket fails
  529. startProgressPolling();
  530. };
  531. }
  532. function startProgressPolling() {
  533. if (cacheProgressCheckInterval) {
  534. clearInterval(cacheProgressCheckInterval);
  535. }
  536. cacheProgressCheckInterval = setInterval(() => {
  537. fetch('/cache-progress')
  538. .then(response => response.json())
  539. .then(data => updateCacheProgress(data))
  540. .catch(error => console.error('Error fetching cache progress:', error));
  541. }, 1000);
  542. }
  543. function updateCacheProgress(data) {
  544. if (!data.is_running && data.stage === 'complete') {
  545. console.log('Initial cache generation completed');
  546. hideCacheProgressModal();
  547. // Trigger cache all prompt after initial cache generation completes
  548. if (typeof onInitialCacheComplete === 'function') {
  549. console.log('Calling onInitialCacheComplete()');
  550. onInitialCacheComplete();
  551. } else {
  552. console.log('onInitialCacheComplete function not found');
  553. }
  554. return;
  555. }
  556. if (!data.is_running && data.stage === 'error') {
  557. progressText.textContent = 'Error occurred';
  558. currentStage.textContent = data.error || 'Unknown error';
  559. currentFile.textContent = '';
  560. return;
  561. }
  562. if (!data.is_running) {
  563. hideCacheProgressModal();
  564. return;
  565. }
  566. // Calculate progress percentage
  567. const percentage = data.total_files > 0 ? Math.round((data.processed_files / data.total_files) * 100) : 0;
  568. // Update progress bar
  569. progressBar.style.width = `${percentage}%`;
  570. progressPercentage.textContent = `${percentage}%`;
  571. // Update text based on stage
  572. let stageText = '';
  573. let progressTextContent = '';
  574. switch (data.stage) {
  575. case 'starting':
  576. stageText = 'Initializing...';
  577. progressTextContent = 'Getting ready...';
  578. break;
  579. case 'metadata':
  580. stageText = 'Processing pattern metadata';
  581. progressTextContent = `${data.processed_files} of ${data.total_files} patterns`;
  582. break;
  583. case 'images':
  584. stageText = 'Generating pattern previews';
  585. progressTextContent = `${data.processed_files} of ${data.total_files} previews`;
  586. break;
  587. default:
  588. stageText = 'Processing...';
  589. progressTextContent = `${data.processed_files} of ${data.total_files} files`;
  590. }
  591. currentStage.textContent = stageText;
  592. progressText.textContent = progressTextContent;
  593. // Update current file
  594. if (data.current_file) {
  595. currentFile.textContent = `Current: ${data.current_file}`;
  596. } else {
  597. currentFile.textContent = '';
  598. }
  599. }
  600. function hideCacheProgressModal() {
  601. modal.classList.add('hidden');
  602. if (cacheProgressSocket) {
  603. cacheProgressSocket.close();
  604. cacheProgressSocket = null;
  605. }
  606. if (cacheProgressCheckInterval) {
  607. clearInterval(cacheProgressCheckInterval);
  608. cacheProgressCheckInterval = null;
  609. }
  610. }
  611. // Expose functions globally for potential external use
  612. window.showCacheProgressModal = showCacheProgressModal;
  613. window.hideCacheProgressModal = hideCacheProgressModal;
  614. }
  615. // Initialize when DOM is loaded
  616. document.addEventListener('DOMContentLoaded', initCacheProgressModal);
  617. </script>
  618. <script>
  619. // Theme switching functionality
  620. document.addEventListener('DOMContentLoaded', function() {
  621. const themeToggle = document.getElementById('theme-toggle');
  622. const themeToggleIcon = document.getElementById('theme-toggle-icon');
  623. // Update icon based on current theme
  624. function updateThemeIcon() {
  625. const isDark = document.documentElement.classList.contains('dark');
  626. themeToggleIcon.textContent = isDark ? 'light_mode' : 'dark_mode';
  627. }
  628. // Initial icon update
  629. updateThemeIcon();
  630. // Theme toggle click handler
  631. themeToggle.addEventListener('click', () => {
  632. const isDark = document.documentElement.classList.toggle('dark');
  633. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  634. updateThemeIcon();
  635. });
  636. });
  637. // Shutdown button functionality
  638. document.addEventListener('DOMContentLoaded', function() {
  639. const shutdownButton = document.getElementById('shutdown-button');
  640. // Shutdown button click handler
  641. shutdownButton.addEventListener('click', async () => {
  642. 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.');
  643. if (!confirmed) return;
  644. try {
  645. showStatusMessage('Initiating shutdown...', 'warning');
  646. const response = await fetch('/api/system/shutdown', { method: 'POST' });
  647. const data = await response.json();
  648. if (data.success) {
  649. showStatusMessage('System is shutting down...', 'success');
  650. } else {
  651. showStatusMessage('Shutdown failed: ' + data.message, 'error');
  652. }
  653. } catch (error) {
  654. showStatusMessage('Failed to shutdown: ' + error.message, 'error');
  655. }
  656. });
  657. });
  658. </script>
  659. <!-- Cache All Previews Prompt Modal -->
  660. <div id="cacheAllPromptModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  661. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
  662. <div class="p-6">
  663. <div class="text-center">
  664. <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Cache All Pattern Previews?</h2>
  665. <p class="text-gray-600 dark:text-gray-400 mb-4 max-w-md mx-auto">
  666. Would you like to cache all pattern previews for faster browsing? This will download and store preview images in your browser for instant loading.
  667. </p>
  668. <div class="bg-amber-50 dark:bg-amber-900 p-3 rounded-lg mb-4 text-sm">
  669. <p class="text-amber-700 dark:text-amber-300">
  670. <strong>Note:</strong> This cache is browser-specific. You'll need to repeat this process for each browser you use.
  671. </p>
  672. </div>
  673. <!-- Progress section (hidden initially) -->
  674. <div id="cacheAllProgress" class="mb-4 hidden">
  675. <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
  676. <div id="cacheAllProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
  677. </div>
  678. <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
  679. <span id="cacheAllProgressText">Starting...</span>
  680. <span id="cacheAllProgressPercentage">0%</span>
  681. </div>
  682. </div>
  683. <!-- Buttons -->
  684. <div id="cacheAllButtons" class="flex gap-3 justify-center">
  685. <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">
  686. Skip for now
  687. </button>
  688. <button id="startCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
  689. Cache All Previews
  690. </button>
  691. </div>
  692. <!-- Completion message (hidden initially) -->
  693. <div id="cacheAllComplete" class="hidden">
  694. <p class="text-green-600 dark:text-green-400 mb-4">✓ All previews cached successfully!</p>
  695. <button id="closeCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
  696. Done
  697. </button>
  698. </div>
  699. </div>
  700. </div>
  701. </div>
  702. </div>
  703. </body>
  704. </html>