From 1d3fcb7473152b367367cc32574b8b126dbc6e26 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 22 Nov 2010 23:08:16 +0100 Subject: [PATCH] tags now have roles and not min_role_id tag page to show associations on persons and sites --- planetlab/common/actions.php | 28 +++++++ planetlab/css/plc_style.css | 4 + planetlab/includes/plc_functions.php | 1 + planetlab/persons/person.php | 1 - planetlab/tags/tag.php | 118 ++++++++++++++++++++++++--- planetlab/tags/tags.php | 22 +---- 6 files changed, 142 insertions(+), 32 deletions(-) diff --git a/planetlab/common/actions.php b/planetlab/common/actions.php index 0b4353d..ba60104 100644 --- a/planetlab/common/actions.php +++ b/planetlab/common/actions.php @@ -99,6 +99,10 @@ $known_actions []= "add-tag-type"; // expects: tag_type_id & tagname & description & category & min_role_id $known_actions []= "delete-tag-types"; // expects: tag_type_ids +$known_actions []= "remove-roles-from-tag-type"; +// expects: tag_type_id & role_ids +$known_actions []= "add-role-to-tag-type"; +// expects: tag_type_id_id & id //////////////////////////////////////// tags $known_actions []= "set-tag-on-node"; @@ -815,6 +819,30 @@ Our support team will be glad to answer any question that you might have. break; } + case 'remove-roles-from-tag-type' : { + $tag_type_id=$_POST['tag_type_id']; + $role_ids=$_POST['role_ids']; + if ( ! $role_ids) { + drupal_set_error("You have not selected role(s) to remove"); + } else { + foreach( $role_ids as $role_id) + if ( $api->DeleteRoleFromTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1 ) + drupal_set_error ("Could not remove role $role_id from tag type $tag_type_id"); + } + plc_redirect (l_tag_roles($tag_type_id)); + } + + case 'add-role-to-tag-type' : { + $tag_type_id=$_POST['tag_type_id']; + $role_id=$_POST['role_id']; + if ( ! $role_id) { + drupal_set_error ("You have not selected a role to add"); + } else if ($api->AddRoleToTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1) { + drupal_set_error("Could not add role $role_id to tag $tag_type_id"); + } + plc_redirect (l_tag_roles($tag_type_id)); + } + //////////////////////////////////////// tags case 'set-tag-on-node': case 'set-tag-on-interface': { diff --git a/planetlab/css/plc_style.css b/planetlab/css/plc_style.css index a361c1d..0a84598 100644 --- a/planetlab/css/plc_style.css +++ b/planetlab/css/plc_style.css @@ -184,3 +184,7 @@ p.note_reservable { text-align: center; font-size: larger; } +span.note_roles { + font-style:italic; + font-size: smaller; +} diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 4befb9c..f007cda 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -130,6 +130,7 @@ function l_person_obj ($person) { return l_person_t($person['person_id'],$perso function l_tags () { return "/db/tags/index.php"; } function l_tag ($tag_type_id) { return "/db/tags/index.php?id=$tag_type_id"; } function l_tag_obj ($tag) { return href(l_tag($tag['tag_type_id']),$tag['tagname']); } +function l_tag_roles ($tag_type_id) { return "/db/tags/index.php?id=$tag_type_id&show_details=0&show_roles=1"; } function l_nodegroups () { return "/db/tags/nodegroups.php"; } function l_nodegroup ($nodegroup_id) { return "/db/tags/nodegroup.php?id=$nodegroup_id"; } diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php index d79020f..107219c 100644 --- a/planetlab/persons/person.php +++ b/planetlab/persons/person.php @@ -320,7 +320,6 @@ if ($local_peer) { $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() ); $can_manage_roles= ( ($local_peer && plc_is_admin()) || $is_pi_of_the_site ); - $table_options=array("search_area"=>false,"notes_area"=>false); $headers=array("Role"=>"string"); if ($can_manage_roles) $headers [plc_delete_icon()]="none"; diff --git a/planetlab/tags/tag.php b/planetlab/tags/tag.php index db09b8c..2f915e9 100644 --- a/planetlab/tags/tag.php +++ b/planetlab/tags/tag.php @@ -1,7 +1,5 @@ GetTagTypes( array( $tag_type_id ) ); $tag_type=$tag_types[0]; $tagname=$tag_type['tagname']; -$min_role_id= $tag_type['min_role_id']; +$role_ids= $tag_type['role_ids']; +$roles= $tag_type['roles']; $description= $tag_type['description']; $category=$tag_type['category']; @@ -47,6 +46,8 @@ $category=$tag_type['category']; $filter=array('tag_type_id'=>$tag_type_id); $node_tags=$api->GetNodeTags($filter); $interface_tags=$api->GetInterfaceTags($filter); +$person_tags=$api->GetPersonTags($filter); +$site_tags=$api->GetSiteTags($filter); // split slice tags into 3 families, whether this applies to the whole slice, or a nodegroup, or a node // using filters for this purpose does not work out very well, maybe a bug in the filter stuff // anyway this is more efficient, and we compute the related node(groups) in the same pass @@ -79,7 +80,7 @@ foreach ($nodegroups as $nodegroup) $nodegroup_hash[$nodegroup['nodegroup_id']]= drupal_set_title("Details for tag type $tagname"); plekit_linetabs($tabs); -// ---------- +//////////////////// details $toggle = new PlekitToggle ('details','Details'); $toggle->start(); $can_update=plc_is_admin(); @@ -92,15 +93,6 @@ $details->th_td("Name",$tagname,"tagname"); $details->th_td("Category",$category,"category",array('width'=>30)); $details->th_td("Description",$description,"description",array('width'=>40)); -if ($can_update) { -// select the option corresponding with min_role_id - $selectors = $details->form()->role_selectors($api->GetRoles(),$min_role_id); - $select_field = $details->form()->select_html("min_role_id",$selectors); - // xxx would need to turn role_id into role name - $details->th_td("Min role",$select_field,"min_role_id",array('input_type'=>'select','value'=>$min_role_id)); - } else { - $details->th_td("Min role",$min_role_id); - } if ($can_update) $details->tr_submit('update-tag-type',"Update tag type"); @@ -115,6 +107,76 @@ $details->end(); $details->form_end(); $toggle->end(); +//////////////////// roles +$form=new PlekitForm(l_actions(), array("tag_type_id"=>$tag_type_id)); +$form->start(); + +$toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles',false))); +$toggle->start(); + +if (! $roles) plc_warning ("This tag type has no role !"); + +$can_manage_roles= plc_is_admin(); + +$headers=array("Role"=>"string"); +if ($can_manage_roles) $headers [plc_delete_icon()]="none"; + +$table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false); +$table=new PlekitTable("tag_roles",$headers,0,$table_options); +$table->start(); + +// construct array of role objs +$role_objs=array(); +for ($n=0; $n$role_ids[$n], 'name'=>$roles[$n]); +} + +if ($role_objs) foreach ($role_objs as $role_obj) { + $table->row_start(); + $table->cell($role_obj['name']); + if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id'])); + $table->row_end(); + } + +// footers : the remove and add buttons +if ($can_manage_roles) { + + // remove + $table->tfoot_start(); + if ($roles) { + $table->row_start(); + $table->cell($form->submit_html("remove-roles-from-tag-type","Remove Roles"), + array('hfill'=>true,'align'=>'right')); + $table->row_end(); + } + + // add + // compute the roles that can be added + if ($can_manage_roles) + // all roles + $exclude_role_ids=array(); + else + // all roles except admin and pi + $exclude_role_ids=array(10,20); + $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids); + $roles_to_add = roles_except ($possible_roles,$role_ids); + if ( $roles_to_add ) { + $selectors=$form->role_selectors($roles_to_add); + $table->row_start(); + $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role")); + // add a role : the button + $add_role_right_area=$form->submit_html("add-role-to-tag-type","Add role"); + $table->cell ($add_role_left_area . $add_role_right_area, + array('hfill'=>true,'align'=>'right')); + $table->row_end(); + } +} +$table->end(); +$toggle->end(); +$form->end(); + +//////////////////// the 5 flavours of objects that the tag may be attached to + // common options for tables below $table_options=array('notes_area'=>false, 'pagesize_area'=>false, 'search_width'=>10); @@ -149,6 +211,36 @@ if (count ($interface_tags)) { $toggle->end(); } +if (count ($site_tags)) { + $toggle=new PlekitToggle('tag_sites',"Sites"); + $toggle->start(); + $table=new PlekitTable("tag_sites",array("L"=>"login_base","value"=>"string"),0,$table_options); + $table->start(); + foreach ($site_tags as $site_tag) { + $table->row_start(); + $table->cell(href(l_site($site_tag['site_id']),$site_tag['login_base'])); + $table->cell($site_tag['value']); + $table->row_end(); + } + $table->end(); + $toggle->end(); +} + +if (count ($person_tags)) { + $toggle=new PlekitToggle('tag_persons',"Persons"); + $toggle->start(); + $table=new PlekitTable("tag_persons",array("E"=>"email","value"=>"string"),0,$table_options); + $table->start(); + foreach ($person_tags as $person_tag) { + $table->row_start(); + $table->cell(href(l_person($person_tag['person_id']),$person_tag['email'])); + $table->cell($person_tag['value']); + $table->row_end(); + } + $table->end(); + $toggle->end(); +} + if (count ($slice_tags)) { $toggle=new PlekitToggle('tag_slices',"Slice tags"); $toggle->start(); diff --git a/planetlab/tags/tags.php b/planetlab/tags/tags.php index 0f57723..75b89dd 100644 --- a/planetlab/tags/tags.php +++ b/planetlab/tags/tags.php @@ -1,7 +1,5 @@ start(); $table = new PlekitTable("tags",$headers,0,array('notes'=>$notes)); $table->start(); -$roles_hash=plc_role_global_hash($api); - $description_width=40; foreach( $tag_types as $tag_type ) { - $role_name=$roles_hash[$tag_type['min_role_id']]; $table->row_start(); $tag_type_id=$tag_type['tag_type_id']; $table->cell(href(l_tag($tag_type_id),$tag_type['tagname'])); $table->cell(wordwrap($tag_type['description'],$description_width,"
")); $table->cell($tag_type['category']); - $table->cell($role_name); - // ref count - // if (plc_is_admin()) $table->cell('xxx'); + $table->cell(plc_vertical_table ($tag_type['roles'])); $table->cell($tag_type_id); if (plc_is_admin()) $table->cell ($form->checkbox_html('tag_type_ids[]',$tag_type_id)); @@ -96,16 +88,10 @@ if (plc_is_admin()) { // an inline area to add a tag type $table->row_start(); - // build the role selector - $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids)); - function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); } - $selectors=array_map("selector_argument",$relevant_roles); - $role_input=$form->select_html("min_role_id",$selectors,array('label'=>"Role")); - $table->cell($form->text_html('tagname','')); $table->cell($form->textarea_html('description','',$description_width,2)); $table->cell($form->text_html('category','')); - $table->cell($role_input); + $table->cell("add roles later"); $table->cell($form->submit_html("add-tag-type","Add"),2); $table->row_end(); } -- 2.47.0