* Improved the navigation bar: don't include all projects (since that

doesn't scale), and include links for jobset/job specific pages.
  The main page now lists the projects.
* Overview pages for jobsets and jobs.
* Links to the channels.
* Jobsets are now defined and edited in a separate action.
This commit is contained in:
Eelco Dolstra
2009-04-02 16:15:57 +00:00
parent db4ce0df06
commit 753e56b6eb
18 changed files with 762 additions and 470 deletions

View File

@ -17,7 +17,16 @@ sub job : Chained('/') PathPart('job') CaptureArgs(3) {
}
sub index : Chained('job') PathPart('') Args(0) {
sub overview : Chained('job') PathPart('') Args(0) {
my ($self, $c) = @_;
$c->stash->{template} = 'job.tt';
getBuildStats($c, scalar $c->stash->{job}->builds);
}
sub all : Chained('job') PathPart Args(0) {
my ($self, $c) = @_;
$c->go($self->action_for("all"));
}

View File

@ -22,7 +22,13 @@ sub jobset : Chained('/') PathPart('jobset') CaptureArgs(2) {
sub index : Chained('jobset') PathPart('') Args(0) {
my ($self, $c) = @_;
$c->go($self->action_for("all"));
$c->stash->{template} = 'jobset.tt';
getBuildStats($c, scalar $c->stash->{jobset}->builds);
$c->stash->{activeJobs} = [$c->stash->{jobset}->jobs->search({active => 1})];
$c->stash->{inactiveJobs} = [$c->stash->{jobset}->jobs->search({active => 0})];
}
@ -36,4 +42,120 @@ sub get_builds : Chained('jobset') PathPart('') CaptureArgs(0) {
}
sub edit : Chained('jobset') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
$c->stash->{template} = 'jobset.tt';
$c->stash->{edit} = 1;
}
sub submit : Chained('jobset') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
requirePost($c);
$c->model('DB')->schema->txn_do(sub {
updateJobset($c, $c->stash->{jobset});
});
$c->res->redirect($c->uri_for($self->action_for("index"),
[$c->stash->{project}->name, $c->stash->{jobset}->name]));
}
sub delete : Chained('jobset') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
requirePost($c);
$c->model('DB')->schema->txn_do(sub {
$c->stash->{jobset}->delete;
});
$c->res->redirect($c->uri_for($c->controller('Project')->action_for("view"),
[$c->stash->{project}->name]));
}
sub updateJobset {
my ($c, $jobset) = @_;
my $jobsetName = trim $c->request->params->{"name"};
error($c, "Invalid jobset name: $jobsetName") unless $jobsetName =~ /^[[:alpha:]][\w\-]*$/;
# The Nix expression path must be relative and can't contain ".." elements.
my $nixExprPath = trim $c->request->params->{"nixexprpath"};
error($c, "Invalid Nix expression path: $nixExprPath") if $nixExprPath !~ /^$relPathRE$/;
my $nixExprInput = trim $c->request->params->{"nixexprinput"};
error($c, "Invalid Nix expression input name: $nixExprInput") unless $nixExprInput =~ /^\w+$/;
$jobset->update(
{ name => $jobsetName
, description => trim($c->request->params->{"description"})
, nixexprpath => $nixExprPath
, nixexprinput => $nixExprInput
});
my %inputNames;
# Process the inputs of this jobset.
foreach my $param (keys %{$c->request->params}) {
next unless $param =~ /^input-(\w+)-name$/;
my $baseName2 = $1;
next if $baseName2 eq "template";
print STDERR "GOT INPUT: $baseName2\n";
my $inputName = trim $c->request->params->{"input-$baseName2-name"};
error($c, "Invalid input name: $inputName") unless $inputName =~ /^[[:alpha:]]\w*$/;
my $inputType = trim $c->request->params->{"input-$baseName2-type"};
error($c, "Invalid input type: $inputType") unless
$inputType eq "svn" || $inputType eq "cvs" || $inputType eq "tarball" ||
$inputType eq "string" || $inputType eq "path" || $inputType eq "boolean" ||
$inputType eq "build";
$inputNames{$inputName} = 1;
my $input;
if ($baseName2 =~ /^\d+$/) { # numeric base name is auto-generated, i.e. a new entry
$input = $jobset->jobsetinputs->create(
{ name => $inputName
, type => $inputType
});
} else { # it's an existing input
$input = ($jobset->jobsetinputs->search({name => $baseName2}))[0];
die unless defined $input;
$input->update({name => $inputName, type => $inputType});
}
# Update the values for this input. Just delete all the
# current ones, then create the new values.
$input->jobsetinputalts->delete_all;
my $values = $c->request->params->{"input-$baseName2-values"};
$values = [] unless defined $values;
$values = [$values] unless ref($values) eq 'ARRAY';
my $altnr = 0;
foreach my $value (@{$values}) {
print STDERR "VALUE: $value\n";
my $value = trim $value;
error($c, "Invalid Boolean value: $value") if
$inputType eq "boolean" && !($value eq "true" || $value eq "false");
$input->jobsetinputalts->create({altnr => $altnr++, value => $value});
}
}
# Get rid of deleted inputs.
my @inputs = $jobset->jobsetinputs->all;
foreach my $input (@inputs) {
$input->delete unless defined $inputNames{$input->name};
}
}
1;

