From 13f4a952a4a97223a8a0319c8bf92b5b0feeae57 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 17 Dec 2024 12:54:13 -0600 Subject: Add function to update a preview table. --- .../phenotypes/add-phenotypes-raw-files.html | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/uploader/templates/phenotypes/add-phenotypes-raw-files.html b/uploader/templates/phenotypes/add-phenotypes-raw-files.html index ef5743e..b0d40fa 100644 --- a/uploader/templates/phenotypes/add-phenotypes-raw-files.html +++ b/uploader/templates/phenotypes/add-phenotypes-raw-files.html @@ -320,5 +320,51 @@ event.preventDefault(); $("#txt-file-na").val("- NA N/A"); }); + + var update_preview = (table, filedata, formdata) => { + table.find("thead tr").remove() + table.find(".data-row").remove(); + var linenum = 0; + var tableheader = table.find("thead"); + var tablebody = table.find("tbody"); + var numheadings = 0; + filedata.forEach((line) => { + if(line.startsWith(formdata.comment_char)) { + return false; + } + var row = $(""); + line.split(formdata.separator) + .map((field) => {return field.trim();}) + .filter((field) => { + return (field !== "" && field != undefined && field != null); + }) + .forEach((field) => { + if(linenum == 0) { + numheadings += 1; + var tablefield = $(""); + tablefield.text(field); + row.append(tablefield); + } else { + add_class(row, "data-row"); + var tablefield = $(""); + tablefield.text(field); + row.append(tablefield); + } + }); + + if(linenum == 0) { + tableheader.append(row); + } else { + tablebody.append(row); + } + linenum += 1; + }); + + if(table.find("tbody tr.data-row").length > 0) { + add_class(table.find(".data-row-template"), "hidden"); + } else { + remove_class(table.find(".data-row-template"), "hidden"); + } + }; {%endblock%} -- cgit v1.2.3