From 9ac6b3f5a03b6608270017694fce844632f93fb9 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 10 Feb 2009 13:09:52 +0000 Subject: [PATCH] reviewed plcdetails --- planetlab/events/events_choser.php | 16 ++--- planetlab/includes/plc_details.php | 104 ++++++++++++++++++----------- planetlab/nodes/node.php | 31 ++++----- planetlab/peers/peer.php | 16 ++--- planetlab/persons/person.php | 45 ++++++------- planetlab/persons/persons.php | 9 ++- planetlab/sites/site.php | 57 ++++++++-------- planetlab/tags/nodegroup.php | 8 +-- planetlab/tags/tag.php | 20 +++--- 9 files changed, 167 insertions(+), 139 deletions(-) diff --git a/planetlab/events/events_choser.php b/planetlab/events/events_choser.php index 45316f7..cd908a2 100644 --- a/planetlab/events/events_choser.php +++ b/planetlab/events/events_choser.php @@ -49,25 +49,25 @@ $form->start(); $details = new PlcDetails (true); $details->start(); -$details->single ($form->submit_html('submit','Show Events'),'center'); +$details->tr ($form->submit_html('submit','Show Events'),'center'); $details->space(); -$details->line ( $form->radio_html ('events','type','Event',true) . "Events", +$details->th_td ( $form->radio_html ('events','type','Event',true) . "Events", $form->text_html('event','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'events.checked=true'))); -$details->line ( $form->radio_html ('sites','type','Site',false) . "Sites", +$details->th_td ( $form->radio_html ('sites','type','Site',false) . "Sites", $form->text_html('site','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'sites.checked=true'))); -$details->line ( $form->radio_html ('persons','type','Person',false) . "Persons", +$details->th_td ( $form->radio_html ('persons','type','Person',false) . "Persons", $form->text_html('person','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'persons.checked=true'))); -$details->line ( $form->radio_html ('nodes','type','Node',false) . "Nodes", +$details->th_td ( $form->radio_html ('nodes','type','Node',false) . "Nodes", $form->text_html('node','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'nodes.checked=true'))); -$details->line ( $form->radio_html ('slices','type','Slice',false) . "Slices", +$details->th_td ( $form->radio_html ('slices','type','Slice',false) . "Slices", $form->text_html('slice','',array('width'=>30,'onSelect'=>'submit()', 'onFocus'=>'slices.checked=true'))); $details->space(); -$details->single ($form->submit_html('submit','Show Events'),'center'); +$details->tr ($form->submit_html('submit','Show Events'),'center'); $details->space(); -$details->line_th(html_div($from_picker->html()) , html_div($until_picker->html())); +$details->th_th(html_div($from_picker->html()) , html_div($until_picker->html())); $details->end(); $form->end(); diff --git a/planetlab/includes/plc_details.php b/planetlab/includes/plc_details.php index c8078bc..5d3c50e 100644 --- a/planetlab/includes/plc_details.php +++ b/planetlab/includes/plc_details.php @@ -14,20 +14,32 @@ drupal_set_html_head(' // fieldname=>value // and we add in-line editing capabilities +// $editable : if not set, no edition will be allowed in the table +// this is typically set to false when user does not have write access +// then each individual th_td provides its form_varname if and only iff edition is desired + +// start & end :create and close a 2-columns table +// th_td -> display label & value, with optional inline editing capability +// th_tds -> not editable, display a (vertical) list of values in the area +// th_th : special cases, display 2 +// xxx todo : accept optional arguments as an options hash, rather than using the set_ methods which are ugly + class PlcDetails { var $editable; var $form; + // various options for the editing area // set manually - var $field_width; - var $field_height; - var $input_type="text"; + var $width; + var $height; + var $input_type; function PlcDetails ($editable) { $this->editable=$editable; $this->form=NULL; - $this->field_width=""; - $this->field_height="2"; + $this->width=""; + $this->height="2"; + $this->input_type="text"; } function form() { return $this->form; } @@ -62,36 +74,66 @@ class PlcDetails { return $html; } - // must be embedded in a line or a single + //////////////////// several forms for submit button // xxx need a way to ask for confirmation + + // must be embedded in a th_td or a tr function submit_html ($name,$display) { if ( ! $this->form) return ""; if ( ! $this->editable) return ""; return $this->form->submit_html($name,$display); } + function tr_submit_html ($name,$display) { + if ( ! $this->form) return ""; + if ( ! $this->editable) return ""; + return $this->tr_html($this->form->submit_html($name,$display),"right"); + } + function tr_submit ($name,$display) { print $this->tr_submit_html ($name,$display); } + + + //////////////////////////////////////// + function set_width ($width) { + $old=$this->width; + $this->width=$width; + return $old; + } + function set_height ($height) { + $old=$this->height; + $this->height=$height; + return $old; + } // give a form_varname if the field can be edited - function line ($title,$value,$form_varname="") { - print $this->line_html ($title,$value,$form_varname); + function th_td ($title,$value,$form_varname="",$options=NULL) { + print $this->th_td_html ($title,$value,$form_varname,$options); } - function line_html ($title,$value,$form_varname="") { + function th_td_html ($title,$value,$form_varname="",$options=NULL) { if ( ! ($this->editable && $form_varname) ) { return "$title$value"; } else { + if (!$options) $options = array(); + // use options if provided, otherwise the latest set_ function + if (array_key_exists('input_type',$options)) $input_type=$options['input_type']; + else $input_type=$this->input_type; + if (array_key_exists('width',$options)) $width=$options['width']; + else $width=$this->width; + if (array_key_exists('height',$options)) $height=$options['height']; + else $height=$this->height; + $html=""; $html .= ""; $html .= ""; // hack: if input_type is select : user provides the input field verbatim - if ( $this->input_type == "select" ) { + if ( $input_type == "select" ) { $html .= $value; - } else if ($this->input_type == "textarea") { + } else if ($input_type == "textarea") { $html .= ""; } else { - $html .= "field_width) $html .= " size=$this->field_width"; + $html .= "lines_html($title,$list); } - function lines_html($title,$list) { - return $this->line_html($title,plc_vertical_table($list,"foo")); + function th_tds($title,$list) { print $this->th_tds_html($title,$list); } + function th_tds_html($title,$list) { + return $this->th_td_html($title,plc_vertical_table($list,"foo")); } - function line_th ($th1,$th2) { print $this->line_th_html ($th1, $th2);} - function line_th_html ($th1, $th2) { + // only for special cases, not editable + function th_th ($th1,$th2) { print $this->th_th_html ($th1, $th2);} + function th_th_html ($th1, $th2) { return "$th1$th2"; } // 1 item, colspan=2 - function single($title,$align=NULL) { print $this->single_html($title,$align);} - function single_html($title,$align=NULL) { + function tr($title,$align=NULL) { print $this->tr_html($title,$align);} + function tr_html($title,$align=NULL) { $result="space_html(); } function space_html () { return " \n"; } - function set_field_width ($field_width) { - $old=$this->field_width; - $this->field_width=$field_width; - return $old; - } - function set_field_height ($field_height) { - $old=$this->field_height; - $this->field_height=$field_height; - return $old; - } - - function set_input_type ($input_type) { - $old=$this->input_type; - $this->input_type=$input_type; - return $old; - } - } ?> diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index 4fbf56f..77350e1 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -103,7 +103,7 @@ $local_peer= ! $peer_id; // extra privileges to admins, and (pi||tech) on this site -$privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech())); +$privileges = (plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech())); $tabs=array(); // available actions @@ -135,23 +135,24 @@ $peers->block_start ($peer_id); $details=new PlcDetails($privileges); $details->start(); if ( ! $local_peer) { - $details->line("Peer",$peers->peer_link($peer_id)); + $details->th_td("Peer",$peers->peer_link($peer_id)); $details->space(); } $details->form_start(l_actions(),array("action"=>"update-node", "node_id"=>$node_id)); -$details->line("Hostname",$hostname,"hostname"); -$details->line("Model",$model,"model"); -$details->line("",$details->submit_html("submit","Update Node")); +$details->th_td("Hostname",$hostname,"hostname"); +$details->th_td("Model",$model,"model"); +$details->tr_submit("submit","Update Node"); $details->form_end(); +if ($privileges) $details->space(); -$details->line("Type",$node_type); -$details->line("Version",$version); +$details->th_td("Type",$node_type); +$details->th_td("Version",$version); // let's use plc_objects $Node = new Node($node); -$details->line("Date created",$Node->dateCreated()); -$details->line("Last contact",$Node->lastContact()); -$details->line("Last update",$Node->lastUpdated()); +$details->th_td("Date created",$Node->dateCreated()); +$details->th_td("Last contact",$Node->lastContact()); +$details->th_td("Last update",$Node->lastUpdated()); // boot area $details->space (); @@ -174,7 +175,7 @@ if ( ! ($local_peer && $privileges)) { $boot_value .= $boot_form->select_html("boot_state",$selectors,NULL,true); $boot_value .= $boot_form->end_html(); } -$details->line ("Boot state",$boot_value); +$details->th_td ("Boot state",$boot_value); // same here for the download area if ( $local_peer && $privileges) { @@ -192,19 +193,19 @@ if ( $local_peer && $privileges) { array("value"=>"download-generic-usb","display"=>"Download generic USB image (requires floppy)")); $download_value .= $download_form->select_html("action",$selectors,"Download mode",true); $download_value .= $download_form->end_html(); - $details->line ("Download",$download_value); + $details->th_td ("Download",$download_value); } // site info and all site nodes $details->space (); -$details->line("Site",l_site_t($site_id,$site_name)); +$details->th_td("Site",l_site_t($site_id,$site_name)); // build list of node links $nodes_area=array(); foreach ($site_node_hash as $hash_node_id => $hash_hostname) { $nodes_area []= l_node_t($hash_node_id,$hash_hostname); } -$details->lines ("All site nodes",$nodes_area); +$details->th_tds ("All site nodes",$nodes_area); $details->end (); @@ -263,7 +264,7 @@ if ( $local_peer ) { function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); } $selector=array_map("tag_selector",$all_tags); $table->cell($form->select_html("tag_type_id",$selector,"Choose")); - $table->cell($form->text_html("value","",array('width'=>8)); + $table->cell($form->text_html("value","",array('width'=>8))); $table->cell($form->submit_html("set-tag-on-node","Set Tag"),2,"left"); $table->row_end(); } diff --git a/planetlab/peers/peer.php b/planetlab/peers/peer.php index 47c24bb..e43ed4a 100644 --- a/planetlab/peers/peer.php +++ b/planetlab/peers/peer.php @@ -42,19 +42,19 @@ drupal_set_title("Details for Peer " . $peername); $details=new PlcDetails(false); $details->start(); -$details->line("Peer name",$peer['peername']); -$details->line("Short name",$peer['shortname']); -$details->line("Hierarchical name",$peer['hrn_root']); -$details->line("API URL",$peer['peer_url']); +$details->th_td("Peer name",$peer['peername']); +$details->th_td("Short name",$peer['shortname']); +$details->th_td("Hierarchical name",$peer['hrn_root']); +$details->th_td("API URL",$peer['peer_url']); $nb=sizeof($peer['site_ids']); -$details->line("Number of sites",href(l_sites_peer($peer_id),"$nb sites")); +$details->th_td("Number of sites",href(l_sites_peer($peer_id),"$nb sites")); $nb=sizeof($peer['node_ids']); -$details->line("Number of nodes",href(l_nodes_peer($peer_id),"$nb nodes")); +$details->th_td("Number of nodes",href(l_nodes_peer($peer_id),"$nb nodes")); $nb=sizeof($peer['person_ids']); -$details->line("Number of users",href(l_persons_peer($peer_id),"$nb users")); +$details->th_td("Number of users",href(l_persons_peer($peer_id),"$nb users")); $nb=sizeof($peer['slice_ids']); -$details->line("Number of slices",href(l_slices_peer($peer_id),"$nb slices")); +$details->th_td("Number of slices",href(l_slices_peer($peer_id),"$nb slices")); $details->end(); // Print footer diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php index ed258d3..7a4d013 100644 --- a/planetlab/persons/person.php +++ b/planetlab/persons/person.php @@ -128,40 +128,35 @@ if ($local_peer && $privileges && ! $enabled ) $enabled_label="Yes"; if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled"); -$can_update = $is_my_account || plc_is_admin(); +$can_update = (plc_is_admin() && $local_peer) || $is_my_account; $details = new PlcDetails($can_update); $details->form_start(l_actions(),array("action"=>"update-person", "person_id"=>$person_id)); $details->start(); -$details->line("Enabled",$enabled_label); -$details->line("Peer",$peers->peer_link($peer_id)); -$details->space(); -// xxx this needs some more work on the PlcDetails class -$details->set_field_width(5); -$details->line("Title",$title,"title"); -$details->set_field_width(""); -$details->line("First Name",$first_name,"first_name"); -$details->line("Last Name",$last_name,"last_name"); -$details->line(href("mailto:$email","Email"),$email,"email"); -$details->line("Phone",$phone,"phone"); -$save_w=$details->set_field_width(40); -$details->line("URL",$url,"url"); -$details->set_field_height(4); -$details->set_input_type("textarea"); -$details->line("Bio",$bio,"bio"); -$details->set_input_type("text"); -$details->set_field_width($save_w); + + +$details->th_td("Title",$title,"title",array('width'=>5)); +$details->th_td("First Name",$first_name,"first_name"); +$details->th_td("Last Name",$last_name,"last_name"); +$details->th_td(href("mailto:$email","Email"),$email,"email"); +$details->th_td("Phone",$phone,"phone"); +$details->th_td("URL",$url,"url",array('width'=>40)); +$details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4)); // xxx need to check that this is working if ($can_update) { - $save_i=$details->set_input_type("password"); - $details->line("Password","","password1"); - $details->line("Repeat","","password2"); - $details->set_input_type($save_i); + $details->th_td("Password","","password1",array('input_type'=>'password')); + $details->th_td("Repeat","","password2",array('input_type'=>'password')); + $details->tr_submit("submit","Update Account"); + $details->space(); + } + +$details->th_td("Enabled",$enabled_label); +if ( ! $local_peer ) { + $details->th_td("Peer",$peers->peer_link($peer_id)); + $details->space(); } -// xxx need fields to reset password ? -$details->line("",$details->submit_html("submit","Update Account")); $details->end(); $details->form_end(); diff --git a/planetlab/persons/persons.php b/planetlab/persons/persons.php index 6645afd..c95cc68 100644 --- a/planetlab/persons/persons.php +++ b/planetlab/persons/persons.php @@ -35,6 +35,9 @@ $tabs=array(); $tabs['My accounts'] = array('url'=>l_persons(), 'values'=>array('site_id'=>plc_my_site_id()), 'bubble'=>'Lists accounts on site ' . plc_my_site_id()); +if (plc_is_admin()) + $tabs['Local accounts'] = array('url'=>l_persons(), + 'values'=>array('peerscope'=>'local')); // -------------------- $person_filter=array(); @@ -135,11 +138,11 @@ if ( ! $persons ) { } $headers = array ("Peer"=>"string", - "Roles"=>"string", "First"=>"string", "Last"=>"string", "Email"=>"string", "Site" => "string", + "Roles"=>"string", "S" => "int", "Status"=>"string", ); @@ -163,11 +166,11 @@ foreach ($persons as $person) { $table->row_start(); $table->cell($shortname); - $table->cell($roles); $table->cell ($person['first_name']); $table->cell ($person['last_name']); $table->cell(l_person_t($person_id,$email)); - $table->cell($login_base); + $table->cell(l_site_t($site_id,$login_base)); + $table->cell($roles); $table->cell(count($person['slice_ids'])); $table->cell(person_status($person)); $table->row_end(); diff --git a/planetlab/sites/site.php b/planetlab/sites/site.php index eac14ef..82c3409 100644 --- a/planetlab/sites/site.php +++ b/planetlab/sites/site.php @@ -139,35 +139,38 @@ if ( ! $enabled ) href (l_sites_pending(),"this page") . " to review pending applications."); -$can_update=plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi()); +$can_update=(plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && plc_is_pi()); $details = new PlcDetails($can_update); if ( ! $site['is_public']) plc_warning("This site is not public!"); $details->start(); -$details->line("Peer",$peers->peer_link($peer_id)); -$details->space(); $details->form_start(l_actions(),array('action'=>'update-site','site_id'=>$site_id)); -$save_w=$details->set_field_width(30); -$details->line("Full name",$sitename,'name'); -$details->set_field_width($save_w); -$details->line("Abbreviated name",$abbreviated_name,'abbreviated_name'); -$details->line("URL",$site_url,'url'); -$details->line("Latitude",$site_lat,'latitude'); -$details->line("Longitude",$site_long,'longitude'); +$details->th_td("Full name",$sitename,'name',array('width'=>50)); +$details->th_td("Abbreviated name",$abbreviated_name,'abbreviated_name',array('width'=>15)); +$details->th_td("URL",$site_url,'url',array('width'=>50)); +$details->th_td("Latitude",$site_lat,'latitude'); +$details->th_td("Longitude",$site_long,'longitude'); + +// modifiable by admins only if (plc_is_admin()) - $details->line("Login base",$login_base,'login_base'); + $details->th_td("Login base",$login_base,'login_base',array('width'=>12)); else - $details->line("Login base",$login_base); + $details->th_td("Login base",$login_base); if (plc_is_admin()) - $details->line("Max slices",$max_slices,'max_slices'); + $details->th_td("Max slices",$max_slices,'max_slices'); else - $details->line("Max slices",$max_slices); -$details->line("",$details->submit_html("submit","Update Site")); + $details->th_td("Max slices",$max_slices); +$details->tr_submit("submit","Update Site"); $details->form_end(); +if ( ! $local_peer) { + $details->space(); + $details->th_td("Peer",$peers->peer_link($peer_id)); + } + if ( $local_peer ) { // Nodes @@ -175,12 +178,12 @@ if ( $local_peer ) { $nb_boot = 0; if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++; $node_label = $nb_boot . " boot / " . count($nodes) . " total"; - $details->line("# Nodes", href(l_nodes_site($site_id),$node_label)); + $details->th_td("# Nodes", href(l_nodes_site($site_id),$node_label)); function n_link ($n) { return l_node_t($n['node_id'],$n['hostname'] . " (" . $n['boot_state'] . ")");} $nodes_label= plc_vertical_table(array_map ("n_link",$nodes)); - $details->line ("Hostnames",$nodes_label); + $details->th_td ("Hostnames",$nodes_label); $button=new PlcFormButton (l_node_add(),"add_node","Add node","POST"); - $details->line("",$button->html()); + $details->tr($button->html(),"right"); // Users $details->space(); @@ -189,14 +192,14 @@ if ( $local_peer ) { count ($techs) . " Techs"; if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50)) $user_label = plc_warning_html ($user_label); - $details->line ("# Users",href(l_persons_site($site_id),$user_label)); + $details->th_td ("# Users",href(l_persons_site($site_id),$user_label)); function p_link ($p) { return l_person_t($p['person_id'],$p['email']); } // PIs - $details->line("PI's",plc_vertical_table (array_map ("p_link",$pis))); + $details->th_td("PI's",plc_vertical_table (array_map ("p_link",$pis))); // techs - $details->line("Techs's",plc_vertical_table (array_map ("p_link",$techs))); + $details->th_td("Techs's",plc_vertical_table (array_map ("p_link",$techs))); if (count ($disabled_persons)) - $details->line("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons))); + $details->th_td("Disabled",plc_vertical_table (array_map ("p_link",$disabled_persons))); // Slices $details->space(); @@ -204,18 +207,18 @@ if ( $local_peer ) { $slice_label = count($slice_ids) . " running / " . $max_slices . " max"; if (count($slice_ids) >= $max_slices) $slice_label = plc_warning_html ($slice_label); - $details->line("# Slices", href(l_slices_site($site_id),$slice_label)); + $details->th_td("# Slices", href(l_slices_site($site_id),$slice_label)); if ($slices) foreach ($slices as $slice) - $details->line($slice['instantiation'],l_slice_obj($slice)); + $details->th_td($slice['instantiation'],l_slice_obj($slice)); $button=new PlcFormButton (l_slice_add(),"slice_add","Add slice","POST"); - $details->line("",$button->html()); + $details->tr($button->html(),"right"); // Addresses if ($addresses) { $details->space(); - $details->line("Addresses",""); + $details->th_td("Addresses",""); foreach ($addresses as $address) { - $details->line(plc_vertical_table($address['address_types']), + $details->th_td(plc_vertical_table($address['address_types']), plc_vertical_table(array($address['line1'], $address['line2'], $address['line3'], diff --git a/planetlab/tags/nodegroup.php b/planetlab/tags/nodegroup.php index 09fb885..b4d20eb 100644 --- a/planetlab/tags/nodegroup.php +++ b/planetlab/tags/nodegroup.php @@ -54,10 +54,10 @@ plc_tabs($tabs); $details=new PlcDetails(false); $details->start(); -$details->line ("Node group name",$nodegroup['groupname']); -$details->line ("Based on tag",href(l_tag($nodegroup['tag_type_id']),$tagname)); -$details->line("Matching value",$nodegroup['value']); -$details->line("# nodes",count($nodegroup['node_ids'])); +$details->th_td ("Node group name",$nodegroup['groupname']); +$details->th_td ("Based on tag",href(l_tag($nodegroup['tag_type_id']),$tagname)); +$details->th_td("Matching value",$nodegroup['value']); +$details->th_td("# nodes",count($nodegroup['node_ids'])); $details->end(); // xxx : add & delete buttons would make sense here too diff --git a/planetlab/tags/tag.php b/planetlab/tags/tag.php index 9e77f2e..2112202 100644 --- a/planetlab/tags/tag.php +++ b/planetlab/tags/tag.php @@ -59,9 +59,9 @@ $details=new PlcDetails ($can_update); $details->form_start(l_actions(),array("action"=>"update-tag-type", "tag_type_id"=>$tag_type_id)); $details->start(); -$details->line("Name",$tagname,"tagname"); -$details->line("Category",$category,"category"); -$details->line("Description",$description,"description"); +$details->th_td("Name",$tagname,"tagname"); +$details->th_td("Category",$category,"category"); +$details->th_td("Description",$description,"description"); // xxx misses in PlcDetails if ($can_update) { @@ -70,19 +70,19 @@ if ($can_update) { $selectors = $details->form()->role_selectors($api,"",$min_role_id); $select_field = $details->form()->select_html("min_role_id",$selectors); $save_i=$details->set_input_type("select"); - $details->line("Min role",$select_field,"min_role_id"); + $details->th_td("Min role",$select_field,"min_role_id"); $details->set_input_type($save_i); } else { - $details->line("Min role",$min_role_id); + $details->th_td("Min role",$min_role_id); } if ($can_update) - $details->single($details->form()->submit_html('update-tag-type',"Update tag type"),"right"); + $details->tr_submit('update-tag-type',"Update tag type"); $details->space(); -$details->line("Used in nodes",count($node_tags)); -$details->line("Used in interfaces",count($interface_tags)); -$details->line("Used in slices",count($slice_tags)); -$details->line("Used in slivers",count($sliver_tags)); +$details->th_td("Used in nodes",count($node_tags)); +$details->th_td("Used in interfaces",count($interface_tags)); +$details->th_td("Used in slices",count($slice_tags)); +$details->th_td("Used in slivers",count($sliver_tags)); $details->end(); $details->form_end(); -- 2.43.0