Remove the ability to add multiple jobset input alternatives

Now each jobset input has exactly one value. (Actually, adding
multiple values was already broken, so all this does is clean up the
UI...)
This commit is contained in:
Eelco Dolstra 2014-09-25 16:43:17 +02:00
parent c28e7ac692
commit 23a9fea26c
3 changed files with 25 additions and 44 deletions

View file

@ -244,25 +244,20 @@ sub updateJobset {
foreach my $name (keys %{$c->stash->{params}->{inputs}}) { foreach my $name (keys %{$c->stash->{params}->{inputs}}) {
my $inputData = $c->stash->{params}->{inputs}->{$name}; my $inputData = $c->stash->{params}->{inputs}->{$name};
my $type = $inputData->{type}; my $type = $inputData->{type};
my $values = $inputData->{values}; my $value = $inputData->{value};
my $emailresponsible = defined $inputData->{emailresponsible} ? 1 : 0; my $emailresponsible = defined $inputData->{emailresponsible} ? 1 : 0;
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};
my $input = $jobset->jobsetinputs->create({ my $input = $jobset->jobsetinputs->create(
name => $name, { name => $name,
type => $type, type => $type,
emailresponsible => $emailresponsible emailresponsible => $emailresponsible
}); });
# Set the values for this input. $value = checkInputValue($c, $name, $type, $value);
my @values = ref($values) eq 'ARRAY' ? @{$values} : ($values); $input->jobsetinputalts->create({altnr => 0, value => $value});
my $altnr = 0;
foreach my $value (@values) {
$value = checkInputValue($c, $name, $type, $value);
$input->jobsetinputalts->create({altnr => $altnr++, value => $value});
}
} }
} }

View file

