From c8011af627265e7e3faca9065271d98590212f7b Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 12 Mar 2009 14:16:12 +0000 Subject: [PATCH] tweaks, fixes, slice user management OK --- planetlab/common/actions.php | 21 ++++ planetlab/css/plc_style.css | 4 + planetlab/nodes/node.php | 4 +- planetlab/slices/slice.php | 192 ++++++++++++++++++------------- plekit/niftycorner/nifty_init.js | 7 +- 5 files changed, 148 insertions(+), 80 deletions(-) diff --git a/planetlab/common/actions.php b/planetlab/common/actions.php index 9c519b8..718e67f 100644 --- a/planetlab/common/actions.php +++ b/planetlab/common/actions.php @@ -67,6 +67,8 @@ $known_actions []= "update-site"; // expects: site_id & name abbreviated_name url latitude longitude [login_base max_slices] //////////////////////////////////////// slices +$known_actions []= "update-slice"; +// expects: slice_id, name, description, url $known_actions []= "renew-slice"; // expects: slice_id & expires $known_actions []= 'remove-persons-from-slice'; @@ -434,6 +436,25 @@ switch ($action) { } //////////////////////////////////////////////////////////// slices + case 'update-slice': { + $slice_id = $_POST['slice_id']; + $name = $_POST['name']; + $description= $_POST['description']; + $url= $_POST['url']; + + $fields= array( "description"=>$description, "url"=>$url ); + $api->UpdateSlice( intval( $slice_id ), $fields ); + $error= $api->error(); + + if( empty( $error ) ) { + drupal_set_message("Update slice $name"); + plc_redirect(l_slice($slice_id)); + } else { + drupal_set_error($error); + } + break; + } + case 'renew-slice': { $slice_id = intval ($_POST['slice_id']); $expires = intval ($_POST['expires']); diff --git a/planetlab/css/plc_style.css b/planetlab/css/plc_style.css index 145ba2a..5fe3782 100644 --- a/planetlab/css/plc_style.css +++ b/planetlab/css/plc_style.css @@ -44,3 +44,7 @@ div.block-planetlab a { font-weight:normal; font-style:italic; } + +div.renewal { + margin: 30px; +} diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index 06d0792..3ba9538 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -147,7 +147,9 @@ if ( ! $local_peer) { } $details->form_start(l_actions(),array("action"=>"update-node", "node_id"=>$node_id)); -$details->th_td("Hostname",$hostname,"hostname"); +// xxx can hostname really be changed like this without breaking the rest, bootcd .. ? +//$details->th_td("Hostname",$hostname,"hostname"); +$details->th_td("Hostname",$hostname); $details->th_td("Model",$model,"model"); $details->tr_submit("submit","Update Node"); $details->form_end(); diff --git a/planetlab/slices/slice.php b/planetlab/slices/slice.php index 1259f61..e90cfa4 100644 --- a/planetlab/slices/slice.php +++ b/planetlab/slices/slice.php @@ -53,6 +53,7 @@ $person_ids=$slice['person_ids']; // get peers $peer_id= $slice['peer_id']; $peers=new Peers ($api); +$local_peer = ! $peer_id; // gets site info $sites= $api->GetSites( array( $site_id ) ); @@ -66,84 +67,32 @@ $max_slices = $site['max_slices']; if (!empty($person_ids)) $persons=$api->GetPersons($person_ids,array('email','enabled')); -////////// -drupal_set_title("Details for slice " . $name); -$local_peer= ! $peer_id; - -$am_in_slice = in_array(plc_my_person_id(),$person_ids); -$privileges = (plc_is_admin() || $am_in_slice); +//////////////////////////////////////// building blocks for the renew area +// Constants +global $DAY; $DAY = 24*60*60; +global $WEEK; $WEEK = 7 * $DAY; +global $MAX_WEEKS; $MAX_WEEKS= 8; // weeks from today +global $GRACE_DAYS; $GRACE_DAYS=10; // days for renewal promoted on top +global $NOW; $NOW=mktime(); -$tabs=array(); -$tabs [] = tab_nodes_slice($slice_id); -$tabs [] = tab_site($site_id); -// are these the right privileges for deletion ? -if ($privileges) { - $tabs ['Delete']= array('url'=>l_actions(), - 'method'=>'post', - 'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id), - 'bubble'=>"Delete slice $name", - 'confirm'=>'Are you sure to delete $name'); +// make the renew area on top and open if the expiration time is less than 10 days from now +function renew_needed ($slice) { + global $DAY, $NOW, $GRACE_DAYS; + $current_exp=$slice['expires']; - $tabs["Events"]=array_merge(tablook_event(), - array('url'=>l_event("Slice","slice",$slice_id), - 'bubble'=>"Events for slice $name")); - $tabs["Comon"]=array_merge(tablook_comon(), - array('url'=>l_comon("slice_id",$slice_id), - 'bubble'=>"Comon page about slice $name")); + $time_left = $current_exp - $NOW; + $visible = $time_left/$DAY <= $GRACE_DAYS; + return $visible; } -plekit_linetabs($tabs); - -//////////////////////////////////////// -$peers->block_start($peer_id); - -$toggle = new PlekitToggle ('slice',"Details", - array('trigger-bubble'=>'Display and modify details for that slice')); -$toggle->start(); - -$details=new PlekitDetails($privileges); -$details->form_start(l_actions(),array('action'=>'update-slice','slice_id'=>$slice_id)); - -$details->start(); -if (! $local_peer) { - $details->th_td("Peer",$peers->peer_link($peer_id)); - $details->space(); - } - - -$details->th_td('Name',$slice['name']); -$details->th_td('Description',$slice['description'],'description', - array('input_type'=>'textarea', - 'width'=>50,'height'=>5)); -$details->th_td('URL',$slice['url'],'url',array('width'=>50)); -$details->th_td('Expires',$expires); -$details->th_td('Instantiation',$slice['instantiation']); -$details->th_td('Site',l_site_obj($site)); -// xxx -//$details->th_td('PIs',...); -$details->end(); - -$details->form_end(); -$toggle->end(); - -//////////////////////////////////////// renewal area - -function renew_area ($slice,$site) { +function renew_area ($slice,$site,$visible) { + global $DAY, $WEEK, $MAX_WEEKS, $GRACE_DAYS, $NOW; - // Constants - $DAY = 24*60*60; - $WEEK = 7 * $DAY; - $MAX_WEEKS= 8; // weeks from today - $now=mktime(); $current_exp=$slice['expires']; - $max_exp= $now + ($MAX_WEEKS * $WEEK); // seconds since epoch + $max_exp= $NOW + ($MAX_WEEKS * $WEEK); // seconds since epoch - // make this area visible only is the expiration time is less than 10 days from now - $time_left = $current_exp - $now; - $visible = $time_left/$DAY <= 10; - // xxx some extra code needed to enable this area only if the slice description is OK: // description and url must be non void $toggle=new PlekitToggle('renew',"Renew this slice", @@ -154,7 +103,7 @@ function renew_area ($slice,$site) { // xxx message could take roles into account if ($site['max_slices']<=0) { $message= <<< EOF -

