iterating on new nodes index
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 9 Jan 2009 22:10:47 +0000 (22:10 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 9 Jan 2009 22:10:47 +0000 (22:10 +0000)
13 files changed:
PLCWWW.spec
httpd.conf [moved from planetlab.conf with 100% similarity]
modules/planetlab.module
planetlab/css/plc_paginate.css [new file with mode: 0644]
planetlab/icons/comon.png
planetlab/icons/delete.png
planetlab/icons/event.png
planetlab/includes/plc_functions.php
planetlab/js/plc_functions.js [moved from planetlab/includes/plc_script.js with 100% similarity]
planetlab/js/plc_paginate.js [new file with mode: 0644]
planetlab/nodes/index.php
planetlab/nodes/newindex.php
planetlab/sites/site_form.php

index 93c7018..20b563f 100644 (file)
@@ -60,7 +60,7 @@ mkdir -p $RPM_BUILD_ROOT/var/www/html
 rsync -a --exclude \*.spec --exclude .svn --exclude CVS ./ $RPM_BUILD_ROOT/var/www/html/
 
 echo "* PLEWWW: Installing config for httpd"
-install -D -m 644 planetlab.conf $RPM_BUILD_ROOT/etc/httpd/conf.d/planetlab.conf
+install -D -m 644 httpd.conf $RPM_BUILD_ROOT/etc/httpd/conf.d/plcwww.conf
 
 %post
 # attempt to perform most of the drupal post-install stuff - assuming version 6.x
similarity index 100%
rename from planetlab.conf
rename to httpd.conf
index 0a2adb8..e1f7d1f 100644 (file)
@@ -128,6 +128,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array())
       $node_item = '';
       $node_item .= '<a href="/db/nodes/">Nodes</a>';
       $node_item .= '<ul>';
+      $node_item .= '<li><a href="/db/nodes/newindex.php"> New nodes page </a></li>';
       $node_item .= '<li><a href="/db/nodes/index.php?site_id='. $plc->person['site_ids'][0] .'">My Site Nodes</a></li>';
       $node_item .= "<li><a href='/db/nodes/add_node.php'>Add Node</a></li>";
       if ( $is_admin) 
