Ignore:
Timestamp:
Dec 23, 2011, 7:40:11 AM (13 years ago)
Author:
rick
Message:

Add extra filter to allow display some and all.

While where fix the filters to make the look more structured.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/wlheatmap/static/heatmap_extensions.js

    r9813 r9815  
    224224        userlist.push(json.gebruiker);
    225225        $.each(json.meetrondje, function(m, meetrondje){
    226           $("#select_dataset").append($("<option/>").attr({"class":json.gebruiker, "value": json.gebruiker + "-" + meetrondje.naam}).text(meetrondje.naam));
     226          $("#select_dataset").append($("<option/>").attr({"class":json.gebruiker, "value": meetrondje.naam}).text(meetrondje.naam));
    227227          $.each(meetrondje.nodes, function(n, nodes){
    228             $("#select_node").append($("<option/>").attr({"class":json.gebruiker + "-" + meetrondje.naam, "value":nodes}).text(nodes));
     228            $("#select_node").append($("<option/>").attr({"class":json.gebruiker + "\\" + meetrondje.naam, "value":nodes}).text(nodes));
    229229            if(jQuery.inArray(nodes, nodelist)<0){
    230230              nodelist.push(nodes);
     
    235235    // Initiate the chain
    236236    $("#select_dataset").chained("#select_user");
    237     $("#select_node").chained("#select_dataset");
     237    $("#select_node").chained("#select_user, #select_dataset");
    238238    }
    239239  );
     
    258258  $("#select_node").change(function(){
    259259    update_lname();
     260    update_raw_filter();
     261  });
     262  $("#select_nodetype").change(function(){
    260263    update_raw_filter();
    261264  });
     
    333336
    334337  function get_raw_filter() {
    335     user = $('#select_user option:selected').text();
    336     dataset = $('#select_dataset option:selected').text();
    337     wlnode = $('#select_node option:selected').text();
     338    var query_array = [];
     339
     340    /* Values to be used to create the filter */
     341    user = $('#select_user option:selected').val();
     342    dataset = $('#select_dataset option:selected').val();
     343    wlnode = $('#select_node option:selected').val();
     344    nodetype = $('#select_nodetype option:selected').val();
    338345    start_date = $('#start_date').val();
    339346    end_date = $('#end_date').val();
    340347    colour = $("#colour").val();
    341348
     349    // some checks if values are correct, and adding them to parts of the link
     350    if (user != 'all') {
     351      query_array.push('meetrondje__gebruiker__naam=' + user);
     352    }
     353    if (dataset != 'all') {
     354      query_array.push('meetrondje__naam=' + dataset);
     355    }
     356    if (wlnode != 'all') {
     357      query_array.push('accespoint__ssid=' + wlnode);
     358    }
     359    if (nodetype) {
     360      query_array.push(nodetype);
     361    }
     362
     363    if (start_date){
     364      sd_d=start_date.substr(0,2);
     365      sd_m=start_date.substr(3,2);
     366      sd_y=start_date.substr(6,4);
     367      query_array.push('meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d);
     368    }
     369    if (end_date){
     370      ed_d=end_date.substr(0,2);
     371      ed_m=end_date.substr(3,2);
     372      ed_y=end_date.substr(6,4);
     373      query_array.push('meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d);
     374    }
     375
     376    var min = $("#select_sig_slider").slider("values")[0];
     377    var max = $("#select_sig_slider").slider("values")[1];
     378    query_array.push('signaal__gte=' + min);
     379    query_array.push('signaal__lte=' + max);
     380
    342381    /**
    343382     * On HEX to RGB:
    344383     * http://stackoverflow.com/questions/5798868/need-some-tips-with-how-to-convert-a-hexadecimal-color-value-to-a-rgb-one/5798900#5798900
     384     * If no colour is defined, use a random colour
    345385     */
    346     colour = parseInt((colour.substr(1, 2)),16) + ',' + parseInt((colour.substr(3, 2)),16) + ',' + parseInt((colour.substr(5, 2)),16);
    347 
    348     // some checks if values are correct, and adding them to parts of the link
    349     if (user == 'all') {
    350       user = '';
     386    if (colour){
     387      colour = [parseInt((colour.substr(1, 2)),16), parseInt((colour.substr(3, 2)),16), parseInt((colour.substr(5, 2)),16)];
    351388    } else {
    352       user='&meetrondje__gebruiker__naam='+user;
    353     }
    354     if (dataset == 'all') {
    355       dataset = '';
    356     } else {
    357       dataset='&meetrondje__naam='+dataset;
    358     }
    359     if (wlnode == 'all'){
    360       wlnode='';
    361     } else {
    362       wlnode='&accespoint__ssid='+wlnode;
    363     }
    364     if (start_date && end_date){
    365       sd_d=start_date.substr(0,2);
    366       sd_m=start_date.substr(3,2);
    367       sd_y=start_date.substr(6,4);
    368 
    369       ed_d=end_date.substr(0,2);
    370       ed_m=end_date.substr(3,2);
    371       ed_y=end_date.substr(6,4);
    372 
    373       start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
    374       end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
    375     }
    376     if (start_date && !end_date){
    377       sd_d=start_date.substr(0,2);
    378       sd_m=start_date.substr(3,2);
    379       sd_y=start_date.substr(6,4);
    380       start_date='&meetrondje__datum__gte=' + sd_y +'-'+ sd_m +'-'+ sd_d;
    381       end_date='';
    382     }
    383     if (!start_date && end_date){
    384       ed_d=end_date.substr(0,2);
    385       ed_m=end_date.substr(3,2);
    386       ed_y=end_date.substr(6,4);
    387       start_date='';
    388       end_date='&meetrondje__datum__lte=' + ed_y +'-'+ ed_m +'-'+ ed_d;
    389     }
    390     if (colour != 'NaN,NaN,NaN'){
    391       colour=colour;
    392     } else {
    393       colour = Math.floor(Math.random()*256)+','+Math.floor (Math.random()*256)+','+Math.floor(Math.random()*256);
    394     }
    395 
    396     var min = $("#select_sig_slider").slider("values")[0];
    397     var max = $("#select_sig_slider").slider("values")[1];
    398     signal = '&signaal__gte=' + min + '&signaal__lte=' + max;
    399 
    400     var raw_filter = "colour=" + colour + user + dataset + wlnode + start_date + end_date + signal
     389      colour = [Math.floor(Math.random()*256), Math.floor (Math.random()*256), Math.floor(Math.random()*256)];
     390    }
     391    query_array.push('colour=' + colour.join(','));
     392
     393    /* Return final result */
     394    var raw_filter = query_array.filter(function() {return true;}).sort().join('&');
    401395    return raw_filter;
    402396  }
     
    458452  }
    459453  var pl = map.getControlsByClass('OpenLayers.Control.Permalink');
    460   pl.updateLink();
     454  pl.updateLink;
    461455});
Note: See TracChangeset for help on using the changeset viewer.