Slice creation and renewal have been temporarily disabled for your +

Slice creation and renewal have been temporarily disabled for your +Slice cannot be renewed any further into the future, try again closer to expiration date. + +EOF; } else { print <<< EOF +

You must provide a short description as well as a link to a project website before renewing it. Do not provide bogus information; if a complaint is lodged against your slice and PlanetLab Operations is unable to determine what the normal behavior of your slice is, your slice may be deleted to resolve the complaint.

NOTE: -Slices cannot be renewed beyond another $max_renewal_weeks week(s) ($max_renewal_date) -.

+Slices cannot be renewed beyond another $max_renewal_weeks week(s) ($max_renewal_date). +

+
EOF; $form = new PlekitForm (l_actions(), @@ -211,7 +166,80 @@ EOF; $toggle->end(); } -renew_area ($slice,$site); +////////// +drupal_set_title("Details for slice " . $name); +$local_peer= ! $peer_id; + +$am_in_slice = in_array(plc_my_person_id(),$person_ids); + +$privileges = (plc_is_admin() || $am_in_slice); + +$tabs=array(); +$tabs [] = tab_nodes_slice($slice_id); +$tabs [] = tab_site($site_id); + +// are these the right privileges for deletion ? +if ($privileges) { + $tabs ['Delete']= array('url'=>l_actions(), + 'method'=>'post', + 'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id), + 'bubble'=>"Delete slice $name", + 'confirm'=>'Are you sure to delete $name'); + + $tabs["Events"]=array_merge(tablook_event(), + array('url'=>l_event("Slice","slice",$slice_id), + 'bubble'=>"Events for slice $name")); + $tabs["Comon"]=array_merge(tablook_comon(), + array('url'=>l_comon("slice_id",$slice_id), + 'bubble'=>"Comon page about slice $name")); +} + +plekit_linetabs($tabs); + +//////////////////////////////////////// +$peers->block_start($peer_id); + +//////////////////////////////////////// renewal area +// (1) close to expiration : show on top and open + +if ($local_peer ) { + $renew_visible = renew_needed ($slice); + if ($renew_visible) renew_area ($slice,$site,true); + } + + +//////////////////// details +$toggle = new PlekitToggle ('slice',"Details", + array('trigger-bubble'=>'Display and modify details for that slice')); +$toggle->start(); + +$details=new PlekitDetails($privileges); +$details->form_start(l_actions(),array('action'=>'update-slice', + 'slice_id'=>$slice_id, + 'name'=>$name)); + +$details->start(); +if (! $local_peer) { + $details->th_td("Peer",$peers->peer_link($peer_id)); + $details->space(); + } + + +$details->th_td('Name',$slice['name']); +$details->th_td('Description',$slice['description'],'description', + array('input_type'=>'textarea', + 'width'=>50,'height'=>5)); +$details->th_td('URL',$slice['url'],'url',array('width'=>50)); +$details->th_td('Expires',$expires); +$details->th_td('Instantiation',$slice['instantiation']); +$details->th_td('Site',l_site_obj($site)); +// xxx show the PIs here +//$details->th_td('PIs',...); +$details->tr_submit("submit","Update Slice"); +$details->end(); + +$details->form_end(); +$toggle->end(); //////////////////// users $persons=$api->GetPersons(array('person_id'=>$slice['person_ids'])); @@ -228,7 +256,8 @@ $headers['first']='string'; $headers['last']='string'; $headers['R']='string'; if ($privileges) $headers[plc_delete_icon()]="none"; -$table=new PlekitTable('persons',$headers,'1',array('caption'=>'Current users', +// xxx caption currently broken, messes pagination +$table=new PlekitTable('persons',$headers,'1',array(//'caption'=>'Current users', 'search_area'=>false, 'notes_area'=>false, 'pagesize_area'=>false)); @@ -265,10 +294,11 @@ if ($privileges) { $headers['last']='string'; $headers['R']='string'; $headers['Add']="none"; - $table=new PlekitTable('add_persons',$headers,'1',array('caption'=>'Users to add', + // xxx caption currently broken, messes pagination + $table=new PlekitTable('add_persons',$headers,'1',array(//'caption'=>'Users to add', 'search_area'=>false, - 'notes_area'=>false)); - // 'pagesize'=>5)); + 'notes_area'=>false, + 'pagesize'=>5)); $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id'])); $form->start(); $table->start(); @@ -297,6 +327,12 @@ $toggle->end(); //////////////////// tags +if ($local_peer ) { + if ( ! $renew_visible) renew_area ($slice,$site,false); + } + +if ($renew_visible) renew_area ($slice,$site,true); + $peers->block_end($peer_id); // Print footer diff --git a/plekit/niftycorner/nifty_init.js b/plekit/niftycorner/nifty_init.js index 49aa5d2..b927d9e 100644 --- a/plekit/niftycorner/nifty_init.js +++ b/plekit/niftycorner/nifty_init.js @@ -14,7 +14,12 @@ function nifty_init () { if ( nifty_inited ) return; var elements=document.getElementsByClassName('nifty-medium'); for (var i=0; i