diff --git a/planetlab/css/plc_paginate.css b/planetlab/css/plc_paginate.css
new file mode 100644 (file)
index 0000000..d1d83cc
--- /dev/null
@@ -0,0 +1,134 @@
+/* Pagination list styles */
+ul.fdtablePaginater
+        {
+        display:table;
+        list-style:none;
+        padding:0;
+        margin:0 auto;
+        text-align:center;
+        height:2em;
+        width:auto;
+        margin-bottom:2em;
+        }
+ul.fdtablePaginater li
+        {
+        display:table-cell;
+        padding-right:4px;
+        color:#666;
+        list-style:none;
+        
+        -moz-user-select:none;
+        -khtml-user-select:none;
+        }
+ul.fdtablePaginater li a.currentPage
+        {
+        border-color:#a84444 !important;
+        color:#000;
+        }
+ul.fdtablePaginater li a:active
+        {
+        border-color:#222 !important;
+        color:#222;
+        }
+ul.fdtablePaginater li a,
+ul.fdtablePaginater li div
+        {
+        display:block;
+        width:2em;
+        font-size:1em;
+        color:#666;
+        padding:0;
+        margin:0;
+        text-decoration:none;
+        outline:none;
+        border:1px solid #ccc;
+        font-family:georgia, serif;
+        }
+ul.fdtablePaginater li div
+        {
+        cursor:normal;
+        opacity:.5;
+        filter:alpha(opacity=50);
+        }
+ul.fdtablePaginater li a span,
+ul.fdtablePaginater li div span
+        {
+        display:block;
+        line-height:2em;
+        border:1px solid #fff;
+        background:#fff url(../media/gradient.gif) repeat-x 0 -20px;
+        }
+ul.fdtablePaginater li a
+        {
+        cursor:pointer;
+        }
+ul.fdtablePaginater li a:focus
+        {
+        color:#333;
+        text-decoration:none;
+        border-color:#aaa;
+        }
+.fdtablePaginaterWrap
+        {
+        text-align:center;
+        clear:both;
+        text-decoration:none;
+        }
+ul.fdtablePaginater li .next-page span,
+ul.fdtablePaginater li .previous-page span,
+ul.fdtablePaginater li .first-page span,
+ul.fdtablePaginater li .last-page span
+        {
+        font-weight:bold !important;
+        }
+/* Keep the table columns an equal size during pagination */
+td.sized1
+        {
+        width:16em;
+        text-align:left;
+        }
+td.sized2
+        {
+        width:10em;
+        text-align:left;
+        }
+td.sized3
+        {
+        width:7em;
+        text-align:left;
+        }
+tfoot td
+        {
+        text-align:right;
+        font-weight:bold;
+        text-transform:uppercase;
+        letter-spacing:1px;
+        }
+#visibleTotal
+        {
+        text-align:center;
+        letter-spacing:auto;
+        }
+* html ul.fdtablePaginater li div span,
+* html ul.fdtablePaginater li div span
+        {
+        background:#eee;
+        }
+tr.invisibleRow
+        {
+        display:none;
+        visibility:hidden;
+        }
+p.paginationText
+        {
+        font-style:oblique;
+        }
+<!--[if IE]>
+<style type="text/css">
+ul.fdtablePaginater {display:inline-block;}
+mul.fdtablePaginater {display:inline;}
+ul.fdtablePaginater li {float:left;}
+ul.fdtablePaginater {text-align:center;}
+table { border-bottom:1px solid #C1DAD7; }
+</style>
+<![endif]-->
index daa35f3..25a7183 100644 (file)
Binary files a/planetlab/icons/comon.png and b/planetlab/icons/comon.png differ
index 4fe6144..56c5910 100644 (file)
Binary files a/planetlab/icons/delete.png and b/planetlab/icons/delete.png differ
index d19658e..2be04c1 100644 (file)
Binary files a/planetlab/icons/event.png and b/planetlab/icons/event.png differ
index 9e7a81d..60a8dc7 100644 (file)
@@ -398,4 +398,29 @@ function plc_peers_option_list ($api) {
     return $result;
 }
 
+function plc_peer_info ($api,$peerscope) {
+  switch ($_GET['peerscope']) {
+  case '':
+    $peer_filter=array();
+    $peer_label="all peers";
+    break;
+  case 'local':
+    $peer_filter=array("peer_id"=>NULL);
+    $peer_label="local peer";
+    break;
+  case 'foreign':
+    $peer_filter=array("~peer_id"=>NULL);
+    $peer_label="foreign peers";
+    break;
+  default:
+    $peer_id=intval($_GET['peerscope']);
+    $peer_filter=array("peer_id"=>$peer_id);
+    $peer=$api->GetPeers(array("peer_id"=>$peer_id));
+    $peer_label='peer "' . $peer[0]['peername'] . '"';
+    break;
+  }
+  return array ($peer_filter,$peer_label);
+}
+    
+
 ?>
diff --git a/planetlab/js/plc_paginate.js b/planetlab/js/plc_paginate.js
new file mode 100644 (file)
index 0000000..fcfe00a
--- /dev/null
@@ -0,0 +1,15 @@
+function displayTextInfo (opts,tablename) {
+
+  if(!("currentPage" in opts)) { return; }
+    
+  var p = document.createElement('p'),
+    t = document.getElementById(tablename+'-fdtablePaginaterWrapTop'),
+    b = document.getElementById(tablename+'-fdtablePaginaterWrapBottom');
+  
+  p.className = "paginationText";    
+  p.appendChild(document.createTextNode("Showing page " + opts.currentPage + " of " + Math.ceil(opts.totalRows / opts.rowsPerPage)));
+                
+  t.insertBefore(p.cloneNode(true), t.firstChild);
+  b.appendChild(p);
+}
+
index 9a7b830..6f7effc 100644 (file)
@@ -63,31 +63,19 @@ function layout_node ($node) {
 // we use GET rather than POST so paginate can display the right contents on subsequent pages
 // can be useful for writing bookmarkable URL's as well
 if( $_GET['nodepattern'] || $_GET['peerscope']) {
+
+  // nodepattern
   $nodepattern= $_GET['nodepattern'];
+  // need to use a hash filter for patterns to be properly handled
   if (empty($nodepattern)) { 
     $nodepattern="*";
   }
   $filter = array_merge (array( "hostname"=>$nodepattern ), $filter);
-  switch ($_GET['peerscope']) {
-  case '':
-    $peer_label="all peers";
-    break;
-  case 'local':
-    $filter=array_merge(array("peer_id"=>NULL),$filter);
-    $peer_label="local peer";
-    break;
-  case 'foreign':
-    $filter=array_merge(array("~peer_id"=>NULL),$filter);
-    $peer_label="foreign peers";
-    break;
-  default:
-    $peer_id=intval($_GET['peerscope']);
-    $filter=array_merge(array("peer_id"=>$peer_id),$filter);
-    $peer=$api->GetPeers(array("peer_id"=>$peer_id));
-    $peer_label='peer "' . $peer[0]['peername'] . '"';
-    break;
-  }
-  // need to use a hash filter for patterns to be properly handled
+
+  // peerscope
+  list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']);
+  $filter=array_merge($filter,$peer_filter);
+
   $nodes= $api->GetNodes($filter, $columns);
   $nodes_count = count ($nodes);
   if ( $nodes_count == 1) {
@@ -181,8 +169,7 @@ elseif( !$_GET['id'] ) {
          </tr></table></form></div>\n
           <br />\n";
 
-
-echo paginate( $nodes, "node_id", "Nodes", 25, "hostname" );
+    echo paginate( $nodes, "node_id", "Nodes", 25, "hostname" );
 
     echo "<script type=\"text/javascript\">\n
 var options = {\n
index 347e1e0..d3a5853 100644 (file)
@@ -11,7 +11,7 @@ global $plc, $api, $adm;
 
 // Print header
 require_once 'plc_drupal.php';
-drupal_set_title('New Nodes');
+drupal_set_title('Nodes');
 include 'plc_header.php';
 
 // Common functions
@@ -22,48 +22,109 @@ require_once 'plc_sorts.php';
 $_person= $plc->person;
 $_roles= $_person['role_ids'];
 
-$header_js='
+$header_autocomplete_js='
+<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
+<script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
+<script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>
+';
+
+$header_tablesort_js='
 <script type="text/javascript" src="/planetlab/tablesort/tablesort.js"></script>
 <script type="text/javascript" src="/planetlab/tablesort/customsort.js"></script>
 <script type="text/javascript" src="/planetlab/tablesort/paginate.js"></script>
-<script type="text/javascript" src="/planetlab/tablesort/more.js"></script>
-<body OnLoad="init();">
+<script type="text/javascript" src="/planetlab/js/plc_paginate.js"></script>
 ';
-$header_css='
-<link href="/planetlab/css/demo.css" rel="stylesheet" type="text/css" />
-<link href="/planetlab/css/more.css" rel="stylesheet" type="text/css" />
-<!--[if IE]>
-<style type="text/css">
-ul.fdtablePaginater {display:inline-block;}
-mul.fdtablePaginater {display:inline;}
-ul.fdtablePaginater li {float:left;}
-ul.fdtablePaginater {text-align:center;}
-table { border-bottom:1px solid #C1DAD7; }
-</style>
-<![endif]-->
+
+$header_tablesort_css='
+<link href="/planetlab/css/plc_style.css" rel="stylesheet" type="text/css" />
+<link href="/planetlab/css/plc_table.css" rel="stylesheet" type="text/css" />
+<link href="/planetlab/css/plc_paginate.css" rel="stylesheet" type="text/css" />
 ';
 
-$header_unused='
+$unused='
+<script type="text/javascript" src="/planetlab/tablesort/more.js"></script>
+<link href="/planetlab/css/more.css" rel="stylesheet" type="text/css" />
+<body OnLoad="init();">
 ';
 
-drupal_set_html_head($header_js);
-drupal_set_html_head($header_css);
+drupal_set_html_head($header_autocomplete_js);
+drupal_set_html_head($header_tablesort_js);
+drupal_set_html_head($header_tablesort_css);
 
-$site_columns=array("site_id","login_base");
-$site_filter=array("login_base"=>"*");
-$sites=$api->GetSites($site_filter,$site_columns);
+$nodepattern=$_GET['nodepattern'];
+$peerscope=$_GET['peerscope'];
+$tablesize=$_GET['tablesize'];
+if (empty($tablesize)) $tablesize=25;
 
-$site_hash=array();
-foreach ($sites as $site) {
-    $site_hash[$site["site_id"]]=$site;
-}
+?>
+
+<div class="plc_filter">
+<form method=get action='newindex.php'>
+<table>
+
+<tr>
+<th><label for='peerscope'>Federation scope </label></th>
+<td colspan=2><select id='peerscope' name='peerscope' onChange='submit()'>
+<?php echo plc_peers_option_list($api); ?>
+</select></td>
+</tr>
+
+<tr>
+<th><label for='nodepattern'>Hostname </label></th>
+<td><input type='text' id='nodepattern' name='nodepattern' 
+     size=40 value='<?php print $nodepattern; ?>'/></td>
+<td><input type=submit value='Go' /></td>
+</tr> 
+
+<tr> 
+<th><label for='tablesize'>Table size</label></th>
+<td> <input type='text' id='tablesize' name='tablesize' 
+      size=3 value='<?php print $tablesize; ?>'/></td>
+<td><input type=submit value='Go' /> </td>
+</tr>
+</table>
+</form>
+</div>
+
+<script type="text/javascript">
+var options = {
+       script:"/planetlab/nodes/test.php?",
+       varname:"input",
+       minchars:1
+};
+var as = new AutoSuggest('nodepattern', options);
+</script>
+
+
+<?php
+
+$peer_filter=array();
+
+// fetch nodes
+$node_columns=array('hostname','site_id','node_id','boot_state','interface_ids');
+if ($nodepattern) {
+  $node_filter['hostname']=$nodepattern;
+ } else {
+  $node_filter=array('hostname'=>"*");
+ }
+
+// peerscope
+list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']);
+$node_filter=array_merge($node_filter,$peer_filter);
 
-$node_columns=array("hostname","site_id","node_id","boot_state");
-$node_filter=array("hostname"=>"*");
 $nodes=$api->GetNodes($node_filter,$node_columns);
 
-$interface_columns=array("ip","node_id");
-$interface_filter=array("is_primary"=>TRUE);
+// build site_ids and interface_ids 
+$site_ids=array();
+$interface_ids=array();
+foreach ($nodes as $node) {
+  $site_ids []= $node['site_id'];
+  $interface_ids = array_merge ($interface_ids,$node['interface_ids']);
+}
+
+// fetch related interfaces
+$interface_columns=array('ip','node_id','interface_id');
+$interface_filter=array('is_primary'=>TRUE,'interface_id'=>$interface_ids);
 $interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
 
 $interface_hash=array();
@@ -71,42 +132,64 @@ foreach ($interfaces as $interface) {
     $interface_hash[$interface['node_id']]=$interface;
 }
 
+// fetch related sites
+$site_columns=array('site_id','login_base');
+$site_filter=array('site_id'=>$site_ids);
+$sites=$api->GetSites($site_filter,$site_columns);
+
+$site_hash=array();
+foreach ($sites as $site) {
+    $site_hash[$site['site_id']]=$site;
+}
+
 ?>
 
-<table id="theTable" cellpadding="0" cellspacing="0" border="0" 
-class="sortable-onload-2 rowstyle-alt colstyle-alt no-arrow paginate-50 max-pages-10">
+<div class="fdtablePaginaterWrap" id="nodes-fdtablePaginaterWrapTop"><p></p></div>
+
+<table id="nodes" cellpadding="0" cellspacing="0" border="0" 
+class="plc_table sortable-onload-3r rowstyle-alt colstyle-alt no-arrow paginationcallback-nodesTextInfo max-pages-15 paginate-<?php print $tablesize; ?>">
 <thead>
 <tr>
-<th align=top>Select </th>
-<th class="sortable">State</th>
-<th class="sortable">Hostname</th>
-<th class="sortable">Site</th>
-<th class="sortable">Region</th>
-<th class="sortable-sortIPAddress">IP</th>
-<th class="sortable">Load</th>
-<th class="sortable">Avg Load</th>
+<th class="sortable plc_table">State</th>
+<th class="sortable plc_table">Hostname</th>
+<th class="sortable plc_table">Site</th>
+<th class="sortable plc_table">Region</th>
+<th class="sortable-sortIPAddress plc_table">IP</th>
+<th class="sortable plc_table">Load</th>
+<th class="sortable plc_table">Avg Load</th>
 </tr>
 </thead>
 <tbody>
 
+<script type"text/javascript">
+function nodesTextInfo (opts) {
+  displayTextInfo (opts,"nodes");
+}
+</script>
+
 <?php
 
+  $fake1=1; $fake2=3.14;
 foreach ($nodes as $node) {
     $hostname=$node['hostname'];
-    $site=$site_hash[$node['site_id']];
+    $node_id=$node['node_id'];
+    $site_id=$node['site_id'];
+    $site=$site_hash[$site_id];
     $login_base = $site['login_base'];
     $node_id=$node['node_id'];
     $ip=$interface_hash[$node['node_id']]['ip'];
+    $interface_id=$interface_hash[$node['node_id']]['interface_id'];
     printf ('<tr id="%s">',$hostname);
-    printf ('<td> <input type="checkbox" id="%s"></td>',$hostname);
-    printf ('<td> %s </td>',$node['boot_state']);
-    printf ('<td> %s </td>',$hostname);
-    printf ('<td> %s </td>',$login_base);
-    printf ('<td> %s </td>',topdomain($hostname));
-    printf ('<td> %s </td>',$ip);
-    printf ('<td> 1.0 </td>');
-    printf ('<td> 10.0 </td>');
+    printf ('<td class="plc_table"> %s </td>',$node['boot_state']);
+    printf ('<td class="plc_table"> <a href="/db/nodes/index.php?id=%s">%s</a></td>',$node_id,$hostname);
+    printf ('<td class="plc_table"> <a href="/db/sites/index.php?id=%s">%s</a></td>',$site_id,$login_base);
+    printf ('<td class="plc_table"> %s </td>',topdomain($hostname));
+    printf ('<td class="plc_table"> <a href="/db/nodes/interfaces.php?id=%s">%s</a></td>', $interface_id,$ip);
+    printf ('<td class="plc_table"> %s </td>', $fake1);
+    printf ('<td class="plc_table"> %s </td>', $fake2);
     printf ( '</tr>');
+    $fake1 += 3;
+    $fake2 += 2;
 }
 
 ?>
@@ -115,3 +198,5 @@ foreach ($nodes as $node) {
 </tfoot>
 </table>
 
+<div class="fdtablePaginaterWrap" id="nodes-fdtablePaginaterWrapBottom"><p></p></div>
+
index 8a677d1..a5105e5 100644 (file)
@@ -57,7 +57,7 @@ function build_site_form ($register_mode) {
 
   if ($register_mode) {
     // required for the following code
-    drupal_set_html_head('<script type="text/javascript" src="/planetlab/includes/plc_script.js"></script>');
+    drupal_set_html_head('<script type="text/javascript" src="/planetlab/js/plc_functions.js"></script>');
 
     $fill_from_pi_button = <<< EOF
 <input type="button" value="Same as PI" onclick='copyValue("edit-pi:first_name","edit-tech:first_name");