View File

@ -23,6 +23,8 @@ sub view : Chained('project') PathPart('') Args(0) {
$c->stash->{template} = 'project.tt';
getBuildStats($c, scalar $c->stash->{project}->builds);
$c->stash->{releaseSets} = [$c->stash->{project}->releasesets->all];
}
@ -40,14 +42,13 @@ sub submit : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
requirePost($c);
$c->model('DB')->schema->txn_do(sub {
updateProject($c, $c->stash->{project});
});
$c->res->redirect($c->uri_for($self->action_for("view"), $c->req->captures));
$c->res->redirect($c->uri_for($self->action_for("view"), [$c->stash->{project}->name]));
}
@ -55,8 +56,7 @@ sub delete : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
requirePost($c);
$c->model('DB')->schema->txn_do(sub {
$c->stash->{project}->delete;
@ -109,6 +109,37 @@ sub create_submit : Path('/create-project/submit') {
}
sub create_jobset : Chained('project') PathPart('create-jobset') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
$c->stash->{template} = 'jobset.tt';
$c->stash->{create} = 1;
$c->stash->{edit} = 1;
}
sub create_jobset_submit : Chained('project') PathPart('create-jobset/submit') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
my $jobsetName = trim $c->request->params->{name};
$c->model('DB')->schema->txn_do(sub {
# Note: $jobsetName is validated in updateProject, which will
# abort the transaction if the name isn't valid.
my $jobset = $c->stash->{project}->jobsets->create(
{name => $jobsetName, nixexprinput => "", nixexprpath => ""});
Hydra::Controller::Jobset::updateJobset($c, $jobset);
});
$c->res->redirect($c->uri_for($c->controller('Jobset')->action_for("index"),
[$c->stash->{project}->name, $jobsetName]));
}
sub updateProject {
my ($c, $project) = @_;
my $projectName = trim $c->request->params->{name};
@ -116,120 +147,22 @@ sub updateProject {
my $displayName = trim $c->request->params->{displayname};
error($c, "Invalid display name: $displayName") if $displayName eq "";
$project->name($projectName);
$project->displayname($displayName);
$project->description(trim $c->request->params->{description});
$project->homepage(trim $c->request->params->{homepage});
$project->enabled(trim($c->request->params->{enabled}) eq "1" ? 1 : 0);
my $owner = $project->owner;
if ($c->check_user_roles('admin')) {
my $owner = trim $c->request->params->{owner};
$owner = trim $c->request->params->{owner};
error($c, "Invalid owner: $owner")
unless defined $c->model('DB::Users')->find({username => $owner});
$project->owner($owner);
}
$project->update;
my %jobsetNames;
foreach my $param (keys %{$c->request->params}) {
next unless $param =~ /^jobset-(\w+)-name$/;
my $baseName = $1;
next if $baseName eq "template";
my $jobsetName = trim $c->request->params->{"jobset-$baseName-name"};
error($c, "Invalid jobset name: $jobsetName") unless $jobsetName =~ /^[[:alpha:]][\w\-]*$/;
# The Nix expression path must be relative and can't contain ".." elements.
my $nixExprPath = trim $c->request->params->{"jobset-$baseName-nixexprpath"};
error($c, "Invalid Nix expression path: $nixExprPath") if $nixExprPath !~ /^$relPathRE$/;
my $nixExprInput = trim $c->request->params->{"jobset-$baseName-nixexprinput"};
error($c, "Invalid Nix expression input name: $nixExprInput") unless $nixExprInput =~ /^\w+$/;
$jobsetNames{$jobsetName} = 1;
my $jobset;
my $description = trim $c->request->params->{"jobset-$baseName-description"};
if ($baseName =~ /^\d+$/) { # numeric base name is auto-generated, i.e. a new entry
$jobset = $project->jobsets->create(
{ name => $jobsetName
, description => $description
, nixexprpath => $nixExprPath
, nixexprinput => $nixExprInput
});
} else { # it's an existing jobset
my $oldName = trim $c->request->params->{"jobset-$baseName-oldName"};
$jobset = ($project->jobsets->search({name => $oldName}))[0] or die;
$jobset->update(
{ name => $jobsetName, description => $description
, nixexprpath => $nixExprPath, nixexprinput => $nixExprInput });
}
my %inputNames;
# Process the inputs of this jobset.
foreach my $param (keys %{$c->request->params}) {
next unless $param =~ /^jobset-$baseName-input-(\w+)-name$/;
my $baseName2 = $1;
next if $baseName2 eq "template";
print STDERR "GOT INPUT: $baseName2\n";
my $inputName = trim $c->request->params->{"jobset-$baseName-input-$baseName2-name"};
error($c, "Invalid input name: $inputName") unless $inputName =~ /^[[:alpha:]]\w*$/;
my $inputType = trim $c->request->params->{"jobset-$baseName-input-$baseName2-type"};
error($c, "Invalid input type: $inputType") unless
$inputType eq "svn" || $inputType eq "cvs" || $inputType eq "tarball" ||
$inputType eq "string" || $inputType eq "path" || $inputType eq "boolean" ||
$inputType eq "build";
$inputNames{$inputName} = 1;
my $input;
if ($baseName2 =~ /^\d+$/) { # numeric base name is auto-generated, i.e. a new entry
$input = $jobset->jobsetinputs->create(
{ name => $inputName
, type => $inputType
});
} else { # it's an existing jobset
$input = ($jobset->jobsetinputs->search({name => $baseName2}))[0];
die unless defined $input;
$input->update({name => $inputName, type => $inputType});
}
# Update the values for this input. Just delete all the
# current ones, then create the new values.
$input->jobsetinputalts->delete_all;
my $values = $c->request->params->{"jobset-$baseName-input-$baseName2-values"};
$values = [] unless defined $values;
$values = [$values] unless ref($values) eq 'ARRAY';
my $altnr = 0;
foreach my $value (@{$values}) {
print STDERR "VALUE: $value\n";
my $value = trim $value;
error($c, "Invalid Boolean value: $value") if
$inputType eq "boolean" && !($value eq "true" || $value eq "false");
$input->jobsetinputalts->create({altnr => $altnr++, value => $value});
}
}
# Get rid of deleted inputs.
my @inputs = $jobset->jobsetinputs->all;
foreach my $input (@inputs) {
$input->delete unless defined $inputNames{$input->name};
}
}
# Get rid of deleted jobsets, i.e., ones that are no longer submitted in the parameters.
my @jobsets = $project->jobsets->all;
foreach my $jobset (@jobsets) {
$jobset->delete unless defined $jobsetNames{$jobset->name};
}
$project->update(
{ name => $projectName
, displayname => $displayName
, description => trim($c->request->params->{description})
, homepage => trim($c->request->params->{homepage})
, enabled => trim($c->request->params->{enabled}) eq "1" ? 1 : 0
, owner => $owner
});
}

View File

@ -13,7 +13,6 @@ __PACKAGE__->config->{namespace} = '';
sub begin :Private {
my ($self, $c) = @_;
$c->stash->{projects} = [$c->model('DB::Projects')->search({}, {order_by => 'displayname'})];
$c->stash->{curUri} = $c->request->uri;
$c->stash->{version} = $ENV{"HYDRA_RELEASE"} || "<devel>";
}
@ -21,8 +20,8 @@ sub begin :Private {
sub index :Path :Args(0) {
my ($self, $c) = @_;
$c->stash->{template} = 'index.tt';
$c->stash->{template} = 'overview.tt';
$c->stash->{projects} = [$c->model('DB::Projects')->search({}, {order_by => 'displayname'})];
getBuildStats($c, $c->model('DB::Builds'));
}
@ -63,18 +62,6 @@ sub queue :Local {
}
sub releasesets :Local {
my ($self, $c, $projectName) = @_;
$c->stash->{template} = 'releasesets.tt';
my $project = $c->model('DB::Projects')->find($projectName);
notFound($c, "Project $projectName doesn't exist.") if !defined $project;
$c->stash->{project} = $project;
$c->stash->{releaseSets} = [$project->releasesets->all];
}
sub getReleaseSet {
my ($c, $projectName, $releaseSetName) = @_;

View File

@ -9,7 +9,7 @@ our @ISA = qw(Exporter);
our @EXPORT = qw(
getBuild getBuildStats getLatestBuilds getChannelData
error notFound
requireLogin requireProjectOwner requireAdmin
requireLogin requireProjectOwner requireAdmin requirePost
trim
$pathCompRE $relPathRE
);
@ -126,6 +126,12 @@ sub requireAdmin {
}
sub requirePost {
my ($c) = @_;
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
}
sub trim {
my $s = shift;
$s =~ s/^\s+|\s+$//g;