Changeset a6f44d6b86937e3b7a7f84eea82557562396a359

Show
Ignore:
Timestamp:
06/10/09 15:50:26 (5 years ago)
Author:
Umar Farooq <umar@omniti.com>
git-committer:
Umar Farooq <umar@omniti.com> 1244649026 +0000
git-parent:

[e85722c8867aa49780d7494d535942c6d3669945]

git-author:
Umar Farooq <umar@omniti.com> 1244649026 +0000
Message:

creating graphs from templates now track their genesis, and update if they match with an existing graph

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ui/web/htdocs/template_browse_json.php

    r0a3bdfb ra6f44d6  
    155155         sidvarclass = $(selected).parents(".collapsable:eq(0)").find("span").attr("class"); 
    156156         if(sidvar_sid_map[sidvarclass] == undefined) sidvar_sid_map[sidvarclass] = Array(); 
    157          sids[i] = $(selected).val(); 
    158          sidvar_sid_map[sidvarclass].push($(selected).val()); 
     157         sval = parseInt($(selected).val()); 
     158         sids[i] = sval; 
     159         sidvar_sid_map[sidvarclass].push(sval); 
    159160}); 
    160161 
     162sidvars.sort(); 
     163textvars.sort(); 
     164 
    161165for (i=0; i<sidvars.length; i++){ 
     166        sidvar_sid_map[sidvars[i]].sort(); 
    162167        sidvals+="&"+sidvars[i]+"="+sidvar_sid_map[sidvars[i]].join(","); 
    163168} 
    164169 
    165170//if we have selected atleast one sid 
    166 if(sids.length > 0){ 
     171if(sids.length > 0){     
    167172        var dataString = 'templateid='+templateid+'&textvars='+textvars.join(',')+'&sidvars='+sidvars.join(',')+textvals+sidvals; 
    168173        $.ajax({ 
  • ui/web/htdocs/template_graph.php

    r43db6fd ra6f44d6  
    1111$var_vals = array(); 
    1212 
     13$genesis_base = "templateid=".$templateid; 
     14 
    1315foreach ($text_vars as $tv) { 
    1416  $rparams[$tv] = $_POST[$tv]; 
     17  $genesis_base.=$tv."=".$_POST[$tv]; 
    1518} 
    1619 
     
    2124//this number is used so we dont end up trying to create multiple graphs with the same title             
    2225$graph_num = 1; 
    23     
    24 function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $rparams, $templateid, $graph_num) 
     26 
     27//this function will create each combination of values for each SID placeholder, against the TEXT placeholders set 
     28//then, it will create graphs for each of these combinations, updating a graph if one already exists with the same genesis 
     29//a graph's genesis is composed of its templateid, its text vars and their values, and its sid vars and their values, and 
     30//should be unique among saved_graphs    
     31function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num) 
    2532    { 
    26          
    27         if ($i >= count($var_vals)){ 
     33        $genesis = $genesis_base; 
     34        if ($i >= count($var_vals)){        
    2835            $vals_combo = explode(",", $combo); 
    2936            for ($j=0; $j<count($vals_combo); $j++) { 
    3037               $rparams[$sid_vars[$j]] = $vals_combo[$j]; 
     38               $genesis.=",".$sid_vars[$j]."=".$vals_combo[$j]; 
    3139            } 
     40 
    3241            $template = new Reconnoiter_GraphTemplate($templateid); 
    3342            $db = Reconnoiter_DB::getDB(); 
    34             $graph_json = $template->newGraph($rparams); 
     43            $graph_json = $template->getNewGraphJSON($rparams); 
    3544            $graph_json = stripslashes($graph_json); 
    3645            $graph_json = json_decode($graph_json, true); 
    3746            $graph_json['title'] = $graph_json['title'].$graph_num; 
     47            $graph_json['genesis'] = $genesis; 
     48 
     49            $grow = $db->getGraphByGenesis($genesis); 
     50            if($grow['graphid']) { 
     51               $graph_json['id'] = $grow['graphid']; 
     52               $graph_id = $db->saveGraph($graph_json); 
     53               return; 
     54            } 
    3855            $graph_id = $db->saveGraph($graph_json); 
    3956            $graph_json['id'] = $graph_id; 
    4057            $graph_id = $db->saveGraph($graph_json); 
     58            return; 
    4159        } 
    4260        else 
     
    4462            foreach ($var_vals[$i] as $vval){ 
    4563                $graph_num++; 
    46                 createGraphsFromCombos(($combo) ? "$combo,$vval" : $vval, $var_vals, $i + 1, $sid_vars, $rparams, $templateid, $graph_num); 
     64                createGraphsFromCombos(($combo) ? "$combo,$vval" : $vval, $var_vals, $i + 1, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num); 
    4765           } 
    4866        } 
    4967    } 
    5068 
    51 createGraphsFromCombos('', $var_vals, 0, $sid_vars, $rparams, $templateid, $graph_num); 
     69createGraphsFromCombos('', $var_vals, 0, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num); 
    5270 
    5371?> 
  • ui/web/lib/Reconnoiter_DB.php

    r2444c13 ra6f44d6  
    419419    return $row; 
    420420  } 
     421  function getGraphByGenesis($genesis) { 
     422    $sth = $this->db->prepare("select * 
     423                                 from prism.saved_graphs 
     424                                where genesis=?"); 
     425    $sth->execute(array($genesis)); 
     426    $row = $sth->fetch(); 
     427    return $row; 
     428  } 
    421429  function deleteWorksheetGraph($ws_id, $graphid) { 
    422430    $sth = $this->db->prepare("delete from prism.saved_worksheets_dep  
     
    470478        $sth = $this->db->prepare("insert into prism.saved_graphs 
    471479                                               (graphid, json, title, 
    472                                                 last_update
    473                                         values (?, ?, ?, current_timestamp)"); 
    474         $sth->execute(array($id, $json, $graph['title'])); 
     480                                                last_update, genesis
     481                                        values (?, ?, ?, current_timestamp, ?)"); 
     482        $sth->execute(array($id, $json, $graph['title'], $graph['genesis'])); 
    475483      } 
    476484      $sth = $this->db->prepare("insert into prism.saved_graphs_dep 
  • ui/web/lib/Reconnoiter_GraphTemplate.php

    r477b283 ra6f44d6  
    2727    return Reconnoiter_GraphTemplate::find_sids($this->row['json']); 
    2828  } 
    29   public function newGraph($params) { 
     29  public function getNewGraphJSON($params) { 
    3030    $v = $this->variables(); 
    3131    global $__rgt_replace_set;