base.html 30 KB

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