tags now have roles and not min_role_id
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 22 Nov 2010 22:08:16 +0000 (23:08 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 22 Nov 2010 22:08:16 +0000 (23:08 +0100)
tag page to show associations on persons and sites

planetlab/common/actions.php
planetlab/css/plc_style.css
planetlab/includes/plc_functions.php
planetlab/persons/person.php
planetlab/tags/tag.php
planetlab/tags/tags.php

index 0b4353d..ba60104 100644 (file)
@@ -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': {
index a361c1d..0a84598 100644 (file)
@@ -184,3 +184,7 @@ p.note_reservable {
     text-align: center;
     font-size: larger; 
 }
+span.note_roles {
+    font-style:italic;
+    font-size: smaller;
+}
index 4befb9c..f007cda 100644 (file)
@@ -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"; }
index d79020f..107219c 100644 (file)
@@ -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";
index db09b8c..2f915e9 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 // Require login
 require_once 'plc_login.php';
 
@@ -39,7 +37,8 @@ $tag_types= $api->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<count($roles); $n++) {
+  $role_objs[]= array('role_id'=>$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();
index 0f57723..75b89dd 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$
-
 // Require login
 require_once 'plc_login.php';
 
@@ -34,7 +32,7 @@ $tabs []= tab_slices();
 drupal_set_title($title);
 plekit_linetabs($tabs);
 
-$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "min_role_id" );
+$tag_type_columns = array( "tag_type_id", "tagname", "category", "description", "roles");
 
 $tag_type_filter=NULL;
 if ($pattern) 
@@ -49,8 +47,7 @@ $notes=array();
 $headers['Name']="string";
 $headers['Description']="string";
 $headers['Category']="string";
-$headers['MR']="string";
-$notes []= "MR: Min Role, needed to manage this tag";
+$headers['Roles']="string";
 
 // xxx ref count would be helpful but seem too expensive to compute at this stage 
 // the individual tag page show those ref counts per type
@@ -64,21 +61,16 @@ $form->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,"<br/>"));
   $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("<span class='note_roles'>add roles later</span>");
   $table->cell($form->submit_html("add-tag-type","Add"),2);
   $table->row_end();
  }