Converting a URL-encoded filter to a LABKEY.Filter - is there a quick and easy way? | Leo Dashevskiy | 2015-04-28 14:48 |
Status: Closed | ||
I meanwhile (it might be a while before the feature request gets realized) cooked myself up something like this: var filters = [], ar, cn, ft, map = { eq: 'EQUAL', dateeq: 'DATE_EQUAL', neq: 'NOT_EQUAL', dateneq: 'DATE_NOT_EQUAL', neqornull: 'NOT_EQUAL_OR_MISSING', gt: 'GREATER_THAN', dategt: 'DATE_GREATER_THAN', gte: 'GREATER_THAN_OR_EQUAL', dategte: 'DATE_GREATER_THAN_OR_EQUAL', lt: 'LESS_THAN', datelt: 'DATE_LESS_THAN', lte: 'LESS_THAN_OR_EQUAL', datelte: 'DATE_LESS_THAN_OR_EQUAL', startswith: 'STARTS_WITH', doesnotstartwith: 'DOES_NOT_START_WITH', contains: 'CONTAINS', doesnotcontain: 'DOES_NOT_CONTAIN', containsoneof: 'CONTAINS_ONE_OF', containsnoneof: 'CONTAINS_NONE_OF', 'in' : 'EQUALS_ONE_OF', notin: 'EQUALS_NONE_OF', between: 'BETWEEN', notbetween: 'NOT_BETWEEN', memberof: 'MEMBER_OF', isblank: 'MISSING', isnonblank: 'NOT_MISSING', hasmvvalue: 'HAS_MISSING_VALUE', nomvvalue: 'DOES_NOT_HAVE_MISSING_VALUE' } ; $.each( params, function( k, v ){ ar = k.split( '~' ); if ( ar.length == 2 ){ ft = LABKEY.Filter.Types[map[ar[1]]]; cn = ar[0]; if ( ft && cn.substring( 0, 6 ) == 'query.' ){ filters.push( LABKEY.Filter.create( cn.substring( 6 ), v, ft ) ); } } }); Where "params" is the input I wrote of and "filters" is the output I wrote of. I got the backwards "map" from the makeFilter() R method (had to reverse it in R) and also clean up some to remove duplicates. By the way, there are a few discrepancies in names between R's makeFilter() method and JS Filter.js file! Oh, something I forgot in the previous post is that a URL encoding for a filter also starts with "query." and not the column name right away as I previously erroneously wrote, so I guess that's another requirement... Thanks. -Leo |
||