base.html 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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. <!-- Preload Material Icons fonts for faster loading -->
  22. <link rel="preload" href="/static/fonts/material-icons/MaterialIcons-Regular.woff2" as="font" type="font/woff2" crossorigin>
  23. <link rel="preload" href="/static/fonts/material-icons/MaterialIconsOutlined-Regular.woff2" as="font" type="font/woff2" crossorigin>
  24. <title>{% block title %}{{ app_name or 'Dune Weaver' }}{% endblock %}</title>
  25. {% if custom_logo %}
  26. {# Favicon is auto-generated from logo as favicon.ico #}
  27. <link rel="apple-touch-icon" sizes="180x180" href="/static/custom/{{ custom_logo }}">
  28. <link rel="icon" type="image/x-icon" href="/static/custom/favicon.ico">
  29. {% else %}
  30. <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
  31. <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
  32. <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
  33. <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
  34. {% endif %}
  35. <link rel="manifest" href="/static/site.webmanifest?v=2">
  36. <link rel="stylesheet" href="/static/css/tailwind.css">
  37. <link rel="stylesheet" href="/static/css/material-icons.css">
  38. <style>
  39. /* Mobile navigation styles */
  40. @media (max-width: 640px) {
  41. nav.flex {
  42. display: grid;
  43. grid-template-columns: repeat(5, 1fr);
  44. gap: 0;
  45. }
  46. nav.flex a {
  47. display: flex;
  48. flex-direction: column;
  49. align-items: center;
  50. justify-content: center;
  51. text-align: center;
  52. padding: 0.75rem 0;
  53. }
  54. nav.flex a .material-icons {
  55. margin-bottom: 0.25rem;
  56. }
  57. }
  58. /* Dark mode styles */
  59. .dark {
  60. color-scheme: dark;
  61. }
  62. .dark body {
  63. background-color: #1a1a1a;
  64. color: #e5e5e5;
  65. }
  66. .dark header {
  67. background-color: #262626;
  68. border-color: #404040;
  69. }
  70. .dark footer {
  71. background-color: #262626;
  72. border-color: #404040;
  73. }
  74. .dark .inactive-tab {
  75. color: #9ca3af;
  76. }
  77. .dark .inactive-tab:hover {
  78. color: #d1d5db;
  79. }
  80. .dark #player-status-bar-container {
  81. background-color: #262626;
  82. color: #e5e5e5;
  83. }
  84. .dark .bg-gray-100 {
  85. background-color: #262626;
  86. }
  87. .dark .bg-gray-200 {
  88. background-color: #404040;
  89. }
  90. .dark .bg-gray-300 {
  91. background-color: #525252;
  92. }
  93. .dark .text-gray-500 {
  94. color: #9ca3af;
  95. }
  96. .dark .text-gray-700 {
  97. color: #d1d5db;
  98. }
  99. .dark .text-gray-800 {
  100. color: #e5e5e5;
  101. }
  102. .dark .border-gray-200 {
  103. border-color: #404040;
  104. }
  105. .dark .hover\:bg-gray-200:hover {
  106. background-color: #404040;
  107. }
  108. .dark .hover\:bg-gray-300:hover {
  109. background-color: #525252;
  110. }
  111. .dark .hover\:border-gray-300:hover {
  112. border-color: #525252;
  113. }
  114. .dark .hover\:bg-gray-50:hover {
  115. background-color: #262626;
  116. }
  117. .dark .bg-white {
  118. background-color: #262626;
  119. }
  120. .dark #shutdown-button:hover {
  121. background-color: #404040;
  122. }
  123. .dark #restart-button:hover {
  124. background-color: #404040;
  125. }
  126. .dark #theme-toggle:hover {
  127. background-color: #404040;
  128. }
  129. .dark .bg-gray-50 {
  130. background-color: #1a1a1a;
  131. }
  132. .dark .text-gray-900 {
  133. color: #e5e5e5;
  134. }
  135. .dark .text-gray-400 {
  136. color: #9ca3af;
  137. }
  138. .dark .border-gray-300 {
  139. border-color: #404040;
  140. }
  141. .dark .focus\:ring-offset-2 {
  142. --tw-ring-offset-color: #262626;
  143. }
  144. .dark .shadow-sm {
  145. box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  146. }
  147. .dark .shadow-lg {
  148. box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  149. }
  150. .dark .shadow-xl {
  151. box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  152. }
  153. /* Existing styles */
  154. .active-tab {
  155. color: #0c7ff2;
  156. border-color: #0c7ff2;
  157. }
  158. .active-tab .material-icons {
  159. color: #0c7ff2;
  160. }
  161. .inactive-tab {
  162. color: #6b7280;
  163. border-color: transparent;
  164. }
  165. .inactive-tab:hover {
  166. color: #374151;
  167. }
  168. #status-message {
  169. transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
  170. }
  171. /* Switch toggle styles */
  172. .switch {
  173. position: relative;
  174. display: inline-block;
  175. width: 40px;
  176. height: 20px;
  177. }
  178. .switch input {
  179. opacity: 0;
  180. width: 0;
  181. height: 0;
  182. }
  183. .slider {
  184. position: absolute;
  185. cursor: pointer;
  186. top: 0;
  187. left: 0;
  188. right: 0;
  189. bottom: 0;
  190. background-color: #ccc;
  191. transition: .4s;
  192. border-radius: 20px;
  193. }
  194. .slider:before {
  195. position: absolute;
  196. content: "";
  197. height: 16px;
  198. width: 16px;
  199. left: 2px;
  200. bottom: 2px;
  201. background-color: white;
  202. transition: .4s;
  203. border-radius: 50%;
  204. }
  205. input:checked + .slider {
  206. background-color: #0c7ff2;
  207. }
  208. input:checked + .slider:before {
  209. transform: translateX(20px);
  210. }
  211. /* Shadow for top of status bar */
  212. .shadow-lg-top {
  213. box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 -2px 4px -2px rgb(0 0 0 / 0.1);
  214. }
  215. /* Marquee animation for pattern name on small screens */
  216. @keyframes marquee {
  217. 0% { transform: translateX(0%); }
  218. 50% { transform: translateX(-50%); }
  219. }
  220. .pattern-marquee {
  221. display: inline-block;
  222. min-width: 100%;
  223. animation: marquee 8s linear infinite;
  224. }
  225. @media (min-width: 640px) { /* sm: and up, disable marquee */
  226. .pattern-marquee {
  227. animation: none !important;
  228. transform: none !important;
  229. }
  230. }
  231. {% block additional_styles %}{% endblock %}
  232. </style>
  233. {% block additional_head %}{% endblock %}
  234. </head>
  235. <body
  236. class="bg-gray-50"
  237. style="font-family: 'Plus Jakarta Sans', 'Noto Sans', sans-serif"
  238. >
  239. <div
  240. class="mt-2 w-full text-center px-4 z-50 pointer-events-none absolute"
  241. id="status-message-container"
  242. >
  243. <p
  244. 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"
  245. id="status-message"
  246. ></p>
  247. </div>
  248. <div
  249. class="relative flex size-full min-h-screen flex-col group/design-root overflow-x-hidden"
  250. >
  251. <div class="layout-container flex min-h-full grow flex-col">
  252. <header
  253. 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"
  254. >
  255. <div class="flex items-center gap-3 text-gray-800">
  256. <a href="/" class="flex items-center gap-3 text-gray-800 hover:opacity-80 transition-opacity">
  257. <div class="text-blue-600 w-9 h-9 rounded-full shadow overflow-hidden">
  258. <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"/>
  259. </div>
  260. <h1
  261. class="text-gray-800 text-xl font-bold leading-tight tracking-tight flex items-center gap-2"
  262. >
  263. {{ app_name or 'Dune Weaver' }}
  264. <span
  265. id="connectionStatusDot"
  266. class="inline-block size-2 rounded-full bg-red-500 ml-2 align-middle"
  267. ></span>
  268. </h1>
  269. </a>
  270. </div>
  271. <div class="flex items-center gap-2">
  272. <!-- Update Available Indicator -->
  273. <button
  274. id="update-indicator"
  275. 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"
  276. aria-label="Update available"
  277. title="Software update available - Click to view"
  278. >
  279. <span class="material-icons text-green-600 dark:text-green-400 animate-pulse">system_update</span>
  280. </button>
  281. <button
  282. id="theme-toggle"
  283. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
  284. aria-label="Toggle dark mode"
  285. >
  286. <span class="material-icons" id="theme-toggle-icon">dark_mode</span>
  287. </button>
  288. <button
  289. id="view-logs-button"
  290. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500"
  291. aria-label="View logs"
  292. title="View Application Logs"
  293. onclick="openLogsModal()"
  294. >
  295. <span class="material-icons">article</span>
  296. </button>
  297. <button
  298. id="restart-button"
  299. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-amber-500"
  300. aria-label="Restart system"
  301. title="Restart Docker Containers"
  302. >
  303. <span class="material-icons text-amber-600">restart_alt</span>
  304. </button>
  305. <button
  306. id="shutdown-button"
  307. class="p-1.5 flex rounded-lg hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-red-500"
  308. aria-label="Shutdown system"
  309. title="Shutdown System (Raspberry Pi only)"
  310. >
  311. <span class="material-icons text-red-600">power_settings_new</span>
  312. </button>
  313. </div>
  314. </header>
  315. <main class="flex flex-1 justify-center px-4 sm:px-6 lg:px-8 pt-16 sm:pt-20">
  316. {% block content %}{% endblock %}
  317. </main>
  318. <!-- Floating Preview Button -->
  319. <button
  320. id="toggle-preview-modal-btn"
  321. 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"
  322. title="Toggle Pattern Preview"
  323. >
  324. <span class="material-icons text-xl">preview</span>
  325. </button>
  326. <footer
  327. class="fixed bottom-0 left-0 right-0 z-10 bg-white border-t border-gray-200 shadow-t-sm"
  328. >
  329. <nav class="mx-auto flex max-w-5xl justify-around">
  330. <a
  331. 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"
  332. href="/"
  333. >
  334. <span class="material-icons">search</span> Browse
  335. </a>
  336. <a
  337. 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"
  338. href="/playlists"
  339. >
  340. <span class="material-icons">list_alt</span> Playlists
  341. </a>
  342. <a
  343. 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"
  344. href="/table_control"
  345. >
  346. <span class="material-icons">table_chart</span> Table Control
  347. </a>
  348. <a
  349. 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"
  350. href="/led"
  351. >
  352. <span class="material-icons">lightbulb</span> <span id="led-nav-label">LED</span>
  353. </a>
  354. <a
  355. 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"
  356. href="/settings"
  357. >
  358. <span class="material-icons">settings</span> Settings
  359. </a>
  360. </nav>
  361. </footer>
  362. </div>
  363. </div>
  364. {% block scripts %}{% endblock %}
  365. <script src="/static/js/base.js"></script>
  366. <!-- Cache Progress Modal -->
  367. <div id="cacheProgressModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  368. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
  369. <div class="p-6">
  370. <div class="text-center">
  371. <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Initializing Pattern Cache</h2>
  372. <p class="text-gray-600 dark:text-gray-400 mb-4">Preparing your pattern previews...</p>
  373. <div class="mb-4">
  374. <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
  375. <div id="cacheProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
  376. </div>
  377. <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
  378. <span id="cacheProgressText">Starting...</span>
  379. <span id="cacheProgressPercentage">0%</span>
  380. </div>
  381. </div>
  382. <div class="text-sm text-gray-500 dark:text-gray-400">
  383. <p id="cacheCurrentStage">Preparing...</p>
  384. <p id="cacheCurrentFile" class="mt-1 truncate"></p>
  385. </div>
  386. </div>
  387. </div>
  388. </div>
  389. </div>
  390. <!-- Player Preview Modal -->
  391. <div id="playerPreviewModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-40 hidden p-4">
  392. <div class="bg-white rounded-lg shadow-xl w-full max-w-5xl max-h-[95vh] flex flex-col">
  393. <div class="flex items-center justify-between p-4 border-b border-gray-200 flex-shrink-0">
  394. <h2 id="playerPreviewTitle" class="text-xl font-semibold text-gray-800">Pattern Preview</h2>
  395. <button id="closePlayerPreview" class="text-gray-400 hover:text-gray-600 transition-colors">
  396. <span class="material-icons text-2xl">close</span>
  397. </button>
  398. </div>
  399. <!-- Canvas Area -->
  400. <div class="flex-1 p-4 flex justify-center items-center overflow-hidden">
  401. <div class="relative flex items-center justify-center w-full h-full">
  402. <div class="relative max-w-[min(800px,90vw)] max-h-[min(600px,80vh)] aspect-square">
  403. <canvas id="playerPreviewCanvas" width="800" height="800" class="w-full h-full rounded-full border border-gray-300 dark:invert"></canvas>
  404. </div>
  405. </div>
  406. </div>
  407. <!-- Pattern Info and Controls -->
  408. <div class="flex-shrink-0 p-4 border-b border-gray-200 flex items-center gap-4 flex-wrap">
  409. <!-- Pattern Preview Image -->
  410. <div class="flex-shrink-0">
  411. <img id="modal-pattern-preview-img"
  412. class="w-[126px] h-[126px] rounded-full border border-gray-300 object-cover dark:invert" src="">
  413. </div>
  414. <div class="flex-grow w-auto">
  415. <div class="flex items-center justify-between mb-2">
  416. <div class="min-w-0 max-w-[50%]">
  417. <div class="overflow-hidden relative">
  418. <p class="text-lg font-semibold whitespace-nowrap" id="modal-pattern-name">
  419. No pattern playing
  420. </p>
  421. </div>
  422. <p class="text-base text-gray-500" id="modal-eta">
  423. ETA: --:--
  424. </p>
  425. </div>
  426. <div class="flex items-center gap-2 flex-shrink-0">
  427. <button
  428. aria-label="Next"
  429. 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"
  430. id="modal-skip-button"
  431. >
  432. <span class="material-icons text-gray-700">skip_next</span>
  433. </button>
  434. <button
  435. aria-label="Pause"
  436. 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"
  437. id="modal-pause-button"
  438. >
  439. <span class="material-icons text-gray-700">pause</span>
  440. </button>
  441. <button
  442. aria-label="Stop"
  443. 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"
  444. id="modal-stop-button"
  445. >
  446. <span class="material-icons text-gray-700">stop</span>
  447. </button>
  448. </div>
  449. </div>
  450. <div class="w-full bg-gray-300 rounded-full h-2.5 mb-2">
  451. <div
  452. class="bg-blue-600 h-2.5 rounded-full"
  453. id="modal-progress-bar"
  454. style="width: 0%"
  455. ></div>
  456. </div>
  457. <div class="flex items-center justify-between">
  458. <div class="text-base text-gray-500">
  459. Next:
  460. <span class="text-gray-700 font-medium" id="modal-next-pattern">None</span>
  461. </div>
  462. <div class="flex items-center gap-3 text-sm">
  463. <span class="text-gray-500">Speed:</span>
  464. <div class="flex items-center gap-2">
  465. <div class="relative min-w-[4ch] text-center cursor-pointer inline-flex items-center" id="modal-speed-container">
  466. <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>
  467. <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" />
  468. </div>
  469. </div>
  470. </div>
  471. </div>
  472. </div>
  473. </div>
  474. </div>
  475. </div>
  476. <script>
  477. // Function to show status message
  478. function showStatusMessage(message, type = "success") {
  479. const statusContainer = document.getElementById(
  480. "status-message-container"
  481. );
  482. const statusMessage = document.getElementById("status-message");
  483. if (!statusContainer || !statusMessage) return;
  484. // Set message and color based on type
  485. statusMessage.textContent = message;
  486. 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 ${
  487. type === "success"
  488. ? "bg-green-50 text-green-700 border border-green-200"
  489. : type === "error"
  490. ? "bg-red-50 text-red-700 border border-red-200"
  491. : type === "warning"
  492. ? "bg-yellow-50 text-yellow-700 border border-yellow-200"
  493. : "bg-blue-50 text-blue-700 border border-blue-200"
  494. }`;
  495. // Show message with animation
  496. requestAnimationFrame(() => {
  497. statusMessage.classList.remove("opacity-0", "-translate-y-2");
  498. statusMessage.classList.add("opacity-100", "translate-y-0");
  499. });
  500. // Hide message after 5 seconds
  501. setTimeout(() => {
  502. statusMessage.classList.remove("opacity-100", "translate-y-0");
  503. statusMessage.classList.add("opacity-0", "-translate-y-2");
  504. }, 5000);
  505. }
  506. // Initial connection status check
  507. async function checkInitialConnectionStatus() {
  508. try {
  509. const response = await fetch("/serial_status");
  510. if (response.ok) {
  511. const data = await response.json();
  512. const statusDot = document.getElementById("connectionStatusDot");
  513. if (statusDot) {
  514. statusDot.className = `inline-block size-2 rounded-full ml-2 align-middle ${
  515. data.connected ? "bg-green-500" : "bg-red-500"
  516. }`;
  517. }
  518. }
  519. } catch (error) {
  520. console.error("Error checking initial connection status:", error);
  521. }
  522. }
  523. // Check initial status on page load
  524. document.addEventListener("DOMContentLoaded", checkInitialConnectionStatus);
  525. // Player bar toggle logic will be handled by base.js
  526. </script>
  527. <script>
  528. // Cache progress modal functionality
  529. let cacheProgressSocket = null;
  530. let cacheProgressCheckInterval = null;
  531. function initCacheProgressModal() {
  532. const modal = document.getElementById('cacheProgressModal');
  533. const progressBar = document.getElementById('cacheProgressBar');
  534. const progressText = document.getElementById('cacheProgressText');
  535. const progressPercentage = document.getElementById('cacheProgressPercentage');
  536. const currentStage = document.getElementById('cacheCurrentStage');
  537. const currentFile = document.getElementById('cacheCurrentFile');
  538. // Check if cache generation is needed on page load
  539. fetch('/cache-progress')
  540. .then(response => response.json())
  541. .then(data => {
  542. if (data.is_running) {
  543. showCacheProgressModal();
  544. }
  545. })
  546. .catch(error => {
  547. console.error('Error checking initial cache progress:', error);
  548. });
  549. function showCacheProgressModal() {
  550. modal.classList.remove('hidden');
  551. // Connect to WebSocket for real-time updates
  552. const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
  553. const wsUrl = `${protocol}//${window.location.host}/ws/cache-progress`;
  554. cacheProgressSocket = new WebSocket(wsUrl);
  555. cacheProgressSocket.onmessage = function(event) {
  556. const data = JSON.parse(event.data);
  557. if (data.type === 'cache_progress') {
  558. updateCacheProgress(data.data);
  559. }
  560. };
  561. cacheProgressSocket.onclose = function() {
  562. // Fallback to polling if WebSocket fails
  563. startProgressPolling();
  564. };
  565. cacheProgressSocket.onerror = function() {
  566. // Fallback to polling if WebSocket fails
  567. startProgressPolling();
  568. };
  569. }
  570. function startProgressPolling() {
  571. if (cacheProgressCheckInterval) {
  572. clearInterval(cacheProgressCheckInterval);
  573. }
  574. cacheProgressCheckInterval = setInterval(() => {
  575. fetch('/cache-progress')
  576. .then(response => response.json())
  577. .then(data => updateCacheProgress(data))
  578. .catch(error => console.error('Error fetching cache progress:', error));
  579. }, 1000);
  580. }
  581. function updateCacheProgress(data) {
  582. if (!data.is_running && data.stage === 'complete') {
  583. console.log('Initial cache generation completed');
  584. hideCacheProgressModal();
  585. // Trigger cache all prompt after initial cache generation completes
  586. if (typeof onInitialCacheComplete === 'function') {
  587. console.log('Calling onInitialCacheComplete()');
  588. onInitialCacheComplete();
  589. } else {
  590. console.log('onInitialCacheComplete function not found');
  591. }
  592. return;
  593. }
  594. if (!data.is_running && data.stage === 'error') {
  595. progressText.textContent = 'Error occurred';
  596. currentStage.textContent = data.error || 'Unknown error';
  597. currentFile.textContent = '';
  598. return;
  599. }
  600. if (!data.is_running) {
  601. hideCacheProgressModal();
  602. return;
  603. }
  604. // Calculate progress percentage
  605. const percentage = data.total_files > 0 ? Math.round((data.processed_files / data.total_files) * 100) : 0;
  606. // Update progress bar
  607. progressBar.style.width = `${percentage}%`;
  608. progressPercentage.textContent = `${percentage}%`;
  609. // Update text based on stage
  610. let stageText = '';
  611. let progressTextContent = '';
  612. switch (data.stage) {
  613. case 'starting':
  614. stageText = 'Initializing...';
  615. progressTextContent = 'Getting ready...';
  616. break;
  617. case 'metadata':
  618. stageText = 'Processing pattern metadata';
  619. progressTextContent = `${data.processed_files} of ${data.total_files} patterns`;
  620. break;
  621. case 'images':
  622. stageText = 'Generating pattern previews';
  623. progressTextContent = `${data.processed_files} of ${data.total_files} previews`;
  624. break;
  625. default:
  626. stageText = 'Processing...';
  627. progressTextContent = `${data.processed_files} of ${data.total_files} files`;
  628. }
  629. currentStage.textContent = stageText;
  630. progressText.textContent = progressTextContent;
  631. // Update current file
  632. if (data.current_file) {
  633. currentFile.textContent = `Current: ${data.current_file}`;
  634. } else {
  635. currentFile.textContent = '';
  636. }
  637. }
  638. function hideCacheProgressModal() {
  639. modal.classList.add('hidden');
  640. if (cacheProgressSocket) {
  641. cacheProgressSocket.close();
  642. cacheProgressSocket = null;
  643. }
  644. if (cacheProgressCheckInterval) {
  645. clearInterval(cacheProgressCheckInterval);
  646. cacheProgressCheckInterval = null;
  647. }
  648. }
  649. // Expose functions globally for potential external use
  650. window.showCacheProgressModal = showCacheProgressModal;
  651. window.hideCacheProgressModal = hideCacheProgressModal;
  652. }
  653. // Initialize when DOM is loaded
  654. document.addEventListener('DOMContentLoaded', initCacheProgressModal);
  655. </script>
  656. <script>
  657. // Theme switching functionality
  658. document.addEventListener('DOMContentLoaded', function() {
  659. const themeToggle = document.getElementById('theme-toggle');
  660. const themeToggleIcon = document.getElementById('theme-toggle-icon');
  661. // Update icon based on current theme
  662. function updateThemeIcon() {
  663. const isDark = document.documentElement.classList.contains('dark');
  664. themeToggleIcon.textContent = isDark ? 'light_mode' : 'dark_mode';
  665. }
  666. // Initial icon update
  667. updateThemeIcon();
  668. // Theme toggle click handler
  669. themeToggle.addEventListener('click', () => {
  670. const isDark = document.documentElement.classList.toggle('dark');
  671. localStorage.setItem('theme', isDark ? 'dark' : 'light');
  672. updateThemeIcon();
  673. });
  674. });
  675. // Shutdown button functionality
  676. document.addEventListener('DOMContentLoaded', function() {
  677. const shutdownButton = document.getElementById('shutdown-button');
  678. // Shutdown button click handler
  679. shutdownButton.addEventListener('click', async () => {
  680. 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.');
  681. if (!confirmed) return;
  682. try {
  683. showStatusMessage('Initiating shutdown...', 'warning');
  684. const response = await fetch('/api/system/shutdown', { method: 'POST' });
  685. const data = await response.json();
  686. if (data.success) {
  687. showStatusMessage('System is shutting down...', 'success');
  688. } else {
  689. showStatusMessage('Shutdown failed: ' + data.message, 'error');
  690. }
  691. } catch (error) {
  692. showStatusMessage('Failed to shutdown: ' + error.message, 'error');
  693. }
  694. });
  695. });
  696. // Restart button functionality
  697. document.addEventListener('DOMContentLoaded', function() {
  698. const restartButton = document.getElementById('restart-button');
  699. // Restart button click handler
  700. restartButton.addEventListener('click', async () => {
  701. 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.');
  702. if (!confirmed) return;
  703. try {
  704. showStatusMessage('Initiating restart...', 'warning');
  705. const response = await fetch('/api/system/restart', { method: 'POST' });
  706. const data = await response.json();
  707. if (data.success) {
  708. showStatusMessage('System is restarting... Page will reload when ready.', 'success');
  709. // Start checking if the server is back online
  710. setTimeout(() => {
  711. checkServerAndReload();
  712. }, 3000);
  713. } else {
  714. showStatusMessage('Restart failed: ' + data.message, 'error');
  715. }
  716. } catch (error) {
  717. showStatusMessage('Failed to restart: ' + error.message, 'error');
  718. }
  719. });
  720. // Function to check if server is back online and reload
  721. function checkServerAndReload() {
  722. const checkInterval = setInterval(async () => {
  723. try {
  724. const response = await fetch('/api/version', { method: 'GET' });
  725. if (response.ok) {
  726. clearInterval(checkInterval);
  727. showStatusMessage('Server is back online. Reloading...', 'success');
  728. setTimeout(() => {
  729. window.location.reload();
  730. }, 1000);
  731. }
  732. } catch (error) {
  733. // Server not ready yet, keep checking
  734. console.log('Server not ready yet, retrying...');
  735. }
  736. }, 2000);
  737. // Stop checking after 60 seconds
  738. setTimeout(() => {
  739. clearInterval(checkInterval);
  740. }, 60000);
  741. }
  742. });
  743. // Update indicator functionality
  744. document.addEventListener('DOMContentLoaded', async function() {
  745. const updateIndicator = document.getElementById('update-indicator');
  746. if (!updateIndicator) return;
  747. // Check for updates
  748. async function checkForUpdates() {
  749. try {
  750. const response = await fetch('/api/version');
  751. const data = await response.json();
  752. // Show indicator if update is available
  753. if (data.update_available) {
  754. updateIndicator.classList.remove('hidden');
  755. } else {
  756. updateIndicator.classList.add('hidden');
  757. }
  758. } catch (error) {
  759. console.error('Failed to check for updates:', error);
  760. }
  761. }
  762. // Initial check
  763. await checkForUpdates();
  764. // Check every hour
  765. setInterval(checkForUpdates, 3600000);
  766. // Click handler - navigate to settings and scroll to update section
  767. updateIndicator.addEventListener('click', () => {
  768. // Navigate to settings page
  769. window.location.href = '/settings#software-version-section';
  770. });
  771. });
  772. </script>
  773. <!-- Cache All Previews Prompt Modal -->
  774. <div id="cacheAllPromptModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  775. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-md">
  776. <div class="p-6">
  777. <div class="text-center">
  778. <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200 mb-2">Cache All Pattern Previews?</h2>
  779. <p class="text-gray-600 dark:text-gray-400 mb-4 max-w-md mx-auto">
  780. Would you like to cache all pattern previews for faster browsing? This will download and store preview images in your browser for instant loading.
  781. </p>
  782. <div class="bg-amber-50 dark:bg-amber-900 p-3 rounded-lg mb-4 text-sm">
  783. <p class="text-amber-700 dark:text-amber-300">
  784. <strong>Note:</strong> This cache is browser-specific. You'll need to repeat this process for each browser you use.
  785. </p>
  786. </div>
  787. <!-- Progress section (hidden initially) -->
  788. <div id="cacheAllProgress" class="mb-4 hidden">
  789. <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
  790. <div id="cacheAllProgressBar" class="bg-blue-600 dark:bg-blue-400 h-2 rounded-full transition-all duration-300" style="width: 0%"></div>
  791. </div>
  792. <div class="mt-2 flex justify-between text-sm text-gray-500 dark:text-gray-400">
  793. <span id="cacheAllProgressText">Starting...</span>
  794. <span id="cacheAllProgressPercentage">0%</span>
  795. </div>
  796. </div>
  797. <!-- Buttons -->
  798. <div id="cacheAllButtons" class="flex gap-3 justify-center">
  799. <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">
  800. Skip for now
  801. </button>
  802. <button id="startCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
  803. Cache All Previews
  804. </button>
  805. </div>
  806. <!-- Completion message (hidden initially) -->
  807. <div id="cacheAllComplete" class="hidden">
  808. <p class="text-green-600 dark:text-green-400 mb-4">✓ All previews cached successfully!</p>
  809. <button id="closeCacheAllBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">
  810. Done
  811. </button>
  812. </div>
  813. </div>
  814. </div>
  815. </div>
  816. </div>
  817. <!-- Logs Modal -->
  818. <div id="logsModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden p-4">
  819. <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-5xl max-h-[90vh] flex flex-col">
  820. <!-- Modal Header -->
  821. <div class="flex items-center justify-between px-6 py-4 border-b border-slate-200 dark:border-gray-600">
  822. <div class="flex items-center gap-3">
  823. <span class="material-icons text-2xl text-slate-600 dark:text-gray-300">article</span>
  824. <h3 class="text-lg font-semibold text-slate-800 dark:text-gray-100">Application Logs</h3>
  825. <span id="logsConnectionStatus" class="text-xs px-2 py-1 rounded-full bg-gray-200 dark:bg-gray-600 text-gray-600 dark:text-gray-300">Connecting...</span>
  826. </div>
  827. <div class="flex items-center gap-2">
  828. <select id="logLevelFilter" onchange="filterLogs()" class="form-select text-xs rounded-lg border-slate-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 py-2 pl-3 pr-10">
  829. <option value="">All Levels</option>
  830. <option value="DEBUG">Debug</option>
  831. <option value="INFO">Info</option>
  832. <option value="WARNING">Warning</option>
  833. <option value="ERROR">Error</option>
  834. <option value="CRITICAL">Critical</option>
  835. </select>
  836. <button
  837. onclick="clearLogs()"
  838. class="flex items-center justify-center gap-1 rounded-lg h-8 px-3 bg-gray-200 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-500 text-gray-700 dark:text-gray-200 text-xs font-medium transition-colors"
  839. >
  840. <span class="material-icons text-sm">delete_sweep</span>
  841. Clear
  842. </button>
  843. <label class="flex items-center gap-1.5 text-sm text-slate-600 dark:text-gray-300">
  844. <input type="checkbox" id="logsAutoScroll" checked class="rounded border-slate-300 dark:border-gray-600">
  845. Auto-scroll
  846. </label>
  847. <button
  848. onclick="closeLogsModal()"
  849. class="flex items-center justify-center rounded-lg size-8 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400 transition-colors"
  850. >
  851. <span class="material-icons">close</span>
  852. </button>
  853. </div>
  854. </div>
  855. <!-- Modal Body -->
  856. <div id="logsContainer" class="flex-1 overflow-y-auto p-4 font-mono text-xs bg-slate-50 dark:bg-gray-900">
  857. <div id="logsContent" class="space-y-1">
  858. <!-- Log entries will be inserted here -->
  859. </div>
  860. </div>
  861. <!-- Modal Footer -->
  862. <div class="px-6 py-3 border-t border-slate-200 dark:border-gray-600 flex items-center justify-between text-xs text-slate-500 dark:text-gray-400">
  863. <span id="logsCount">0 entries</span>
  864. <span id="logsInfo">Showing last 500 log entries</span>
  865. </div>
  866. </div>
  867. </div>
  868. <script>
  869. // ============================================================================
  870. // Application Logs Modal
  871. // ============================================================================
  872. let logsWebSocket = null;
  873. let logsEntries = [];
  874. const MAX_LOG_ENTRIES = 500;
  875. const LOG_LEVEL_COLORS = {
  876. DEBUG: 'text-gray-500 dark:text-gray-400',
  877. INFO: 'text-blue-600 dark:text-blue-400',
  878. WARNING: 'text-amber-600 dark:text-amber-400',
  879. ERROR: 'text-red-600 dark:text-red-400',
  880. CRITICAL: 'text-red-700 dark:text-red-300 font-bold'
  881. };
  882. const LOG_LEVEL_BG = {
  883. DEBUG: 'bg-gray-100 dark:bg-gray-700',
  884. INFO: 'bg-blue-50 dark:bg-blue-900/30',
  885. WARNING: 'bg-amber-50 dark:bg-amber-900/30',
  886. ERROR: 'bg-red-50 dark:bg-red-900/30',
  887. CRITICAL: 'bg-red-100 dark:bg-red-900/50'
  888. };
  889. function openLogsModal() {
  890. const modal = document.getElementById('logsModal');
  891. modal.classList.remove('hidden');
  892. loadInitialLogs();
  893. connectLogsWebSocket();
  894. modal.addEventListener('click', (e) => {
  895. if (e.target === modal) closeLogsModal();
  896. });
  897. document.addEventListener('keydown', handleLogsEscapeKey);
  898. }
  899. function closeLogsModal() {
  900. const modal = document.getElementById('logsModal');
  901. modal.classList.add('hidden');
  902. if (logsWebSocket) {
  903. logsWebSocket.close();
  904. logsWebSocket = null;
  905. }
  906. document.removeEventListener('keydown', handleLogsEscapeKey);
  907. }
  908. function handleLogsEscapeKey(e) {
  909. if (e.key === 'Escape') closeLogsModal();
  910. }
  911. async function loadInitialLogs() {
  912. const logsContent = document.getElementById('logsContent');
  913. logsContent.innerHTML = '<div class="text-gray-500 dark:text-gray-400">Loading logs...</div>';
  914. try {
  915. const response = await fetch('/api/logs?limit=500');
  916. const data = await response.json();
  917. logsEntries = data.logs || [];
  918. renderLogs();
  919. updateLogsCount();
  920. const container = document.getElementById('logsContainer');
  921. container.scrollTop = container.scrollHeight;
  922. } catch (error) {
  923. console.error('Failed to load logs:', error);
  924. logsContent.innerHTML = '<div class="text-red-500">Failed to load logs</div>';
  925. }
  926. }
  927. function connectLogsWebSocket() {
  928. const statusEl = document.getElementById('logsConnectionStatus');
  929. const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
  930. const wsUrl = `${protocol}//${window.location.host}/ws/logs`;
  931. try {
  932. logsWebSocket = new WebSocket(wsUrl);
  933. logsWebSocket.onopen = () => {
  934. statusEl.textContent = 'Live';
  935. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300';
  936. };
  937. logsWebSocket.onmessage = (event) => {
  938. const message = JSON.parse(event.data);
  939. if (message.type === 'log_entry') addLogEntry(message.data);
  940. };
  941. logsWebSocket.onclose = () => {
  942. statusEl.textContent = 'Disconnected';
  943. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-gray-200 dark:bg-gray-600 text-gray-600 dark:text-gray-300';
  944. };
  945. logsWebSocket.onerror = (error) => {
  946. console.error('Logs WebSocket error:', error);
  947. statusEl.textContent = 'Error';
  948. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300';
  949. };
  950. } catch (error) {
  951. console.error('Failed to connect to logs WebSocket:', error);
  952. statusEl.textContent = 'Failed';
  953. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300';
  954. }
  955. }
  956. function addLogEntry(entry) {
  957. logsEntries.unshift(entry);
  958. if (logsEntries.length > MAX_LOG_ENTRIES) logsEntries.pop();
  959. const logsContent = document.getElementById('logsContent');
  960. const entryEl = createLogEntryElement(entry);
  961. logsContent.appendChild(entryEl);
  962. const autoScroll = document.getElementById('logsAutoScroll').checked;
  963. if (autoScroll) {
  964. const container = document.getElementById('logsContainer');
  965. container.scrollTop = container.scrollHeight;
  966. }
  967. const levelFilter = document.getElementById('logLevelFilter').value;
  968. if (levelFilter && entry.level !== levelFilter) entryEl.classList.add('hidden');
  969. updateLogsCount();
  970. }
  971. function createLogEntryElement(entry) {
  972. const div = document.createElement('div');
  973. div.className = `log-entry flex gap-2 py-1 px-2 rounded ${LOG_LEVEL_BG[entry.level] || 'bg-gray-50 dark:bg-gray-800'}`;
  974. div.dataset.level = entry.level;
  975. const timestamp = new Date(entry.timestamp);
  976. const timeStr = timestamp.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
  977. const msStr = timestamp.getMilliseconds().toString().padStart(3, '0');
  978. div.innerHTML = `
  979. <span class="text-gray-400 dark:text-gray-500 shrink-0">${timeStr}.${msStr}</span>
  980. <span class="${LOG_LEVEL_COLORS[entry.level] || 'text-gray-600'} shrink-0 w-16">${entry.level}</span>
  981. <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>
  982. <span class="text-slate-700 dark:text-gray-200 break-all">${escapeHtmlLogs(entry.message)}</span>
  983. `;
  984. return div;
  985. }
  986. function escapeHtmlLogs(text) {
  987. const div = document.createElement('div');
  988. div.textContent = text;
  989. return div.innerHTML;
  990. }
  991. function renderLogs() {
  992. const logsContent = document.getElementById('logsContent');
  993. logsContent.innerHTML = '';
  994. const reversedLogs = [...logsEntries].reverse();
  995. const levelFilter = document.getElementById('logLevelFilter').value;
  996. for (const entry of reversedLogs) {
  997. const entryEl = createLogEntryElement(entry);
  998. if (levelFilter && entry.level !== levelFilter) entryEl.classList.add('hidden');
  999. logsContent.appendChild(entryEl);
  1000. }
  1001. }
  1002. function filterLogs() {
  1003. const levelFilter = document.getElementById('logLevelFilter').value;
  1004. const entries = document.querySelectorAll('#logsContent .log-entry');
  1005. let visibleCount = 0;
  1006. entries.forEach(entry => {
  1007. if (!levelFilter || entry.dataset.level === levelFilter) {
  1008. entry.classList.remove('hidden');
  1009. visibleCount++;
  1010. } else {
  1011. entry.classList.add('hidden');
  1012. }
  1013. });
  1014. const countEl = document.getElementById('logsCount');
  1015. if (levelFilter) {
  1016. countEl.textContent = `${visibleCount} of ${logsEntries.length} entries (filtered)`;
  1017. } else {
  1018. countEl.textContent = `${logsEntries.length} entries`;
  1019. }
  1020. }
  1021. function updateLogsCount() {
  1022. const countEl = document.getElementById('logsCount');
  1023. const levelFilter = document.getElementById('logLevelFilter').value;
  1024. if (levelFilter) {
  1025. const filteredCount = logsEntries.filter(e => e.level === levelFilter).length;
  1026. countEl.textContent = `${filteredCount} of ${logsEntries.length} entries (filtered)`;
  1027. } else {
  1028. countEl.textContent = `${logsEntries.length} entries`;
  1029. }
  1030. }
  1031. async function clearLogs() {
  1032. try {
  1033. await fetch('/api/logs', { method: 'DELETE' });
  1034. logsEntries = [];
  1035. document.getElementById('logsContent').innerHTML = '<div class="text-gray-500 dark:text-gray-400 text-center py-4">Logs cleared</div>';
  1036. updateLogsCount();
  1037. } catch (error) {
  1038. console.error('Failed to clear logs:', error);
  1039. }
  1040. }
  1041. </script>
  1042. </body>
  1043. </html>