@ -22,7 +22,7 @@ our @EXPORT = qw(
sendEmail sendEmail
paramToList paramToList
backToReferer backToReferer
$pathCompRE $relPathRE $relNameRE $projectNameRE $jobsetNameRE $jobNameRE $systemRE $userNameRE $pathCompRE $relPathRE $relNameRE $projectNameRE $jobsetNameRE $jobNameRE $systemRE $userNameRE $inputNameRE
@buildListColumns @buildListColumns
parseJobsetName parseJobsetName
showJobName showJobName
@ -235,6 +235,7 @@ Readonly our $jobsetNameRE => "(?:[A-Za-z_][A-Za-z0-9-_\.]*)";
Readonly our $jobNameRE => "(?:$attrNameRE(?:\\.$attrNameRE)*)"; Readonly our $jobNameRE => "(?:$attrNameRE(?:\\.$attrNameRE)*)";
Readonly our $systemRE => "(?:[a-z0-9_]+-[a-z0-9_]+)"; Readonly our $systemRE => "(?:[a-z0-9_]+-[a-z0-9_]+)";
Readonly our $userNameRE => "(?:[a-z][a-z0-9_\.]*)"; Readonly our $userNameRE => "(?:[a-z][a-z0-9_\.]*)";
Readonly our $inputNameRE => "(?:[A-Za-z_][A-Za-z0-9-_]*)";
sub parseJobsetName { sub parseJobsetName {

View file

@ -2,28 +2,25 @@
[% PROCESS common.tt %] [% PROCESS common.tt %]
[% USE format %] [% USE format %]
[% BLOCK renderJobsetInputAlt %]
<button type="button" class="btn btn-warning" onclick='$(this).parents(".inputalt").remove()'><i class="icon-trash icon-white"></i></button>
<input type="text" [% HTML.attributes(value => alt.value, name => name) %]/>
<br />
[% END %]
[% BLOCK renderJobsetInput %] [% BLOCK renderJobsetInput %]
<tr class="input [% extraClass %]" [% IF id %]id="[% id %]"[% END %]> <tr class="input [% extraClass %]" [% IF id %]id="[% id %]"[% END %]>
<td> <td>
<button type="button" class="btn btn-warning" onclick='$(this).parents(".input").remove()'><i class="icon-trash icon-white"></i></button> <button type="button" class="btn btn-warning" onclick='$(this).parents(".input").remove()'><i class="icon-trash icon-white"></i></button>
</td>
<td>
<input type="text" id="[% baseName %]-name" name="[% baseName %]-name" [% HTML.attributes(value => input.name) %]/> <input type="text" id="[% baseName %]-name" name="[% baseName %]-name" [% HTML.attributes(value => input.name) %]/>
</td> </td>
<td> <td>
[% INCLUDE renderSelection curValue=input.type param="$baseName-type" options=inputTypes %] [% INCLUDE renderSelection curValue=input.type param="$baseName-type" options=inputTypes %]
</td> </td>
<td class="inputalts" id="[% baseName %]"> <td id="[% baseName %]">
[% FOREACH alt IN input.search_related('jobsetinputalts', {}, { order_by => 'altnr' }) %] [% alt = input.search_related('jobsetinputalts', {altnr => 0}) %]
<span class="inputalt"> <input type="text" [% HTML.attributes(value => alt.value, id => "$baseName-value", name => "$baseName-value") %]/>
[% INCLUDE renderJobsetInputAlt alt=alt name="$baseName-values" %] [% IF input.jobsetinputalts_rs.count > 1 %]
</span> <div class="alert alert-warning">Warning: This input had more
than one value. This is no longer supported. The additional
values have been removed.</div>
[% END %] [% END %]
[% IF edit %]<button type="button" class="add-inputalt btn btn-success" onclick='return false'><i class="icon-plus icon-white"></i></button>[% END %]
</td> </td>
<td> <td>
<input type="checkbox" id="[% baseName %]-emailresponsible" name="[% baseName %]-emailresponsible" [% IF input.emailresponsible; 'checked="checked"'; END %]/> <input type="checkbox" id="[% baseName %]-emailresponsible" name="[% baseName %]-emailresponsible" [% IF input.emailresponsible; 'checked="checked"'; END %]/>
@ -34,7 +31,7 @@
[% BLOCK renderJobsetInputs %] [% BLOCK renderJobsetInputs %]
<table class="table table-striped table-condensed"> <table class="table table-striped table-condensed">
<thead> <thead>
<tr><th>Input name</th><th>Type</th><th>Values</th><th>Notify committers</th></tr> <tr><th></th><th>Input name</th><th>Type</th><th>Value</th><th>Notify committers</th></tr>
</thead> </thead>
<tbody class="inputs"> <tbody class="inputs">
[% FOREACH input IN jobset.jobsetinputs %] [% FOREACH input IN jobset.jobsetinputs %]
@ -151,10 +148,6 @@
[% INCLUDE renderJobsetInput input="" extraClass="template" id="input-template" baseName="input-template" %] [% INCLUDE renderJobsetInput input="" extraClass="template" id="input-template" baseName="input-template" %]
</table> </table>
<tt class="inputalt" id="inputalt-template" style="display: none">
[% INCLUDE renderJobsetInputAlt alt=alt %]
</tt>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
@ -166,22 +159,18 @@
var x = $("#input-template").clone(true).attr("id", "").insertBefore($(this).parents("tr")).show(); var x = $("#input-template").clone(true).attr("id", "").insertBefore($(this).parents("tr")).show();
$("#input-template-name", x).attr("name", newid + "-name"); $("#input-template-name", x).attr("name", newid + "-name");
$("#input-template-type", x).attr("name", newid + "-type"); $("#input-template-type", x).attr("name", newid + "-type");
$("#input-template-value", x).attr("name", newid + "-value");
$("#input-template-emailresponsible", x).attr("name", newid + "-emailresponsible"); $("#input-template-emailresponsible", x).attr("name", newid + "-emailresponsible");
$("#input-template", x).attr("id", newid); $("#input-template", x).attr("id", newid);
return false; return false;
}); });
$(".add-inputalt").click(function() {
var x = $("#inputalt-template").clone(true).insertBefore($(this)).attr("id", "").show();
$("input", x).attr("name", x.parents(".inputalts").attr("id") + "-values");
});
}); });
$("#submit-jobset").click(function() { $("#submit-jobset").click(function() {
var formElements = $(this).parents("form").serializeArray(); var formElements = $(this).parents("form").serializeArray();
var data = { 'inputs': {} }; var data = { 'inputs': {} };
var inputs = {}; var inputs = {};
for (var i = 0; i < formElements.length; i++) { for (var i = 0; formElements.length > i; i++) {
var elem = formElements[i]; var elem = formElements[i];
var match = elem.name.match(/^input-([\w-]+)-(\w+)$/); var match = elem.name.match(/^input-([\w-]+)-(\w+)$/);
if (match === null) { if (match === null) {
@ -190,19 +179,15 @@
var baseName = match[1]; var baseName = match[1];
var param = match[2]; var param = match[2];
if (baseName === "template") { if (baseName === "template") continue;
continue;
}
if (!(baseName in inputs)) { if (!(baseName in inputs))
inputs[baseName] = {}; inputs[baseName] = {};
}
if (param === "name") { if (param === "name")
data.inputs[elem.value] = inputs[baseName]; data.inputs[elem.value] = inputs[baseName];
} else { else
inputs[baseName][param] = elem.value; inputs[baseName][param] = elem.value;
}
} }
} }
redirectJSON({ redirectJSON({