add tags sections to sites and persons
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 28 Aug 2012 15:06:16 +0000 (17:06 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 28 Aug 2012 15:06:16 +0000 (17:06 +0200)
planetlab/common/actions.php
planetlab/includes/plc_functions.php
planetlab/persons/person.php
planetlab/sites/site.php

index 8c4beab..09b1866 100644 (file)
@@ -111,10 +111,18 @@ $known_actions []= "add-role-to-tag-type";
 //////////////////////////////////////// tags
 $known_actions []= "set-tag-on-node";
 //     expects:        node_id tagname value
+$known_actions []= "set-tag-on-site";
+//     expects:        site_id tagname value
+$known_actions []= "set-tag-on-person";
+//     expects:        person_id tagname value
 $known_actions []= "set-tag-on-interface";
 //     expects:        interface_id tagname value
 $known_actions []= "delete-node-tags";
 //     expects:        node_id & node_tag_ids
+$known_actions []= "delete-site-tags";
+//     expects:        site_id & site_tag_ids
+$known_actions []= "delete-person-tags";
+//     expects:        person_id & person_tag_ids
 $known_actions []= "delete-interface-tags";
 //     expects:        interface_id & interface_tag_ids
 
@@ -895,15 +903,25 @@ Our support team will be glad to answer any question that you might have.
 
 //////////////////////////////////////// tags   
  case 'set-tag-on-node': 
- case 'set-tag-on-interface': {
+ case 'set-tag-on-site': 
+ case 'set-tag-on-person': 
+ case 'set-tag-on-interface': 
+   {
    
-   $node_mode = false;
-   if ($action == 'set-tag-on-node') $node_mode=true;
-
-   if ($node_mode)
-     $node_id = intval($_POST['node_id']);
+   $mode = NULL;
+   if ($action == 'set-tag-on-node') $mode='node';
+   if ($action == 'set-tag-on-site') $mode='site';
+   if ($action == 'set-tag-on-person') $mode='person';
+   if ($action == 'set-tag-on-interface') $mode='interface';
+
+   if ($mode=='node') 
+     $id = intval($_POST['node_id']);
+   else if ($mode=='site')
+     $id = intval($_POST['site_id']);
+   else if ($mode=='person')
+     $id = intval($_POST['person_id']);
    else 
-     $interface_id=intval($_POST['interface_id']);
+     $id = intval($_POST['interface_id']);
    $tag_type_id = intval($_POST['tag_type_id']);
    $value = $_POST['value'];
 
@@ -911,28 +929,42 @@ Our support team will be glad to answer any question that you might have.
    if (count ($tag_types) != 1) {
      drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
    } else {
-     if ($node_mode) 
-       $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
+     if ($mode=='node') 
+       $tags = $api->GetNodeTags (array('node_id'=>$id, 'tag_type_id'=> $tag_type_id));
+     else if ($mode=='site')
+       $tags = $api->GetSiteTags (array('site_id'=>$id, 'tag_type_id'=> $tag_type_id));
+     else if ($mode=='person')
+       $tags = $api->GetPersonTags (array('person_id'=>$id, 'tag_type_id'=> $tag_type_id));
      else
-       $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
+       $tags = $api->GetInterfaceTags (array('interface_id'=>$id, 'tag_type_id'=> $tag_type_id));
+
+     // already has a tag set
      if ( count ($tags) == 1) {
        $tag=$tags[0];
-       if ($node_mode) {
-        $tag_id=$tag['node_tag_id'];
-        $result=$api->UpdateNodeTag($tag_id,$value);
-       } else {
-        $tag_id=$tag['interface_tag_id'];
-        $result=$api->UpdateInterfaceTag($tag_id,$value);
-       }
+       if ($mode=='node') 
+        $result=$api->UpdateNodeTag($tag['node_tag_id'],$value);
+       else if ($mode=='site') 
+        $result=$api->UpdateSiteTag($tag['site_tag_id'],$value);
+       else if ($mode=='person') 
+        $result=$api->UpdatePersonTag($tag['person_tag_id'],$value);
+       else 
+        $result=$api->UpdateInterfaceTag($tag['interface_tag_id'],$value);
+
        if ($result == 1) 
         drupal_set_message ("Updated tag, new value = $value");
        else
         drupal_set_error ("Could not update tag");
+
+     // no such tag set yet on that object
      } else {
-       if ($node_mode)
-        $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
+       if ($mode=='node')
+        $tag_id = $api->AddNodeTag($id,$tag_type_id,$value);
+       else if ($mode=='site')
+        $tag_id = $api->AddSiteTag($id,$tag_type_id,$value);
+       else if ($mode=='person')
+        $tag_id = $api->AddPersonTag($id,$tag_type_id,$value);
        else
-        $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
+        $tag_id = $api->AddInterfaceTag($id,$tag_type_id,$value);
        if ($tag_id) 
         drupal_set_message ("Created tag, new value = $value");
        else
@@ -940,22 +972,40 @@ Our support team will be glad to answer any question that you might have.
      }
    }
    
-   if ($node_mode)
-     plc_redirect (l_node_tags($node_id));
+   if ($mode=='node')
+     plc_redirect (l_node_tags($id));
+   else if ($mode=='site')
+     plc_redirect (l_site_tags($id));
+   else if ($mode=='person')
+     plc_redirect (l_person_tags($id));
    else
-     plc_redirect (l_interface_tags($interface_id));
+     plc_redirect (l_interface_tags($id));
  }
 
- case 'delete-node-tags' : 
- case 'delete-interface-tags' : {
+ case 'delete-node-tags': 
+ case 'delete-site-tags':
+ case 'delete-person-tags':
+ case 'delete-interface-tags': {
 
-   $node_mode = false;
-   if ($action == 'delete-node-tags') $node_mode=true;
+   $mode = NULL;
+   if ($action == 'delete-node-tags') $mode='node';
+   if ($action == 'delete-site-tags') $mode='site';
+   if ($action == 'delete-person-tags') $mode='person';
+   if ($action == 'delete-interface-tags') $mode='interface';
 
-   if ($node_mode)
+   if ($mode=='node') {
+     $id=$_POST['node_id'];
      $tag_ids=$_POST['node_tag_ids'];
-   else
+   } else if ($mode=='site') {
+     $id=$_POST['site_id'];
+     $tag_ids=$_POST['site_tag_ids'];
+   } else if ($mode=='person') {
+     $id=$_POST['person_id'];
+     $tag_ids=$_POST['person_tag_ids'];
+   } else {
+     $id=$_POST['interface_id'];
      $tag_ids=$_POST['interface_tag_ids'];
+   }
 
    if ( ! $tag_ids) {
      drupal_set_message("action=$action - No tag selected");
@@ -964,8 +1014,12 @@ Our support team will be glad to answer any question that you might have.
    $success=true;
    $counter=0;
    foreach( $tag_ids as $tag_id ) {
-     if ($node_mode)
+     if ($mode=='node') 
        $retcod = $api->DeleteNodeTag( intval( $tag_id ));
+     else if ($mode=='site')
+       $retcod = $api->DeleteSiteTag( intval( $tag_id ));
+     else if ($mode=='person')
+       $retcod = $api->DeletePersonTag( intval( $tag_id ));
      else
        $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
      if ($retcod != 1) 
@@ -977,10 +1031,16 @@ Our support team will be glad to answer any question that you might have.
      drupal_set_message ("Deleted $counter tag(s)");
    else
      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
-   if ($node_mode)
-     plc_redirect(l_node_tags($_POST['node_id']));
+
+   if ($mode=='node')
+     plc_redirect (l_node_tags($id));
+   else if ($mode=='site')
+     plc_redirect (l_site_tags($id));
+   else if ($mode=='person')
+     plc_redirect (l_person_tags($id));
    else
-     plc_redirect(l_interface_tags($_POST['interface_id']));
+     plc_redirect (l_interface_tags($id));
+
  }
 
 //////////////////////////////////////// nodegroups
index 678de29..5db3d54 100644 (file)
@@ -102,6 +102,7 @@ function l_sites_peer ($peer_id)    { return "/db/sites/index.php?peerscope=$peer_i
 function l_site ($site_id)             { return "/db/sites/index.php?id=$site_id"; }
 function l_site_t ($site_id,$text)     { return href (l_site($site_id),$text); }
 function l_site_obj($site)             { return href (l_site($site['site_id']),$site['name']); }
+function l_site_tags ($site_id)                { return "/db/sites/site.php?id=$site_id&show_tags=1"; }
 
 function l_slices ()                   { return "/db/slices/index.php"; }
 function l_slices_peer ($peer_id)      { return "/db/slices/index.php?peerscope=$peer_id"; }
@@ -128,6 +129,7 @@ function l_person_t ($person_id,$text)      { return href (l_person($person_id),$text
 function l_persons_site ($site_id)     { return "/db/persons/index.php?site_id=$site_id"; }
 function l_persons_slice ($slice_id)   { return "/db/persons/index.php?slice_id=$slice_id"; }
 function l_person_obj ($person)                { return l_person_t($person['person_id'],$person['email']); }
+function l_person_tags ($person_id)    { return "/db/persons/person.php?id=$person_id&show_tags=1"; }
 
 function l_tags ()                     { return "/db/tags/index.php"; }
 function l_tag ($tag_type_id)          { return "/db/tags/index.php?id=$tag_type_id"; }
index 5b74a7f..bd499ad 100644 (file)
@@ -379,6 +379,65 @@ if ($local_peer) {
   $toggle->end();
  }
 
+//////////////////////////////////////////////////////////// Tags
+// tags section
+if ($local_peer) {
+  $tags=$api->GetPersonTags (array('person_id'=>$person_id));
+  function get_tagname ($tag) { return $tag['tagname'];}
+  // xxx looks like tech-only see an error here, 
+  // might be that GetPersonTags is not accessible or something
+  $tagnames = array_map ("get_tagname",$tags);
+  
+  $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
+                             array('bubble'=>'Inspect and set tags on that person',
+                                   'visible'=>get_arg('show_tags')));
+  $toggle->start();
+
+  $headers=array("Name"=>"string",
+                "Value"=>"string",
+                );
+  if (plc_is_admin()) $headers[plc_delete_icon()]="none";
+  
+  $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
+  $table=new PlekitTable("person_tags",$headers,0,$table_options);
+  $table->start();
+  if ($tags) foreach ($tags as $tag) {
+      $table->row_start();
+      $table->cell(l_tag_obj($tag));
+      $table->cell($tag['value']);
+      // the remove checkbox
+      if (plc_is_admin()) $table->cell ($form->checkbox_html('person_tag_ids[]',$tag['person_tag_id']));
+      $table->row_end();
+    }
+  
+  if ($privileges) {
+    $table->tfoot_start();
+
+    // remove tag 
+    $table->row_start();
+    $table->cell($form->submit_html("delete-person-tags","Remove Tags"),
+                // use the whole columns and right adjust
+                array('hfill'=>true,'align'=>'right'));
+    $table->row_end();
+
+    // set tag area
+    $table->row_start();
+    // get list of tag names in the person/* category    
+    $all_tags= $api->GetTagTypes( array ("category"=>"person*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
+    // xxx cannot use onchange=submit() - would need to somehow pass action name 
+    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,array('label'=>"Choose")));
+    $table->cell($form->text_html("value","",array('width'=>8)));
+    $table->cell($form->submit_html("set-tag-on-person","Set Tag"),array('columns'=>2,'align'=>'left'));
+    $table->row_end();
+  }
+  
+  $table->end();
+  $toggle->end();
+
+}
+
 //////////////////////////////
 $form->end();
 $peers->block_end($peer_id);
index dc10a90..e9fa028 100644 (file)
@@ -382,6 +382,67 @@ if ( $local_peer ) {
   $table->end();
   $toggle->end();
 
+  $form=new PlekitForm (l_actions(), array('site_id'=>$site_id));
+  $form->start();
+  //////////////////////////////////////////////////////////// Tags
+  // tags section
+  // already inside a if ( $local_peer )...
+  
+  $tags=$api->GetSiteTags (array('site_id'=>$site_id));
+  function get_tagname ($tag) { return $tag['tagname'];}
+  // xxx looks like tech-only see an error here, 
+  // might be that GetSiteTags is not accessible or something
+  $tagnames = array_map ("get_tagname",$tags);
+  
+  $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
+                             array('bubble'=>'Inspect and set tags on that site',
+                                   'visible'=>get_arg('show_tags')));
+  $toggle->start();
+
+  $headers=array("Name"=>"string",
+                "Value"=>"string",
+                );
+  if (plc_is_admin()) $headers[plc_delete_icon()]="none";
+  
+  $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
+  $table=new PlekitTable("site_tags",$headers,0,$table_options);
+  $table->start();
+  if ($tags) foreach ($tags as $tag) {
+      $table->row_start();
+      $table->cell(l_tag_obj($tag));
+      $table->cell($tag['value']);
+      // the remove checkbox
+      if (plc_is_admin()) $table->cell ($form->checkbox_html('site_tag_ids[]',$tag['site_tag_id']));
+      $table->row_end();
+    }
+  
+  if ($is_site_pi || $is_site_admin) {
+    $table->tfoot_start();
+
+    // remove tag 
+    $table->row_start();
+    $table->cell($form->submit_html("delete-site-tags","Remove Tags"),
+                // use the whole columns and right adjust
+                array('hfill'=>true,'align'=>'right'));
+    $table->row_end();
+
+    // set tag area
+    $table->row_start();
+    // get list of tag names in the site/* category    
+    $all_tags= $api->GetTagTypes( array ("category"=>"site*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
+    // xxx cannot use onchange=submit() - would need to somehow pass action name 
+    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,array('label'=>"Choose")));
+    $table->cell($form->text_html("value","",array('width'=>8)));
+    $table->cell($form->submit_html("set-tag-on-site","Set Tag"),array('columns'=>2,'align'=>'left'));
+    $table->row_end();
+  }
+  
+  $table->end();
+  $toggle->end();
+  $form->end();
+
   //////////////////// Addresses
   $toggle=new PlekitToggle ('addresses',"Addresses",
                            array('visible'=>get_arg('show_addresses')));