forked from lix-project/hydra
Fix jobset input handling in the API
Signed-off-by: Shea Levy <shea@shealevy.com>
This commit is contained in:
parent
04d8adaad3
commit
ec6568f9b7
|
@ -218,13 +218,11 @@ sub updateJobset {
|
||||||
# Set the inputs of this jobset.
|
# Set the inputs of this jobset.
|
||||||
$jobset->jobsetinputs->delete;
|
$jobset->jobsetinputs->delete;
|
||||||
|
|
||||||
foreach my $param (keys %{$c->stash->{params}}) {
|
foreach my $name (keys %{$c->stash->{params}->{inputs}}) {
|
||||||
next unless $param =~ /^input-(\w+)-name$/;
|
my $inputData = $c->stash->{params}->{inputs}->{$name};
|
||||||
my $baseName = $1;
|
my $type = $inputData->{type};
|
||||||
next if $baseName eq "template";
|
my $values = $inputData->{values};
|
||||||
my $name = $c->stash->{params}->{$param};
|
my $emailresponsible = defined $inputData->{emailresponsible} ? 1 : 0;
|
||||||
my $type = $c->stash->{params}->{"input-$baseName-type"};
|
|
||||||
my $values = $c->stash->{params}->{"input-$baseName-values"};
|
|
||||||
|
|
||||||
error($c, "Invalid input name ‘$name’.") unless $name =~ /^[[:alpha:]][\w-]*$/;
|
error($c, "Invalid input name ‘$name’.") unless $name =~ /^[[:alpha:]][\w-]*$/;
|
||||||
error($c, "Invalid input type ‘$type’.") unless defined $c->stash->{inputTypes}->{$type};
|
error($c, "Invalid input type ‘$type’.") unless defined $c->stash->{inputTypes}->{$type};
|
||||||
|
@ -232,7 +230,7 @@ sub updateJobset {
|
||||||
my $input = $jobset->jobsetinputs->create({
|
my $input = $jobset->jobsetinputs->create({
|
||||||
name => $name,
|
name => $name,
|
||||||
type => $type,
|
type => $type,
|
||||||
emailresponsible => defined $c->stash->{params}->{"input-$baseName-emailresponsible"} ? 1 : 0
|
emailresponsible => $emailresponsible
|
||||||
});
|
});
|
||||||
|
|
||||||
# Set the values for this input.
|
# Set the values for this input.
|
||||||
|
|
|
@ -178,13 +178,41 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#submit-jobset").click(function() {
|
$("#submit-jobset").click(function() {
|
||||||
|
var formElements = $(this).parents("form").serializeArray();
|
||||||
|
var data = { 'inputs': {} };
|
||||||
|
var inputs = {};
|
||||||
|
for (var i = 0; i < formElements.length; i++) {
|
||||||
|
var elem = formElements[i];
|
||||||
|
var match = elem.name.match(/^input-(\w+)-(\w+)$/);
|
||||||
|
if (match === null) {
|
||||||
|
data[elem.name] = elem.value;
|
||||||
|
} else {
|
||||||
|
var baseName = match[1];
|
||||||
|
var param = match[2];
|
||||||
|
|
||||||
|
if (baseName === "template") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(baseName in inputs)) {
|
||||||
|
inputs[baseName] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param === "name") {
|
||||||
|
data.inputs[elem.value] = inputs[baseName];
|
||||||
|
} else {
|
||||||
|
inputs[baseName][param] = elem.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
redirectJSON({
|
redirectJSON({
|
||||||
[% IF create || clone %]
|
[% IF create || clone %]
|
||||||
url: "[% c.uri_for('/jobset' project.name '.new') %]",
|
url: "[% c.uri_for('/jobset' project.name '.new') %]",
|
||||||
[% ELSE %]
|
[% ELSE %]
|
||||||
url: "[% c.uri_for('/jobset' project.name jobset.name) %]",
|
url: "[% c.uri_for('/jobset' project.name jobset.name) %]",
|
||||||
[% END %]
|
[% END %]
|
||||||
data: $(this).parents("form").serialize(),
|
data: JSON.stringify(data),
|
||||||
|
contentType: 'application/json',
|
||||||
type: 'PUT'
|
type: 'PUT'
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue