Implement DELETE for jobsets and use it in the web interface

This commit is contained in:
Eelco Dolstra 2013-10-03 17:54:40 +02:00
parent ae13dd3e67
commit 851c3329d0
5 changed files with 46 additions and 40 deletions

View file

@ -1,5 +1,6 @@
package Hydra::Controller::Jobset; package Hydra::Controller::Jobset;
use utf8;
use strict; use strict;
use warnings; use warnings;
use base 'Hydra::Base::Controller::ListBuilds'; use base 'Hydra::Base::Controller::ListBuilds';
@ -135,6 +136,21 @@ sub jobset_PUT {
} }
} }
sub jobset_DELETE {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
txn_do($c->model('DB')->schema, sub {
$c->stash->{jobset}->jobsetevals->delete_all;
$c->stash->{jobset}->builds->delete_all;
$c->stash->{jobset}->delete;
});
my $uri = $c->uri_for($c->controller('Project')->action_for("project"), [$c->stash->{project}->name]);
$self->status_ok($c, entity => { redirect => "$uri" });
}
sub jobs_tab : Chained('jobsetChain') PathPart('jobs-tab') Args(0) { sub jobs_tab : Chained('jobsetChain') PathPart('jobs-tab') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
@ -207,15 +223,6 @@ sub submit : Chained('jobsetChain') PathPart Args(0) {
requirePost($c); requirePost($c);
requireProjectOwner($c, $c->stash->{project}); requireProjectOwner($c, $c->stash->{project});
if (($c->request->params->{submit} // "") eq "delete") {
txn_do($c->model('DB')->schema, sub {
$c->stash->{jobset}->jobsetevals->delete_all;
$c->stash->{jobset}->builds->delete_all;
$c->stash->{jobset}->delete;
});
return $c->res->redirect($c->uri_for($c->controller('Project')->action_for("project"), [$c->stash->{project}->name]));
}
my $newName = trim $c->stash->{params}->{name}; my $newName = trim $c->stash->{params}->{name};
my $oldName = trim $c->stash->{jobset}->name; my $oldName = trim $c->stash->{jobset}->name;
unless ($oldName eq $newName) { unless ($oldName eq $newName) {

View file

@ -452,7 +452,10 @@ BLOCK makePopover %]
BLOCK menuItem %] BLOCK menuItem %]
<li class="[% IF "${root}${curUri}" == uri %]active[% END %]" [% IF confirmmsg %]onclick="javascript:return confirm('[% confirmmsg %]')"[% END %]> <li class="[% IF "${root}${curUri}" == uri %]active[% END %]" [% IF confirmmsg %]onclick="javascript:return confirm('[% confirmmsg %]')"[% END %]>
<a href="[% uri %]" [% IF modal %]data-toggle="modal"[% END %]>[% title %]</a> <a href="[% uri %]" [% IF modal %]data-toggle="modal"[% END %]>
[% IF icon %]<i class="[% icon %] icon-black"></i> [%+ END %]
[% title %]
</a>
</li> </li>
[% END; [% END;

View file

@ -133,18 +133,6 @@
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> [%IF create %]Create[% ELSE %]Apply changes[% END %]</button> <button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> [%IF create %]Create[% ELSE %]Apply changes[% END %]</button>
[% IF !create %]
<button id="delete-jobset" type="submit" class="btn btn-danger" name="submit" value="delete">
<i class="icon-trash icon-white"></i>
Delete this jobset
</button>
<script type="text/javascript">
$("#delete-jobset").click(function() {
return confirm("Are you sure you want to delete this jobset?");
});
</script>
[% END %]
</div> </div>
</fieldset> </fieldset>

View file

@ -49,9 +49,10 @@
<b class="caret"></b> <b class="caret"></b>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
[% INCLUDE menuItem uri = c.uri_for('/jobset' project.name jobset.name 'edit') title="Edit configuration" %] [% INCLUDE menuItem title="Edit configuration" icon="icon-edit" uri=c.uri_for(c.controller('Jobset').action_for('edit'), [project.name, jobset.name]) %]
[% INCLUDE menuItem uri = c.uri_for('/jobset' project.name jobset.name 'clone') title="Clone this jobset" %] [% INCLUDE menuItem title="Delete this jobset" icon="icon-trash" uri="javascript:deleteJobset()" %]
[% INCLUDE menuItem uri = "javascript:confirmEvaluateJobset()" title="Evaluate this jobset" %] [% INCLUDE menuItem title="Clone this jobset" uri=c.uri_for('/jobset' project.name jobset.name 'clone') %]
[% INCLUDE menuItem title="Evaluate this jobset" uri="javascript:confirmEvaluateJobset()" %]
</ul> </ul>
</li> </li>
[% END %] [% END %]
@ -114,8 +115,6 @@
<div id="tabs-configuration" class="tab-pane"> <div id="tabs-configuration" class="tab-pane">
<a class="btn pull-right" href="[% c.uri_for('/jobset' project.name jobset.name "edit") %]"><i class="icon-edit"></i> Edit</a>
<table class="info-table"> <table class="info-table">
<tr> <tr>
<th>Description:</th> <th>Description:</th>
@ -167,16 +166,25 @@
'Are you sure you want to force evaluation of this jobset?', 'Are you sure you want to force evaluation of this jobset?',
function(c) { function(c) {
if (!c) return; if (!c) return;
$.post("[% HTML.escape(c.uri_for('/api/push', { jobsets = project.name _ ':' _ jobset.name, force = "1" })) %]") requestJSON({
.done(function(data) { url: "[% HTML.escape(c.uri_for('/api/push', { jobsets = project.name _ ':' _ jobset.name, force = "1" })) %]",
if (data.error) success: function(data) {
bootbox.alert("Unable to schedule the jobset for evaluation: " + data.error); bootbox.alert("The jobset has been scheduled for evaluation.");
else }
bootbox.alert("The jobset has been scheduled for evaluation."); });
}) });
.fail(function() { bootbox.alert("Server request failed!"); }); };
function deleteJobset() {
bootbox.confirm(
'Are you sure you want to delete this jobset?',
function(c) {
if (!c) return;
redirectJSON({
url: "[% c.uri_for(c.controller('Jobset').action_for('jobset'), [project.name, jobset.name]) %]",
type: 'DELETE'
});
}); });
return;
}; };
</script> </script>

View file

@ -9,10 +9,10 @@
<b class="caret"></b> <b class="caret"></b>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="[% c.uri_for('/project' project.name 'edit') %]"><i class="icon-edit icon-black"></i> Edit configuration</a></li> [% INCLUDE menuItem title="Edit configuration" icon="icon-edit" uri=c.uri_for(c.controller('Project').action_for('edit'), [project.name]) %]
<li><a href="javascript:deleteProject()"><i class="icon-trash icon-black"></i> Delete this project</a></li> [% INCLUDE menuItem title="Delete this project" icon="icon-trash" uri="javascript:deleteProject()" %]
[% INCLUDE menuItem uri = c.uri_for(c.controller('Project').action_for('create_jobset'), [project.name]) title = "Create jobset" %] [% INCLUDE menuItem title="Create jobset" icon="icon-plus" uri=c.uri_for(c.controller('Project').action_for('create_jobset'), [project.name]) %]
[% INCLUDE menuItem uri = c.uri_for('/project' project.name 'create-release') title = "Create release" %] [% INCLUDE menuItem title="Create release" icon="icon-plus" uri=c.uri_for(c.controller('Project').action_for('create_release'), [project.name]) %]
</ul> </ul>
</li> </li>
[% END %] [% END %]