diff options
author | Frederick Muriuki Muriithi | 2024-12-17 12:54:13 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-12-17 15:59:06 -0600 |
commit | 13f4a952a4a97223a8a0319c8bf92b5b0feeae57 (patch) | |
tree | 7e760ec2a126b999bccfa2e11879cabe02a78ab9 | |
parent | 5fb7ed201e07237a1df7a9d4f55dc25daaccfac4 (diff) | |
download | gn-uploader-13f4a952a4a97223a8a0319c8bf92b5b0feeae57.tar.gz |
Add function to update a preview table.
-rw-r--r-- | uploader/templates/phenotypes/add-phenotypes-raw-files.html | 46 |
1 files changed, 46 insertions, 0 deletions
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 = $("<tr></tr>"); + 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 = $("<th></th>"); + tablefield.text(field); + row.append(tablefield); + } else { + add_class(row, "data-row"); + var tablefield = $("<td></td>"); + 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"); + } + }; </script> {%endblock%} |