-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodec_tasks.html
More file actions
785 lines (730 loc) · 48.1 KB
/
codec_tasks.html
File metadata and controls
785 lines (730 loc) · 48.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CODEC — Tasks</title>
<link rel="icon" href="https://i.imgur.com/jD1X5W8.png">
<link rel="apple-touch-icon" href="https://i.imgur.com/jD1X5W8.png">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #121215; --surface: #1a1a1d; --surface-2: #212125; --surface-3: #2a2a2e;
--border: #303035; --border-hover: #424248;
--text: #ececec; --text-muted: #9a9aa0; --text-dim: #6a6a70;
--accent: #E8711A; --accent-hover: #f07d2a; --accent-dim: rgba(232,113,26,0.10);
--danger: #ef4444; --success: #22c55e; --info: #3b82f6;
--font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
--mono: 'JetBrains Mono', 'SF Mono', monospace;
--radius-sm: 6px; --radius: 10px;
}
[data-theme="light"] {
--bg: #f7f5f2; --surface: #fff; --surface-2: #f0ece6; --surface-3: #e8e4de;
--border: #d5d0ca; --border-hover: #bbb;
--text: #1a1a1a; --text-muted: #555; --text-dim: #777;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom, 0px); }
a { color: var(--accent); text-decoration: none; }
/* ── Header ── */
.header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.header-left { display: flex; align-items: center; gap: 10px; }
.header-left img { width: 32px; height: 32px; }
.header-left h1 { font-family: var(--mono); font-size: 16px; font-weight: 700; letter-spacing: 2px; color: var(--accent); }
.logo-link { display: flex; align-items: center; }
.page-nav { display: flex; align-items: center; gap: 1px; position: absolute; left: 50%; transform: translateX(-50%); background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; }
.nav-link { padding: 5px 14px; color: var(--text-muted); text-decoration: none; font-size: 12px; font-weight: 500; border-radius: 4px; transition: all 0.15s ease; white-space: nowrap; text-align: center; }
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }
.header-right { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); width: 30px; height: 30px; cursor: pointer; color: var(--text-muted); transition: all 0.15s ease; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface-2); }
.icon-btn:active { transform: scale(0.93); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); flex-shrink: 0; transition: all 0.3s; }
.status-dot.on { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,0.5); }
[data-theme="light"] .icon-btn { border-color: #bbb; color: #444; }
[data-theme="light"] .icon-btn:hover { border-color: #999; color: #1a1a1a; background: #e8e4de; }
[data-theme="light"] .nav-link.active { color: var(--accent); background: var(--accent-dim); }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }
/* ── Container ── */
.container { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
/* ── Tabs ── */
.tabs { display: flex; gap: 4px; margin-bottom: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; }
.tab { flex: 1; padding: 10px 16px; border: none; background: none; color: var(--text-muted); font-family: var(--font); font-size: 13px; font-weight: 500; cursor: pointer; border-radius: var(--radius-sm); transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 6px; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--accent); background: var(--accent-dim); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; transition: border-color 0.2s; }
.card:hover { border-color: var(--border-hover); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-title { font-size: 15px; font-weight: 600; }
.card-meta { font-size: 12px; color: var(--text-muted); font-family: var(--mono); }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
/* ── Buttons ── */
.btn { padding: 8px 16px; border-radius: var(--radius-sm); font-family: var(--font); font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); transition: all 0.2s; }
.btn:hover { border-color: var(--border-hover); background: var(--surface-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: rgba(239,68,68,0.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
/* ── Toggle ── */
.toggle-wrap { display: flex; align-items: center; gap: 8px; }
.toggle { position: relative; width: 40px; height: 22px; cursor: pointer; }
.toggle input { display: none; }
.toggle-slider { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border); border-radius: 11px; transition: all 0.2s; }
.toggle-slider::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--text-muted); border-radius: 50%; transition: all 0.2s; }
.toggle input:checked + .toggle-slider { background: var(--accent-dim); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::after { background: var(--accent); transform: translateX(18px); }
.toggle-label { font-size: 13px; color: var(--text-muted); }
/* ── Form ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: var(--font); font-size: 14px; transition: border-color 0.2s; }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--accent); }
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-dim); }
.form-textarea { min-height: 60px; resize: vertical; }
.form-select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7a7a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
/* ── New Schedule Form ── */
.new-schedule-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; display: none; }
.new-schedule-form.visible { display: block; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* ── Status badges ── */
.badge { display: inline-block; padding: 3px 8px; border-radius: var(--radius-sm); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-success { background: rgba(34,197,94,0.1); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.1); color: var(--info); }
.badge-muted { background: var(--surface-3); color: var(--text-muted); }
/* ── History ── */
.history-entry { display: grid; grid-template-columns: 160px 1fr auto auto; gap: 12px; align-items: center; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; font-size: 13px; }
.history-ts { font-family: var(--mono); font-size: 12px; color: var(--text-muted); }
.history-crew { font-weight: 500; }
.history-duration { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
/* ── Heartbeat ── */
.heartbeat-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.heartbeat-tasks { margin-top: 12px; }
.heartbeat-task-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.heartbeat-task-item:last-child { border-bottom: none; }
/* ── Reports ── */
.report-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; cursor: pointer; transition: border-color 0.2s, background 0.2s; }
.report-card:hover { border-color: var(--border-hover); background: var(--surface-2); }
.report-card.unread { border-left: 3px solid var(--accent); }
.report-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.report-title { font-size: 14px; font-weight: 600; }
.report-ts { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.report-body { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-top: 8px; white-space: pre-wrap; }
.report-actions-bar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
/* ── Notification bell ── */
.notif-bell { position: relative; }
.notif-badge { position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 4px; line-height: 1; pointer-events: none; }
.notif-badge.hidden { display: none; }
/* ── Toast ── */
.toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 10px 20px; border-radius: var(--radius); font-size: 13px; font-family: var(--font); box-shadow: 0 4px 12px rgba(0,0,0,0.3); opacity: 0; transform: translateY(10px); animation: toastIn 0.25s ease forwards; pointer-events: auto; }
.toast.out { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }
/* ── Empty state ── */
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-icon { margin-bottom: 12px; color: var(--text-dim); }
.empty-text { font-size: 14px; }
/* ── Loading ── */
.loading { text-align: center; padding: 32px; color: var(--text-dim); font-size: 13px; }
/* ── Responsive ── */
@media (max-width: 768px) {
.header { padding: 10px 12px; }
.header-left h1 { display: none; }
.page-nav{position:fixed;bottom:0;left:0;right:0;z-index:9998;transform:none;border-radius:0;padding:6px 0;justify-content:center;background:var(--surface);border-top:1px solid var(--border);gap:0}
.nav-link{padding:8px 12px;font-size:11px}
.container { padding: 16px 12px; }
.form-row { grid-template-columns: 1fr; }
.history-entry { grid-template-columns: 1fr; gap: 4px; }
}
@media (max-width: 480px) {
.tabs { flex-wrap: wrap; }
.tab { font-size: 12px; padding: 8px 12px; }
}
.webcam-pip{position:fixed;bottom:80px;right:20px;width:240px;border-radius:14px;overflow:hidden;border:2px solid var(--accent);box-shadow:0 4px 24px rgba(0,0,0,.5);z-index:9999;display:none;background:#000;transition:width .3s,height .3s,border-radius .3s}
.webcam-pip img,.webcam-pip video{width:100%;display:block}
.webcam-pip.expanded{width:640px;max-width:90vw;border-radius:10px}
.pip-bar{display:flex;justify-content:center;gap:10px;padding:6px;background:rgba(0,0,0,.6)}
.pip-btn{background:rgba(255,255,255,.15);border:none;color:#fff;width:34px;height:34px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s}
.pip-btn:hover{background:var(--accent)}
.pip-btn.snap-btn{background:rgba(255,80,80,.7)}
.pip-btn.snap-btn:hover{background:#e33}
</style>
</head>
<body>
<div class="header">
<div class="header-left">
<a href="/" class="logo-link"><img src="https://i.imgur.com/jD1X5W8.png" alt="CODEC"></a>
<h1><a href="/" style="color:inherit;text-decoration:none">CODEC</a></h1>
</div>
<nav class="page-nav">
<a href="/chat" class="nav-link">Chat</a>
<a href="/voice" class="nav-link">Voice</a>
<a href="/vibe" class="nav-link">Vibe</a>
<a href="/tasks" class="nav-link active">Tasks</a>
</nav>
<div class="header-right">
<div class="status-dot" id="statusDot" title="CODEC status"></div>
<a href="/" class="icon-btn" title="Home"><svg class="ico" viewBox="0 0 24 24"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg></a>
<button class="icon-btn" id="voiceBtn" onclick="toggleVoiceReply()" title="Voice replies"><svg class="ico" viewBox="0 0 24 24"><path d="M11 5L6 9H2v6h4l5 4V5z"/><line x1="23" y1="9" x2="17" y2="15" id="muteX1"/><line x1="17" y1="9" x2="23" y2="15" id="muteX2"/></svg></button>
<button class="icon-btn" onclick="takeScreenshot()" title="Screenshot"><svg class="ico" viewBox="0 0 24 24"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg></button>
<button class="icon-btn" id="photoBtn" onclick="takeServerPhoto()" title="Photo (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><path d="M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"/><circle cx="12" cy="13" r="4"/></svg></button>
<button class="icon-btn" id="camBtn" onclick="toggleWebcamPip()" title="Live video (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg></button>
<button class="icon-btn notif-bell" id="notifBellBtn" onclick="showTab('reports')" title="Reports"><svg class="ico" viewBox="0 0 24 24"><path d="M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 01-3.46 0"/></svg><span class="notif-badge hidden" id="notifBadge">0</span></button>
<button class="icon-btn" id="themeBtn" onclick="toggleTheme()" title="Toggle theme"><svg class="ico" viewBox="0 0 24 24" id="themeIco"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></button>
<button class="icon-btn" onclick="window.location.href='/#settings'" title="Settings"><svg class="ico" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg></button>
<button class="icon-btn" onclick="lockSession()" title="Lock"><svg class="ico" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg></button>
</div>
</div>
<div class="container">
<div class="tabs">
<button class="tab active" onclick="showTab('schedules')" id="tab-schedules"><svg class="ico ico-sm" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>Schedules</button>
<button class="tab" onclick="showTab('heartbeat')" id="tab-heartbeat"><svg class="ico ico-sm" viewBox="0 0 24 24"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>Heartbeat</button>
<button class="tab" onclick="showTab('history')" id="tab-history"><svg class="ico ico-sm" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>History</button>
<button class="tab" onclick="showTab('reports')" id="tab-reports"><svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>Reports</button>
</div>
<!-- ── Schedules Tab ── -->
<div class="tab-panel active" id="panel-schedules">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
<h2 style="font-size:16px; font-weight:600;">Scheduled Tasks</h2>
<button class="btn btn-primary btn-sm" onclick="toggleNewForm()">+ New Schedule</button>
</div>
<div class="new-schedule-form" id="newScheduleForm">
<h3 style="font-size:14px; font-weight:600; margin-bottom:14px;">Create New Schedule</h3>
<div class="form-row">
<div class="form-group">
<label class="form-label">Crew</label>
<select class="form-select" id="newCrew">
<option value="analyst">Analyst</option>
<option value="writer">Writer</option>
<option value="coder">Coder</option>
<option value="researcher">Researcher</option>
<option value="advisor">Advisor</option>
<option value="teacher">Teacher</option>
<option value="planner">Planner</option>
<option value="ops">Ops</option>
<option value="security">Security</option>
<option value="creative">Creative</option>
</select>
</div>
<div class="form-group">
<label class="form-label">Cron Expression</label>
<input class="form-input" id="newCron" placeholder="0 8 * * *" value="0 8 * * *">
</div>
</div>
<div class="form-group">
<label class="form-label">Topic / Description</label>
<input class="form-input" id="newTopic" placeholder="Daily morning briefing...">
</div>
<div class="form-group">
<div class="toggle-wrap">
<label class="toggle">
<input type="checkbox" id="newEnabled" checked>
<span class="toggle-slider"></span>
</label>
<span class="toggle-label">Enabled</span>
</div>
</div>
<div style="display:flex; gap:8px; justify-content:flex-end;">
<button class="btn btn-sm" onclick="toggleNewForm()">Cancel</button>
<button class="btn btn-primary btn-sm" onclick="createSchedule()">Create</button>
</div>
</div>
<div id="schedulesList">
<div class="loading">Loading schedules...</div>
</div>
</div>
<!-- ── Heartbeat Tab ── -->
<div class="tab-panel" id="panel-heartbeat">
<div class="heartbeat-section">
<h2 style="font-size:16px; font-weight:600; margin-bottom:16px;">Heartbeat Configuration</h2>
<div class="form-row">
<div class="form-group">
<label class="form-label">Interval (minutes)</label>
<input class="form-input" type="number" id="hbInterval" min="1" max="1440" value="5">
</div>
<div class="form-group">
<label class="form-label">Status</label>
<div class="toggle-wrap" style="margin-top:8px;">
<label class="toggle">
<input type="checkbox" id="hbEnabled" checked>
<span class="toggle-slider"></span>
</label>
<span class="toggle-label" id="hbStatusLabel">Enabled</span>
</div>
</div>
</div>
<div class="form-group">
<label class="form-label">Tasks</label>
<div class="heartbeat-tasks" id="hbTasksList"></div>
<div style="display:flex; gap:8px; margin-top:10px;">
<input class="form-input" id="newHbTask" placeholder="Add a task..." style="flex:1;">
<button class="btn btn-sm" onclick="addHbTask()">Add</button>
</div>
</div>
<div style="margin-top:16px; display:flex; justify-content:flex-end;">
<button class="btn btn-primary" onclick="saveHeartbeat()">Save Configuration</button>
</div>
</div>
</div>
<!-- ── History Tab ── -->
<div class="tab-panel" id="panel-history">
<h2 style="font-size:16px; font-weight:600; margin-bottom:16px;">Run History</h2>
<div id="historyList">
<div class="loading">Loading history...</div>
</div>
</div>
<!-- ── Reports Tab ── -->
<div class="tab-panel" id="panel-reports">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
<h2 style="font-size:16px; font-weight:600;">Task Reports</h2>
<button class="btn btn-sm" onclick="markAllReportsRead()">Mark All Read</button>
</div>
<div id="reportsList">
<div class="loading">Loading reports...</div>
</div>
</div>
</div>
<div class="toast-container" id="toastContainer"></div>
<script>
// CSRF: auto-inject token header on state-changing requests
(function(){var _f=window.fetch;window.fetch=function(u,o){o=o||{};if(o.method&&o.method!=='GET'){var c=document.cookie.match(/codec_csrf=([^;]+)/);if(c){o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-csrf-token',c[1])}else{o.headers['x-csrf-token']=c[1]}}}return _f.call(this,u,o)}})();
// E2E encryption layer — AES-256-GCM via ECDH key exchange
var _e2eKey=null;
(function(){var _f2=window.fetch;function _b64(buf){return btoa(String.fromCharCode.apply(null,new Uint8Array(buf)))}function _unb64(s){var b=atob(s),a=new Uint8Array(b.length);for(var i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a}
window._e2eNegotiate=function(){return crypto.subtle.generateKey({name:'ECDH',namedCurve:'P-256'},true,['deriveBits']).then(function(kp){return crypto.subtle.exportKey('raw',kp.publicKey).then(function(pub){return _f2('/api/auth/keyexchange',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pub:_b64(pub)})}).then(function(r){return r.json()}).then(function(d){var srvPub=_unb64(d.pub);return crypto.subtle.importKey('raw',srvPub,{name:'ECDH',namedCurve:'P-256'},false,[]).then(function(srvKey){return crypto.subtle.deriveBits({name:'ECDH',public:srvKey},kp.privateKey,256)}).then(function(bits){return crypto.subtle.importKey('raw',bits,{name:'HKDF'},false,['deriveKey'])}).then(function(hkdfKey){return crypto.subtle.deriveKey({name:'HKDF',hash:'SHA-256',salt:new Uint8Array(0),info:new TextEncoder().encode('codec-e2e')},hkdfKey,{name:'AES-GCM',length:256},false,['encrypt','decrypt'])}).then(function(k){_e2eKey=k;sessionStorage.setItem('_e2eReady','1')})})})}).catch(function(e){console.warn('E2E negotiation failed:',e)})};
window.fetch=function(u,o){o=o||{};if(!_e2eKey)return _f2.call(this,u,o);var method=(o.method||'GET').toUpperCase();if(method!=='GET'&&o.body){var iv=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:'AES-GCM',iv:iv},_e2eKey,new TextEncoder().encode(o.body)).then(function(ct){o.body=JSON.stringify({iv:_b64(iv),ct:_b64(ct)});o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-e2e','1');o.headers.set('Content-Type','application/json')}else{o.headers['x-e2e']='1';o.headers['Content-Type']='application/json'}return _f2.call(this,u,o)}.bind(this)).then(_decResp)}return _f2.call(this,u,o).then(_decResp)};
function _decResp(r){if(!_e2eKey||r.headers.get('x-e2e')!=='1')return r;return r.clone().json().then(function(d){if(!d.iv||!d.ct)return r;var iv=_unb64(d.iv),ct=_unb64(d.ct);return crypto.subtle.decrypt({name:'AES-GCM',iv:iv},_e2eKey,ct).then(function(pt){var txt=new TextDecoder().decode(pt);return new Response(txt,{status:r.status,headers:r.headers})})}).catch(function(){return r})}
if(sessionStorage.getItem('_e2eReady'))window._e2eNegotiate();
})();
/* ── Theme ── */
function toggleTheme(){var t=document.documentElement.getAttribute('data-theme')==='light'?'dark':'light';document.documentElement.setAttribute('data-theme',t);localStorage.setItem('codec-theme',t);updateThemeIcon(t)}
function updateThemeIcon(t){var ico=document.getElementById('themeIco');if(t==='light'){ico.innerHTML='<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/>'}else{ico.innerHTML='<circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>'}}
function lockSession(){fetch('/api/auth/logout',{method:'POST'}).then(function(){document.cookie='codec_session=;path=/;max-age=0;SameSite=Strict'+(location.protocol==='https:'?';Secure':'');window.location.href='/auth'})}
var _voiceOn=false;
function toggleVoiceReply(){_voiceOn=!_voiceOn;updateVoiceIcon()}
function updateVoiceIcon(){var b=document.getElementById('voiceBtn');if(!b)return;var m1=document.getElementById('muteX1'),m2=document.getElementById('muteX2');if(m1)m1.style.display=_voiceOn?'none':'';if(m2)m2.style.display=_voiceOn?'none':'';b.style.borderColor=_voiceOn?'var(--accent)':''}
function takeScreenshot(){fetch('/api/screenshot',{method:'POST'}).then(function(r){return r.json()}).then(function(d){if(d.path)alert('Screenshot saved: '+d.path)}).catch(function(){})}
// ── Server Photo (Mac webcam) ──
function takeServerPhoto() {
var btn = document.getElementById('photoBtn');
btn.style.borderColor = 'var(--accent)';
showToast('Capturing from Mac webcam...');
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
btn.style.borderColor = '';
if (d.error) { showToast('Error: ' + d.error); return; }
showToast('Photo saved: ' + d.filename);
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) showToast(d2.analysis);
});
}).catch(function(e) { btn.style.borderColor = ''; showToast('Camera error: ' + e.message); });
}
// ── Live Webcam PIP (Mac MJPEG stream) ──
var _pipDrag = { active: false, x: 0, y: 0 };
function toggleWebcamPip() {
var pip = document.getElementById('webcamPip');
if (pip.style.display === 'block') { closeWebcamPip(); return; }
var img = document.getElementById('pipVideo');
img.src = '/api/webcam/stream?' + Date.now();
pip.style.display = 'block';
document.getElementById('camBtn').style.borderColor = 'var(--accent)';
}
function closeWebcamPip() {
var img = document.getElementById('pipVideo');
img.src = '';
document.getElementById('webcamPip').style.display = 'none';
document.getElementById('webcamPip').classList.remove('expanded');
var btn = document.getElementById('camBtn'); if (btn) btn.style.borderColor = '';
}
function expandPip() {
document.getElementById('webcamPip').classList.toggle('expanded');
}
function snapFromPip() {
showToast('Snapshot from Mac webcam...');
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
if (d.error) { showToast('Error: ' + d.error); return; }
showToast('Photo saved: ' + d.filename);
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) showToast(d2.analysis);
});
}).catch(function(e) { showToast('Snap error: ' + e.message); });
}
function savePipFrame() {
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
if (d.filename) showToast('Saved: ' + d.filename);
else showToast('Error saving');
}).catch(function(e) { showToast('Save error: ' + e.message); });
}
(function() {
var pip = document.getElementById('webcamPip'); if (!pip) return;
pip.addEventListener('mousedown', function(e) {
if (e.target.closest('.pip-btn')) return;
_pipDrag = { active: true, x: e.clientX - pip.offsetLeft, y: e.clientY - pip.offsetTop };
});
document.addEventListener('mousemove', function(e) {
if (!_pipDrag.active) return;
pip.style.left = (e.clientX - _pipDrag.x) + 'px';
pip.style.top = (e.clientY - _pipDrag.y) + 'px';
pip.style.right = 'auto'; pip.style.bottom = 'auto';
});
document.addEventListener('mouseup', function() { _pipDrag.active = false; });
})();
function pollStatus(){fetch('/api/health').then(function(r){return r.json()}).then(function(d){var dot=document.getElementById('statusDot');if(dot){dot.classList.toggle('on',!!d.ok)}}).catch(function(){var dot=document.getElementById('statusDot');if(dot)dot.classList.remove('on')})}
pollStatus();setInterval(pollStatus,15000);
(function(){var s=localStorage.getItem('codec-theme');if(s==='light'){document.documentElement.setAttribute('data-theme','light');updateThemeIcon('light')}})();
/* ── Tabs ── */
function showTab(name) {
document.querySelectorAll('.tab').forEach(function(t){ t.classList.remove('active'); });
document.querySelectorAll('.tab-panel').forEach(function(p){ p.classList.remove('active'); });
document.getElementById('tab-' + name).classList.add('active');
document.getElementById('panel-' + name).classList.add('active');
window.location.hash = name;
if (name === 'reports') loadReports();
}
/* ── Toast ── */
function showToast(msg) {
var container = document.getElementById('toastContainer');
var el = document.createElement('div');
el.className = 'toast';
el.textContent = msg;
container.appendChild(el);
setTimeout(function(){ el.classList.add('out'); }, 2700);
setTimeout(function(){ el.remove(); }, 3000);
}
/* ── Schedules ── */
var schedules = [];
function loadSchedules() {
fetch('/api/schedules').then(function(r){ return r.json(); }).then(function(data) {
schedules = data.schedules || [];
renderSchedules();
}).catch(function() {
document.getElementById('schedulesList').innerHTML = '<div class="empty"><div class="empty-icon"><svg style="width:28px;height:28px;display:inline-block;vertical-align:middle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg></div><div class="empty-text">Could not load schedules</div></div>';
});
}
function renderSchedules() {
var el = document.getElementById('schedulesList');
if (!schedules.length) {
el.innerHTML = '<div class="empty"><div class="empty-icon"><svg style="width:28px;height:28px;display:inline-block;vertical-align:middle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg></div><div class="empty-text">No scheduled tasks yet. Click "+ New Schedule" to create one.</div></div>';
return;
}
var html = '';
schedules.forEach(function(s) {
var enabled = s.enabled !== false;
var cronStr = s.cron || (s.hour !== undefined ? (s.minute || 0) + ' ' + s.hour + ' * * ' + (Array.isArray(s.days) ? s.days.join(',') : (s.days || '*')) : 'N/A');
var lastRun = s.last_run || 'Never';
html += '<div class="card">';
html += '<div class="card-header">';
html += '<div><span class="card-title">' + escHtml(s.crew || 'Unknown') + '</span>';
if (s.topic) html += '<div style="font-size:12px;color:var(--text-muted);margin-top:2px;">' + escHtml(s.topic) + '</div>';
html += '</div>';
html += '<div class="toggle-wrap">';
html += '<label class="toggle"><input type="checkbox" ' + (enabled ? 'checked' : '') + ' onchange="toggleSchedule(\'' + s.id + '\', this.checked)"><span class="toggle-slider"></span></label>';
html += '<span class="badge ' + (enabled ? 'badge-success' : 'badge-muted') + '">' + (enabled ? 'Active' : 'Disabled') + '</span>';
html += '</div></div>';
html += '<div style="display:flex;gap:16px;font-size:12px;color:var(--text-muted);">';
html += '<span style="font-family:var(--mono);"><svg style="width:12px;height:12px;display:inline-block;vertical-align:middle;margin-right:3px" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>' + escHtml(cronStr) + '</span>';
html += '<span>Last run: ' + escHtml(lastRun) + '</span>';
html += '</div>';
html += '<div class="card-actions">';
html += '<button class="btn btn-sm btn-primary" onclick="runNow(\'' + s.id + '\')">Run Now</button>';
html += '<button class="btn btn-sm" style="background:var(--accent);color:#fff" onclick="editSchedule(\'' + s.id + '\')">Edit</button>';
html += '<button class="btn btn-sm btn-danger" onclick="deleteSchedule(\'' + s.id + '\')">Delete</button>';
html += '</div></div>';
});
el.innerHTML = html;
}
function toggleNewForm() {
var f = document.getElementById('newScheduleForm');
f.classList.toggle('visible');
}
function createSchedule() {
var cronParts = document.getElementById('newCron').value.trim().split(/\s+/);
var payload = {
crew: document.getElementById('newCrew').value,
topic: document.getElementById('newTopic').value,
minute: parseInt(cronParts[0]) || 0,
hour: parseInt(cronParts[1]) || 8,
days: cronParts.length >= 5 ? cronParts[4] : '*'
};
fetch('/api/schedules', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload) })
.then(function(r){ return r.json(); })
.then(function() {
toggleNewForm();
document.getElementById('newTopic').value = '';
loadSchedules();
})
.catch(function(e){ alert('Error creating schedule: ' + e); });
}
function toggleSchedule(id, enabled) {
fetch('/api/schedules/' + id, { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ enabled: enabled }) })
.then(function(){ loadSchedules(); });
}
function runNow(id) {
fetch('/api/schedules/' + id + '/run', { method: 'POST' })
.then(function(r){ return r.json(); })
.then(function(data) {
if (data.status === 'running') {
showToast('⏳ Task running — switching to Reports...');
setTimeout(function(){ showTab('reports'); loadReports(); }, 800);
} else {
showToast(data.error || 'Failed to trigger task');
}
})
.catch(function(e){ showToast('Error: ' + e); });
}
function editSchedule(id) {
var sched = schedules.find(function(s) { return s.id === id; });
if (!sched) return;
var presets = {
'every12h': '0 */12 * * *',
'every24h': '0 8 * * *',
'daily8am': '0 8 * * *',
'weekly': '0 9 * * 1',
'custom': ''
};
var currentCron = (sched.cron || []).join(' ');
var choice = prompt(
'Edit schedule for: ' + (sched.crew || 'task') + '\n\n' +
'Current: ' + currentCron + '\n\n' +
'Enter new cron (5 fields) or a preset:\n' +
' every12h = every 12 hours\n' +
' daily = every day at 8am\n' +
' weekly = every Monday 9am\n' +
' Or type custom cron: "0 */6 * * *"',
currentCron
);
if (!choice) return;
var cron = presets[choice.trim().toLowerCase()] || choice.trim();
var parts = cron.split(/\s+/);
if (parts.length !== 5) { alert('Invalid cron — need 5 fields (min hour dom month dow)'); return; }
fetch('/api/schedules/' + id, {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({cron: parts})
}).then(function() { loadSchedules(); }).catch(function(e) { alert('Error: ' + e); });
}
function deleteSchedule(id) {
if (!confirm('Delete this schedule?')) return;
fetch('/api/schedules/' + id, { method: 'DELETE' })
.then(function(){ loadSchedules(); })
.catch(function(e){ alert('Error: ' + e); });
}
/* ── Heartbeat ── */
var hbTasks = [];
function loadHeartbeat() {
fetch('/api/heartbeat/config').then(function(r){ return r.json(); }).then(function(data) {
document.getElementById('hbInterval').value = data.interval_minutes || 5;
document.getElementById('hbEnabled').checked = data.enabled !== false;
document.getElementById('hbStatusLabel').textContent = data.enabled !== false ? 'Enabled' : 'Disabled';
hbTasks = data.tasks || ['status_check'];
renderHbTasks();
}).catch(function() {
hbTasks = ['status_check'];
renderHbTasks();
});
}
function renderHbTasks() {
var el = document.getElementById('hbTasksList');
if (!hbTasks.length) {
el.innerHTML = '<div style="font-size:13px;color:var(--text-dim);padding:8px 0;">No tasks configured</div>';
return;
}
var html = '';
hbTasks.forEach(function(task, i) {
html += '<div class="heartbeat-task-item">';
html += '<span style="font-family:var(--mono);font-size:13px;flex:1;">' + escHtml(task) + '</span>';
html += '<button class="btn btn-sm btn-danger" onclick="removeHbTask(' + i + ')" style="padding:3px 8px;">✕</button>';
html += '</div>';
});
el.innerHTML = html;
}
function addHbTask() {
var inp = document.getElementById('newHbTask');
var val = inp.value.trim();
if (!val) return;
hbTasks.push(val);
inp.value = '';
renderHbTasks();
}
function removeHbTask(i) {
hbTasks.splice(i, 1);
renderHbTasks();
}
function saveHeartbeat() {
var payload = {
enabled: document.getElementById('hbEnabled').checked,
interval_minutes: parseInt(document.getElementById('hbInterval').value) || 5,
tasks: hbTasks
};
fetch('/api/heartbeat/config', { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload) })
.then(function(r){ return r.json(); })
.then(function(data) {
if (data.saved) alert('Heartbeat configuration saved.');
else alert('Error saving configuration.');
})
.catch(function(e){ alert('Error: ' + e); });
}
/* ── History ── */
function loadHistory() {
fetch('/api/schedules/history').then(function(r){ return r.json(); }).then(function(data) {
var el = document.getElementById('historyList');
if (!data || !data.length) {
el.innerHTML = '<div class="empty"><div class="empty-icon"><svg style="width:28px;height:28px;display:inline-block;vertical-align:middle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg></div><div class="empty-text">No run history yet. Scheduled tasks will appear here after they run.</div></div>';
return;
}
var html = '';
data.forEach(function(entry) {
var line = entry.line || '';
// Try to parse structured entries: "timestamp | crew | status | duration | result"
var parts = line.split('|').map(function(s){ return s.trim(); });
if (parts.length >= 3) {
var status = (parts[2] || '').toLowerCase();
var badgeClass = status === 'success' ? 'badge-success' : status === 'failed' ? 'badge-danger' : 'badge-info';
html += '<div class="history-entry">';
html += '<span class="history-ts">' + escHtml(parts[0]) + '</span>';
html += '<span class="history-crew">' + escHtml(parts[1]) + '</span>';
html += '<span class="badge ' + badgeClass + '">' + escHtml(parts[2]) + '</span>';
html += '<span class="history-duration">' + escHtml(parts[3] || '') + '</span>';
html += '</div>';
} else {
html += '<div class="card" style="padding:10px;margin-bottom:6px;"><span style="font-family:var(--mono);font-size:12px;">' + escHtml(line) + '</span></div>';
}
});
el.innerHTML = html;
}).catch(function() {
document.getElementById('historyList').innerHTML = '<div class="empty"><div class="empty-icon"><svg style="width:28px;height:28px;display:inline-block;vertical-align:middle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg></div><div class="empty-text">No run history available.</div></div>';
});
}
/* ── Reports ── */
var reports = [];
var _reportPollTimer = null;
function loadReports() {
fetch('/api/notifications').then(function(r){ return r.json(); }).then(function(data) {
reports = (data.notifications || data || []).filter(function(n){ return n.type === 'task_report'; });
renderReports();
// Auto-refresh every 5s if any task is still running
var hasRunning = reports.some(function(r){ return r.status === 'running'; });
if (hasRunning && !_reportPollTimer) {
_reportPollTimer = setInterval(function(){ loadReports(); }, 5000);
} else if (!hasRunning && _reportPollTimer) {
clearInterval(_reportPollTimer);
_reportPollTimer = null;
}
}).catch(function() {
document.getElementById('reportsList').innerHTML = '<div class="empty"><div class="empty-icon"><svg style="width:28px;height:28px;display:inline-block;vertical-align:middle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg></div><div class="empty-text">Could not load reports</div></div>';
});
}
function renderReports() {
var el = document.getElementById('reportsList');
if (!reports.length) {
el.innerHTML = '<div class="empty"><div class="empty-icon"><svg style="width:28px;height:28px;display:inline-block;vertical-align:middle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg></div><div class="empty-text">No task reports yet. Reports will appear here after scheduled tasks run.</div></div>';
return;
}
var html = '';
reports.forEach(function(r) {
var isUnread = !r.read;
var status = (r.status || 'info').toLowerCase();
var badgeClass = status === 'success' ? 'badge-success' : status === 'error' || status === 'failed' ? 'badge-danger' : status === 'running' ? 'badge-info' : status === 'warning' ? 'badge-info' : 'badge-muted';
var statusLabel = status === 'running' ? '⏳ Running...' : status;
var ts = r.timestamp ? new Date(r.timestamp).toLocaleString() : (r.created ? new Date(r.created).toLocaleString() : '');
html += '<div class="report-card' + (isUnread ? ' unread' : '') + '" onclick="markReportRead(\'' + r.id + '\', this)">';
html += '<div class="report-header">';
html += '<span class="report-title">' + escHtml(r.title || 'Task Report') + '</span>';
html += '<div style="display:flex;align-items:center;gap:8px;">';
html += '<span class="badge ' + badgeClass + '">' + escHtml(statusLabel) + '</span>';
html += '<span class="report-ts">' + escHtml(ts) + '</span>';
html += '</div></div>';
if (r.doc_url) {
html += '<div style="margin:8px 0;"><a href="' + escHtml(r.doc_url) + '" target="_blank" class="btn btn-primary btn-sm" style="text-decoration:none;display:inline-flex;align-items:center;gap:6px;" onclick="event.stopPropagation()"><svg style="width:14px;height:14px" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Open Full Report</a></div>';
}
if (r.body || r.message) {
var bodyText = escHtml(r.body || r.message);
bodyText = bodyText.replace(/📄\s*\[View Full Report\]\([^)]+\)\n*/g, '');
if (bodyText.trim()) {
html += '<div class="report-body">' + bodyText.substring(0, 500) + (bodyText.length > 500 ? '...' : '') + '</div>';
}
}
html += '</div>';
});
el.innerHTML = html;
}
function markReportRead(id, el) {
if (el) el.classList.remove('unread');
fetch('/api/notifications/' + id + '/read', { method: 'POST' }).then(function() {
pollNotifCount();
}).catch(function(){});
}
function markAllReportsRead() {
var promises = [];
reports.forEach(function(r) {
if (!r.read) {
promises.push(fetch('/api/notifications/' + r.id + '/read', { method: 'POST' }));
}
});
Promise.all(promises).then(function() {
document.querySelectorAll('.report-card.unread').forEach(function(el){ el.classList.remove('unread'); });
reports.forEach(function(r){ r.read = true; });
pollNotifCount();
}).catch(function(){});
}
/* ── Notification badge polling ── */
function pollNotifCount() {
fetch('/api/notifications/count').then(function(r){ return r.json(); }).then(function(data) {
var count = data.unread || data.count || 0;
var badge = document.getElementById('notifBadge');
if (badge) {
badge.textContent = count;
badge.classList.toggle('hidden', count === 0);
}
}).catch(function(){});
}
/* ── Utils ── */
function escHtml(s) {
var d = document.createElement('div');
d.textContent = s;
return d.innerHTML;
}
/* ── Init ── */
document.addEventListener('DOMContentLoaded', function() {
loadSchedules();
loadHeartbeat();
loadHistory();
pollNotifCount();
setInterval(pollNotifCount, 30000);
// Handle hash-based tab navigation
var hash = window.location.hash.replace('#', '');
if (hash && document.getElementById('tab-' + hash)) {
showTab(hash);
}
});
/* ── Toggle label update ── */
document.addEventListener('DOMContentLoaded', function() {
var hbCheck = document.getElementById('hbEnabled');
if (hbCheck) {
hbCheck.addEventListener('change', function() {
document.getElementById('hbStatusLabel').textContent = this.checked ? 'Enabled' : 'Disabled';
});
}
});
</script>
<div class="webcam-pip" id="webcamPip">
<img id="pipVideo" alt="Mac Webcam" onclick="expandPip()" style="cursor:pointer" />
<div class="pip-bar">
<button class="pip-btn snap-btn" onclick="snapFromPip()" title="Snapshot + Analyze"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="4"/></svg></button>
<button class="pip-btn" onclick="savePipFrame()" title="Save photo"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/></svg></button>
<button class="pip-btn" onclick="expandPip()" title="Expand / Shrink"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button>
<button class="pip-btn" onclick="closeWebcamPip()" title="Close"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button>
</div>
</div>
</body>
</html>