forked from lix-project/hydra
Hydra/20: Jobset clone feature
This commit is contained in:
parent
2ef90804c6
commit
85928a4222
|
@ -252,4 +252,49 @@ sub updateJobset {
|
|||
}
|
||||
|
||||
|
||||
sub clone : Chained('jobset') PathPart('clone') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $jobset = $c->stash->{jobset};
|
||||
requireProjectOwner($c, $jobset->project);
|
||||
|
||||
$c->stash->{template} = 'clone-jobset.tt';
|
||||
}
|
||||
|
||||
sub clone_submit : Chained('jobset') PathPart('clone/submit') Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $jobset = $c->stash->{jobset};
|
||||
requireProjectOwner($c, $jobset->project);
|
||||
requirePost($c);
|
||||
|
||||
my $newjobsetName = trim $c->request->params->{"newjobset"};
|
||||
error($c, "Invalid jobset name: $newjobsetName") unless $newjobsetName =~ /^[[:alpha:]][\w\-]*$/;
|
||||
|
||||
my $newjobset;
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
$newjobset = $jobset->project->jobsets->create(
|
||||
{ name => $newjobsetName
|
||||
, description => $jobset->description
|
||||
, nixexprpath => $jobset->nixexprpath
|
||||
, nixexprinput => $jobset->nixexprinput
|
||||
, enabled => 0
|
||||
, enableemail => $jobset->enableemail
|
||||
, emailoverride => $jobset->emailoverride
|
||||
});
|
||||
|
||||
foreach my $input ($jobset->jobsetinputs) {
|
||||
my $newinput = $newjobset->jobsetinputs->create({name => $input->name, type => $input->type});
|
||||
foreach my $inputalt ($input->jobsetinputalts) {
|
||||
$newinput->jobsetinputalts->create({altnr => $inputalt->altnr, value => $inputalt->value});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$c->res->redirect($c->uri_for($c->controller('Jobset')->action_for("edit"), [$jobset->project->name, $newjobsetName]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
|
18
src/root/clone-jobset.tt
Normal file
18
src/root/clone-jobset.tt
Normal file
|
@ -0,0 +1,18 @@
|
|||
[% WRAPPER layout.tt title="Clone Jobset" %]
|
||||
[% PROCESS common.tt %]
|
||||
[% USE HTML %]
|
||||
[% edit=1 %]
|
||||
|
||||
<form action="[% c.uri_for('/jobset' jobset.project.name jobset.name 'clone' 'submit') %]" method="post">
|
||||
|
||||
<h2>Cloning jobset [% jobset.project.name %]:[% jobset.name %]</h2>
|
||||
<p>
|
||||
Name <tt><input type="text" class="string" name="newjobset" [% HTML.attributes(value => "") %] /></tt>
|
||||
</p>
|
||||
<p>
|
||||
<button type="submit">Next</button>
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
[% END %]
|
|
@ -151,7 +151,13 @@
|
|||
[% END %]
|
||||
[% END %]
|
||||
<div id="tabs-setup">
|
||||
<h2>Information[% IF !edit %] <a class="smallLink" href="[% c.uri_for('/jobset' project.name jobset.name 'edit') %]">[Edit]</a>[% END %]</h2>
|
||||
<h2>Information</h2>
|
||||
|
||||
[% IF !edit && c.user_exists %]
|
||||
<p>
|
||||
[ <a href="[% c.uri_for('/jobset' project.name jobset.name 'edit') %]">Edit</a> | <a href="[% c.uri_for('/jobset' project.name jobset.name 'clone') %]">Clone</a> ]
|
||||
</p>
|
||||
[% END %]
|
||||
|
||||
<table class="layoutTable">
|
||||
[% IF edit %]
|
||||
|
|
Loading…
Reference in a new issue