Changeset 477b283b142129db6f024d07d097d16c48a241a2
- Timestamp:
- 11/26/08 21:06:47
(4 years ago)
- Author:
- Umar Farooq <umar@omniti.com>
- git-committer:
- Umar Farooq <umar@omniti.com> 1227733607 +0000
- git-parent:
[d5f3933236fd3c615389600886bda1a30b0f9870]
- git-author:
- Umar Farooq <umar@omniti.com> 1227733607 +0000
- Message:
functionality to use templates to create graphs
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r171b238 |
r477b283 |
|
| 549 | 549 | background:transparent url(../images/icon-data-txt.png) no-repeat scroll 30px 1px; |
|---|
| 550 | 550 | padding-left:45px; |
|---|
| | 551 | } |
|---|
| | 552 | #browselist ul li ul li ul li span.templatesid { |
|---|
| | 553 | padding-left:30px; |
|---|
| 551 | 554 | } |
|---|
| 552 | 555 | #browselist ul li ul li ul li ul li span { |
|---|
| rcee63b8 |
r477b283 |
|
| 34 | 34 | error_log("------"); |
|---|
| 35 | 35 | |
|---|
| | 36 | $templateid; |
|---|
| | 37 | $template; |
|---|
| | 38 | |
|---|
| | 39 | if($_REQUEST[$l1]){ |
|---|
| | 40 | $templateid = $_REQUEST[$l1]; |
|---|
| | 41 | $template = new Reconnoiter_GraphTemplate($templateid); |
|---|
| | 42 | } |
|---|
| | 43 | |
|---|
| 36 | 44 | $bag = array(); |
|---|
| 37 | 45 | |
|---|
| … | … | |
| 54 | 62 | |
|---|
| 55 | 63 | else if($want == 'targetname') { |
|---|
| 56 | | $templateid = $_REQUEST[$l1]; |
|---|
| 57 | | error_log("retreive template = $templateid"); |
|---|
| 58 | | $template = new Reconnoiter_GraphTemplate($templateid); |
|---|
| 59 | 64 | |
|---|
| 60 | 65 | $target_sid_map = array(); |
|---|
| … | … | |
| 70 | 75 | |
|---|
| 71 | 76 | foreach ($target_sid_map as $target_name => $sid_list) { |
|---|
| | 77 | $params = array(); |
|---|
| | 78 | $params['thetemplate'] = $templateid; |
|---|
| 72 | 79 | $sidlist = implode(",", $sid_list); |
|---|
| | 80 | $params['targetname'] = $sidlist; |
|---|
| | 81 | $params['num_sids'] = $template->num_sids; |
|---|
| 73 | 82 | $jitem = array ('id' => $target_name, |
|---|
| 74 | 83 | 'text' => $target_name, |
|---|
| 75 | 84 | 'hasChildren' => true, |
|---|
| 76 | 85 | 'classes' => $want, |
|---|
| 77 | | 'params' => array('targetname' => $sidlist) |
|---|
| | 86 | 'params' => $params |
|---|
| 78 | 87 | ); |
|---|
| 79 | 88 | $bag[] = $jitem; |
|---|
| … | … | |
| 81 | 90 | } |
|---|
| 82 | 91 | else if($want == 'sid') { |
|---|
| | 92 | $thetemplateid = $_REQUEST['thetemplate']; |
|---|
| | 93 | $num_sids = $_REQUEST['num_sids']; |
|---|
| | 94 | |
|---|
| 83 | 95 | $sid_list = explode (",", $_REQUEST[$l2]); |
|---|
| 84 | | |
|---|
| | 96 | $ctext = "<form id='template-graph' name='template-graph' action=''>"; |
|---|
| | 97 | $ctext.= "<select multiple='multiple' name='sid_select' size='5' id='sid_select' >"; |
|---|
| 85 | 98 | foreach($sid_list as $sid) { |
|---|
| 86 | | $sname = $db->get_sid_name($sid); |
|---|
| 87 | | error_log("got $name as the sid name"); |
|---|
| 88 | | $jitem = array ('id' => $sname, |
|---|
| 89 | | 'text' => $sname, |
|---|
| | 99 | $sname = $db->make_name_for_template($sid); |
|---|
| | 100 | $ctext.="<option value='$sid'> $sname</option><br />"; |
|---|
| | 101 | } |
|---|
| | 102 | |
|---|
| | 103 | $ctext.="</select><br>Select ".$num_sids." from above."; |
|---|
| | 104 | $ctext .= "<br>Graph Title:"; |
|---|
| | 105 | $ctext.="<input type='text' size='15' name='graph_name' id='graph_name'><br>"; |
|---|
| | 106 | |
|---|
| | 107 | $ctext.=<<<LINK |
|---|
| | 108 | <a href="javascript:CreateGraphFromTemplate('$thetemplateid', '$num_sids')"> |
|---|
| | 109 | LINK; |
|---|
| | 110 | |
|---|
| | 111 | $ctext.=" <b>Create Graph</b></a></form>"; |
|---|
| | 112 | $ctext.= <<<JS |
|---|
| | 113 | <script type='text/javascript'> |
|---|
| | 114 | |
|---|
| | 115 | function CreateGraphFromTemplate(templateid, num_sids){ |
|---|
| | 116 | |
|---|
| | 117 | var graph_name = $("#graph_name").val(); |
|---|
| | 118 | var sids = []; |
|---|
| | 119 | |
|---|
| | 120 | $("#sid_select :selected").each(function(i, selected){ |
|---|
| | 121 | sids[i] = $(selected).text(); |
|---|
| | 122 | }); |
|---|
| | 123 | |
|---|
| | 124 | if(sids.length==num_sids){ |
|---|
| | 125 | var dataString = 'templateid='+templateid+'&graph_name='+graph_name+'&sids='+sids; |
|---|
| | 126 | |
|---|
| | 127 | $.ajax({ |
|---|
| | 128 | type: "POST", |
|---|
| | 129 | url: "template_graph.php", |
|---|
| | 130 | data: dataString, |
|---|
| | 131 | success: function() { } |
|---|
| | 132 | }); |
|---|
| | 133 | } |
|---|
| | 134 | } |
|---|
| | 135 | |
|---|
| | 136 | </script> |
|---|
| | 137 | JS; |
|---|
| | 138 | |
|---|
| | 139 | $jitem = array ('id' => 'whatever', |
|---|
| | 140 | 'text' => $ctext, |
|---|
| 90 | 141 | 'hasChildren' => false, |
|---|
| 91 | | 'classes' => $want, |
|---|
| | 142 | 'classes' => 'templatesid', |
|---|
| 92 | 143 | 'params' => array(), |
|---|
| 93 | 144 | ); |
|---|
| 94 | | $bag[] = $jitem; |
|---|
| 95 | | } |
|---|
| 96 | | |
|---|
| | 145 | $bag[] = $jitem; |
|---|
| 97 | 146 | } |
|---|
| 98 | | |
|---|
| 99 | | |
|---|
| 100 | 147 | |
|---|
| 101 | | /* |
|---|
| 102 | | $rparams = array( 'SwitchPort' => '1130', 'SwitchPort2' => '1139', 'SwitchName' => 'testingmultiplegraphs' ); |
|---|
| 103 | | //error_log("rparams: ".print_r($rparams, true)); |
|---|
| 104 | | $graph_json = $template->newGraph($rparams); |
|---|
| 105 | | $graph_json = stripslashes($graph_json); |
|---|
| 106 | | $graph_json = json_decode($graph_json, true); |
|---|
| 107 | | $graph_id = $db->saveGraph($graph_json); |
|---|
| 108 | | |
|---|
| 109 | | $graph_json['id'] = $graph_id; |
|---|
| 110 | | // error_log("graph json: ".print_r($graph_json, true)); |
|---|
| 111 | | $graph_id = $db->saveGraph($graph_json); |
|---|
| 112 | | //error_log("saved to graph id = $graph_id"); |
|---|
| 113 | | */ |
|---|
| 114 | 148 | |
|---|
| 115 | 149 | echo json_encode($bag); |
|---|
| rcee63b8 |
r477b283 |
|
| 462 | 462 | } |
|---|
| 463 | 463 | |
|---|
| 464 | | public function get_sid_name($sid) { |
|---|
| 465 | | $sql = "select m.name from stratcon.mv_loading_dock_check_s m where m.sid = ?"; |
|---|
| | 464 | public function make_name_for_template($sid) { |
|---|
| | 465 | $sql = "select m.* from stratcon.mv_loading_dock_check_s m where m.sid = ?"; |
|---|
| 466 | 466 | $binds = array(); |
|---|
| 467 | 467 | if($sid) { |
|---|
| … | … | |
| 471 | 471 | $row = $sth->fetch(); |
|---|
| 472 | 472 | } |
|---|
| 473 | | return $row['name']; |
|---|
| | 473 | return $row['target']."`".$row['module']."`".$row['name']."`".$sid; |
|---|
| 474 | 474 | } |
|---|
| 475 | 475 | } |
|---|
| r9748163 |
r477b283 |
|
| 19 | 19 | } |
|---|
| 20 | 20 | } |
|---|
| | 21 | public $num_sids; |
|---|
| | 22 | |
|---|
| 21 | 23 | public function variables() { |
|---|
| 22 | 24 | return Reconnoiter_GraphTemplate::find_variables($this->row['json']); |
|---|
| … | … | |
| 91 | 93 | } |
|---|
| 92 | 94 | public function find_sids($json) { |
|---|
| | 95 | $this->num_sids = 0; |
|---|
| 93 | 96 | $sids = array(); |
|---|
| 94 | 97 | $vs = Reconnoiter_GraphTemplate::find_variables($json); |
|---|
| | 98 | //vs will be multiD array containing variable names, their types (text/sid) and metric |
|---|
| | 99 | //names and metric types |
|---|
| | 100 | |
|---|
| 95 | 101 | foreach($vs as $v => $d) { |
|---|
| 96 | 102 | if(isset($d['SID'])) { |
|---|
| | 103 | $this->num_sids++; |
|---|
| 97 | 104 | $sql = "select m.* from stratcon.mv_loading_dock_check_s as m"; |
|---|
| 98 | 105 | $binds = array(); |
|---|