From cc80f3553825a3e1f170776319a927c0ca90fbb2 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 21 Apr 2009 21:50:10 +0000 Subject: [PATCH] slice_add dialog : multiple sites & more robust --- planetlab/common/actions.php | 9 ++-- planetlab/css/plc_style.css | 6 +++ planetlab/slices/slice.php | 4 +- planetlab/slices/slice_add.php | 78 +++++++++++++++++----------------- 4 files changed, 51 insertions(+), 46 deletions(-) diff --git a/planetlab/common/actions.php b/planetlab/common/actions.php index 0f7623e..8a3b0fb 100644 --- a/planetlab/common/actions.php +++ b/planetlab/common/actions.php @@ -448,12 +448,11 @@ switch ($action) { //////////////////////////////////////////////////////////// slices case 'delete-slice': { $slice_id = $_POST['slice_id']; - $api->DeleteSlice( intval( $slice_id ) ); - $error= $api->error(); - if( empty( $error ) ) { - drupal_set_message("Deleted slice $slice_id"); + if ($api->DeleteSlice( intval( $slice_id )) == 1 ) { + drupal_set_message("Slice $slice_id deleted"); + plc_redirect(l_slices()); } else { - drupal_set_error($error); + drupal_set_error("Could not delete slice $slice_id " . $api->error()); } break; } diff --git a/planetlab/css/plc_style.css b/planetlab/css/plc_style.css index 960a7a0..1edabeb 100644 --- a/planetlab/css/plc_style.css +++ b/planetlab/css/plc_style.css @@ -98,3 +98,9 @@ div.slice_add * { h3.node_download { text-align: center; } +div#add_slice_in_site { + text-align:center; +} +#add_slice_choose_site { + margin:20px ; +} diff --git a/planetlab/slices/slice.php b/planetlab/slices/slice.php index 97b6e23..6509cc4 100644 --- a/planetlab/slices/slice.php +++ b/planetlab/slices/slice.php @@ -183,7 +183,7 @@ if ($am_in_slice) { drupal_set_title("Slice " . $name); } -$privileges = ( $local_peer && (plc_is_admin() || $am_in_slice)); +$privileges = ( $local_peer && (plc_is_admin() || plc_is_pi() || $am_in_slice)); $tabs=array(); $tabs [] = tab_nodes_slice($slice_id); @@ -195,7 +195,7 @@ if ($privileges) { 'method'=>'post', 'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id), 'bubble'=>"Delete slice $name", - 'confirm'=>'Are you sure to delete $name'); + 'confirm'=>"Are you sure to delete slice $name"); $tabs["Events"]=array_merge(tablook_event(), array('url'=>l_event("Slice","slice",$slice_id), diff --git a/planetlab/slices/slice_add.php b/planetlab/slices/slice_add.php index 980654c..6a056b1 100644 --- a/planetlab/slices/slice_add.php +++ b/planetlab/slices/slice_add.php @@ -87,10 +87,7 @@ if ( $_POST['add-slice'] ) { // add it! $slice_id= $api->AddSlice( $fields ); - if ($slice_id < 0) { - drupal_set_error("Could not create slice $name " . $api->error() ); - $check=false; - } else { + if ($slice_id > 0) { drupal_set_message ("Slice $slice_id created"); if ($person_ids) { // Add people @@ -111,6 +108,9 @@ if ( $_POST['add-slice'] ) { drupal_set_error ("Could not add all selected persons, only $counter were added"); } plc_redirect(l_slice($slice_id) ); + } else { + drupal_set_error("Could not create slice $name " . $api->error() ); + $check=false; } } } @@ -148,18 +148,37 @@ if( $error['description'] ) $desc_error= " class='plc-warning'"; -// add javaScript code -print <<< EOF - -EOF; +// is there a need to consider several sites ? +$multiple_sites=false; +$site_columns=array('name','login_base','site_id'); +if (plc_is_admin ()) { + $multiple_sites=true; + $filter=NULL; + } else if (count (plc_my_site_ids()) > 1) { + $multiple_sites=true; + $filter=plc_my_site_ids(); + } + +if ($multiple_sites) { + print "
"; + $other_sites=$api->GetSites($filter,$site_columns); + $selectors=array(); + foreach ($other_sites as $other_site) { + $selector=array('display'=>$other_site['name'], + 'value'=>$other_site['site_id']); + if ($other_site['site_id']==$other_site_id) $selector['selected']='selected'; + $selectors []= $selector; + } + $site_form = new PleKitForm (l_slice_add(),array(),'get'); + $site_form->start(); + print $site_form->label_html('site_id','Or choose some other site'); + print $site_form->select_html('site_id',$selectors,array('autosubmit'=>true, + 'id'=>'add_slice_choose_site')); + $site_form->end(); + print "
"; + } + print <<< EOF

You must provide a short description of the new slice @@ -189,30 +208,11 @@ print $form->hidden_html("site_id",$site_id); $details->start(); -// is the user on several sites ? -if (plc_is_admin () || count (plc_my_site_ids()) > 1) { - // site selector - not implemented yet -//// // displays a site select list for admins and multi-site users -//// if( count( $_person['site_ids'] ) > 1 || in_array( 10, $_roles ) ) { -//// // get sites depending on role and sites associated. -//// if( in_array( 10, $_roles ) ) -//// $site_info= $api->GetSites( NULL, array( "name", "site_id", "login_base" ) ); -//// elseif( count( $_person['site_ids'] ) > 1 ) -//// $site_info= $api->GetSites( $_person['site_ids'], array( "name", "site_id", "login_base" ) ); -//// -//// echo "Site: \n"; - -} - +$running=count($site['slice_ids']); +$max=$site['max_slices']; +$allocated = " $running running / $max max"; +if ($running >= $max) $allocated = plc_warning_html($allocated); +$details->th_td("Allocated slices",$allocated); $details->th_td("Name",$name ? $name : $base, "name"); $details->th_td("URL",$url,"url"); $details->th_td("Description",$description,"description", -- 2.47.0