-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1504 lines (1328 loc) · 79.5 KB
/
Copy pathindex.html
File metadata and controls
1504 lines (1328 loc) · 79.5 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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Student Support Intelligence Dashboard</title>
<link href="https://fonts.googleapis.com" rel="preconnect" />
<link crossorigin="" href="https://fonts.gstatic.com" rel="preconnect" />
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600;700&display=swap"
rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap"
rel="stylesheet" />
<script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
<script id="tailwind-config">
tailwind.config = {
darkMode: "class",
theme: {
extend: {
colors: {
"primary": "#137fec",
"primary-dark": "#0b5ed7",
"secondary": "#6c757d",
"success": "#198754",
"danger": "#dc3545",
"warning": "#ffc107",
"background-light": "#f8f9fa",
"background-dark": "#212529",
"surface-light": "#ffffff",
"surface-dark": "#2c3034",
"border-light": "#dee2e6",
"border-dark": "#373b3e"
},
fontFamily: { "display": ["Lexend", "sans-serif"] }
}
}
}
</script>
<style>
body {
font-family: 'Lexend', sans-serif;
}
.material-symbols-outlined {
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.course-card {
opacity: 0;
transform: translateY(20px);
}
.audit-enter {
animation: slideDown 0.3s ease-out forwards;
}
@keyframes slideDown {
from {
opacity: 0;
max-height: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
max-height: 2000px;
transform: translateY(0);
}
}
.audit-badge-ontime {
background: #dcfce7;
color: #166534;
}
.audit-badge-late {
background: #fee2e2;
color: #991b1b;
}
.drop-arrow {
transition: transform 0.2s ease;
}
.drop-arrow.rotated {
transform: rotate(180deg);
}
.tab-btn {
padding: 0.5rem 1.25rem;
font-size: 0.875rem;
font-weight: 600;
border-radius: 0.5rem 0.5rem 0 0;
border: 1px solid transparent;
border-bottom: none;
cursor: pointer;
transition: all 0.15s;
color: #6c757d;
background: transparent;
}
.tab-btn:hover {
color: #212529;
background: #f8f9fa;
}
.tab-btn.active {
color: #137fec;
background: #fff;
border-color: #dee2e6;
}
.history-cell {
min-width: 110px;
flex-shrink: 0;
}
.delta-up {
color: #16a34a;
}
.delta-down {
color: #dc2626;
}
.delta-same {
color: #9ca3af;
}
.delta-new {
color: #2563eb;
}
.group-btn {
padding: 0.375rem 0.875rem;
font-size: 0.75rem;
font-weight: 600;
border-radius: 9999px;
border: 1px solid #dee2e6;
cursor: pointer;
transition: all 0.15s;
color: #6c757d;
background: #fff;
}
.group-btn:hover {
border-color: #137fec;
color: #137fec;
}
.group-btn.active {
background: #137fec;
color: #fff;
border-color: #137fec;
}
</style>
<script>
// Public demo mode: provides google.script.run when this page is opened outside Apps Script.
(function () {
if (window.google && window.google.script && window.google.script.run) return;
const today = new Date();
const iso = days => new Date(today.getTime() + days * 86400000).toISOString();
const dashboard = {
studentName: "Jordan Sample",
gsCoachingCourse: { courseId: "10001", courseName: "Student Success Seminar" },
courses: [
{ courseId: "20001", name: "Project Management 201", grade: "91.4% A-", gradeStatus: "#38b48b", missing: 1, late: 1, upcoming: 2, missingList: [{ name: "Reflection memo" }], lateList: [{ name: "Sprint retrospective" }], upcomingList: [{ name: "Team plan" }, { name: "Quiz 4" }] },
{ courseId: "20002", name: "Business Analytics 110", grade: "78.2% C+", gradeStatus: "#e8a44c", missing: 2, late: 0, upcoming: 1, missingList: [{ name: "Data lab" }, { name: "Chart review" }], lateList: [], upcomingList: [{ name: "Dashboard draft" }] }
]
};
const audit = {
audits: [{
courseName: "Project Management 201",
onTimeCount: 2,
lateCount: 1,
missingCount: 1,
upcomingCount: 1,
onTime: [{ name: "Planning worksheet", dueAt: iso(-6), submittedAt: iso(-6), score: 9, pointsPossible: 10 }],
late: [{ name: "Sprint retrospective", dueAt: iso(-4), submittedAt: iso(-2), score: 8, pointsPossible: 10 }],
missing: [{ name: "Reflection memo", dueAt: iso(-1), score: null, pointsPossible: 10 }],
upcoming: [{ name: "Team plan", dueAt: iso(3) }]
}]
};
const calls = {
getDashboardData: () => dashboard,
getWatchListAccess: () => ({ allowed: true }),
getRiskListData: () => ({
snapshotDate: today.toLocaleDateString(),
lastUpdated: today.toISOString(),
rows: [
{ studentName: "Jordan Sample", iNumber: "SAMPLE-001", canvasId: "10001", riskScore: 78, riskLevel: "high", riskRank: 1, riskPercentile: 95, trend7Day: 8, summaryReasons: ["Missing work", "Recent grade drop"] },
{ studentName: "Taylor Demo", iNumber: "SAMPLE-002", canvasId: "10002", riskScore: 42, riskLevel: "concern", riskRank: 2, riskPercentile: 70, trend7Day: -3, summaryReasons: ["Low participation"] }
]
}),
getGradeHistoryData: () => ({
periods: [
{ label: "Week 1", sublabel: "Sample", courses: [{ courseId: "20001", name: "Project Management 201", grade: "88%", direction: "new", delta: 0 }] },
{ label: "Week 2", sublabel: "Sample", courses: [{ courseId: "20001", name: "Project Management 201", grade: "91%", direction: "up", delta: 3 }] }
]
}),
getIntervalAssignmentAudit: () => audit
};
function runner(success, failure) {
return new Proxy({}, {
get(_target, prop) {
if (prop === "withSuccessHandler") return fn => runner(fn, failure);
if (prop === "withFailureHandler") return fn => runner(success, fn);
return (...args) => setTimeout(() => {
try {
const value = calls[prop] ? calls[prop](...args) : {};
if (success) success(value);
} catch (error) {
if (failure) failure(error);
}
}, 150);
}
});
}
window.google = { script: { run: runner(null, null) } };
})();
</script>
</head>
<body
class="bg-background-light dark:bg-background-dark min-h-screen flex flex-col font-display text-[#212529] dark:text-[#f8f9fa]">
<header class="bg-[#212529] text-white px-6 py-3 flex items-center justify-between shadow-sm sticky top-0 z-50">
<div class="flex items-center gap-3">
<span class="material-symbols-outlined text-primary text-3xl">school</span>
<h1 class="text-lg font-medium tracking-wide">Student Support Intelligence Dashboard</h1>
</div>
</header>
<main class="flex-1 w-full max-w-[1200px] mx-auto p-4 md:p-8 flex flex-col gap-8">
<section class="flex flex-col items-center justify-center py-8">
<div class="w-full max-w-2xl text-center space-y-6">
<div class="space-y-2">
<h2 class="text-3xl font-bold text-gray-800 dark:text-white">Student Search</h2>
<p class="text-secondary dark:text-gray-400">Enter a student's I-Number to view their live Canvas
report.</p>
</div>
<div
class="flex w-full shadow-sm rounded-lg overflow-hidden border border-border-light dark:border-border-dark bg-white dark:bg-surface-dark">
<div class="pl-4 flex items-center justify-center text-secondary">
<span class="material-symbols-outlined">search</span>
</div>
<input id="searchInput"
class="w-full border-none focus:ring-0 text-base py-4 px-4 bg-transparent placeholder-gray-400 dark:text-white"
placeholder="Enter Student I-Number (e.g. 123456789)" type="text" />
<button id="searchBtn"
class="bg-primary hover:bg-primary-dark text-white px-8 font-medium transition-colors flex items-center gap-2">
Search
</button>
</div>
</div>
</section>
<div id="errorBanner"
class="hidden bg-red-50 border border-red-300 text-red-800 rounded-lg p-4 text-sm font-medium">
<div class="flex items-center gap-2 mb-1">
<span class="material-symbols-outlined text-red-600">error</span>
<strong>Error</strong>
</div>
<p id="errorMessage"></p>
</div>
<div id="loadingState" class="hidden flex-col items-center justify-center py-12">
<span class="material-symbols-outlined animate-spin text-primary text-5xl mb-4">progress_activity</span>
<p class="text-secondary font-medium">Fetching live Canvas data...</p>
</div>
<div id="dashboardContent" class="flex flex-col gap-8">
<section
id="studentSummarySection"
class="hidden bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm p-6">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-6">
<div class="flex items-center gap-4">
<div
class="h-16 w-16 rounded-full bg-gray-100 dark:bg-gray-700 flex items-center justify-center border border-gray-200 dark:border-gray-600">
<span class="material-symbols-outlined text-4xl text-gray-400">person</span>
</div>
<div>
<h3 id="ui-studentName" class="text-2xl font-bold text-gray-900 dark:text-white">Student
Name</h3>
<p class="text-secondary dark:text-gray-400 text-sm">ID: <span id="ui-studentId">---</span>
</p>
</div>
</div>
<div id="gradebookLinkContainer" class="hidden">
<a id="gradebookLink" href="#" target="_blank"
class="inline-flex items-center gap-2 px-5 py-3 bg-gradient-to-r from-primary to-primary-dark text-white font-bold rounded-lg shadow-md hover:shadow-lg hover:scale-[1.02] transition-all duration-200">
<span class="material-symbols-outlined">open_in_new</span>
<span id="gradebookLinkText">Open Canvas Gradebook for Notes</span>
</a>
</div>
</div>
</section>
<!-- Tab Navigation -->
<div class="flex gap-1 border-b border-border-light dark:border-border-dark">
<button id="tabDashboard" class="tab-btn active" onclick="switchTab('dashboard')">
<span class="material-symbols-outlined text-[18px] align-middle mr-1">grid_view</span>Dashboard
</button>
<button id="tabHistory" class="tab-btn" onclick="switchTab('history')">
<span class="material-symbols-outlined text-[18px] align-middle mr-1">timeline</span>Grade History
</button>
<button id="tabWatch" class="tab-btn hidden" onclick="switchTab('watch')">
<span class="material-symbols-outlined text-[18px] align-middle mr-1">monitoring</span>Watch List
</button>
</div>
<!-- Watch List Tab Content -->
<div id="watchListTabContent" class="hidden flex-col gap-6">
<section class="bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm p-6">
<div class="flex flex-col lg:flex-row lg:items-end justify-between gap-4">
<div>
<h3 class="text-xl font-bold text-gray-800 dark:text-white flex items-center gap-2">
<span class="material-symbols-outlined text-primary">monitoring</span>
Watch List
</h3>
<p id="watchListUpdated" class="text-xs text-secondary mt-1">Not loaded. Use the button when you are ready to view tutor watch items.</p>
</div>
<div class="flex flex-wrap items-center gap-3">
<div class="flex items-center gap-2">
<span class="material-symbols-outlined text-secondary text-[18px]">search</span>
<input id="watchSearchInput"
class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm text-sm"
placeholder="Search students" type="text" />
</div>
<select id="watchRiskFilter"
class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm text-sm">
<option value="all">All Risk</option>
<option value="critical">Critical</option>
<option value="high">High Risk</option>
<option value="concern">Concern</option>
<option value="monitor">Monitor</option>
<option value="healthy">Healthy</option>
</select>
<select id="watchSortSelect"
class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm text-sm">
<option value="risk">Sort: Risk</option>
<option value="trend">Sort: Trend</option>
<option value="name">Sort: Name</option>
</select>
<button id="watchRefreshButton"
class="inline-flex items-center gap-2 px-4 py-2 bg-primary hover:bg-primary-dark text-white rounded-lg font-medium text-sm transition-colors shadow-sm">
<span class="material-symbols-outlined text-[18px]">refresh</span>
Load Watch List
</button>
</div>
</div>
</section>
<div id="watchListLoadingState" class="hidden flex items-center gap-3 p-6 justify-center">
<span class="material-symbols-outlined animate-spin text-primary text-3xl">progress_activity</span>
<span class="text-secondary font-medium text-sm">Loading watch list...</span>
</div>
<div id="watchListEmpty" class="hidden p-10 text-center text-gray-400 italic bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm"></div>
<section class="bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="bg-gray-50 dark:bg-gray-800 border-b border-border-light dark:border-border-dark">
<tr class="text-left text-xs uppercase tracking-wider text-secondary">
<th class="px-4 py-3 font-bold">Student</th>
<th class="px-4 py-3 font-bold min-w-[280px]">Risk Index</th>
<th class="px-4 py-3 font-bold">Trend</th>
<th class="px-4 py-3 font-bold">Key Reasons</th>
</tr>
</thead>
<tbody id="watchListRows" class="divide-y divide-border-light dark:divide-border-dark"></tbody>
</table>
</div>
</section>
</div>
<!-- Dashboard Tab Content -->
<div id="dashboardTabContent">
<section
class="bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm p-6">
<div class="flex flex-col gap-4">
<div class="flex flex-wrap items-center gap-4">
<div class="flex items-center gap-2">
<span class="material-symbols-outlined text-primary">calendar_month</span>
<label for="lastApptDate"
class="text-sm font-bold text-gray-800 dark:text-white">From:</label>
</div>
<input type="date" id="lastApptDate"
class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm focus:border-primary focus:ring focus:ring-primary/50 text-sm" />
<div class="flex items-center gap-2">
<label for="untilDate"
class="text-sm font-bold text-gray-800 dark:text-white">Until:</label>
</div>
<input type="date" id="untilDate"
class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm focus:border-primary focus:ring focus:ring-primary/50 text-sm" />
</div>
<div class="flex flex-wrap items-center gap-3">
<button id="recalcButton"
class="inline-flex items-center gap-2 px-4 py-2 bg-primary hover:bg-primary-dark text-white rounded-lg font-medium text-sm transition-colors shadow-sm">
<span class="material-symbols-outlined text-[18px]">refresh</span>
Refresh Dashboard
</button>
<button id="auditButton"
class="inline-flex items-center gap-2 px-4 py-2 bg-[#212529] hover:bg-gray-700 text-white rounded-lg font-medium text-sm transition-colors shadow-sm">
<span class="material-symbols-outlined text-[18px]">fact_check</span>
Run Assignment Audit
</button>
</div>
</div>
<p class="text-xs text-secondary mt-2">Set the interval for On-Time calculations. "From" = last
appointment date. "Until" defaults to today.</p>
</section>
<div class="flex items-center justify-between pt-2">
<h3 class="text-xl font-bold text-gray-800 dark:text-white flex items-center gap-2">
<span class="material-symbols-outlined text-primary">grid_view</span>
Current Semester Courses
</h3>
</div>
<div id="courseGrid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"></div>
<section id="auditSection" class="hidden">
<div class="flex items-center gap-2 mb-4">
<span class="material-symbols-outlined text-primary text-2xl">checklist</span>
<h3 class="text-xl font-bold text-gray-800 dark:text-white">Assignment Audit</h3>
<span id="auditDateRange" class="text-base text-secondary ml-2"></span>
</div>
<div id="auditLoadingState" class="hidden flex items-center gap-3 p-6 justify-center">
<span class="material-symbols-outlined animate-spin text-primary text-3xl">progress_activity</span>
<span class="text-secondary font-medium text-sm">Auditing assignments...</span>
</div>
<div id="auditResults" class="space-y-6"></div>
</section>
</div><!-- /dashboardTabContent -->
<!-- Grade History Tab Content -->
<div id="historyTabContent" class="hidden flex-col gap-6">
<section class="bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm p-6">
<div class="flex flex-wrap items-center gap-3 mb-2">
<span class="text-sm font-bold text-gray-800 dark:text-white">Group by:</span>
<button class="group-btn active" data-group="weekly" onclick="changeHistoryGroup('weekly', this)">Weekly</button>
<button class="group-btn" data-group="daily" onclick="changeHistoryGroup('daily', this)">Daily</button>
<button class="group-btn" data-group="monthly" onclick="changeHistoryGroup('monthly', this)">Monthly</button>
<button class="group-btn" data-group="custom" onclick="changeHistoryGroup('custom', this)">Custom</button>
<div id="historyCustomRange" class="hidden flex items-center gap-2 ml-2">
<input type="date" id="historyFrom" class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm text-sm" />
<span class="text-xs text-secondary">to</span>
<input type="date" id="historyTo" class="rounded-md border-gray-300 dark:border-gray-600 dark:bg-surface-dark dark:text-white shadow-sm text-sm" />
<button onclick="loadGradeHistory('custom')" class="px-3 py-1.5 bg-primary text-white text-xs font-bold rounded-lg hover:bg-primary-dark">Go</button>
</div>
</div>
<p class="text-xs text-secondary">View how grades changed over time. Data comes from daily Canvas snapshots.</p>
</section>
<div id="historyLoadingState" class="hidden flex items-center gap-3 p-6 justify-center">
<span class="material-symbols-outlined animate-spin text-primary text-3xl">progress_activity</span>
<span class="text-secondary font-medium text-sm">Loading grade history...</span>
</div>
<div id="historyEmpty" class="hidden p-10 text-center text-gray-400 italic">No grade history data available for this student yet.</div>
<div id="historyResults" class="space-y-6"></div>
</div><!-- /historyTabContent -->
</div>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<script>
var currentStudentId = "";
var currentCanvasData = null;
var watchListRows = [];
var canViewWatchList = false;
// ═══════════ Helpers ═══════════
function showError(msg) {
var banner = document.getElementById("errorBanner");
document.getElementById("errorMessage").innerText = msg;
banner.classList.remove("hidden");
}
function hideError() {
document.getElementById("errorBanner").classList.add("hidden");
}
function hideLoading() {
document.getElementById("loadingState").classList.add("hidden");
document.getElementById("loadingState").classList.remove("flex");
}
function showLoading() {
document.getElementById("loadingState").classList.remove("hidden");
document.getElementById("loadingState").classList.add("flex");
}
function formatDateForInput(date) {
var y = date.getFullYear();
var m = String(date.getMonth() + 1);
if (m.length < 2) m = "0" + m;
var d = String(date.getDate());
if (d.length < 2) d = "0" + d;
return y + "-" + m + "-" + d;
}
function formatDisplayDate(isoStr) {
if (!isoStr) return "N/A";
var d = new Date(isoStr);
return d.toLocaleDateString("en-US", { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" });
}
function getGradeParts(gradeText) {
var gradeString = gradeText || "N/A N/A";
var parts = gradeString.split(" ");
return {
percent: parts[0] || "N/A",
letter: parts.length > 1 ? parts[1] : "N/A",
full: gradeString
};
}
function getAuditGradeText(item) {
if (item && item.submissionGrade && item.submissionGrade !== "N/A") {
return escapeHtml(item.submissionGrade);
}
if (item && item.hasGrade) return "Grade recorded";
return "N/A";
}
function escapeHtml(value) {
return String(value === null || typeof value === "undefined" ? "" : value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
// ═══════════ Toggle Dropdown ═══════════
function toggleDrop(dropId) {
var el = document.getElementById(dropId);
var arrow = document.getElementById("arrow-" + dropId);
if (el.classList.contains("hidden")) {
el.classList.remove("hidden");
if (arrow) arrow.classList.add("rotated");
} else {
el.classList.add("hidden");
if (arrow) arrow.classList.remove("rotated");
}
}
// ═══════════ Event Listeners ═══════════
document.getElementById("searchBtn").addEventListener("click", searchStudent);
document.getElementById("searchInput").addEventListener("keydown", function (e) {
if (e.key === "Enter") searchStudent();
});
document.getElementById("auditButton").addEventListener("click", runAudit);
document.getElementById("recalcButton").addEventListener("click", recalcInterval);
document.getElementById("watchRefreshButton").addEventListener("click", loadWatchList);
document.getElementById("watchSearchInput").addEventListener("input", renderFilteredWatchList);
document.getElementById("watchRiskFilter").addEventListener("change", renderFilteredWatchList);
document.getElementById("watchSortSelect").addEventListener("change", renderFilteredWatchList);
loadWatchListAccess();
// ═══════════ SEARCH ═══════════
function searchStudent() {
var studentId = document.getElementById("searchInput").value.trim();
if (!studentId) {
showError("Please enter an I-Number.");
return;
}
hideError();
document.getElementById("dashboardContent").classList.add("hidden");
document.getElementById("auditSection").classList.add("hidden");
switchTab("dashboard");
showLoading();
currentStudentId = studentId;
console.log("searchStudent called with: " + studentId);
try {
if (typeof google === "undefined" || !google.script || !google.script.run) {
throw new Error("google.script.run not available. Deploy this via Google Apps Script.");
}
console.log("Calling getDashboardData...");
google.script.run
.withSuccessHandler(renderDashboard)
.withFailureHandler(function (err) {
hideLoading();
var msg = err && err.message ? err.message : String(err);
console.error("getDashboardData failed:", msg);
showError("Backend Error: " + msg);
})
.getDashboardData(studentId);
} catch (e) {
hideLoading();
console.error("searchStudent error:", e);
showError(e.message);
}
}
// ═══════════ RENDER DASHBOARD ═══════════
function renderDashboard(data) {
console.log("renderDashboard called", data);
hideLoading();
hideError();
if (data.error) {
showError("Canvas Error: " + data.error);
return;
}
currentCanvasData = data;
var dashboardContent = document.getElementById("dashboardContent");
dashboardContent.classList.remove("hidden");
dashboardContent.classList.add("flex");
document.getElementById("studentSummarySection").classList.remove("hidden");
// Student Header
document.getElementById("ui-studentName").innerText = data.studentName || "Unknown Student";
document.getElementById("ui-studentId").innerText = currentStudentId || "N/A";
// Gradebook Link
var linkContainer = document.getElementById("gradebookLinkContainer");
if (data.gsCoachingCourse) {
var url = "https://canvas.example.edu/courses/" + data.gsCoachingCourse.courseId + "/gradebook";
document.getElementById("gradebookLink").href = url;
document.getElementById("gradebookLinkText").innerText = "Open Canvas Gradebook (" + data.gsCoachingCourse.courseName + ")";
linkContainer.classList.remove("hidden");
} else {
linkContainer.classList.add("hidden");
}
// Set default date pickers: 7 days ago → today
var sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
document.getElementById("lastApptDate").value = formatDateForInput(sevenDaysAgo);
document.getElementById("untilDate").value = formatDateForInput(new Date());
// Course Cards
var grid = document.getElementById("courseGrid");
grid.innerHTML = "";
if (data.courses && data.courses.length > 0) {
for (var i = 0; i < data.courses.length; i++) {
var course = data.courses[i];
// Skip the Support Seminar A / Support Seminar B coaching course
if (data.gsCoachingCourse && course.courseId == data.gsCoachingCourse.courseId) continue;
var hexColor = course.gradeStatus || "#f8fafc";
var isLightColor = hexColor === "#d3ec95" || hexColor === "#f2f9b2" || hexColor === "#ffefac" || hexColor === "#fed790" || hexColor === "#b8e17b";
var badgeTextColor = isLightColor ? "#333" : "#fff";
var gradeDisplayColor = isLightColor ? "#5c5c5c" : hexColor;
var hasMissing = course.missing > 0;
var hasLate = course.late > 0;
var hasUpcoming = course.upcoming > 0;
var missingClass = hasMissing ? "text-[#e95f3c] font-bold" : "text-gray-900";
var missingIconClass = hasMissing ? "text-[#e95f3c]" : "text-gray-400";
var lateClass = hasLate ? "text-orange-600 font-bold" : "text-gray-900";
var lateIconClass = hasLate ? "text-orange-500" : "text-gray-400";
var upcomingClass = hasUpcoming ? "text-sky-700 font-bold" : "text-gray-900";
var upcomingIconClass = hasUpcoming ? "text-sky-600" : "text-gray-400";
var gradeParts = getGradeParts(course.grade);
var percentPart = gradeParts.percent;
var letterPart = gradeParts.letter;
// Unique IDs for dropdowns
var missingDropId = "missing-drop-" + i;
var lateDropId = "late-drop-" + i;
var upcomingDropId = "upcoming-drop-" + i;
var onTimeDropId = "ontime-drop-" + i;
var card = document.createElement("div");
card.className = "course-card bg-white dark:bg-surface-dark rounded-lg border border-border-light dark:border-border-dark shadow-sm flex flex-col";
card.style.cssText = "border-left: 8px solid " + hexColor + " !important; background-color: " + hexColor + "10;";
var cardInner = '';
// Header
cardInner += '<div class="p-5 border-b border-border-light flex justify-between items-start">';
cardInner += '<h4 class="text-lg font-bold text-gray-900 dark:text-white leading-tight">' + course.name + '</h4>';
cardInner += '<span class="inline-flex items-center px-2 py-1 rounded text-[10px] font-black uppercase tracking-wider" ';
cardInner += 'style="background-color: ' + hexColor + '; color: ' + badgeTextColor + '; border: 1px solid rgba(0,0,0,0.1);">';
cardInner += letterPart;
cardInner += '</span></div>';
// Body
cardInner += '<div class="p-5 flex-1 flex flex-col gap-4">';
cardInner += '<div class="flex justify-between items-end">';
cardInner += '<span class="text-sm text-secondary">' + (course.gradeEstimated ? 'Grade from scored work' : 'Current Grade') + '</span>';
cardInner += '<span class="text-3xl font-black" style="color: ' + gradeDisplayColor + '">' + percentPart + '</span>';
cardInner += '</div>';
cardInner += '<div class="space-y-1 pt-2">';
// --- MISSING ROW (clickable) ---
cardInner += '<div class="cursor-pointer select-none rounded hover:bg-gray-50 dark:hover:bg-gray-800 px-2 py-1.5 -mx-2 transition-colors" onclick="toggleDrop(\'' + missingDropId + '\')">';
cardInner += '<div class="flex justify-between text-sm">';
cardInner += '<span class="text-gray-600 dark:text-gray-400 flex items-center gap-1">';
cardInner += '<span class="material-symbols-outlined text-[18px] ' + missingIconClass + '">assignment_late</span>';
cardInner += 'Missing (Semester)';
cardInner += '<span class="material-symbols-outlined text-[14px] text-gray-400 drop-arrow" id="arrow-' + missingDropId + '">expand_more</span>';
cardInner += '</span>';
cardInner += '<span class="' + missingClass + '">' + course.missing + '</span>';
cardInner += '</div></div>';
// Missing dropdown
cardInner += '<div id="' + missingDropId + '" class="hidden pl-7 pb-2">';
if (course.missingList && course.missingList.length > 0) {
for (var m = 0; m < course.missingList.length; m++) {
cardInner += '<div class="flex items-center gap-1.5 py-0.5 text-xs text-gray-600 dark:text-gray-400">';
cardInner += '<span class="material-symbols-outlined text-[14px] text-red-400">close</span>';
cardInner += '<span>' + course.missingList[m].name + '</span>';
cardInner += '</div>';
}
} else {
cardInner += '<p class="text-xs text-gray-400 italic">None</p>';
}
cardInner += '</div>';
// --- LATE ROW (clickable) ---
cardInner += '<div class="cursor-pointer select-none rounded hover:bg-gray-50 dark:hover:bg-gray-800 px-2 py-1.5 -mx-2 transition-colors" onclick="toggleDrop(\'' + lateDropId + '\')">';
cardInner += '<div class="flex justify-between text-sm">';
cardInner += '<span class="text-gray-600 dark:text-gray-400 flex items-center gap-1">';
cardInner += '<span class="material-symbols-outlined text-[18px] ' + lateIconClass + '">schedule</span>';
cardInner += 'Late (Interval)';
cardInner += '<span class="material-symbols-outlined text-[14px] text-gray-400 drop-arrow" id="arrow-' + lateDropId + '">expand_more</span>';
cardInner += '</span>';
cardInner += '<span class="' + lateClass + '">' + course.late + '</span>';
cardInner += '</div></div>';
// Late dropdown
cardInner += '<div id="' + lateDropId + '" class="hidden pl-7 pb-2">';
if (course.lateList && course.lateList.length > 0) {
for (var l = 0; l < course.lateList.length; l++) {
cardInner += '<div class="flex items-center gap-1.5 py-0.5 text-xs text-orange-600">';
cardInner += '<span class="material-symbols-outlined text-[14px]">schedule</span>';
cardInner += '<span>' + course.lateList[l].name + '</span>';
cardInner += '</div>';
}
} else {
cardInner += '<p class="text-xs text-gray-400 italic">None</p>';
}
cardInner += '</div>';
// --- UPCOMING ROW (clickable) ---
cardInner += '<div class="cursor-pointer select-none rounded hover:bg-gray-50 dark:hover:bg-gray-800 px-2 py-1.5 -mx-2 transition-colors" onclick="toggleDrop(\'' + upcomingDropId + '\')">';
cardInner += '<div class="flex justify-between text-sm">';
cardInner += '<span class="text-gray-600 dark:text-gray-400 flex items-center gap-1">';
cardInner += '<span class="material-symbols-outlined text-[18px] ' + upcomingIconClass + '">event_upcoming</span>';
cardInner += 'Upcoming';
cardInner += '<span class="material-symbols-outlined text-[14px] text-gray-400 drop-arrow" id="arrow-' + upcomingDropId + '">expand_more</span>';
cardInner += '</span>';
cardInner += '<span class="' + upcomingClass + '">' + (course.upcoming || 0) + '</span>';
cardInner += '</div></div>';
// Upcoming dropdown
cardInner += '<div id="' + upcomingDropId + '" class="hidden pl-7 pb-2">';
if (course.upcomingList && course.upcomingList.length > 0) {
for (var u = 0; u < course.upcomingList.length; u++) {
var upcomingDueStr = formatDisplayDate(course.upcomingList[u].dueAt);
cardInner += '<div class="flex items-center gap-1.5 py-0.5 text-xs text-sky-700 dark:text-sky-300">';
cardInner += '<span class="material-symbols-outlined text-[14px]">event_upcoming</span>';
cardInner += '<span>' + course.upcomingList[u].name + ' · Due ' + upcomingDueStr + '</span>';
cardInner += '</div>';
}
} else {
cardInner += '<p class="text-xs text-gray-400 italic">None</p>';
}
cardInner += '</div>';
// --- ON-TIME ROW (clickable) ---
cardInner += '<div class="cursor-pointer select-none rounded hover:bg-gray-50 dark:hover:bg-gray-800 px-2 py-1.5 -mx-2 transition-colors" onclick="toggleDrop(\'' + onTimeDropId + '\')">';
cardInner += '<div class="flex justify-between text-sm">';
cardInner += '<span class="text-gray-600 dark:text-gray-400 flex items-center gap-1">';
cardInner += '<span class="material-symbols-outlined text-[18px] text-green-500">check_circle</span>';
cardInner += 'On-Time (Interval)';
cardInner += '<span class="material-symbols-outlined text-[14px] text-gray-400 drop-arrow" id="arrow-' + onTimeDropId + '">expand_more</span>';
cardInner += '</span>';
cardInner += '<span class="font-bold text-gray-900 dark:text-white">' + course.onTime + '</span>';
cardInner += '</div></div>';
// On-Time dropdown
cardInner += '<div id="' + onTimeDropId + '" class="hidden pl-7 pb-2">';
if (course.onTimeList && course.onTimeList.length > 0) {
for (var o = 0; o < course.onTimeList.length; o++) {
cardInner += '<div class="flex items-center gap-1.5 py-0.5 text-xs text-green-600">';
cardInner += '<span class="material-symbols-outlined text-[14px]">task_alt</span>';
cardInner += '<span>' + course.onTimeList[o].name + '</span>';
cardInner += '</div>';
}
} else {
cardInner += '<p class="text-xs text-gray-400 italic">None</p>';
}
cardInner += '</div>';
cardInner += '</div></div>';
card.innerHTML = cardInner;
grid.appendChild(card);
}
} else {
grid.innerHTML = '<div class="col-span-full p-10 text-center text-gray-400 italic">No active courses found for this student.</div>';
}
// Clear previous audit
document.getElementById("auditSection").classList.add("hidden");
document.getElementById("auditResults").innerHTML = "";
// Animate cards
setTimeout(function () {
if (typeof anime !== "undefined") {
anime({
targets: ".course-card",
translateY: [20, 0],
opacity: [0, 1],
delay: anime.stagger(100),
easing: "easeOutCubic",
duration: 500
});
}
}, 50);
}
// ═══════════ TAB SWITCHING ═══════════
function loadWatchListAccess() {
try {
if (typeof google === "undefined" || !google.script || !google.script.run) return;
google.script.run
.withSuccessHandler(applyWatchListAccess)
.withFailureHandler(function () {
applyWatchListAccess({ allowed: false });
})
.getWatchListAccess();
} catch (e) {
applyWatchListAccess({ allowed: false });
}
}
function applyWatchListAccess(access) {
canViewWatchList = !!(access && access.allowed);
var watchButton = document.getElementById("tabWatch");
var watchTab = document.getElementById("watchListTabContent");
if (canViewWatchList) {
watchButton.classList.remove("hidden");
} else {
var wasShowingWatchList = watchButton.classList.contains("active") || watchTab.classList.contains("flex");
watchButton.classList.add("hidden");
watchButton.classList.remove("active");
watchTab.classList.add("hidden");
watchTab.classList.remove("flex");
watchListRows = [];
document.getElementById("watchListRows").innerHTML = "";
document.getElementById("watchListEmpty").classList.add("hidden");
if (wasShowingWatchList) switchTab("dashboard");
}
}
function loadWatchList() {
if (!canViewWatchList) {
applyWatchListAccess({ allowed: false });
return;
}
var loading = document.getElementById("watchListLoadingState");
var empty = document.getElementById("watchListEmpty");
var rows = document.getElementById("watchListRows");
document.getElementById("watchListUpdated").innerText = "Loading risk snapshot...";
loading.classList.remove("hidden");
empty.classList.add("hidden");
rows.innerHTML = "";
try {
if (typeof google === "undefined" || !google.script || !google.script.run) {
throw new Error("google.script.run not available. Deploy this via Google Apps Script.");
}
google.script.run
.withSuccessHandler(renderWatchList)
.withFailureHandler(function (err) {
loading.classList.add("hidden");
showWatchListEmpty("Error loading watch list: " + (err && err.message ? err.message : String(err)));
})
.getRiskListData();
} catch (e) {
loading.classList.add("hidden");
showWatchListEmpty(e.message);
}
}
function renderWatchList(data) {
document.getElementById("watchListLoadingState").classList.add("hidden");
if (data.error) {
watchListRows = [];
document.getElementById("watchListUpdated").innerText = data.error;
showWatchListEmpty(data.error);
return;
}
watchListRows = data.rows || [];
document.getElementById("watchRefreshButton").innerHTML = '<span class="material-symbols-outlined text-[18px]">refresh</span>Refresh';
var updatedText = data.snapshotDate ? "Snapshot: " + data.snapshotDate : "Snapshot loaded";
if (data.lastUpdated) {
updatedText += " - Updated " + new Date(data.lastUpdated).toLocaleString();
}
document.getElementById("watchListUpdated").innerText = updatedText + " - " + watchListRows.length + " students";
renderFilteredWatchList();
}
function renderFilteredWatchList() {
var query = document.getElementById("watchSearchInput").value.trim().toLowerCase();
var riskFilter = document.getElementById("watchRiskFilter").value;
var sortMode = document.getElementById("watchSortSelect").value;
var filtered = [];
for (var i = 0; i < watchListRows.length; i++) {
var row = watchListRows[i];
var haystack = ((row.studentName || "") + " " + (row.iNumber || "") + " " + (row.canvasId || "")).toLowerCase();
if (query && haystack.indexOf(query) === -1) continue;
if (riskFilter !== "all" && getNormalizedRiskLevel(row.riskLevel) !== riskFilter) continue;
filtered.push(row);
}
filtered.sort(function (a, b) {
if (sortMode === "name") return String(a.studentName).localeCompare(String(b.studentName));
if (sortMode === "trend") return Math.abs(b.trend7Day || 0) - Math.abs(a.trend7Day || 0);
if ((b.riskScore || 0) !== (a.riskScore || 0)) return (b.riskScore || 0) - (a.riskScore || 0);
return String(a.studentName).localeCompare(String(b.studentName));
});
var body = document.getElementById("watchListRows");
body.innerHTML = "";
if (filtered.length === 0) {
showWatchListEmpty(watchListRows.length === 0 ? "No watch list data available." : "No students match the current filters.");
return;
}
document.getElementById("watchListEmpty").classList.add("hidden");
for (var r = 0; r < filtered.length; r++) {
body.appendChild(buildWatchListRow(filtered[r]));
}
}
function buildWatchListRow(row) {
var tr = document.createElement("tr");
tr.className = "hover:bg-gray-50 dark:hover:bg-gray-800 cursor-pointer transition-colors";
tr.onclick = function () {
openWatchListStudent(row.iNumber);
};
var riskScore = row.riskScore || 1;
var riskLevel = getNormalizedRiskLevel(row.riskLevel);
var riskColors = getRiskColors(riskLevel);
var riskLabel = row.riskLabel || getRiskLabel(riskLevel);
var priorityText = getPriorityText(row.riskRank, row.riskPercentile);
var trend = row.trend7Day || 0;
var trendInfo = getTrendInfo(trend);
var trendIcon = trendInfo.icon;
var trendClass = trendInfo.cssClass;
var trendText = trendInfo.label;
var reasons = row.summaryReasons && row.summaryReasons.length > 0 ? row.summaryReasons : ["No major risk signals"];
var html = "";
html += '<td class="px-4 py-3 align-top">';
html += '<div class="font-bold text-gray-900 dark:text-white">' + escapeHtml(row.studentName) + '</div>';
html += '<div class="text-xs text-secondary">I-Number: ' + escapeHtml(row.iNumber || "N/A") + '</div>';
html += '</td>';
html += '<td class="px-4 py-3 align-top">';
html += '<div class="flex items-center gap-3">';
html += '<div class="h-3 flex-1 rounded-full bg-gray-100 dark:bg-gray-700 overflow-hidden min-w-[160px]">';
html += '<div class="h-full rounded-full" style="width: ' + Math.min(100, Math.max(1, riskScore)) + '%; background: ' + riskColors.bar + ';"></div>';
html += '</div>';
html += '<span class="font-black text-gray-900 dark:text-white w-8 text-right">' + riskScore + '</span>';
html += '<span class="px-2 py-1 rounded-full text-[10px] font-bold uppercase whitespace-nowrap ' + riskColors.badge + '">' + escapeHtml(riskLabel) + '</span>';
html += '</div>';
if (priorityText) {
html += '<div class="mt-1 text-[11px] text-secondary">' + escapeHtml(priorityText) + '</div>';
}
html += '</td>';
html += '<td class="px-4 py-3 align-top">';
html += '<div class="inline-flex items-center gap-1 font-bold whitespace-nowrap ' + trendClass + '">';