1
0

base.html 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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-20 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-20 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 Bottom Panel -->
  818. <div id="logsPanel" class="fixed left-0 right-0 z-20 bg-white dark:bg-gray-800 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1)] flex flex-col transition-transform duration-300 ease-out" style="bottom: 0; height: 45vh; transform: translateY(100%);">
  819. <!-- Panel Header -->
  820. <div class="flex items-center justify-between px-4 py-2 border-b border-slate-200 dark:border-gray-600 shrink-0">
  821. <div class="flex items-center gap-2">
  822. <span class="material-icons text-lg text-slate-600 dark:text-gray-300">article</span>
  823. <h3 class="text-sm font-semibold text-slate-800 dark:text-gray-100">Logs</h3>
  824. <span id="logsConnectionStatus" class="text-xs px-2 py-0.5 rounded-full bg-gray-200 dark:bg-gray-600 text-gray-600 dark:text-gray-300">Connecting...</span>
  825. </div>
  826. <div class="flex items-center gap-2">
  827. <select id="logLevelFilter" onchange="filterLogs()" class="form-select text-xs rounded border-slate-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 py-1 pl-2 pr-8">
  828. <option value="">All</option>
  829. <option value="DEBUG">Debug</option>
  830. <option value="INFO">Info</option>
  831. <option value="WARNING">Warn</option>
  832. <option value="ERROR">Error</option>
  833. <option value="CRITICAL">Critical</option>
  834. </select>
  835. <button
  836. onclick="clearLogs()"
  837. class="flex items-center justify-center rounded h-7 px-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-500 text-gray-700 dark:text-gray-200 text-xs font-medium transition-colors"
  838. title="Clear logs"
  839. >
  840. <span class="material-icons text-sm">delete_sweep</span>
  841. </button>
  842. <label class="flex items-center gap-1 text-xs text-slate-600 dark:text-gray-300">
  843. <input type="checkbox" id="logsAutoScroll" checked class="rounded border-slate-300 dark:border-gray-600 w-3.5 h-3.5">
  844. Auto
  845. </label>
  846. <button
  847. onclick="closeLogsModal()"
  848. class="flex items-center justify-center rounded size-7 hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400 transition-colors"
  849. title="Close logs"
  850. >
  851. <span class="material-icons text-lg">close</span>
  852. </button>
  853. </div>
  854. </div>
  855. <!-- Panel Body -->
  856. <div id="logsContainer" class="flex-1 overflow-y-auto p-2 font-mono text-xs bg-slate-50 dark:bg-gray-900">
  857. <div id="logsContent" class="space-y-0.5">
  858. <!-- Log entries will be inserted here -->
  859. </div>
  860. </div>
  861. <!-- Panel Footer -->
  862. <div class="px-4 py-1.5 border-t border-slate-200 dark:border-gray-600 flex items-center justify-between text-xs text-slate-500 dark:text-gray-400 shrink-0">
  863. <span id="logsCount">0 entries</span>
  864. <span id="logsInfo">Last 500 entries</span>
  865. </div>
  866. </div>
  867. <script>
  868. // ============================================================================
  869. // Application Logs Bottom Panel
  870. // ============================================================================
  871. let logsWebSocket = null;
  872. let logsEntries = [];
  873. let logsPanelOpen = false;
  874. const MAX_LOG_ENTRIES = 500;
  875. const LOGS_PANEL_HEIGHT = '45vh';
  876. const LOG_LEVEL_COLORS = {
  877. DEBUG: 'text-gray-500 dark:text-gray-400',
  878. INFO: 'text-blue-600 dark:text-blue-400',
  879. WARNING: 'text-amber-600 dark:text-amber-400',
  880. ERROR: 'text-red-600 dark:text-red-400',
  881. CRITICAL: 'text-red-700 dark:text-red-300 font-bold'
  882. };
  883. const LOG_LEVEL_BG = {
  884. DEBUG: 'bg-gray-100 dark:bg-gray-700',
  885. INFO: 'bg-blue-50 dark:bg-blue-900/30',
  886. WARNING: 'bg-amber-50 dark:bg-amber-900/30',
  887. ERROR: 'bg-red-50 dark:bg-red-900/30',
  888. CRITICAL: 'bg-red-100 dark:bg-red-900/50'
  889. };
  890. function openLogsModal(skipSave = false) {
  891. if (logsPanelOpen) return;
  892. logsPanelOpen = true;
  893. const panel = document.getElementById('logsPanel');
  894. const footer = document.querySelector('footer');
  895. const previewBtn = document.getElementById('toggle-preview-modal-btn');
  896. // Slide panel up
  897. panel.style.transform = 'translateY(0)';
  898. // Push footer up
  899. if (footer) {
  900. footer.style.transition = 'transform 0.3s ease-out';
  901. footer.style.transform = `translateY(-${LOGS_PANEL_HEIGHT})`;
  902. }
  903. // Push floating preview button up
  904. if (previewBtn) {
  905. previewBtn.style.transition = 'transform 0.3s ease-out';
  906. previewBtn.style.transform = `translateY(-${LOGS_PANEL_HEIGHT})`;
  907. }
  908. // Persist state across pages
  909. if (!skipSave) {
  910. localStorage.setItem('logsPanelOpen', 'true');
  911. }
  912. loadInitialLogs();
  913. connectLogsWebSocket();
  914. document.addEventListener('keydown', handleLogsEscapeKey);
  915. }
  916. function closeLogsModal() {
  917. if (!logsPanelOpen) return;
  918. logsPanelOpen = false;
  919. const panel = document.getElementById('logsPanel');
  920. const footer = document.querySelector('footer');
  921. const previewBtn = document.getElementById('toggle-preview-modal-btn');
  922. // Slide panel down
  923. panel.style.transform = 'translateY(100%)';
  924. // Reset footer position
  925. if (footer) {
  926. footer.style.transform = 'translateY(0)';
  927. }
  928. // Reset floating button position
  929. if (previewBtn) {
  930. previewBtn.style.transform = 'translateY(0)';
  931. }
  932. // Persist state across pages
  933. localStorage.removeItem('logsPanelOpen');
  934. if (logsWebSocket) {
  935. logsWebSocket.close();
  936. logsWebSocket = null;
  937. }
  938. document.removeEventListener('keydown', handleLogsEscapeKey);
  939. }
  940. function handleLogsEscapeKey(e) {
  941. if (e.key === 'Escape') closeLogsModal();
  942. }
  943. // Restore logs panel state on page load
  944. document.addEventListener('DOMContentLoaded', function() {
  945. if (localStorage.getItem('logsPanelOpen') === 'true') {
  946. // Small delay to ensure DOM is ready
  947. setTimeout(() => openLogsModal(true), 100);
  948. }
  949. });
  950. async function loadInitialLogs() {
  951. const logsContent = document.getElementById('logsContent');
  952. logsContent.innerHTML = '<div class="text-gray-500 dark:text-gray-400">Loading logs...</div>';
  953. try {
  954. const response = await fetch('/api/logs?limit=500');
  955. const data = await response.json();
  956. logsEntries = data.logs || [];
  957. renderLogs();
  958. updateLogsCount();
  959. const container = document.getElementById('logsContainer');
  960. container.scrollTop = container.scrollHeight;
  961. } catch (error) {
  962. console.error('Failed to load logs:', error);
  963. logsContent.innerHTML = '<div class="text-red-500">Failed to load logs</div>';
  964. }
  965. }
  966. function connectLogsWebSocket() {
  967. const statusEl = document.getElementById('logsConnectionStatus');
  968. const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
  969. const wsUrl = `${protocol}//${window.location.host}/ws/logs`;
  970. try {
  971. logsWebSocket = new WebSocket(wsUrl);
  972. logsWebSocket.onopen = () => {
  973. statusEl.textContent = 'Live';
  974. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-300';
  975. };
  976. logsWebSocket.onmessage = (event) => {
  977. const message = JSON.parse(event.data);
  978. if (message.type === 'log_entry') addLogEntry(message.data);
  979. };
  980. logsWebSocket.onclose = () => {
  981. statusEl.textContent = 'Disconnected';
  982. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-gray-200 dark:bg-gray-600 text-gray-600 dark:text-gray-300';
  983. };
  984. logsWebSocket.onerror = (error) => {
  985. console.error('Logs WebSocket error:', error);
  986. statusEl.textContent = 'Error';
  987. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300';
  988. };
  989. } catch (error) {
  990. console.error('Failed to connect to logs WebSocket:', error);
  991. statusEl.textContent = 'Failed';
  992. statusEl.className = 'text-xs px-2 py-1 rounded-full bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300';
  993. }
  994. }
  995. function addLogEntry(entry) {
  996. logsEntries.unshift(entry);
  997. if (logsEntries.length > MAX_LOG_ENTRIES) logsEntries.pop();
  998. const logsContent = document.getElementById('logsContent');
  999. const entryEl = createLogEntryElement(entry);
  1000. logsContent.appendChild(entryEl);
  1001. const autoScroll = document.getElementById('logsAutoScroll').checked;
  1002. if (autoScroll) {
  1003. const container = document.getElementById('logsContainer');
  1004. container.scrollTop = container.scrollHeight;
  1005. }
  1006. const levelFilter = document.getElementById('logLevelFilter').value;
  1007. if (levelFilter && entry.level !== levelFilter) entryEl.classList.add('hidden');
  1008. updateLogsCount();
  1009. }
  1010. function createLogEntryElement(entry) {
  1011. const div = document.createElement('div');
  1012. div.className = `log-entry flex gap-2 py-1 px-2 rounded ${LOG_LEVEL_BG[entry.level] || 'bg-gray-50 dark:bg-gray-800'}`;
  1013. div.dataset.level = entry.level;
  1014. const timestamp = new Date(entry.timestamp);
  1015. const timeStr = timestamp.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
  1016. const msStr = timestamp.getMilliseconds().toString().padStart(3, '0');
  1017. div.innerHTML = `
  1018. <span class="text-gray-400 dark:text-gray-500 shrink-0">${timeStr}.${msStr}</span>
  1019. <span class="${LOG_LEVEL_COLORS[entry.level] || 'text-gray-600'} shrink-0 w-16">${entry.level}</span>
  1020. <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>
  1021. <span class="text-slate-700 dark:text-gray-200 break-all">${escapeHtmlLogs(entry.message)}</span>
  1022. `;
  1023. return div;
  1024. }
  1025. function escapeHtmlLogs(text) {
  1026. const div = document.createElement('div');
  1027. div.textContent = text;
  1028. return div.innerHTML;
  1029. }
  1030. function renderLogs() {
  1031. const logsContent = document.getElementById('logsContent');
  1032. logsContent.innerHTML = '';
  1033. const reversedLogs = [...logsEntries].reverse();
  1034. const levelFilter = document.getElementById('logLevelFilter').value;
  1035. for (const entry of reversedLogs) {
  1036. const entryEl = createLogEntryElement(entry);
  1037. if (levelFilter && entry.level !== levelFilter) entryEl.classList.add('hidden');
  1038. logsContent.appendChild(entryEl);
  1039. }
  1040. }
  1041. function filterLogs() {
  1042. const levelFilter = document.getElementById('logLevelFilter').value;
  1043. const entries = document.querySelectorAll('#logsContent .log-entry');
  1044. let visibleCount = 0;
  1045. entries.forEach(entry => {
  1046. if (!levelFilter || entry.dataset.level === levelFilter) {
  1047. entry.classList.remove('hidden');
  1048. visibleCount++;
  1049. } else {
  1050. entry.classList.add('hidden');
  1051. }
  1052. });
  1053. const countEl = document.getElementById('logsCount');
  1054. if (levelFilter) {
  1055. countEl.textContent = `${visibleCount} of ${logsEntries.length} entries (filtered)`;
  1056. } else {
  1057. countEl.textContent = `${logsEntries.length} entries`;
  1058. }
  1059. }
  1060. function updateLogsCount() {
  1061. const countEl = document.getElementById('logsCount');
  1062. const levelFilter = document.getElementById('logLevelFilter').value;
  1063. if (levelFilter) {
  1064. const filteredCount = logsEntries.filter(e => e.level === levelFilter).length;
  1065. countEl.textContent = `${filteredCount} of ${logsEntries.length} entries (filtered)`;
  1066. } else {
  1067. countEl.textContent = `${logsEntries.length} entries`;
  1068. }
  1069. }
  1070. async function clearLogs() {
  1071. try {
  1072. await fetch('/api/logs', { method: 'DELETE' });
  1073. logsEntries = [];
  1074. document.getElementById('logsContent').innerHTML = '<div class="text-gray-500 dark:text-gray-400 text-center py-4">Logs cleared</div>';
  1075. updateLogsCount();
  1076. } catch (error) {
  1077. console.error('Failed to clear logs:', error);
  1078. }
  1079. }
  1080. </script>
  1081. </body>
  1082. </html>