Commit cf8fb65c authored by Leigh Stoller's avatar Leigh Stoller

Add Instance and Run annotations, which for now are text boxes on the

show pages. The annotations are stored as specially named metadata
items.  All this will change, but this was a quick hack. The UI needs
work, and we probably want to support multiple annotations later, but
this will do for now.
parent 52ba37d0
......@@ -673,7 +673,8 @@ sub NewMetadata($$$$;$)
if (defined($type));
# Current set of allowed types;
my @okay_types = ("tid", "template_description", "parameter_description");
my @okay_types = ("tid", "template_description", "parameter_description",
"annotation");
if (defined($type)) {
if (! grep {$_ eq $type} @okay_types) {
......@@ -1120,9 +1121,11 @@ sub CopyMetadata($$$)
# XXX Some metadata is special ...
#
if (defined($type)) {
# XXX Skip the tid and template descriptions.
# XXX Skip the tid and template descriptions and annotations.
next
if ($type eq "tid" or $type eq "template_description");
if ($type eq "tid" ||
$type eq "template_description" ||
$type eq "annotation");
#
# XXX Skip parameters that were deleted or whose description
......
......@@ -8,7 +8,7 @@ include("defs.php3");
include_once("template_defs.php");
require("Sajax.php");
sajax_init();
sajax_export("GraphShow");
sajax_export("ModifyAnno");
#
# Only known and logged in users ...
......@@ -41,15 +41,12 @@ if (! $instance->ValidRun($runidx)) {
#
# For the Sajax Interface
#
function GraphShow($which, $arg0, $arg1)
function ModifyAnno($newtext)
{
global $template, $instance, $runidx;
global $this_user, $template, $instance, $runidx;
ob_start();
$instance->ShowGraphArea($which, $runidx, $arg0, $arg1);
$html = ob_get_contents();
ob_end_clean();
return $html;
$instance->SetRunAnnotation($this_user, $runidx, $newtext);
return 0;
}
#
......@@ -62,23 +59,14 @@ sajax_handle_client_request();
# Standard Testbed Header after argument checking.
#
PAGEHEADER("Experiment Run");
echo $instance->RunPageHeader($runidx);
echo "<br><br>\n";
$instance->ShowRun($runidx);
echo "<script type='text/javascript' language='javascript'>\n";
sajax_show_javascript();
echo "</script>\n";
#
# Throw up graph stuff.
#
if (0) {
echo "<center>\n";
echo "<br>";
$instance->ShowGraphArea("pps", $runidx);
echo "</center>\n";
}
echo $instance->RunPageHeader($runidx);
echo "<br><br>\n";
$instance->ShowRun($runidx);
#
# Standard Testbed Footer
......
......@@ -6,11 +6,9 @@
#
include("defs.php3");
include_once("template_defs.php");
if (0) {
require("Sajax.php");
sajax_init();
sajax_export("GraphShow");
}
sajax_export("ModifyAnno");
#
# Only known and logged in users ...
......@@ -38,47 +36,32 @@ if (! $template->AccessCheck($this_user, $TB_EXPT_READINFO)) {
#
# For the Sajax Interface
#
function GraphShow($which, $arg0, $arg1)
function ModifyAnno($newtext)
{
global $template, $instance;
global $this_user, $template, $instance;
ob_start();
$instance->ShowGraphArea($which, -1, $arg0, $arg1);
$html = ob_get_contents();
ob_end_clean();
return $html;
$instance->SetAnnotation($this_user, $newtext);
return 0;
}
#
# See if this request is to the above function. Does not return
# if it is. Otherwise return and continue on.
#
if (0) {
sajax_handle_client_request();
}
#
# Standard Testbed Header after argument checking.
#
PAGEHEADER("Template Instance");
echo $instance->PageHeader();
echo "<br><br>\n";
$instance->Show(1);
if (0) {
echo "<script type='text/javascript' language='javascript'>\n";
sajax_show_javascript();
echo "</script>\n";
#
# Throw up graph stuff.
#
echo "<center>\n";
echo "<br>";
$instance->ShowGraphArea("pps");
echo "</center>\n";
}
echo $instance->PageHeader();
echo "<br><br>\n";
$instance->Show(1, 1);
#
# Standard Testbed Footer
......
......@@ -679,8 +679,8 @@ class Template
echo "<center>";
echo "<div id=fee style='display: block; overflow: hidden; ".
"position: relative; z-index:1010; height: 400px; ".
"width: 700px; border: 2px solid black;'>\n";
"position: relative; z-index:1010; height: 200px; ".
"width: 575px; border: 2px solid black;'>\n";
echo "<div id=\"mygraphdiv\" style='position:relative;'>\n";
echo "<div id='CurrentTemplate' style='display: block; opacity: 1; ".
......@@ -1109,7 +1109,7 @@ class TemplateInstance
#
# Show an instance.
#
function Show($detailed) {
function Show($detailed, $withanno = 0) {
$exptidx = $this->exptidx();
$runidx = $this->runidx();
$guid = $this->guid();
......@@ -1168,6 +1168,10 @@ class TemplateInstance
echo "</table>\n";
}
if ($withanno) {
$this->ShowAnnotation();
}
if ($detailed) {
$this->ShowRunList(1);
}
......@@ -1423,6 +1427,132 @@ class TemplateInstance
echo "</table>\n";
}
#
# Get the annotation for an instance, or a link to create one.
#
function GetAnnotation() {
$exptidx = $this->exptidx();
$annoname = "__instance_annotation_${exptidx}";
$template = $this->template();
if (($metadata = $template->LookupMetadataByName($annoname))) {
return $metadata->value();
}
return null;
}
function GetRunAnnotation($runidx) {
$exptidx = $this->exptidx();
$annoname = "__experimentrun_annotation_${exptidx}_${runidx}";
$template = $this->template();
if (($metadata = $template->LookupMetadataByName($annoname))) {
return $metadata->value();
}
return null;
}
function SetAnnotation($this_user, $annotation) {
$exptidx = $this->exptidx();
$annoname = "__instance_annotation_${exptidx}";
$template = $this->template();
$uid = $this_user->uid();
$foo = rand();
$datafile = "/tmp/${uid}-${foo}.txt";
$guid = $template->guid();
$vers = $template->vers();
$action = ($this->GetAnnotation() ? "modify" : "add");
if (! ($fp = fopen($datafile, "w"))) {
TBERROR("Could not create temporary file $datafile", 1);
}
fwrite($fp, $annotation);
fclose($fp);
chmod($datafile, 0666);
SUEXEC($this_user->uid(), $template->pid(),
"webtemplate_metadata -a $action -f $datafile -t annotation ".
" $annoname $guid/$vers",
SUEXEC_ACTION_CONTINUE);
unlink($datafile);
return 0;
}
function SetRunAnnotation($this_user, $runidx, $annotation) {
$exptidx = $this->exptidx();
$annoname = "__experimentrun_annotation_${exptidx}_${runidx}";
$template = $this->template();
$uid = $this_user->uid();
$foo = rand();
$datafile = "/tmp/${uid}-${foo}.txt";
$guid = $template->guid();
$vers = $template->vers();
$action = ($this->GetRunAnnotation($runidx) ? "modify" : "add");
if (! ($fp = fopen($datafile, "w"))) {
TBERROR("Could not create temporary file $datafile", 1);
}
fwrite($fp, $annotation);
fclose($fp);
chmod($datafile, 0666);
SUEXEC($this_user->uid(), $template->pid(),
"webtemplate_metadata -a $action -f $datafile -t annotation ".
" $annoname $guid/$vers",
SUEXEC_ACTION_CONTINUE);
unlink($datafile);
return 0;
}
#
# Display annotation in text box with button to change.
#
function ShowAnnotation() {
$annotation = $this->GetAnnotation();
if (! $annotation) {
$annotation = "";
}
echo "<center>";
echo "<b>Annotation</b><br>\n";
echo "<form action='fee' method=post>\n";
echo "<textarea id='annotation' rows=5 cols=80>$annotation".
"</textarea></form>";
echo "<button name=submit type=button value=submit ".
"onclick=\"ModifyAnno();\">Submit Changes</button>\n";
echo "<center>";
echo "<script type='text/javascript' language='javascript'>
function ModifyAnno() {
textarea = getObjbyName('annotation');
x_ModifyAnno(textarea.value, ModifyAnno_cb);
}
function ModifyAnno_cb(val) {
}
</script>\n";
}
function ShowRunAnnotation($runidx) {
$annotation = $this->GetRunAnnotation($runidx);
if (! $annotation) {
$annotation = "";
}
echo "<center>";
echo "<b>Annotation</b><br>\n";
echo "<form action='fee' method=post>\n";
echo "<textarea id='annotation' rows=5 cols=80>$annotation".
"</textarea></form>";
echo "<button name=submit type=button value=submit ".
"onclick=\"ModifyAnno();\">Submit Changes</button>\n";
echo "<center>";
echo "<script type='text/javascript' language='javascript'>
function ModifyAnno() {
textarea = getObjbyName('annotation');
x_ModifyAnno(textarea.value, ModifyAnno_cb);
}
function ModifyAnno_cb(val) {
}
</script>\n";
}
#
# Check if a valid run.
#
......@@ -1542,6 +1672,8 @@ class TemplateInstance
echo "</tr>\n";
echo "</table>\n";
$this->ShowRunAnnotation($runidx);
$archive_url =
"cvsweb/cvsweb.php3/$exptidx/tags/runs/$runid/?instance=$exptidx".
"&embedded=1";
......
......@@ -34,6 +34,7 @@ $guid = $template->guid();
$vers = $template->vers();
$pid = $template->pid();
$eid = $template->eid();
$tid = $template->tid();
$exptidx = $experiment->idx();
$unix_gid = $experiment->UnixGID();
$this_url = CreateURL("template_show", $template);
......@@ -288,7 +289,7 @@ if (isset($action) && $action == "deletetemplate" &&
#
# Standard Testbed Header after argument checking.
#
PAGEHEADER("Template: $guid/$vers");
PAGEHEADER("Template $tid ($guid/$vers)");
SUBPAGESTART();
......@@ -344,12 +345,29 @@ if ($template->InstanceCount()) {
SUBMENUEND_2B();
# See below; for getting the tab correct at the first page load.
if (!isset($show)) {
$show = "vis";
}
if ($show == "vis") {
$li_current = "li_vis";
$init_show = Show("vis", 0, 0);
}
elseif ($show == "nsfile") {
$li_current = "li_nsfile";
$init_show = Show("nsfile", 0, 0);
}
elseif ($show == "graph") {
$li_current = "li_graph";
$init_show = Show("graph", 0, 0);
}
#
# The center area is a form that can show NS file, Template Graph, or Vis.
#
echo "<script type='text/javascript' src='template_sup.js'></script>\n";
echo "<script type='text/javascript' language='javascript'>
var li_current = 'li_vis';
var li_current = '$li_current';
function Show(which) {
li = getObjbyName(li_current);
li.style.backgroundColor = '#DDE';
......@@ -428,37 +446,27 @@ $bodyclosestring = "<script type='text/javascript'>SET_DHTML();</script>\n";
echo "<div width=\"100%\" align=center>\n";
echo "<ul id=\"topnavbar\">\n";
echo "<li>
<a href=\"#A\"
style=\"background-color:white\" ".
<a href=\"#A\" " .
($show == "vis" ? "style=\"background-color:white\"" : " ") .
"id=\"li_vis\" onclick=\"Show('vis');\">".
"Visualization</a></li>\n";
"Topology</a></li>\n";
echo "<li>
<a href=\"#B\"
id=\"li_nsfile\" onclick=\"Show('nsfile');\">".
"NS File</a></li>\n";
<a href=\"#B\" " .
($show == "nsfile" ? "style=\"background-color:white\"" : " ") .
"id=\"li_nsfile\" onclick=\"Show('nsfile');\">".
"NS File</a></li>\n";
echo "<li>
<a href=\"#C\"
id=\"li_graph\" onclick=\"Show('graph');\">".
"History</a></li>\n";
<a href=\"#C\" " .
($show == "graph" ? "style=\"background-color:white\"" : " ") .
"id=\"li_graph\" onclick=\"Show('graph');\">".
"History</a></li>\n";
echo "</ul>\n";
#
# Start out with ...
#
echo "<div align=center width=\"100%\" id=\"showexp_visarea\">\n";
if (!isset($show) || $show == "vis") {
echo Show("vis", 0, 0);
}
elseif ($show == "nsfile") {
echo Show("nsfile", 0, 0);
}
elseif ($show == "graph") {
echo Show("graph", 0, 0);
}
else {
echo Show("vis", 0, 0);
}
echo $init_show;
echo "</div>\n";
echo "</div>\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment