-
Notifications
You must be signed in to change notification settings - Fork 5
/
RoarDataTable.vue
1093 lines (1033 loc) · 42.2 KB
/
RoarDataTable.vue
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
<template>
<div v-if="!props.data">
<SkeletonTable />
</div>
<div v-else>
<div class="w-full gap-1 pt-1 flex justify-content-center align-items-center flex-wrap mt-3">
<slot name="filterbar"></slot>
<span class="p-float-label my-3">
<PvMultiSelect
id="ms-columns"
v-tooltip.top="'Show and hide columns'"
:model-value="selectedColumns"
:options="inputColumns"
option-label="header"
:max-selected-labels="3"
class="w-2 md:w-10rem"
selected-items-label="{0} columns selected"
@update:model-value="onColumnToggle"
/>
<label for="ms-columns" class="view-label2">Select Columns</label>
</span>
<span class="p-float-label my-3">
<PvMultiSelect
id="ms-freeze"
:model-value="frozenColumns"
:options="inputColumns"
option-label="header"
:max-selected-labels="3"
class="w-2 md:w-10rem"
selected-items-label="{0} columns frozen"
:show-toggle-all="false"
@update:model-value="onFreezeToggle"
/>
<label for="ms-columns" class="view-label2">Freeze Columns</label>
</span>
<span class="flex flex-row flex-wrap justify-content-end gap-2 max-h-3 export-wrapper">
<PvButton
v-tooltip.bottom="'Expand or Compress table rows'"
text
:label="rowViewMode"
class="my-1 m-1 h-3rem text-primary surface-ground border-none border-round h-2rem text-sm hover:bg-gray-300"
@click="toggleView"
/>
<PvButton
v-if="allowExport"
v-tooltip.bottom="
`Export scores for ${selectedRows.length} student${
selectedRows.length > 1 ? 's' : ''
} to CSV file for spreadsheet import`
"
label="Export Selected"
:badge="selectedRows?.length?.toString()"
:disabled="selectedRows.length === 0"
class="m-1 h-3rem bg-primary text-white border-none border-round h-2rem text-sm hover:bg-red-900"
@click="exportCSV(true, $event)"
data-cy="data-table__export-selected-btn"
/>
<PvButton
v-if="allowExport"
v-tooltip.bottom="'Export all scores for all students to a CSV file for spreadsheet import.'"
label="Export Whole Table"
class="m-1 h-3rem bg-primary text-white border-none border-round h-2rem text-sm hover:bg-red-900"
@click="exportCSV(false, $event)"
data-cy="data-table__export-table-btn"
/>
</span>
</div>
<div class="flex flex-column">
<span style="height: 10px">
<div class="relative flex justify-content-end mt-0 mr-2 z-1" style="top: 25px; width: 20%; left: 80%">
<slot />
</div>
</span>
<span>
<PvDataTable
ref="dataTable"
v-model:filters="refFilters"
v-model:selection="selectedRows"
class="scrollable-container"
:class="{ compressed: compressedRows }"
:value="data"
:row-hover="true"
:reorderable-columns="true"
:resizable-columns="true"
:export-filename="exportFilename"
removable-sort
sort-mode="multiple"
:multi-sort-meta="lazyPreSorting"
show-gridlines
filter-display="menu"
paginator
:rows="pageLimit"
:always-show-paginator="true"
paginator-position="both"
:rows-per-page-options="[10, 25, 50, 100]"
:total-records="totalRecords"
:loading="loading"
scrollable
:select-all="selectAll"
data-cy="roar-data-table"
@select-all-change="onSelectAll"
@row-select="onSelectionChange"
@row-unselect="onSelectionChange"
>
<PvColumnGroup type="header" class="mt-2">
<PvRow v-if="groupheaders" class="flex mt-2">
<!-- Spacer Header -->
<!-- colspan = getSpacerHeaderWidth-->
<PvColumn
header="Student Information"
:colspan="getSpacerColumnWidth"
header-style="background-color: var(--primary-color); color:white; border:1px border-left-none solid white; justify-content:center; margin-top:1rem; text-align: center;"
/>
<!-- Foundations -->
<!-- v-if="primarySpacerColumns" :colspan="primarySpacerColumns" -->
<PvColumn
v-if="primarySpacerColumns"
:colspan="primarySpacerColumns"
header-style="background-color: var(--primary-color); color:white; border:1px solid white; justify-content:center; margin-top:1rem; text-align: center;"
>
<template #header>
<div class="flex flex-row">
<div>Foundational Reading Skills</div>
<div class="ml-2">
<PvButton class="p-0 border-none border-circle bg-primary" @click="toggle($event, 'primary')"
><i v-tooltip.top="'Learn more'" class="pi pi-info-circle text-white p-1 border-circle"></i
></PvButton>
</div>
</div>
</template>
</PvColumn>
<!-- Spanish -->
<!-- v-if="spanishColumns" :colspan="spanishColumns" -->
<PvColumn
v-if="spanishSpacerColumns"
:colspan="spanishSpacerColumns"
header-style="background-color: var(--primary-color); color:white; border:1px solid white; justify-content:center; margin-top:1rem; text-align: center;"
>
<template #header>
<div class="flex flex-row">
<div>Spanish</div>
<div class="ml-2">
<PvButton class="p-0 border-none border-circle bg-primary" @click="toggle($event, 'spanish')"
><i v-tooltip.top="'Learn more'" class="pi pi-info-circle text-white p-1 border-circle"></i
></PvButton>
</div>
</div>
</template>
</PvColumn>
<!-- Spanish Math-->
<!-- v-if="spanishMathColumns" :colspan="spanishMathColumns" -->
<PvColumn
v-if="spanishMathSpacerColumns"
:colspan="spanishMathSpacerColumns"
header-style="background-color: var(--primary-color); color:white; border:1px solid white; justify-content:center; margin-top:1rem; text-align: center;"
>
<template #header>
<div class="flex flex-row">
<div>Spanish Math</div>
<div class="ml-2">
<PvButton class="p-0 border-none border-circle bg-primary" @click="toggle($event, 'spanishmath')"
><i v-tooltip.top="'Learn more'" class="pi pi-info-circle text-white p-1 border-circle"></i
></PvButton>
</div>
</div>
</template>
</PvColumn>
<!-- inDev -->
<!-- v-if="supplemenaryColumns" :colspan="supplementaryColumns" -->
<PvColumn
v-if="supplementarySpacerColumns"
:colspan="supplementarySpacerColumns"
header-style="background-color: var(--primary-color); color:white; border:1px solid white; justify-content:center; margin-top:1rem; text-align: center;"
>
<template #header>
<div class="flex flex-row">
<div>Supplementary<br />(In Development)</div>
<div class="mt-1 ml-2">
<PvButton
class="p-0 border-none border-circle bg-primary"
@click="toggle($event, 'supplementary')"
><i v-tooltip.top="'Learn more'" class="pi pi-info-circle text-white p-1 border-circle"></i
></PvButton>
</div>
</div>
</template>
</PvColumn>
<!-- inRoam -->
<!-- v-if="mathSpacerColumns" :colspan="supplementaryColumns" -->
<PvColumn
v-if="mathSpacerColumns"
:colspan="mathSpacerColumns"
header-style="background-color: var(--primary-color); color:white; border:1px solid white; justify-content:center; margin-top:1rem; text-align: center;"
>
<template #header>
<div class="flex flex-row">
<div>Mathematics<br />(In Development)</div>
<div class="mt-1 ml-2">
<PvButton class="p-0 border-none border-circle bg-primary" @click="toggle($event, 'math')"
><i v-tooltip.top="'Learn more'" class="pi pi-info-circle text-white p-1 border-circle"></i
></PvButton>
</div>
</div>
</template>
</PvColumn>
<!-- inRoav -->
<!-- v-if="visionSpacerColumns" :colspan="supplementaryColumns" -->
<PvColumn
v-if="visionSpacerColumns"
:colspan="visionSpacerColumns"
header-style="background-color: var(--primary-color); color:white; border:1px solid white; justify-content:center; margin-top:1rem; text-align: center;"
>
<template #header>
<div class="flex flex-row">
<div>Vision<br />(In Development)</div>
<div class="mt-1">
<PvButton class="p-0 border-none border-circle bg-primary" @click="toggle($event, 'vision')"
><i v-tooltip.top="'Learn more'" class="pi pi-info-circle text-white p-1 border-circle"></i
></PvButton>
</div>
</div>
</template>
</PvColumn>
</PvRow>
<PvRow>
<PvColumn
selection-mode="multiple"
header-style="background-color: var(--primary-color); border:none;"
:reorderable-column="false"
frozen
/>
<PvColumn
v-for="(col, index) of computedColumns"
:key="col.field + '_' + index"
:field="col.field"
:data-type="col.dataType"
:sortable="col.sort !== false"
:show-filter-match-modes="
!col.useMultiSelect && col.dataType !== 'score' && col.dataType !== 'progress'
"
:show-filter-operator="col.allowMultipleFilters === true"
:filter-field="col?.filterField ? col.filterField : col.field"
:show-add-button="col.allowMultipleFilters === true"
:frozen="col.pinned"
:style="col.style"
align-frozen="left"
:header-style="
col.headerStyle ||
`background:var(--primary-color); color:white; padding-top:0; margin-top:0; padding-bottom:0; margin-bottom:0; border:0; margin-left:0`
"
>
<template #header>
<div
v-tooltip.top="`${toolTipByHeader(col.header)}`"
:style="[
toolTipByHeader(col.header).length > 0
? 'text-decoration: underline dotted #0000CD; text-underline-offset: 3px'
: null,
]"
>
{{ col.header }}
</div>
</template>
<template v-if="col.dataType" #filter="{ filterModel }">
<div v-if="col.dataType === 'text' && !col.useMultiSelect" class="filter-content">
<PvInputText
v-model="filterModel.value"
type="text"
class="p-column-filter p-3"
placeholder="Filter"
/>
</div>
<PvInputNumber
v-if="col.dataType === 'number' && !col.useMultiSelect"
v-model="filterModel.value"
type="text"
class="p-column-filter"
placeholder="Search"
/>
<PvMultiSelect
v-if="col.useMultiSelect"
v-model="filterModel.value"
:options="_get(refOptions, col.field)"
placeholder="Any"
:show-toggle-all="false"
class="p-column-filter"
/>
<PvCalendar
v-if="col.dataType === 'date' && !col.useMultiSelect"
v-model="filterModel.value"
date-format="mm/dd/yy"
placeholder="mm/dd/yyyy"
/>
<div v-if="col.dataType === 'boolean' && !col.useMultiSelect" class="flex flex-row gap-2">
<PvTriStateCheckbox v-model="filterModel.value" input-id="booleanFilter" style="padding-top: 2px" />
<label for="booleanFilter">{{ col.header + '?' }}</label>
</div>
<div v-if="col.dataType === 'score'">
<PvDropdown
v-model="filterModel.value"
option-label="label"
option-group-label="label"
option-group-children="items"
:options="taskFilterOptions"
data-cy="score-filter-dropdown"
style="margin-bottom: 0.5rem"
>
<template #option="{ option }">
<div class="flex align-items-center">
<div v-if="supportLevelColors[option]" class="flex gap-2">
<div
class="small-circle tooltip"
:style="`background-color: ${supportLevelColors[option]};`"
/>
<span class="tooltiptext">{{ option }}</span>
</div>
<div v-else-if="progressTags[option]">
<PvTag
:severity="progressTags[option]?.severity"
:value="progressTags[option]?.value"
:icon="progressTags[option]?.icon"
class="p-0.5 m-0 font-bold"
/>
</div>
<div v-else>
<span class="tooltiptext">{{ option }}</span>
</div>
</div>
</template>
<template #value="{ value }">
<div v-if="supportLevelColors[value]" class="flex gap-2">
<div
class="small-circle tooltip"
:style="`background-color: ${supportLevelColors[value]};`"
/>
<span class="tooltiptext">{{ value }}</span>
</div>
<div v-else-if="progressTags[value]">
<PvTag
:severity="progressTags[value]?.severity"
:value="progressTags[value]?.value"
:icon="progressTags[value]?.icon"
class="p-0.5 m-0 font-bold"
/>
</div>
<div v-else>
<span class="tooltiptext">{{ value }}</span>
</div>
</template>
</PvDropdown>
</div>
<div v-if="col.dataType === 'progress'">
<PvDropdown
v-model="filterModel.value"
:options="['Assigned', 'Started', 'Completed', 'Optional']"
style="margin-bottom: 0.5rem"
data-cy="progress-filter-dropdown"
>
<template #option="{ option }">
<div v-if="progressTags[option]" class="flex align-items-center">
<PvTag
:severity="progressTags[option]?.severity"
:value="progressTags[option]?.value"
:icon="progressTags[option]?.icon"
:style="`min-width: 2rem; font-weight: bold`"
rounded
/>
</div>
</template>
<template #value="{ value }">
<PvTag
v-if="progressTags[value]"
:severity="progressTags[value]?.severity"
:value="progressTags[value]?.value"
:icon="progressTags[value]?.icon"
:style="`min-width: 2rem; font-weight: bold`"
rounded
/>
</template>
</PvDropdown>
</div>
</template>
</PvColumn>
</PvRow>
</PvColumnGroup>
<PvOverlayPanel ref="op" append-to="body" class="overflow-y-scroll" style="width: 60vh; max-height: 30vh">
<template v-if="selectedColumn === 'primary'">
<h3 class="font-bold">Foundational Reading Skills</h3>
<div>
<h4 class="font-bold">Word</h4>
Word indicates which students are in need of support in word-level decoding and automaticity. Word has
been validated, and national norms are provided.<br />
<h4 class="font-bold">Sentence</h4>
Sentence indicates which students are in need of support in sentence-level fluency. Sentence has been
validated, and national norms are provided.<br />
<h4 class="font-bold">Phoneme</h4>
Phoneme indicates which students are in need of support in phonological awareness. Below this student
table, in the Phoneme tab, you will find scores for subdomains of phonological awareness skills that can
guide instruction. Phoneme has been validated, and national norms are provided. <br />
<h4 class="font-bold">Letter</h4>
Letter indicates which students are in need of support in letter names and sounds. Below this student
table, in the Letter tab, you will find scores for subdomains of letter skills that can guide
instruction. Letter has been validated, and raw scores are provided.
</div>
</template>
<template v-if="selectedColumn === 'spanish'">
<h3 class="font-bold">Spanish</h3>
<div>
Spanish-language versions of the assessments provide additional information for Spanish-speaking
students. <br />
<br />
Spanish assessments are undergoing validation, and raw scores are provided. <br /><br />
These scores will be included in the development of national norms and support categories.
</div>
</template>
<template v-if="selectedColumn === 'spanishmath'">
<h3 class="font-bold">Spanish Mathematics</h3>
<div>
Spanish-language mathematics assessments provide additional insight into areas such as arithmetic
fluency, calculation ability, and mathematical procedures based on common core standards <br />
<br />
Mathematics assessments are undergoing validation, and raw scores are provided. <br /><br />
These scores will be included in the development of national norms and support categories.
</div>
</template>
<template v-else-if="selectedColumn === 'supplementary'">
<h3 class="font-bold">Supplementary</h3>
<div>
Supplementary assessments provide additional insight into areas such as morphology, syntax, language
comprehension, and rapid automatized naming. <br />
<br />
Supplementary assessments are undergoing validation, and raw scores are provided. <br /><br />
These scores will be included in the development of national norms and support categories.
</div>
</template>
<template v-else-if="selectedColumn === 'math'">
<h3 class="font-bold">Mathematics</h3>
<div>
Mathematics assessments provide additional insight into areas such as arithmetic fluency, calculation
ability, and mathematical procedures based on common core standards<br />
<br />
Mathematics assessments are undergoing validation, and raw scores are provided. <br /><br />
These scores will be included in the development of national norms and support categories.
</div>
</template>
<template v-else-if="selectedColumn === 'vision'">
<h3 class="font-bold">Vision</h3>
<div>
Vision assessments provide additional insight into areas such as visual acuity and visual crowding.
<br />
<br />
Vision assessments are undergoing validation, and raw scores are provided. <br /><br />
These scores will be included in the development of national norms and support categories.
</div>
</template>
</PvOverlayPanel>
<PvColumn
selection-mode="multiple"
header-style="background-color: var(--primary-color); border:none;"
:reorderable-column="false"
frozen
/>
<PvColumn
v-for="(col, index) of computedColumns"
:key="col.field + '_' + index"
:field="col.field"
:data-type="col.dataType"
:sortable="col.sort !== false"
:show-filter-match-modes="!col.useMultiSelect && col.dataType !== 'score' && col.dataType !== 'progress'"
:show-filter-operator="col.allowMultipleFilters === true"
:filter-field="col?.filterField ? col.filterField : col.field"
:show-add-button="col.allowMultipleFilters === true"
:frozen="col.pinned"
:style="col.style"
align-frozen="left"
header-style="background:var(--primary-color); color:white; padding-top:0; margin-top:0; padding-bottom:0; margin-bottom:0; border:0; margin-left:0"
>
<template #body="{ data: colData }">
<!-- If column is a score field, use a dedicated component to render tags and scores -->
<div v-if="col.field && col.field?.split('.')[0] === 'scores'">
<TableScoreTag :col-data="colData" :col="col" />
</div>
<div v-else-if="col.dataType == 'progress'">
<PvTag
v-if="_get(colData, col.field)"
:severity="_get(colData, col.severityField)"
:value="_get(colData, col.field)"
:icon="_get(colData, col.iconField)"
:style="`min-width: 2rem; font-weight: bold;`"
rounded
/>
</div>
<div
v-else-if="col.tagOutlined && _get(colData, col.tagColor)"
class="circle"
:style="`border: 1px solid black; background-color: ${_get(colData, col.tagColor)}; color: ${
_get(colData, col.tagColor) === 'white' ? 'black' : 'white'
}; outline: 1px dotted #0000CD; outline-offset: 3px`"
/>
<div v-else-if="col.chip && col.dataType === 'array' && _get(colData, col.field) !== undefined">
<PvChip v-for="chip in _get(colData, col.field)" :key="chip" :label="chip" />
</div>
<div v-else-if="col.link">
<router-link :to="{ name: col.routeName, params: colData.routeParams }">
<PvButton
v-tooltip.right="colData.tooltip"
severity="secondary"
text
class="border-none border-round bg-white text-primary p-2 hover:surface-200"
:label="colData.routeParams.buttonLabel"
:aria-label="col.routeTooltip"
:icon="col.routeIcon"
data-cy="data-table__entry-details-btn"
size="small"
/>
</router-link>
</div>
<div v-else-if="col.button">
<PvButton
severity="secondary"
text
class="border-none border-round bg-white text-primary p-2 hover:surface-200"
:label="col.buttonLabel"
:aria-label="col.buttonTooltip"
:icon="col.buttonIcon"
data-cy="event-button"
size="small"
@click="$emit(col.eventName, colData)"
/>
</div>
<div v-else-if="col.dataType === 'date'">
{{ getFormattedDate(_get(colData, col.field)) }}
</div>
<div v-else-if="col.field === 'user.lastName'">
{{ _get(colData, col.field) }}
</div>
<div v-else>
{{ _get(colData, col.field) }}
</div>
</template>
<template v-if="col.dataType" #sorticon="{ sorted, sortOrder }">
<i v-if="!sorted && currentSort.length === 0" class="pi pi-sort-alt ml-2" />
<i v-if="sorted && sortOrder === 1" class="pi pi-sort-amount-down-alt ml-2" />
<i v-else-if="sorted && sortOrder === -1" class="pi pi-sort-amount-up-alt ml-2" />
</template>
</PvColumn>
<template #empty>
<div class="flex flex-column align-items-center align-text-left my-8">
<div class="text-lg font-bold my-2">No results found</div>
<div class="font-light">The filters applied have no matching results .</div>
<PvButton
text
class="my-2 bg-primary p-2 border-none border-round text-white hover:bg-red-900"
@click="resetFilters"
>Reset Filters</PvButton
>
</div>
</template>
</PvDataTable>
</span>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue';
import { useToast } from 'primevue/usetoast';
import { FilterMatchMode, FilterOperator } from 'primevue/api';
import SkeletonTable from '@/components/SkeletonTable.vue';
import _get from 'lodash/get';
import _map from 'lodash/map';
import _forEach from 'lodash/forEach';
import _find from 'lodash/find';
import _toUpper from 'lodash/toUpper';
import _startCase from 'lodash/startCase';
import { supportLevelColors, progressTags } from '@/helpers/reports';
import TableScoreTag from '@/components/reports/TableScoreTag.vue';
/*
Using the DataTable
Required Props: columns, data
Optional Props: allowExport (default: true), exportFilename (default: 'datatable-export')
Columns:
Array of objects consisting of a field and header at minimum.
- Field must match the key of the entry in the data object.
- Header is an optional string that is displayed at the top of
the column.
- dataType is a string that defines the data type of the column.
options are TEXT, NUMERIC, or DATE
- Sort (optional) is a boolean field that determines whether sorting
is to be allowed on the field. If it is not present, defaults to true.
- allowMultipleFilters (optional) is a boolean field that determines whether
users have the option of apply multiple filters.
- useMultiSelect is an optional boolean field that determines whether the
filter will be a multi-select dropdown. options are generated by the
given data.
- Pinned (optional) is a boolean field allowing the column to persist when
scrolled left-to-right. It is suggested that this only be used on
the leftmost column.
*/
const rowViewMode = ref('Expand View');
const countForVisualize = ref(false); //for starting compress
const toggleView = () => {
compressedRows.value = !compressedRows.value;
increasePadding();
};
const props = defineProps({
columns: { type: Array, required: true },
data: { type: Array, required: true },
allowExport: { type: Boolean, default: true },
exportFilename: { type: String, default: 'datatable-export' },
pageLimit: { type: Number, default: 15 },
totalRecords: { type: Number, required: false, default: 0 },
loading: { type: Boolean, default: false },
lazy: { type: Boolean, default: false },
lazyPreSorting: { type: Array, required: false, default: () => [] },
isInsideListOrgs: {
type: Boolean,
default: false,
},
groupheaders: { type: Boolean, default: false },
});
const inputColumns = ref(props.columns);
const selectedColumns = ref(props.columns);
// Filter the live data (props.columns) with the selections of selectedColumns
const computedColumns = computed(() => {
return _map(selectedColumns.value, (col) => {
return _find(props.columns, (pcol) => pcol.header === col.header);
});
});
const currentSort = ref([]);
const selectedRows = ref([]);
const taskFilterOptions = ref([
{
label: 'Support Categories',
code: 'SupportCategories',
items: ['Green', 'Yellow', 'Pink'],
},
{
label: 'Progress Status',
code: 'ProgressStatus',
items: ['Completed', 'Started', 'Assigned'],
},
{
label: 'Other Filters',
code: 'Other',
items: ['Optional', 'Assessed', 'Unreliable'],
},
]);
const toast = useToast();
const selectAll = ref(false);
const onSelectAll = () => {
selectAll.value = !selectAll.value;
if (selectAll.value) {
selectedRows.value = props.data;
toast.add({
severity: 'info',
summary: 'Rows selected',
detail: `You selected ${selectedRows.value.length} rows but there are
${props.totalRecords} total rows in all of this table's pages. If you
would like to export all rows, please click the "Export Whole Table"
button.`,
life: 5000,
});
} else {
selectedRows.value = [];
}
emit('selection', selectedRows.value);
};
const onSelectionChange = () => {
emit('selection', selectedRows.value);
};
const dataTable = ref();
const exportCSV = (exportSelected) => {
if (exportSelected) {
emit('export-selected', selectedRows.value);
return;
}
emit('export-all');
};
const compressedRows = ref(false);
const padding = '1rem 1rem';
function increasePadding() {
if (!countForVisualize.value) {
document.documentElement?.style.setProperty('--padding-value', padding);
rowViewMode.value = 'Compact View';
} else {
rowViewMode.value = 'Expand View';
document.documentElement?.style.setProperty('--padding-value', '0 1.5rem 0 1.5rem');
}
countForVisualize.value = !countForVisualize.value;
}
// Generate filters and options objects
const dataTypesToFilterMatchMode = {
NUMERIC: FilterMatchMode.EQUALS,
NUMBER: FilterMatchMode.EQUALS,
TEXT: FilterMatchMode.CONTAINS,
STRING: FilterMatchMode.CONTAINS,
DATE: FilterMatchMode.DATE_IS,
BOOLEAN: FilterMatchMode.EQUALS,
SCORE: FilterMatchMode.CONTAINS,
PROGRESS: FilterMatchMode.CONTAINS,
};
const computedFilters = computed(() => {
let filters = {};
let options = {};
_forEach(computedColumns.value, (column) => {
// Check if header text is supplied; if not, generate.
if (!_get(column, 'header')) {
column['header'] = _startCase(_get(column, 'field'));
}
// Choose whether to default to field or a custom filterField (e.g. tag based filters)
const fieldOrFilterField = column?.filterField ? column.filterField : column.field;
const dataType = _toUpper(_get(column, 'dataType'));
let returnMatchMode = null;
// generate return matchmode
if (dataTypesToFilterMatchMode[dataType]) {
returnMatchMode = { value: null, matchMode: dataTypesToFilterMatchMode[dataType] };
}
// case for where multiselect ( can affect any type of data type)
if (_get(column, 'useMultiSelect')) {
returnMatchMode = { value: null, matchMode: FilterMatchMode.IN };
options[column.field] = getUniqueOptions(column);
}
if (returnMatchMode) {
filters[fieldOrFilterField] = {
operator: FilterOperator.AND,
constraints: [returnMatchMode],
};
}
});
return { computedOptions: options, computedFilters: filters };
});
const refOptions = ref(computedFilters.value.computedOptions);
const refFilters = ref(computedFilters.value.computedFilters);
const resetFilters = () => {
refFilters.value = computedFilters.value.computedFilters;
// emit('reset-filters');
};
let toolTipByHeader = (header) => {
const headerToTooltipMap = {
Word: 'Assesses decoding skills at the word level. \n\n Percentile ranges from 0-99 \n Raw Score ranges from 100-900',
Letter:
'Assesses decoding skills at the word level. \n\n Percentile ranges from 0-99 \n Raw Score ranges from 0-90',
Phoneme:
'Assesses phonological awareness: sound matching and elision. \n\n Percentile ranges from 0-99 \n Raw Score ranges from 0-57',
Sentence:
'Assesses reading fluency at the sentence level. \n\n Percentile ranges from 0-99 \n Raw Score ranges from 0-130 ',
Palabra:
'Assesses decoding skills at the word level in Spanish. This test is still in the research phase. \n\n Percentile ranges from 0-99 \n Raw Score ranges from 100-900',
};
return headerToTooltipMap[header] || '';
};
// Generate list of options given a column
function getUniqueOptions(column) {
const field = _get(column, 'field');
let options = [];
_forEach(props.data, (entry) => {
if (!options.includes(_get(entry, field))) {
options.push(_get(entry, field));
}
});
return options;
}
const primaryTasks = [
'scores.letter.percentCorrect',
'scores.letter.percentile',
'scores.pa.percentile',
'scores.swr.percentile',
'scores.sre.percentile',
'scores.pa.standardScore',
'scores.swr.standardScore',
'scores.sre.standardScore',
'scores.sre.rawScore',
'scores.pa.rawScore',
'scores.swr.rawScore',
'scores.sre.rawScore',
];
const spanishTasks = [
'scores.letter-es.percentCorrect',
'scores.letter-es.percentile',
'scores.pa-es.percentCorrect',
'scores.swr-es.percentCorrect',
'scores.sre-es.correctIncorrectDifference',
'scores.pa-es.percentile',
'scores.swr-es.percentile',
'scores.sre-es.percentile',
'scores.letter-es.rawScore',
'scores.pa-es.rawScore',
'scores.swr-es.rawScore',
'scores.sre-es.rawScore',
];
const spanishMathTasks = [
'scores.fluency-arf-es.numCorrect',
'scores.fluency-calf-es.numCorrect',
'scores.fluency-arf-es.percentile',
'scores.fluency-calf-es.percentile',
];
const supplementaryTasks = [
'scores.morphology.percentCorrect',
'scores.cva.percentCorrect',
'scores.vocab.percentCorrect',
'scores.trog.percentCorrect',
'scores.phonics.percentCorrect',
'scores.morphology.percentile',
'scores.cva.percentile',
'scores.vocab.percentile',
'scores.trog.percentile',
'scores.phonics.percentile',
];
const roamTasks = [
'scores.fluency-arf.numCorrect',
'scores.fluency-calf.numCorrect',
'scores.roam-alpaca.percentile',
'scores.egma-math.percentile',
'scores.fluency-arf.numCorrect',
'scores.fluency-calf.numCorrect',
'scores.roam-alpaca.percentCorrect',
'scores.egma-math.percentCorrect',
'scores.fluency-calf.percentile',
'scores.fluency-arf.percentile',
];
const roavTasks = [
'scores.ran.percentile',
'scores.crowding.percentile',
'scores.roav-mep.percentile',
'scores.mep.percentile',
'scores.mep-pseudo.percentile',
'scores.ran.percentCorrect',
'scores.crowding.percentCorrect',
'scores.roav-mep.percentCorrect',
'scores.mep.percentCorrect',
'scores.mep-pseudo.percentCorrect',
];
const getSpacerColumnWidth = computed(() => {
// Look through computedColumns.value
// Find first instance of a Spanish or supplementary or math or vision column
// If found, return the index of that first column, return that as the length of the spacer row
const columns = computedColumns.value;
const allTasks = [
...primaryTasks,
...spanishTasks,
...spanishMathTasks,
...supplementaryTasks,
...roamTasks,
...roavTasks,
];
for (let i = 0; i < columns.length; i++) {
if (allTasks.includes(columns[i].field)) {
return i + 1;
}
}
return columns.length;
});
const primarySpacerColumns = computed(() => {
// Return the number of the primary columns in computedColumns.value
// Return 0 if no Spanish columns
const columns = computedColumns.value;
return columns.filter((column) => primaryTasks.includes(column.field)).length;
});
const spanishSpacerColumns = computed(() => {
// Return the number of the spanish columns in computedColumns.value
// Return 0 if no Spanish columns
const columns = computedColumns.value;
return columns.filter((column) => spanishTasks.includes(column.field)).length;
});
const spanishMathSpacerColumns = computed(() => {
// Return the number of the spanish columns in computedColumns.value
// Return 0 if no Spanish columns
const columns = computedColumns.value;
return columns.filter((column) => spanishMathTasks.includes(column.field)).length;
});
const supplementarySpacerColumns = computed(() => {
// Return the number of supplementary columns in computedColumns.value
const columns = computedColumns.value;
return columns.filter((column) => supplementaryTasks.includes(column.field)).length;
});
const mathSpacerColumns = computed(() => {
// Return the number of math columns in computedColumns.value
const columns = computedColumns.value;
return columns.filter((column) => roamTasks.includes(column.field)).length;
});
const visionSpacerColumns = computed(() => {
// Return the number of vision columns in computedColumns.value
const columns = computedColumns.value;
return columns.filter((column) => roavTasks.includes(column.field)).length;
});
function getFormattedDate(date) {
if (date && !isNaN(date)) {
return date.toLocaleDateString('en-us', { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' });
} else return '';
}
const onColumnToggle = (selected) => {
selectedColumns.value = inputColumns.value.filter((col) => selected.includes(col));
};
const frozenColumns = ref(inputColumns.value.filter((col) => col.pinned));
const onFreezeToggle = (selected) => {
frozenColumns.value = inputColumns.value.filter((col) => selected.includes(col));
selectedColumns.value = selectedColumns.value.map((col) => {
col.pinned = selected.includes(col);
return col;
});
};
const op = ref();
const selectedColumn = ref(null);
const toggle = (event, column) => {
selectedColumn.value = column;
op.value.toggle(event);
};
// Pass through data table events
const emit = defineEmits(['export-all', 'selection', 'reset-filters', 'export-selected', 'export-org-users']);
</script>
<style>
.small-circle {
border-color: white;
display: inline-block;
border-radius: 50%;
border-width: 5px;
height: 15px;
width: 15px;
vertical-align: middle;
margin-right: 5px;
margin-left: 5px;
margin-top: 3px;
margin-bottom: 3px;
}
.p-checkbox .p-checkbox-box {
border: 2px solid var(--surface-300);
background: var(--surface-a);
width: 16px;
height: 16px;
color: var(--text-color);
border-radius: var(--border-radius);
transition: none;
}
.p-checkbox-box.p-component.p-highlight {
background-color: var(--primary-color);
color: white;
border: none;
padding: 0.25rem;
}
.circle {
border-color: white;
display: inline-block;
border-radius: 50%;
border-width: 5px;
height: 25px;
width: 25px;
vertical-align: middle;
margin-right: 10px;
margin-left: 10px;
margin-top: 5px;
margin-bottom: 5px;
}
button.p-button.p-component.softer {
background: #f3adad;
color: black;