about summary refs log tree commit diff
diff options
context:
space:
mode:
authorpi coding agent <pi@localhost>2026-11-05 20:10:23 +0000
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-05 14:16:45 -0600
commitaec6f7a927f1cf44bc5e7dfe3951ddddf3425872 (patch)
tree1615d11dbfde0b1c258cc2c8cc1d490c9e26e83a
parente4ffb00d2f505ba11ec175ada2c85288d80a6050 (diff)
downloadgn-uploader-aec6f7a927f1cf44bc5e7dfe3951ddddf3425872.tar.gz
Share missing-value symbol parsing in the browser
Add `uploader/static/js/data_utils.js` with `parseSymbols`, the JS counterpart
of `r_qtl.utils.parse_missing_values_symbols`, and use it in the CSV previews
(files.js and the phenotypes raw-files template) instead of their inline
space-splitting. Load data_utils.js before files.js.
-rw-r--r--uploader/static/js/data_utils.js19
-rw-r--r--uploader/static/js/files.js6
-rw-r--r--uploader/templates/genotypes/add-genotypes-records-csv.html1
-rw-r--r--uploader/templates/phenotypes/add-phenotypes-raw-files.html7
4 files changed, 23 insertions, 10 deletions
diff --git a/uploader/static/js/data_utils.js b/uploader/static/js/data_utils.js
new file mode 100644
index 0000000..4bc1d1b
--- /dev/null
+++ b/uploader/static/js/data_utils.js
@@ -0,0 +1,19 @@
+/**
+ * General data utilities.
+ */
+
+/**
+ * Parse a whitespace- and/or comma-separated list of unique symbols.
+ *
+ * This mirrors the Python `r_qtl.utils.parse_missing_values_symbols` so that
+ * previews and server-side processing interpret symbol lists the same way.
+ */
+var parseSymbols = (value) => {
+    return [...new Set(
+        (value || "")
+            .replace(/,/g, " ")
+            .split(/\s+/)
+            .map((item) => { return item.trim(); })
+            .filter((item) => { return Boolean(item); })
+    )];
+};
diff --git a/uploader/static/js/files.js b/uploader/static/js/files.js
index 7532df3..eaa5991 100644
--- a/uploader/static/js/files.js
+++ b/uploader/static/js/files.js
@@ -141,11 +141,7 @@ var updatePreview = (table, filedata, formdata, numrows) => {
         .split(" ")
         .map((v) => {return v.trim();})
         .filter((v) => {return Boolean(v);});
-    var navalues = formdata
-        .na_strings
-        .split(" ")
-        .map((v) => {return v.trim();})
-        .filter((v) => {return Boolean(v);});
+    var navalues = parseSymbols(formdata.na_strings);
     filedata.forEach((line) => {
         if(comment_chars.includes(line[0]) || linenum >= numrows) {
             return false;
diff --git a/uploader/templates/genotypes/add-genotypes-records-csv.html b/uploader/templates/genotypes/add-genotypes-records-csv.html
index a99bbbb..6bb9b01 100644
--- a/uploader/templates/genotypes/add-genotypes-records-csv.html
+++ b/uploader/templates/genotypes/add-genotypes-records-csv.html
@@ -163,6 +163,7 @@
 
 <script src="{{url_for('base.node_modules',
              filename='resumablejs/resumable.js')}}"></script>
+<script src="/static/js/data_utils.js"></script>
 <script src="/static/js/files.js"></script>
 
 {{add_csv_fields_event_handlers()}}
diff --git a/uploader/templates/phenotypes/add-phenotypes-raw-files.html b/uploader/templates/phenotypes/add-phenotypes-raw-files.html
index 79556cf..e76657a 100644
--- a/uploader/templates/phenotypes/add-phenotypes-raw-files.html
+++ b/uploader/templates/phenotypes/add-phenotypes-raw-files.html
@@ -425,6 +425,7 @@
 {%block more_javascript%}
 <script src="{{url_for('base.node_modules',
              filename='resumablejs/resumable.js')}}"></script>
+<script type="text/javascript" src="/static/js/data_utils.js"></script>
 <script type="text/javascript" src="/static/js/files.js"></script>
 
 <script type="text/javascript">
@@ -451,11 +452,7 @@
       var tableheader = table.find("thead");
       var tablebody = table.find("tbody");
       var numheadings = 0;
-      var navalues = formdata
-          .na_strings
-          .split(" ")
-          .map((v) => {return v.trim();})
-          .filter((v) => {return Boolean(v);});
+      var navalues = parseSymbols(formdata.na_strings);
       filedata.forEach((line) => {
           if(line.startsWith(formdata.comment_char) || linenum >= numrows) {
               return false;