Commit c201620c authored by David Johnson's avatar David Johnson

Add geni-lib script parameter warnings/errors, groups, helpdocs.

(The bulk of the code is in the parameter form formatter/decorator JS
code; I only applied it to the wizard for now... but it's
straightforward to copy it into the old parameter code ;))

The portal can now render the parameter form in much more complex ways.
It supports a notion of advanced parameter groups, a panel containing
parameters that is closed by default but expandable; generic parameter
groups; per-parameter detailed helpdocs in an expandable subpanel (and
an expand-all-help link that will also expand all the parameter group
panels), and error messages and warnings.  A summary of both errors and
warnings is displayed at the top of the form, and specific error message
details are displayed near parameters.  The error message display is
flexible to generic user messages -- basically if the error is a proper
geni-lib portal error/warning, but not a parameter error/warning, it
will be displayed at the top of the parameter form (along with any
others).  If it's an "improper" one, we'll still do our best to display
it.  If you warn a user, you can provide a set of parameter values that
"fix" the warning, and the Portal UI will change the form values and
tell the user it did so.  You can't do this on error; the assumption is
the user has to fix the error.

Finally, the portal now tries to rungenilib in warnings-are-fatal mode
the first time parameter bind (to generate rspec) is attempted.  If they
go backwards to re-parameterize, warnings should be fatal again.  It's
too hard to figure out when we should stop warnings-fatal mode; we can't
block the user's progress if they really want to proceed in the face of
warnings.
parent 42ce02e4
......@@ -46,11 +46,12 @@ sub usage()
exit(-1);
}
my $optlist = "do:pb:";
my $optlist = "do:pb:W";
my $debug = 0;
my $getparams = 0;
my $paramfile;
my $ofile;
my $warningsfatal = 0;
#
# Configure variables
......@@ -111,6 +112,9 @@ if (defined($options{"d"})) {
if (defined($options{"p"})) {
$getparams = 1;
}
if (defined($options{"W"})) {
$warningsfatal = 1;
}
if (defined($options{"b"})) {
$paramfile = $options{"b"};
# Must taint check!
......@@ -187,6 +191,7 @@ system("touch $outfile") == 0 or
my $cmdargs = "$TB/libexec/rungenilib.proxy ";
$cmdargs .= " -u " . $this_user->uid();
$cmdargs .= ($getparams ? " -p " : "");
$cmdargs .= ($warningsfatal ? " -W " : "");
#
# We want to send over both files via STDIN, so combine them, and pass
......
......@@ -39,10 +39,11 @@ sub usage()
exit(-1);
}
my $optlist = "u:vpb:";
my $optlist = "u:vpb:W";
my $user;
my $getparams= 0;
my $paramsize;
my $warningsfatal = 0;
#
# Configure variables
......@@ -100,6 +101,9 @@ if (defined($options{"b"})) {
if (defined($options{"u"})) {
$user = $options{"u"};
}
if (defined($options{"W"})) {
$warningsfatal = 1;
}
#
# First option has to be the -u option, the user to run this script as.
......@@ -193,6 +197,9 @@ if ($getparams) {
elsif (defined($paramsize) && $paramsize) {
$ENV{'GENILIB_PORTAL_PARAMS_PATH'} = $pfile;
}
if ($warningsfatal) {
$ENV{'GENILIB_PORTAL_WARNINGS_ARE_FATAL'} = "1";
}
#
# Fork a child process to run the parser in.
......
This diff is collapsed.
......@@ -299,6 +299,12 @@ function Do_CheckScript()
SPITAJAX_ERROR(1, "Missing script");
return;
}
$warningsfatal = "";
if (isset($ajax_args["warningsfatal"]) && $ajax_args["warningsfatal"]) {
$warningsfatal = "-W";
}
$infname = tempnam("/tmp", "genilibin");
$outfname = tempnam("/tmp", "genilibout");
......@@ -312,7 +318,7 @@ function Do_CheckScript()
# Invoke the backend.
#
$retval = SUEXEC($this_uid, "nobody",
"webrungenilib -o $outfname $infname",
"webrungenilib $warningsfatal -o $outfname $infname",
SUEXEC_ACTION_IGNORE);
if ($retval != 0) {
......@@ -386,6 +392,12 @@ function Do_BindParameters()
SPITAJAX_RESPONSE(0);
return;
}
$warningsfatal = "";
if (isset($ajax_args["warningsfatal"]) && $ajax_args["warningsfatal"]) {
$warningsfatal = "-W";
}
$infname = tempnam("/tmp", "genilibin");
$parmfname = tempnam("/tmp", "genilibparm");
$outfname = tempnam("/tmp", "genilibout");
......@@ -405,7 +417,7 @@ function Do_BindParameters()
# Invoke the backend.
#
$retval = SUEXEC($this_uid, "nobody",
"webrungenilib -b $parmfname -o $outfname $infname",
"webrungenilib $warningsfatal -b $parmfname -o $outfname $infname",
SUEXEC_ACTION_CONTINUE);
if ($retval != 0) {
......
......@@ -506,18 +506,42 @@ class Profile
}
$fields = json_decode($json_data);
$defaults = array();
$form = "";
$formBasic = "";
$formAdvanced = "";
$formGroups = "";
while (list ($name, $val) = each ($fields)) {
$form = "";
$type = $val->type;
$prompt = $val->description;
$defval = $val->defaultValue;
$options = $val->legalValues;
$longhelp = $val->longDescription;
$advanced = $val->advanced;
$groupId = $val->groupId;
$groupName = $val->groupName;
$hasGroup = false;
$data_help_string = "";
$advanced_attr = "";
$defaults[$name] = $defval;
if (!isset($prompt) || !$prompt) {
$prompt = $name;
}
if (!isset($advanced)) {
$advanced = false;
}
# Let advanced-tagged params dominate groupId; we don't generate groupId yet anyway.
if ($advanced) {
$advanced_attr = " pp-param-group='advanced' pp-param-group-name='Advanced Parameters'";
}
else if (isset($groupId) && $groupId && isset($groupName) && $groupName) {
$advanced_attr = " pp-param-group='$groupId' pp-param-group-name='$groupName'";
$hasGroup = true;
}
if (isset($longhelp) && $longhelp) {
$data_help_string = "data-help='$longhelp'";
}
if ($type == "boolean") {
$form .=
......@@ -527,6 +551,7 @@ class Profile
" class='format-me' ".
" data-key='$name' ".
" data-label='$prompt' ".
" $data_help_string $advanced_attr".
" value='checked' ".
" type='checkbox'>";
if ($defval) {
......@@ -542,6 +567,7 @@ class Profile
" class='form-control format-me' ".
" data-key='$name' ".
" data-label='$prompt' ".
" $data_help_string $advanced_attr".
" placeholder='Please Select'> ";
foreach ($options as $option) {
if (gettype($option) == "array") {
......@@ -568,10 +594,24 @@ class Profile
"class='form-control format-me' ".
"data-key='$name' ".
"data-label='$prompt' ".
"$data_help_string $advanced_attr".
"type='text'>";
}
if ($advanced) {
$formAdvanced .= $form;
}
else if ($hasGroup) {
$formGroups .= $form;
}
else {
$formBasic .= $form;
}
}
return array($form, $defaults);
$finalForm = $formBasic . $formAdvanced . $formGroups;
return array($finalForm, $defaults);
}
}
?>
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