Commit 9c5bb2c4 authored by Leigh Stoller's avatar Leigh Stoller

Instance and Run descriptions are now modifiable metadata items.

parent d60a5736
......@@ -674,7 +674,7 @@ sub NewMetadata($$$$;$)
# Current set of allowed types;
my @okay_types = ("tid", "template_description", "parameter_description",
"annotation");
"annotation", "instance_description", "run_description");
if (defined($type)) {
if (! grep {$_ eq $type} @okay_types) {
......@@ -712,15 +712,32 @@ sub NewMetadata($$$$;$)
# Some metadata is special ...
if (defined($type)) {
if ($type eq "parameter_description") {
$query_result =
DBQueryWarn("update experiment_template_parameters set ".
" metadata_guid='$guid', ".
" metadata_vers='$version' ".
"where parent_guid='$template_guid' and ".
" parent_vers='$template_vers' and ".
" name=$safename");
return -1
if (!$query_result);
DBQueryWarn("update experiment_template_parameters set ".
" metadata_guid='$guid', ".
" metadata_vers='$version' ".
"where parent_guid='$template_guid' and ".
" parent_vers='$template_vers' and ".
" name=$safename")
or return -1;
}
elsif ($type eq "instance_description" &&
$name =~ /^__instance_description_(\d*)$/) {
my $exptidx = $1;
DBQueryWarn("update experiment_template_instances set ".
" description=$safevalue ".
"where exptidx='$exptidx'")
or return -1;
}
elsif ($type eq "run_description" &&
$name =~ /^__run_description_(\d*)_(\d*)$/) {
my $exptidx = $1;
my $runidx = $2;
DBQueryWarn("update experiment_runs set ".
" description=$safevalue ".
"where exptidx='$exptidx' and idx='$runidx'")
or return -1;
}
}
......@@ -795,8 +812,8 @@ sub ModifyMetadata($$$$)
return -1
if ($already_exists <= 0);
$name = DBQuoteSpecial($name);
$value = DBQuoteSpecial(encode_entities($value));
my $safename = DBQuoteSpecial($name);
my $safevalue = DBQuoteSpecial(encode_entities($value));
DBQueryWarn("lock tables experiment_template_metadata_items write")
or return -1;
......@@ -821,7 +838,7 @@ sub ModifyMetadata($$$$)
" uid='$creator_uid', uid_idx='$creator_dbid', ".
" parent_guid='$parent_guid',".
" parent_vers='$parent_vers'," .
" name=$name, value=$value, created=now()")) {
" name=$safename, value=$safevalue, created=now()")) {
DBQueryWarn("unlock tables");
return -1;
}
......@@ -841,7 +858,7 @@ sub ModifyMetadata($$$$)
#
if (defined($metadata_type)) {
if ($metadata_type eq "tid") {
DBQueryWarn("update experiment_templates set tid=$value ".
DBQueryWarn("update experiment_templates set tid=$safevalue ".
"where guid='$template_guid' and ".
" vers='$template_vers'")
or return -1;
......@@ -851,7 +868,8 @@ sub ModifyMetadata($$$$)
Template::mysystem("$makegraph $template_guid");
}
elsif ($metadata_type eq "template_description") {
DBQueryWarn("update experiment_templates set description=$value ".
DBQueryWarn("update experiment_templates set ".
" description=$safevalue ".
"where guid='$template_guid' and ".
" vers='$template_vers'")
or return -1;
......@@ -864,8 +882,27 @@ sub ModifyMetadata($$$$)
" metadata_vers='$metadata_vers' ".
"where parent_guid='$template_guid' and ".
" parent_vers='$template_vers' and ".
" name=$name")
or return -1
" name=$safename")
or return -1;
}
elsif ($metadata_type eq "instance_description" &&
$name =~ /^__instance_description_(\d*)$/) {
my $exptidx = $1;
DBQueryWarn("update experiment_template_instances set ".
" description=$safevalue ".
"where exptidx='$exptidx'")
or return -1;
}
elsif ($metadata_type eq "run_description" &&
$name =~ /^__run_description_(\d*)_(\d*)$/) {
my $exptidx = $1;
my $runidx = $2;
DBQueryWarn("update experiment_runs set ".
" description=$safevalue ".
"where exptidx='$exptidx' and idx='$runidx'")
or return -1;
}
}
return 0;
......@@ -1260,7 +1297,7 @@ sub MetadataList($$)
#
# Create a new Instance record, using the package below.
#
sub NewInstance($$$)
sub NewInstance($$$;$)
{
my ($self, $eid, $creator, $description) = @_;
......@@ -1276,10 +1313,21 @@ sub NewInstance($$$)
$args{'eid'} = $eid;
$args{'uid'} = $creator->uid();
$args{'uid_idx'} = $creator->uid_idx();
$args{'description'} = $description
if (defined($description));
return Template::Instance->Create(\%args);
my $newinstance = Template::Instance->Create(\%args);
return undef
if (!defined($newinstance));
#
# The description is versioned metadata the user can modify.
#
if (defined($description)) {
my $exptidx = $newinstance->exptidx();
$self->NewMetadata("__instance_description_${exptidx}", $description,
$creator, "instance_description");
}
return $newinstance;
}
#
......@@ -1763,26 +1811,13 @@ sub LookupByExptidx($$)
sub Create($$)
{
my ($class, $argref) = @_;
my $description;
return undef
if (ref($class));
# must treat specially.
if (exists($argref->{'description'})) {
$description = DBQuoteSpecial($argref->{'description'});
delete($argref->{'description'});
}
my $query = "insert into experiment_template_instances set ".
join(",", map("$_='" . $argref->{$_} . "'", keys(%{$argref})));
if (defined($description)) {
$query .= ", "
if (defined($argref) && scalar(keys%{$argref}));
$query .= "description=$description";
}
my $query_result = DBQueryWarn($query);
return undef
if (! $query_result);
......@@ -2204,9 +2239,9 @@ sub DeleteBindings($)
#
# Run records are also integral to Template Instances.
#
sub NewRun($$;$)
sub NewRun($$$;$)
{
my ($self, $runid, $description) = @_;
my ($self, $runid, $this_user, $description) = @_;
# Must be a real reference.
return undef
......@@ -2227,6 +2262,16 @@ sub NewRun($$;$)
$run->Delete();
return undef;
}
#
# The description is versioned metadata the user can modify.
#
if (defined($description) && $description ne "") {
$self->template()->NewMetadata("__run_description_${idx}_${runidx}",
$description,
$this_user, "run_description");
}
Refresh($self);
return $run;
}
......@@ -3344,24 +3389,18 @@ sub Stringify($)
#
# Create a new run object.
#
sub Create($$$;$)
sub Create($$$$)
{
my ($class, $instance, $runid, $description) = @_;
return undef
if (ref($class));
my $exptidx = $instance->exptidx();
my $dclause = "";
if (defined($description) && $description ne "") {
$description = DBQuoteSpecial($description);
$dclause = "description=$description , ";
}
my $exptidx = $instance->exptidx();
my $query_result =
DBQueryWarn("insert into experiment_runs set ".
" $dclause exptidx='$exptidx', runid='$runid' ");
" exptidx='$exptidx', runid='$runid' ");
return undef
if (! $query_result);
......
......@@ -381,7 +381,7 @@ if ($?) {
#
# All instances currently start with a default run.
#
$run = $instance->NewRun($eid, $instance->description());
$run = $instance->NewRun($eid, $this_user, $instance->description());
if (!defined($run)) {
fatal(-1, "Could not create new experiment run for $instance!");
}
......
......@@ -1079,6 +1079,10 @@ class TemplateInstance
return (is_null($this->instance) ? -1 :
$this->instance['pause_time']);
}
function description() {
return (is_null($this->instance) ? -1 :
$this->instance['description']);
}
function template() {
return (is_null($this->instance) ? -1 : $this->template);
}
......@@ -1118,8 +1122,14 @@ class TemplateInstance
$uid = $this->uid();
$start = $this->start_time();
$stop = $this->stop_time();
$template= $this->template();
$pcount = $template->ParameterCount();
$description = $this->description();
$template = $this->template();
$pcount = $template->ParameterCount();
# Instance descriptions are metatdata that can be changed.
# But use a naming convention.
$desc_metaname = "__instance_description_$exptidx";
$desc_metadata = $template->LookupMetadataByName($desc_metaname);
if (! ($user = User::Lookup($uid))) {
TBERROR("Could not lookup object for user $uid", 1);
......@@ -1149,6 +1159,37 @@ class TemplateInstance
MakeLink("template",
"guid=$guid&version=$vers", "$guid/$vers"));
ShowItem("ID", $exptidx);
if ($description && $description != "") {
$onmouseover = MakeMouseOver($description);
if (strlen($description) > 40) {
$description = substr($description, 0, 40) . " <b>... </b>";
}
}
else {
$onmouseover = "";
$description = "Click to Add";
}
# If no metadata, assume its for an instance prior to modifiable
# instance descriptions.
if ($desc_metadata) {
$desc_anchor =
MakeAnchor(CreateURL("template_metadata",
$template, $desc_metadata) .
"&action=modify",
$description, $onmouseover);
}
else {
$desc_anchor =
MakeAnchor(CreateURL("template_metadata", $template) .
"&action=add".
"&metadata_type=instance_description".
"&formfields[name]=${desc_metaname}",
$description, $onmouseover);
}
ShowItem("Description", $desc_anchor);
if ($this->experiment) {
ShowItem("Experiment", MakeAnchor($showexp_url, $this->eid()));
}
......@@ -1578,6 +1619,7 @@ class TemplateInstance
$exptidx = $this->exptidx();
$guid = $this->guid();
$vers = $this->vers();
$template= $this->template();
$query_result =
DBQueryFatal("select r.* from experiment_runs as r ".
......@@ -1596,6 +1638,11 @@ class TemplateInstance
$end_tag = $row['ending_archive_tag'];
$description = $row['description'];
# Run descriptions are metatdata that can be changed.
# But use a naming convention.
$desc_metaname = "__run_description_${exptidx}_${runidx}";
$desc_metadata = $template->LookupMetadataByName($desc_metaname);
if (!isset($stop))
$stop = "&nbsp";
......@@ -1617,26 +1664,41 @@ class TemplateInstance
ShowItem("Instance",
MakeLink("instance", "instance=$exptidx", "$exptidx"));
ShowItem("ID", $runidx);
if ($description && $description != "") {
$onmouseover = MakeMouseOver($description);
if (strlen($description) > 40) {
$description = substr($description, 0, 40) . " <b>... </b>";
}
}
else {
$onmouseover = "";
$description = "Click to Add";
}
# If no metadata, assume its for an instance prior to modifiable
# instance descriptions.
if ($desc_metadata) {
$desc_anchor =
MakeAnchor(CreateURL("template_metadata",
$template, $desc_metadata) .
"&action=modify",
$description, $onmouseover);
}
else {
$desc_anchor =
MakeAnchor(CreateURL("template_metadata", $template) .
"&action=add".
"&metadata_type=run_description".
"&formfields[name]=${desc_metaname}",
$description, $onmouseover);
}
ShowItem("Description", $desc_anchor);
ShowItem("Started", $start);
ShowItem("Stopped", $stop);
ShowItem("Start Tag", $start_tag);
ShowItem("End Tag", $end_tag);
if (isset($description) && $description != "") {
echo "<tr>
<td align=center colspan=2>
Description
</td>
</tr>
<tr>
<td colspan=2 align=center class=left>
<textarea readonly
rows=5 cols=50>" .
ereg_replace("\r", "", $description) .
"</textarea>
</td>
</tr>\n";
}
echo "</table>\n";
echo "</td>\n";
......@@ -2273,6 +2335,16 @@ function TBvalid_template_metadata_type($token) {
"metadata_type",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR);
}
function TBvalid_template_instance_description($token) {
return TBcheck_dbslot($token, "experiment_template_instances",
"description",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR);
}
function TBvalid_experiment_run_description($token) {
return TBcheck_dbslot($token, "experiment_runs",
"description",
TBDB_CHECKDBSLOT_WARN|TBDB_CHECKDBSLOT_ERROR);
}
function MakeMouseOver($string)
{
......
......@@ -26,6 +26,7 @@ $optargs = OptionalPageArguments("template", PAGEARG_TEMPLATE,
"submit", PAGEARG_STRING,
"metadata", PAGEARG_METADATA,
"metadata_type", PAGEARG_STRING,
"referrer", PAGEARG_STRING,
"formfields", PAGEARG_ARRAY);
# Need these below.
......@@ -39,7 +40,7 @@ $unix_gid = $template->UnixGID();
#
function SPITFORM($action, $formfields, $errors)
{
global $template, $metadata;
global $template, $metadata, $referrer;
global $metadata_type;
$template_guid = $template->guid();
......@@ -94,6 +95,10 @@ function SPITFORM($action, $formfields, $errors)
echo "<form action='${url}&action=$action' method=post>\n";
echo "<table align=center border=1>\n";
if (isset($referrer) && $referrer != "") {
echo "<input type=hidden name=referrer value='$referrer'>";
}
#
# Template GUID and Version. These are read-only fields.
#
......@@ -253,7 +258,8 @@ if (!isset($submit)) {
else {
$defaults["name"] = "";
$defaults["value"] = "";
}
}
$referrer = $_SERVER['HTTP_REFERER'];
#
# Allow formfields that are already set to override defaults
......@@ -333,7 +339,7 @@ if ($action == "add") {
$errors["Metadata Name"] = "Name already in use";
}
if (isset($metadata_type)) {
$command_opts .= "-t $metadata_type ";
$command_opts .= "-t " . escapeshellarg($metadata_type) . " ";
}
$command_opts .= "-a add " . escapeshellarg($formfields["name"]);
}
......@@ -386,6 +392,16 @@ if (isset($metadata_type)) {
$errors["Description"] = TBFieldErrorString();
}
}
elseif ($metadata_type == "instance_description") {
if (!TBvalid_template_instance_description($formfields["value"])) {
$errors["Description"] = TBFieldErrorString();
}
}
elseif ($metadata_type == "run_description") {
if (!TBvalid_experiment_run_description($formfields["value"])) {
$errors["Description"] = TBFieldErrorString();
}
}
}
if (count($errors)) {
......@@ -444,5 +460,9 @@ if ($retval) {
return;
}
header("Location: ".
"template_show.php?guid=$template_guid&version=$template_vers");
if (isset($referrer)) {
header("Location: $referrer");
}
else {
header("Location: ". CreateURL("template_show", $template));
}
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