From a4fd21d94e5412e120e6483e750557d5c8501949 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 2 Jun 2016 21:04:01 +0000 Subject: Fixed some issues with global search result tables, including: - Wrong digits for mean expression and additive effect - Bad loooking width on some columns, like Max LRS Location - Janky functionality for column resizing and drag-and-dropping (just disabled these functions) - Geno and Pheno global search tables weren't built in the same way, so now they are I also fixed the sorting to always put N/A's at the bottom of the table by editing naturalSort.js --- .../DataTables/js/dataTables.naturalSort.js | 122 +++++++++++---------- wqflask/wqflask/templates/gsearch_gene.html | 82 ++++---------- wqflask/wqflask/templates/gsearch_pheno.html | 67 ++++++----- wqflask/wqflask/templates/search_result_page.html | 20 ---- 4 files changed, 124 insertions(+), 167 deletions(-) diff --git a/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js b/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js index c9e26682..0198fd48 100755 --- a/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js +++ b/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js @@ -1,56 +1,68 @@ -(function() { - -/* - * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license - * Author: Jim Palmer (based on chunking idea from Dave Koelle) - * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo - * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js - */ -function naturalSort (a, b) { - var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi, - sre = /(^[ ]*|[ ]*$)/g, - dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, - hre = /^0x[0-9a-f]+$/i, - ore = /^0/, - // convert all to strings and trim() - x = a.toString().replace(sre, '') || '', - y = b.toString().replace(sre, '') || '', - // chunk/tokenize - xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), - yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), - // numeric, hex or date detection - xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)), - yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null; - // first try and sort Hex codes or Dates - if (yD) - if ( xD < yD ) return -1; - else if ( xD > yD ) return 1; - // natural sorting through split numeric strings and default strings - for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { - // find floats not starting with '0', string or 0 if not defined (Clint Priest) - var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; - var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; - // handle numeric vs string comparison - number < string - (Kyle Adams) - if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1; - // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' - else if (typeof oFxNcL !== typeof oFyNcL) { - oFxNcL += ''; - oFyNcL += ''; - } - if (oFxNcL < oFyNcL) return -1; - if (oFxNcL > oFyNcL) return 1; - } - return 0; -} - -jQuery.extend( jQuery.fn.dataTableExt.oSort, { - "natural-asc": function ( a, b ) { - return naturalSort(a,b); - }, - - "natural-desc": function ( a, b ) { - return naturalSort(a,b) * -1; - } -} ); - +(function() { + +/* + * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license + * Author: Jim Palmer (based on chunking idea from Dave Koelle) + * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo + * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js + */ +function naturalSort (a, b) { + var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi, + sre = /(^[ ]*|[ ]*$)/g, + dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, + hre = /^0x[0-9a-f]+$/i, + ore = /^0/, + // convert all to strings and trim() + x = a.toString().replace(sre, '') || '', + y = b.toString().replace(sre, '') || '', + // chunk/tokenize + xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), + yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), + // numeric, hex or date detection + xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)), + yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null; + + // first try and sort Hex codes or Dates + if (yD) + if ( xD < yD ) return -1; + else if ( xD > yD ) return 1; + + // natural sorting through split numeric strings and default strings + for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { + // find floats not starting with '0', string or 0 if not defined (Clint Priest) + var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; + var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; + // handle numeric vs string comparison - number < string - (Kyle Adams) + if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1; + // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' + else if (typeof oFxNcL !== typeof oFyNcL) { + oFxNcL += ''; + oFyNcL += ''; + } + if (oFxNcL < oFyNcL) return -1; + if (oFxNcL > oFyNcL) return 1; + } + + return 0; +} + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "natural-asc": function ( a, b ) { + // first check if null or n/a + if (a == "N/A" || a == "NA") return 1; + else if (b == "N/A" || b == "NA") return -1; + else { + return naturalSort(a,b); + } + }, + + "natural-desc": function ( a, b ) { + if (a == "N/A" || a == "NA") return 1; + else if (b == "N/A" || b == "NA") return -1; + else { + return naturalSort(a,b) * -1; + } + } +} ); + }()); \ No newline at end of file diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 37e26817..ff4254aa 100755 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -38,7 +38,7 @@
+ | Index | Species | Group | @@ -44,21 +45,22 @@||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
- | {{ loop.index }} | -{{ this_trait.dataset.group.species }} | -{{ this_trait.dataset.group.name }} | -{{ this_trait.name }} | -{{ this_trait.description_display }} | -{{ this_trait.authors }} | -{{ this_trait.pubmed_text }} | -{{ this_trait.LRS_score_repr }} | -{{ this_trait.LRS_location_repr }} | -{{ '%0.3f' % this_trait.additive|float }} | ++ | {{ loop.index }} | +{{ this_trait.dataset.group.species }} | +{{ this_trait.dataset.group.name }} | +{{ this_trait.name }} | +{{ this_trait.description_display }} | +{{ this_trait.authors }} | +{{ this_trait.pubmed_text }} | +{{ '%0.1f' % this_trait.LRS_score_repr|float }} | +{{ this_trait.LRS_location_repr }} | +{{ '%0.3f' % this_trait.additive|float }} |