-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadminDash.js
More file actions
1472 lines (1252 loc) · 44.9 KB
/
adminDash.js
File metadata and controls
1472 lines (1252 loc) · 44.9 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
$.extend(UIOWA_AdminDash, {
sanitizeCellData: function (cellData) {
return cellData.replaceAll("<", "<").replaceAll(">", ">");
},
finalData: {},
initDatatable: function () {
let self = this;
let tempFormatting = self.loadedReport.meta.column_formatting;
const replacePeriod = "_"
let columnsContainingPeriods = []
if (tempFormatting !== undefined) {
const columnConfigArray = Object.entries(
self.loadedReport.meta.column_formatting
);
let researchPurposeIndex = "";
for (let i = 0; i < columnConfigArray.length; i++) {
const column = columnConfigArray[i];
const originalColumnName = column[0]
let columnName = column[0];
const columnConfig = column[1];
if (columnName.includes(".")) {
columnsContainingPeriods = [...columnsContainingPeriods, originalColumnName]
columnName = columnName.replaceAll(".", replacePeriod)
}
for (let i2 = 0; i2 < self.loadedReport.columns.length; i2++) {
if (self.loadedReport.columns[i2].includes(".")) {
columnsContainingPeriods = [...columnsContainingPeriods, self.loadedReport.columns[i2]]
const newColumnName = self.loadedReport.columns[i2].replaceAll(".", replacePeriod)
self.loadedReport.columns[i2] = self.loadedReport.columns[i2].replaceAll(".", replacePeriod)
UIOWA_AdminDash.loadedReport.meta.column_formatting[newColumnName] = { ...self.loadedReport.meta.column_formatting[originalColumnName] }
UIOWA_AdminDash.loadedReport.meta.column_formatting[newColumnName].column_name = newColumnName
UIOWA_AdminDash.loadedReport.meta.column_formatting[newColumnName].dashboard_display_header = newColumnName
delete self.loadedReport.meta.column_formatting[originalColumnName]
}
}
let newColumns = {};
if (columnConfig.code_type === "4") {
researchPurposeIndex = columnName;
for (let j = 0; j < self.formattingReference.purpose_other.length; j++) {
const tempColumnConfig = {
...columnConfig,
["column_name"]: self.formattingReference.purpose_other[j].trim(),
["code_type"]: "",
["dashboard_display_header"]: self.formattingReference.purpose_other[j].trim(),
};
newColumns = {
...newColumns,
[JSON.stringify(self.formattingReference.purpose_other[j]).trim()]: tempColumnConfig,
};
}
tempFormatting = {
...tempFormatting,
...newColumns,
};
self.loadedReport.meta.column_formatting[columnName] = newColumns;
delete self.loadedReport.meta.column_formatting[researchPurposeIndex];
}
}
self.columnsContainingPeriods = columnsContainingPeriods
}
if (columnsContainingPeriods.length >= 1) {
for (let i2 = 0; i2 < self.loadedReport.data.length; i2++) {
for (const column of Object.keys(self.loadedReport.data[i2])) {
const newColumnName = column.replaceAll(".", replacePeriod)
if (column.includes(".")) {
self.loadedReport.data[i2][newColumnName] = self.loadedReport.data[i2][column]
delete self.loadedReport.data[i2][column]
}
}
}
}
// report edit shortcut (admins only)
$(".edit-report").click(function () {
let loadedReportMeta = self.loadedReport.meta;
let url =
self.urlLookup.redcapBase +
"/DataEntry/record_home.php?pid=" +
self.configPID +
"&id=" +
loadedReportMeta.config.report_id;
if ("project_join_info" in loadedReportMeta) {
url += "&arm=2";
}
window.open(url, "_blank");
});
let data = self.loadedReport.data;
let columns = $.map(self.loadedReport.columns, function (column_name) {
return {
title: column_name,
data: column_name,
className: "",
contentPadding: "mmm",
createdCell: function (td, cellData, rowData, row, col) {
$(td).css("text-align", "center");
},
};
});
if (self.loadedReport.meta.column_formatting) {
// set column titles and renderers
columns = $.map(self.loadedReport.columns, function (column_name) {
column_name = column_name.replaceAll(".", replacePeriod)
let columnDetails =
self.loadedReport.meta.column_formatting[column_name];
let column = {
// TODO get proper column name
// This is the value that will display as the column header.
title:
columnDetails.dashboard_display_header !== ""
? columnDetails.dashboard_display_header
: column_name,
data: column_name,
// className: "",
className: columnDetails.dashboard_show_column === "0" ? "noVis" : "",
contentPadding: "mmm",
createdCell: function (td, cellData, rowData, row, col) {
$(td).css("text-align", "center");
},
};
// only apply column formatting for sql reports
// This code controls the TD formatting.
if (self.loadedReport.meta.config.report_sql !== "") {
$.fn.dataTable.render.adFormat = function (column_name) {
return function (data, type, row) {
return self.adFormat(column_name, data, type, row);
};
};
column.render = $.fn.dataTable.render.adFormat(column_name);
}
return column;
});
// add column for child row collapse buttons (if at least one column needs it)
// let hasChildRow = false;
// $.each(self.loadedReport.meta.column_formatting, function (column_name, value) {
//
// if (value.dashboard_show_column === '2') {
// hasChildRow = true;
// }
// });
// if (hasChildRow) {
// $('.report-table > thead > tr:first').prepend('<th></th>');
//
// columns.unshift({
// className: 'details-control',
// orderable: false,
// data: null,
// defaultContent: '',
// render: function () {
// return '<i class="fa fa-plus-square" aria-hidden="true"></i>';
// },
// width:"15px"
// });
// }
}
// init DataTable
let table = $(".report-table").DataTable({
data: data,
scrollXInner: true,
// scrollY: true,
// stateSave: true, todo - saved sorting can be confusing
colReorder: true,
fixedHeader: {
header: true,
headerOffset: $("#redcap-home-navbar-collapse").height(),
},
columns: columns,
order: [],
initComplete: function () {
let hasFilters = false;
let $filterRow = $('<tr class="filter-row"></tr>');
// add column filters
this.api()
.columns()
.every(function () {
let $filter = self.dtFilterInit(this);
if ($filter) {
$filterRow.append($filter);
hasFilters = true;
}
});
if (hasFilters) {
$("thead").append($filterRow);
}
},
});
// generate export buttons
self.dtExportInit(table);
if (
self.loadedReport.ready &&
((self.executiveView && self.executiveExport) || !self.executiveView)
) {
$("#buttons").show(); // TODO change this so buttons won't render at all instead of just being hidden
}
// } else {
// $("#buttons").hide();
// }
// show/hide columns
if (self.loadedReport.ready) {
new $.fn.dataTable.Buttons(table, {
buttons: [
{
text: "Show/Hide Columns",
extend: "colvis",
columns: ":not(.noVis)",
},
],
})
.container()
.appendTo($("#visButtons"));
// sync filter visibility with column
table.on("column-visibility.dt", function (e, settings, column, state) {
let $filterTd = $(".filter-row > td").eq(column);
state ? $filterTd.show() : $filterTd.hide();
});
}
// child row show/hide logic
$(".report-table tbody").on("click", "td.details-control", function () {
let tr = $(this).closest("tr");
let row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass("shown");
} else {
// Open this row
row.child(self.formatChildRow(row.data())).show();
tr.addClass("shown");
}
});
},
formatChildRow: function (row) {
let self = this;
let columnDetails = this.loadedReport.meta.column_formatting;
let htmlRows = "";
$.each(columnDetails, function (column_name, details) {
let data = self.adFormat(column_name, row[column_name], row);
if (details.dashboard_show_column === "2") {
htmlRows = htmlRows.concat(
"<tr>" +
"<td>" +
(details.dashboard_display_header !== ""
? details.dashboard_display_header
: column_name) +
"</td>" +
"<td>" +
data +
"</td>" +
"</tr>"
);
}
});
// `d` is the original data object for the row
return (
'<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
htmlRows +
"</table>"
);
},
splitData: function (data, column_name) {
let separator =
this.loadedReport.meta.column_formatting[column_name]
.group_concat_separator;
return separator !== "" ? data.split(separator) : [data];
},
dtFilterInit: function (column) {
let self = this;
let $filterTd = $('<td data-column-index="' + column.index() + '"></td>');
let column_name = self.loadedReport.columns[column.index()];
let columnDetails =
self.loadedReport.meta.column_formatting !== undefined
? self.loadedReport.meta.column_formatting[column_name]
: undefined;
// todo
if (column_name === undefined) {
return;
}
// hide column
if (
columnDetails !== undefined &&
columnDetails.dashboard_show_column === "0"
) {
column.visible(false);
return;
}
// add dropdown filter
if (
columnDetails !== undefined &&
columnDetails.dashboard_show_filter === "2"
) {
$filterTd.append(
'<select style="width: 100%"><option value=""></option></select>'
);
let $select = $filterTd.find("select").on("change", function () {
let val = $.fn.dataTable.util.escapeRegex($(this).val());
column
// .search( val ? '^'+val+'$' : '', true, false || val ).draw()
.search(val, true, false)
.draw();
});
const columnData = column.data();
let uniqueNames = [];
$.each(columnData, function (i, el) {
if ($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
let multiPurpose = [];
$.each(uniqueNames, function (idx, value) {
// todo filtering for null values
if (value !== null) {
if (value.length >= 2 && !multiPurpose.includes(value)) {
multiPurpose = [...multiPurpose, value];
}
let labels = [];
if (columnDetails !== undefined && columnDetails.code_type !== "") {
if (columnDetails.code_type === "1") {
labels = self.formattingReference.status
}
else if (columnDetails.code_type === "2") {
labels = self.formattingReference.purpose
}
else if (columnDetails.code_type === "3" || columnDetails.code_type === "4") {
labels = self.formattingReference.purpose_other
}
}
if (columnDetails !== undefined &&
columnDetails.code_type !== "" && idx === 0 && columnDetails.code_type != "4") {
$.each(labels, function (idx2, option) {
$select.append(
'<option value="' + option.trim() + '">' + option.trim() + "</option>"
);
});
}
else if (columnDetails !== undefined &&
columnDetails.code_type == "" && idx === 0) {
let valuesInColumn = []
$select.append(
'<option value="' + "FALSE" + '">' + "FALSE" + "</option>"
);
$select.append(
'<option value="' + "TRUE" + '">' + "TRUE" + "</option>"
);
let valuesWithComma = []
$.each(self.loadedReport.data, function (idx2, dataRow) {
let columnName = columnDetails.column_name
if (columnDetails.column_name.includes(" ")) {
let columnName = JSON.stringify(columnDetails.column_name)
}
const dataValue = dataRow[columnName]
if (dataValue != undefined && dataValue.includes(",")) {
const dataValues = dataValue.split(",")
for (const dataPart of dataValues) {
const dataPartTrimmed = dataPart.trim()
if (!valuesWithComma.includes(dataPartTrimmed)) {
valuesWithComma = [...valuesWithComma, dataPartTrimmed]
valuesInColumn = [...valuesInColumn, dataPartTrimmed]
}
}
}
});
if (valuesInColumn.length == 0) {
}
// else {
// $.each(valuesInColumn, function (idx2, dataRow) {
// console.log(valuesInColumn)
// console.log(dataRow)
// $select.append(
// '<option value="' + dataRow + '">' + dataRow + "</option>"
// );
// })
// }
}
}
});
}
// add free text filter
else if (
columnDetails === undefined ||
columnDetails.dashboard_show_filter === "1"
) {
$filterTd.append('<input style="width: 100%"/>');
$("input", $filterTd).on("keyup change clear", function () {
if (column.search() !== this.value) {
// todo split grouped data and filter items
// let groupData = column.data().split()
column.search(this.value).draw();
}
});
}
return $filterTd;
},
dtExportInit: function (table) {
let buttonCommon = {
title: this.loadedReport.meta.config.report_title,
exportOptions: {
orthogonal: "export",
// format: {
// body: function ( data, row, column, node ) {
// // Strip $ from salary column to make it numeric
// return column === 5 ?
// data.replace( /[$,]/g, '' ) :
// data;
// }
// }
},
};
if (
this.loadedReport.ready &&
((self.executiveView && self.executiveExport) || !self.executiveView)
) {
// export buttons
new $.fn.dataTable.Buttons(table, {
buttons: [
$.extend(true, {}, buttonCommon, {
extend: "copyHtml5",
}),
$.extend(true, {}, buttonCommon, {
extend: "csvHtml5",
}),
// $.extend( true, {}, buttonCommon, {
// extend: 'pdfHtml5'
// } ),
$.extend(
true,
{
text: "JSON",
action: function (e, dt, button, config) {
let data = dt.buttons.exportData();
$.fn.dataTable.fileSave(
new Blob([JSON.stringify(data)]),
buttonCommon.title + ".json"
);
},
},
buttonCommon
),
],
})
.container()
.appendTo($("#buttons"));
}
},
adFormat: function (column_name, data, type, row) {
if (data === null) {
return type === "display"
? '<span class="text-muted">null</span>'
: "null";
}
let self = this;
let columnDetails = self.loadedReport.meta.column_formatting[column_name];
let sourceColumn =
columnDetails.link_source_column !== ""
? columnDetails.link_source_column
: column_name;
data = self.splitData(data, sourceColumn);
let sourceData = data;
let formattedSeparator = type === "export" ? ";" : "<br />";
if (sourceColumn !== column_name) {
sourceData = self.splitData(row[sourceColumn], sourceColumn);
}
// for each item (in case data is grouped)
data = $.map(data, function (item, index) {
if (item === null) {
return type === "display"
? '<span class="text-muted">null</span>'
: "null";
}
//todo
// fix for "Archived" projects
// if (value === 3) {
// value = 2;
// }
let formattedVal = item;
let rawUrl = "";
let iconsHtml = "";
// Replace coded value with label
if (columnDetails.code_type !== "") {
try {
// if export, check if labels are preferred
if (type === "export" && columnDetails.export_codes === "0") {
formattedVal = item;
} else {
if (columnDetails.code_type == "1") {
formattedVal = self.adFormat_code(item, columnDetails.code_type);
}
else if (columnDetails.code_type == "2") {
formattedVal = self.adFormat_code(item, columnDetails.code_type);
}
else if (columnDetails.code_type == "3") {
// formattedVal = self.adFormat_code(item, columnDetails.code_type);
const arrayOfFormattedVals = item.split(",");
let codesAsLabels = "";
$.each(arrayOfFormattedVals, function (idx, value) {
const index = self.formattingReference.purpose_other.indexOf(value);
if (idx === arrayOfFormattedVals.length - 1) {
codesAsLabels += self.formattingReference.purpose_other[value].trim();
} else {
codesAsLabels += self.formattingReference.purpose_other[value].trim() + ", ";
}
});
formattedVal = codesAsLabels;
}
else if (
columnDetails.code_type == "4"
) {
const arrayOfFormattedVals = item.split(",");
let codesAsLabels = "";
$.each(arrayOfFormattedVals, function (idx, value) {
const index = self.formattingReference.purpose_other.indexOf(value);
if (idx === arrayOfFormattedVals.length - 1) {
codesAsLabels += self.formattingReference.purpose_other[value].trim();
} else {
codesAsLabels += self.formattingReference.purpose_other[value].trim() + ", ";
}
});
formattedVal = codesAsLabels;
} else {
formattedVal = self.adFormat_code(item, columnDetails.code_type);
}
}
if (type === "filter") {
return formattedVal; //todo broken
}
} catch (e) {
console.groupCollapsed(
"Failed to replace codes with labels for " + column_name
);
console.groupEnd();
}
}
// generate url for linking
if (columnDetails.link_type !== "" && !self.executiveView) {
try {
// formattedVal = "hi";
rawUrl = self.adFormat_url(
item,
sourceData[index],
columnDetails.link_type,
columnDetails.specify_custom_link
);
if (type === "export") {
if (columnDetails.export_urls === "1") {
formattedVal = self.sanitizeCellData(rawUrl);
} else {
formattedVal = self.sanitizeCellData(item);
}
} else if (type === "filter") {
formattedVal = self.sanitizeCellData(item);
} else {
formattedVal = `<a href="${rawUrl}" target="_blank">${self.sanitizeCellData(
formattedVal
)}</a>`; //$.fn.dataTable.render.text()
}
} catch (e) {
console.groupCollapsed(
"Failed to generate url(s) for " + column_name
);
console.groupEnd();
}
}
// prepend hint icons
if (
(columnDetails.hint_icons___1 === "1" ||
columnDetails.hint_icons___2 === "1") &&
type === "display"
) {
try {
let columnReference = {
withTags: self.loadedReport.columns,
tagless: $.map(self.loadedReport.columns, function (value) {
return value.split("#")[0];
}),
};
if (item) {
iconsHtml = self.adFormat_icons(
item,
index,
row,
columnReference,
columnDetails
);
}
} catch (e) {
console.groupCollapsed(
"Failed to process hint icon(s) for " + column_name
);
console.groupEnd();
}
}
return iconsHtml + formattedVal;
});
data = data.join(formattedSeparator);
return data;
},
adFormat_url: function (value, sourceValue, linkIndex, customUrl) {
let url = "";
// set custom url
if (linkIndex === "99") {
url = customUrl.replace("{value}", sourceValue);
}
// set mailto
else if (linkIndex === "9") {
url = "mailto:" + sourceValue;
}
// set redcap url
else {
try {
url =
this.urlLookup.redcapBase +
this.formattingReference.links[linkIndex - 1].trim() +
sourceValue;
} catch (error) {
// invalid link index
console.error(error);
return value;
}
}
return url;
},
adFormat_code: function (value, codeIndex) {
if (codeIndex === "1") {
// Project Status
return this.formattingReference.status[value];
} else if (codeIndex === "2") {
// Project Purpose
return this.formattingReference.purpose[value].trim();
}
else if (codeIndex === "3") {
return this.formattingReference.purpose_other[value].trim();
}
},
adFormat_icons: function (value, index, row, columnReference, columnDetails) {
let returnHtml = "";
// suspended users
if (
columnDetails.hint_icons___1 === "1" &&
columnReference.tagless.includes("user_suspended_time")
) {
let suspendedColumnName =
columnReference.withTags[
columnReference.tagless.indexOf("user_suspended_time")
];
let suspendedValue =
row[suspendedColumnName] !== null
? this.splitData(row[suspendedColumnName], suspendedColumnName)[index]
: null;
if (suspendedValue !== null && suspendedValue.length > 8) {
returnHtml += `<span class="user-detail" title="User suspended" data-toggle="tooltip" data-placement="left">
<i class="fas fa-ban fa-fw" style="color: red;"></i>
</span>`;
}
}
// project status
if (columnDetails.hint_icons___2 === "1") {
let hintIcon = {};
if (columnReference.tagless.includes("status")) {
let iconLookup = [
{
class: "",
tooltip: "Development",
icon: "wrench",
color: "#444",
},
{
class: "",
tooltip: "Production",
icon: "check-square",
color: "#00A000",
},
{
class: "",
tooltip: "Analysis/Cleanup",
icon: "minus-circle",
color: "#A00000",
},
];
let statusColumnName =
columnReference.withTags[columnReference.tagless.indexOf("status")];
let statusValue = this.splitData(
row[statusColumnName],
statusColumnName
)[index];
hintIcon = iconLookup[statusValue];
}
if (columnReference.tagless.includes("completed_time")) {
let completedColumnName =
columnReference.withTags[
columnReference.tagless.indexOf("completed_time")
];
let completedValue = this.splitData(
row[completedColumnName],
completedColumnName
)[index];
if (completedValue) {
hintIcon = {
class: "",
tooltip: "Completed",
icon: "archive",
color: "#C00000",
};
}
}
if (columnReference.tagless.includes("date_deleted")) {
let deletedColumnName =
columnReference.withTags[
columnReference.tagless.indexOf("date_deleted")
];
let deletedValue = this.splitData(
row[deletedColumnName],
deletedColumnName
)[index];
if (deletedValue) {
hintIcon = {
class: "",
tooltip: "Deleted",
icon: "trash",
color: "#A00000",
};
}
}
returnHtml += `<span class="${hintIcon.class}" title="${hintIcon.tooltip}" data-toggle="tooltip" data-placement="left">
<i class="fas fa-${hintIcon.icon} fa-fw" style="color: ${hintIcon.color};"></i>
</span>`;
}
return returnHtml;
},
csvTo2dArray: function (parseMe) {
let delimiter = ",";
if (UIOWA_AdminDash.delimiter === "SPACE") {
delimiter = " ";
} else if (UIOWA_AdminDash.delimiter === "TAB") {
delimiter = "\t";
} else if (UIOWA_AdminDash.delimiter === "|") {
delimiter = "[|]";
} else if (UIOWA_AdminDash.delimiter === "^") {
delimiter = "[/\^]";
} else {
delimiter = UIOWA_AdminDash.delimiter;
}
const splitFinder = new RegExp(`${delimiter}|\r?\n|"(\\"|[^"])*?"`, `g`);
let currentRow = [];
const rowsOut = [currentRow];
let lastIndex = (splitFinder.lastIndex = 0);
// add text from lastIndex to before a found newline or comma
const pushCell = (endIndex) => {
endIndex = endIndex || parseMe.length;
const addMe = parseMe.substring(lastIndex, endIndex);
// remove quotes around the item
currentRow.push(addMe.replace(/^"|"$/g, ""));
lastIndex = splitFinder.lastIndex;
};
let regexResp;
// for each regexp match (either comma, newline, or quoted item)
while ((regexResp = splitFinder.exec(parseMe))) {
const split = regexResp[0];
// if it's not a quote capture, add an item to the current row
// (quote captures will be pushed by the newline or comma following)
if (split.startsWith(`"`) === false) {
const splitStartIndex = splitFinder.lastIndex - split.length;
pushCell(splitStartIndex);
// then start a new row if newline
const isNewLine = /^\r?\n$/.test(split);
if (isNewLine) {
rowsOut.push((currentRow = []));
}
}
}
// make sure to add the trailing text (no commas or newlines after)
pushCell();
return rowsOut;
},
generateMultiColumnResearchPurpose: function () {
const columnConfigArray = Object.entries(
UIOWA_AdminDash.loadedReport.meta.column_formatting
);
// let researchPurposeIndex = "";
let finalColumns = [];
for (let i = 0; i < columnConfigArray.length; i++) {
const column = columnConfigArray[i];
const columnName = column[0];
const columnConfig = column[1];
let newColumns = UIOWA_AdminDash.loadedReport.meta.column_formatting;
if (columnConfig.code_type === "4") {
researchPurposeIndex = columnName;
for (let j = 0; j < UIOWA_AdminDash.formattingReference.purpose_other.length; j++) {
const tempColConfig = {
...columnConfig,
["column_name"]: UIOWA_AdminDash.formattingReference.purpose_other[j].trim(),
// ["link_source_column"]: "purpose_other",
["code_type"]: "",
["dashboard_display_header"]:
UIOWA_AdminDash.formattingReference.purpose_other[j].trim(),
};
newColumns = {
...newColumns,
[JSON.stringify(UIOWA_AdminDash.formattingReference.purpose_other[j]).trim()]:
tempColConfig,
};
finalColumns = [
...finalColumns,
JSON.stringify(UIOWA_AdminDash.formattingReference.purpose_other[j].trim()),
];
}
tempFormatting = {
...tempFormatting,
...newColumns,
};
UIOWA_AdminDash.loadedReport.meta.column_formatting = tempFormatting;
} else {
finalColumns = [...finalColumns, columnName];
}
}
return finalColumns;
},
generateMultiColumnResearchPurposeColumns: function (idx, columns) {
const removeIndex = columns.indexOf(idx);
purposeOtherIndex = removeIndex;
purposeOtherName = idx;
const newArray = columns.toSpliced(removeIndex, 1);
newArray.splice(removeIndex, 0, ...UIOWA_AdminDash.formattingReference.purpose_other);
return newArray;
},
generateMultiColumnResearchPurposeData: function (newJson, columnFormatting) {
tempFormatting = UIOWA_AdminDash.loadedReport.meta.column_formatting;
for (let i7 = 0; i7 < newJson.length; i7++) {
let row = newJson[i7];
let newData = {};
const rowProps = Object.entries(columnFormatting);
for (let i8 = 0; i8 < rowProps.length; i8++) {
const propConfig = rowProps[i8][1];
if (propConfig.code_type === "4") {
let purposeOtherValues = []
if (row[propConfig.column_name] != undefined && row[propConfig.column_name].includes(",")) {
purposeOtherValues = row[propConfig.column_name].split(",");
} else {
purposeOtherValues = [row[propConfig.column_name]]
}
for (
let idx10 = 0;
idx10 < UIOWA_AdminDash.formattingReference.purpose_other.length;
idx10++
) {