Commit 05d06d35 authored by Leigh Stoller's avatar Leigh Stoller

Another checkpoint. Mostly this one hooks up the zoom controls on the

show template page, to some primitive zoom code in the backend. It will
do for now.
parent b152599e
......@@ -519,6 +519,7 @@ CREATE TABLE experiment_stats (
CREATE TABLE experiment_template_graphs (
parent_guid varchar(16) NOT NULL default '',
scale float(10,3) NOT NULL default '1.0',
image mediumblob,
imap mediumtext,
PRIMARY KEY (parent_guid)
......@@ -613,6 +614,7 @@ CREATE TABLE experiment_template_metadata_items (
parent_guid varchar(16) default NULL,
parent_vers smallint(5) unsigned NOT NULL default '0',
template_guid varchar(16) NOT NULL default '',
uid varchar(8) NOT NULL default '',
name varchar(64) NOT NULL default '',
value tinytext,
created datetime default NULL,
......
......@@ -3338,3 +3338,6 @@ last_net_act,last_cpu_act,last_ext_act);
the last statement made an incompatible change to the "log" table]
unlock tables;
4.57: Changes to templates.sql. Skip this revision for now.
......@@ -59,6 +59,8 @@ CREATE TABLE experiment_templates (
CREATE TABLE experiment_template_graphs (
-- Backlink to the template the input belongs to.
parent_guid varchar(16) NOT NULL default '',
-- Current scale factor.
scale float(10,3) NOT NULL default '1.0',
image mediumblob,
imap mediumtext,
PRIMARY KEY (parent_guid)
......@@ -185,6 +187,8 @@ CREATE TABLE experiment_template_metadata_items (
-- Record the template GUID this metadata associated with. This is for
-- permission checks and for deletion.
template_guid varchar(16) NOT NULL default '',
-- Creator of this record
uid varchar(8) NOT NULL default '',
-- Key/Value pairs.
name varchar(64) NOT NULL default '',
value tinytext,
......
......@@ -663,9 +663,9 @@ sub DeleteTemplateInputFiles($$)
#
# Add a metadata record. This is used for new templates.
#
sub NewTemplateMetadata($$$$)
sub NewTemplateMetadata($$$$$)
{
my ($template_guid, $template_version, $name, $value) = @_;
my ($template_guid, $template_version, $name, $value, $creator) = @_;
my $guid;
my $version = 1;
......@@ -677,7 +677,7 @@ sub NewTemplateMetadata($$$$)
my $query_result =
DBQueryWarn("insert into experiment_template_metadata_items set ".
" guid='$guid', vers='$version', ".
" guid='$guid', vers='$version', uid='$creator', ".
" template_guid='$template_guid', ".
" name=$name, value=$value, created=now()");
return -1
......@@ -749,9 +749,9 @@ sub DeleteTemplateMetadata($$)
# Copy exiting template metadata to a child. This is likely to change
# since we probably want to share at some point.
#
sub CopyTemplateMetadata($$$)
sub CopyTemplateMetadata($$$$)
{
my ($from_guid, $from_version, $to_version) = @_;
my ($from_guid, $from_version, $to_version, $copier) = @_;
#
# Copy the toplevel items.
......@@ -785,7 +785,7 @@ sub CopyTemplateMetadata($$$)
or return -1;
DBQueryWarn("insert into experiment_template_metadata_items set ".
" guid='$guid', vers='$version', ".
" guid='$guid', vers='$version', uid='$copier', ".
" template_guid='$from_guid', ".
" name=$name, value=$value, created=now()")
or return -1;
......
......@@ -663,9 +663,9 @@ sub DeleteTemplateInputFiles($$)
#
# Add a metadata record. This is used for new templates.
#
sub NewTemplateMetadata($$$$)
sub NewTemplateMetadata($$$$$)
{
my ($template_guid, $template_version, $name, $value) = @_;
my ($template_guid, $template_version, $name, $value, $creator) = @_;
my $guid;
my $version = 1;
......@@ -677,7 +677,7 @@ sub NewTemplateMetadata($$$$)
my $query_result =
DBQueryWarn("insert into experiment_template_metadata_items set ".
" guid='$guid', vers='$version', ".
" guid='$guid', vers='$version', uid='$creator', ".
" template_guid='$template_guid', ".
" name=$name, value=$value, created=now()");
return -1
......@@ -749,9 +749,9 @@ sub DeleteTemplateMetadata($$)
# Copy exiting template metadata to a child. This is likely to change
# since we probably want to share at some point.
#
sub CopyTemplateMetadata($$$)
sub CopyTemplateMetadata($$$$)
{
my ($from_guid, $from_version, $to_version) = @_;
my ($from_guid, $from_version, $to_version, $copier) = @_;
#
# Copy the toplevel items.
......@@ -785,7 +785,7 @@ sub CopyTemplateMetadata($$$)
or return -1;
DBQueryWarn("insert into experiment_template_metadata_items set ".
" guid='$guid', vers='$version', ".
" guid='$guid', vers='$version', uid='$copier', ".
" template_guid='$from_guid', ".
" name=$name, value=$value, created=now()")
or return -1;
......
......@@ -268,20 +268,21 @@ $justexit = 0;
# The description is versioned metadata the user can modify.
#
libTemplates::NewTemplateMetadata($guid, $version,
"description", $description) == 0
"description", $description, $dbuid) == 0
or fatal(-1, "Failed to insert metadata record for description");
#
# The TID is versioned metadata the user can modify.
#
libTemplates::NewTemplateMetadata($guid, $version, "TID", $tid) == 0
libTemplates::NewTemplateMetadata($guid, $version, "TID", $tid, $dbuid) == 0
or fatal(-1, "Failed to insert metadata record for description");
#
# Copy the rest of the metadata.
#
if ($modify) {
libTemplates::CopyTemplateMetadata($parent_guid, $parent_vers, $version)
libTemplates::CopyTemplateMetadata($parent_guid,
$parent_vers, $version, $dbuid)
== 0 or fatal(-1, "Failed to copy metadata records");
}
......
......@@ -21,11 +21,13 @@ sub usage()
"<guid> - GUID to graph\n");
exit(-1);
}
my $optlist = "vap:";
my $optlist = "vap:z:";
my %options = ();
my $verbose = 0;
my $prefix = "/tmp/dot$$";
my $showall = 0;
my $scale = 1.0;
my $zoom;
my $guid;
#
......@@ -138,14 +140,58 @@ if ($hidden{$rootnode}) {
exit(0);
}
# Defaults;
my $size = 8;
my $fontsize = 10;
my $bwidth = 0.75;
my $bheight = 0.25;
my $arrowsize= 0.7;
my $nodesep = 0.25;
my $ranksep = 0.50;
#
# Grab the current scale so we know what to do.
#
$query_result =
DBQueryFatal("select scale from experiment_template_graphs ".
"where parent_guid='$guid'");
exit(-1)
if (!$query_result->num_rows);
my ($curscale) = $query_result->fetchrow_array();
#
# Change scale if zooming and then recalc the defaults.
#
if (defined($zoom)) {
if ($zoom eq "in") {
$scale = $curscale * 1.25;
}
else {
$scale = $curscale / 1.25;
}
}
else {
$scale = $curscale;
}
$bwidth = $bwidth * $scale;
$bheight = $bheight * $scale;
$arrowsize = $arrowsize * $scale;
$nodesep = $nodesep * $scale;
$ranksep = $ranksep * $scale;
open(DOT, "> $dotfile") or
tbdie("Could not open $dotfile!");
print DOT "digraph TemplateGraph {\n";
print DOT " size=\"8,8\"\n";
print DOT " rankdir=\"LR\"\n";
print DOT " nodesep=$nodesep\n";
print DOT " ranksep=$ranksep\n";
print DOT " fontname=\"Courier\"\n";
print DOT " node [shape=rectangle,fontsize=10,height=0.3,width=0.8,fixedsize=true]\n";
print DOT " edge [fontsize=8]\n";
print DOT " node [shape=rectangle,fontsize=$fontsize,".
"height=$bheight,width=$bwidth,fixedsize=true]\n";
print DOT " edge [arrowsize=$arrowsize]\n";
print DOT " subgraph guid {\n";
print DOT " label = \"$guid\";\n";
......@@ -179,10 +225,24 @@ while (@kids) {
$table .= "</table>";
my $tooltip = "return escape(\'$table\')";
#
# Figure out a point size that makes the label fit inside. We do not
# want to go too big of course.
#
# Target labelwidth is 80% of the box, converted to points.
my $labelwidth = ($bwidth * 0.80) / 0.0139;
# And the fontsize ... I made this up.
my $fontsize = int((($labelwidth / length($tid)) * 1.8) + 0.5);
# But we do not want the font arbitrarily large.
$fontsize = 10
if ($fontsize > 10);
if (!exists($versions{"$vers"})) {
print DOT " $vers [label=\"$tid\",href=\"$url\",".
"tooltip=\"$tooltip\"];\n";
print DOT " $vers [fontsize=$fontsize,".
"label=\"$tid\",href=\"$url\",tooltip=\"$tooltip\"];\n";
$versions{"$vers"} = $vers;
}
......@@ -215,17 +275,18 @@ my $imapdata = `cat $imapfile`;
#
$imapdata =~ s/title=/onmouseover=/g;
print "$imapdata\n";
#print "$imapdata\n";
$gifdata = DBQuoteSpecial($gifdata);
$imapdata = DBQuoteSpecial($imapdata);
DBQueryFatal("replace into experiment_template_graphs set ".
" parent_guid='$guid', ".
" scale='$scale', ".
" image=$gifdata, ".
" imap=$imapdata");
#unlink($dotfile, $gifdata, $imapdata);
#unlink($dotfile, $giffile, $imapfile);
exit(0);
......@@ -267,4 +328,11 @@ sub ParseArgs()
if (defined($options{"a"})) {
$showall = 1;
}
if (defined($options{"z"})) {
$zoom = $options{"z"};
if ($zoom ne "in" && $zoom ne "out") {
die("Improper zoom request: $zoom!\n");
}
}
}
......@@ -12,7 +12,7 @@ var WindowTimer;
var StateChangeTimer;
// Number of minutes (in ms of course) before we kill the popup.
var POPUPTIME = (2 * 60000);
var POPUPTIME = (5 * 60000);
// Experiment being watched.
var pid;
......
......@@ -965,7 +965,7 @@ function SHOWTEMPLATEGRAPH($guid)
echo "<center>";
# echo "<h3>Template Graph</h3>\n";
echo "<div id=fee style='display: block; overflow: hidden; position: relative; z-index:1010; height: 400px; width: 600px; border: 2px solid black;'>\n";
echo "<div id=fee style='display: block; overflow: hidden; position: relative; z-index:1010; height: 400px; width: 700px; border: 2px solid black;'>\n";
echo "<div id=\"D$guid\" style='position:relative;'>\n";
echo $imap;
......
......@@ -24,27 +24,76 @@ if (!TBvalid_guid($guid)) {
PAGEARGERROR("Invalid characters in GUID!");
}
#
# Get the data from the DB.
#
$query_result =
DBQueryFatal("select image from experiment_template_graphs ".
"where parent_guid='$guid'");
if (isset($zoom)) {
if ($zoom != "in" && $zoom != "out") {
PAGEARGERROR("Invalid characters in zoom factor!");
}
}
else {
unset($zoom);
}
function SPITERROR()
{
header("Content-type: image/gif");
readfile("coming-soon-thumb.gif");
}
function SPITGRAPH($guid)
{
#
# Get the data from the DB.
#
$query_result =
DBQueryWarn("select image from experiment_template_graphs ".
"where parent_guid='$guid'");
if ($query_result && mysql_num_rows($query_result)) {
if (!$query_result || !mysql_num_rows($query_result)) {
# No Data. Spit back a stub image.
SPITERROR();
return;
}
$row = mysql_fetch_array($query_result);
$data = $row['image'];
if (strlen($data)) {
if ($data != "") {
header("Content-type: image/png");
echo "$data";
return;
}
else {
SPITERROR();
}
}
# No Data. Spit back a stub image.
header("Content-type: image/gif");
readfile("coming-soon-thumb.gif");
#
# If the request did not specify a zoom, return whatever we have.
#
if (!isset($zoom)) {
SPITGRAPH($guid);
return;
}
#
# Otherwise regen the picture, zooming in or out.
#
$optarg = "-z " . ($zoom == "in" ? "in" : "out");
if (! TBGuid2PidGid($guid, $pid, $gid)) {
TBERROR("Could not get template pid,gid for template $guid", 0);
SPITERROR();
}
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
$retval = SUEXEC($uid, "$pid,$unix_gid", "webtemplate_graph $optarg $guid",
SUEXEC_ACTION_CONTINUE);
if ($retval) {
SPITERROR();
}
else {
SPITGRAPH();
}
#
# No Footer!
......
......@@ -405,7 +405,7 @@ else {
#
DBQueryFatal("insert into experiment_template_metadata_items set ".
" guid='$metadata_guid',vers='$metadata_newvers', ".
" template_guid='$template_guid', ".
" template_guid='$template_guid', uid='$uid', ".
$extrastuff .
" name='$name', value='$value', created=now()");
......
......@@ -158,18 +158,27 @@ function SearchTemplates($guid, $terms) {
CheckArguments($guid, $version);
if (isset($action)) {
if ($action == "hide") {
DBQueryFatal("UPDATE experiment_templates SET hidden=1 ".
"WHERE guid='$guid' and vers='$version'");
if (isset($action) || isset($zoomin) || isset($zoomout)) {
if (isset($action)) {
if ($action == "hide") {
DBQueryFatal("UPDATE experiment_templates SET hidden=1 ".
"WHERE guid='$guid' and vers='$version'");
}
else if ($action == "show") {
DBQueryFatal("UPDATE experiment_templates SET hidden=0 ".
"WHERE guid='$guid' and vers='$version'");
}
else if ($action == "showall") {
DBQueryFatal("UPDATE experiment_templates SET hidden=0 ".
"WHERE guid='$guid'");
}
}
else if ($action == "show") {
DBQueryFatal("UPDATE experiment_templates SET hidden=0 ".
"WHERE guid='$guid' and vers='$version'");
$optarg = "";
if (isset($zoomin) && $zoomin == "zoomin") {
$optarg = "-z in";
}
else if ($action == "showall") {
DBQueryFatal("UPDATE experiment_templates SET hidden=0 ".
"WHERE guid='$guid'");
elseif (isset($zoomout) && $zoomout == "zoomout") {
$optarg = "-z out";
}
if (! TBGuid2PidGid($guid, $pid, $gid)) {
......@@ -178,7 +187,7 @@ if (isset($action)) {
# Need to update the template graph.
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
SUEXEC($uid, "$pid,$unix_gid", "webtemplate_graph $guid",
SUEXEC($uid, "$pid,$unix_gid", "webtemplate_graph $optarg $guid",
SUEXEC_ACTION_DIE);
}
......@@ -249,24 +258,16 @@ SHOWTEMPLATEGRAPH($guid);
#
# Define the zoom buttons. This should go elsewhere.
#
echo "<script type=text/javascript>
function ZoomOut() {
}
function ZoomIn() {
}
function ShowAll() {
open('template_show.php?guid=$guid&version=$version&action=showall',
'_self');
}
</script>\n";
echo "<center>\n";
echo "<button name=showall type=button onClick='ShowAll();'>";
echo "<form action='template_show.php?guid=$guid&version=$version'
method=post>\n";
echo "<button name=action type=submit value=showall>";
echo " Show All Templates</button></a>&nbsp &nbsp ";
echo "<button name=zoomout type=button onClick='ZoomOut();'>";
echo "<button name=zoomout type=submit value=zoomout>";
echo " Zoom Out</button>\n";
echo "<button name=zoomin type=button onClick='ZoomIn();'>";
echo "<button name=zoomin type=submit value=zoomin>";
echo "Zoom In</button>\n";
echo "</form>\n";
echo "</center>\n";
SUBPAGEEND();
......
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