From 851c3329d097d818d288eff49d7b396d1faf90f2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 3 Oct 2013 17:54:40 +0200 Subject: [PATCH] Implement DELETE for jobsets and use it in the web interface --- src/lib/Hydra/Controller/Jobset.pm | 25 +++++++++++++-------- src/root/common.tt | 5 ++++- src/root/edit-jobset.tt | 12 ---------- src/root/jobset.tt | 36 ++++++++++++++++++------------ src/root/project.tt | 8 +++---- 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index daa7ecb6..1cbca3ea 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -1,5 +1,6 @@ package Hydra::Controller::Jobset; +use utf8; use strict; use warnings; 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) { my ($self, $c) = @_; @@ -207,15 +223,6 @@ sub submit : Chained('jobsetChain') PathPart Args(0) { requirePost($c); 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 $oldName = trim $c->stash->{jobset}->name; unless ($oldName eq $newName) { diff --git a/src/root/common.tt b/src/root/common.tt index b99e3408..5107190e 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -452,7 +452,10 @@ BLOCK makePopover %] BLOCK menuItem %]
  • - [% title %] + + [% IF icon %] [%+ END %] + [% title %] +
  • [% END; diff --git a/src/root/edit-jobset.tt b/src/root/edit-jobset.tt index 0ec080a7..fa364a55 100644 --- a/src/root/edit-jobset.tt +++ b/src/root/edit-jobset.tt @@ -133,18 +133,6 @@
    - - [% IF !create %] - - - [% END %]
    diff --git a/src/root/jobset.tt b/src/root/jobset.tt index 541785c2..54dbfb1e 100644 --- a/src/root/jobset.tt +++ b/src/root/jobset.tt @@ -49,9 +49,10 @@ [% END %] @@ -114,8 +115,6 @@
    - Edit - @@ -167,16 +166,25 @@ 'Are you sure you want to force evaluation of this jobset?', function(c) { if (!c) return; - $.post("[% HTML.escape(c.uri_for('/api/push', { jobsets = project.name _ ':' _ jobset.name, force = "1" })) %]") - .done(function(data) { - if (data.error) - bootbox.alert("Unable to schedule the jobset for evaluation: " + data.error); - else - bootbox.alert("The jobset has been scheduled for evaluation."); - }) - .fail(function() { bootbox.alert("Server request failed!"); }); + requestJSON({ + url: "[% HTML.escape(c.uri_for('/api/push', { jobsets = project.name _ ':' _ jobset.name, force = "1" })) %]", + success: function(data) { + bootbox.alert("The jobset has been scheduled for evaluation."); + } + }); + }); + }; + + 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; }; diff --git a/src/root/project.tt b/src/root/project.tt index 9b5721e1..2398f53d 100644 --- a/src/root/project.tt +++ b/src/root/project.tt @@ -9,10 +9,10 @@ [% END %]
    Description: