* Refactoring.

This commit is contained in:
Eelco Dolstra 2009-03-13 15:41:19 +00:00
parent 3af294f848
commit 3c86b3652c
12 changed files with 54 additions and 63 deletions

View file

@ -17,7 +17,7 @@ sub build : Chained('/') PathPart CaptureArgs(1) {
notFound($c, "Build with ID $id doesn't exist.")
if !defined $c->stash->{build};
$c->stash->{curProject} = $c->stash->{build}->project;
$c->stash->{project} = $c->stash->{build}->project;
}

View file

@ -10,16 +10,10 @@ use Hydra::Helper::CatalystUtils;
sub job : Chained('/') PathPart('job') CaptureArgs(3) {
my ($self, $c, $projectName, $jobsetName, $jobName) = @_;
# !!! cut&paste from Project::project.
my $project = $c->model('DB::Projects')->find($projectName)
or notFound($c, "Project $projectName doesn't exist.");
$c->stash->{curProject} = $project;
$c->stash->{jobset} = $project->jobsets->find({name => $jobsetName})
or notFound($c, "Jobset $jobsetName doesn't exist.");
$c->stash->{jobName} = $jobName;
$c->stash->{job} = $c->model('DB::Jobs')->find({project => $projectName, jobset => $jobsetName, name => $jobName})
or notFound($c, "Job $projectName:$jobsetName:$jobName doesn't exist.");
$c->stash->{project} = $c->stash->{job}->project;
$c->stash->{jobset} = $c->stash->{job}->jobset;
}
@ -32,10 +26,9 @@ sub index : Chained('job') PathPart('') Args(0) {
# Hydra::Base::Controller::ListBuilds needs this.
sub get_builds : Chained('job') PathPart('') CaptureArgs(0) {
my ($self, $c) = @_;
$c->stash->{allBuilds} =
$c->stash->{jobset}->builds->search({job => $c->stash->{jobName}});
$c->stash->{allBuilds} = $c->stash->{job}->builds;
$c->stash->{channelBaseName} =
$c->stash->{curProject}->name . "-" . $c->stash->{jobset}->name . "-" . $c->stash->{jobName};
$c->stash->{project}->name . "-" . $c->stash->{jobset}->name . "-" . $c->stash->{job}->name;
}

View file

@ -13,7 +13,7 @@ sub jobset : Chained('/') PathPart('jobset') CaptureArgs(2) {
my $project = $c->model('DB::Projects')->find($projectName)
or notFound($c, "Project $projectName doesn't exist.");
$c->stash->{curProject} = $project;
$c->stash->{project} = $project;
$c->stash->{jobset} = $project->jobsets->find({name => $jobsetName})
or notFound($c, "Jobset $jobsetName doesn't exist.");
@ -32,7 +32,7 @@ sub get_builds : Chained('jobset') PathPart('') CaptureArgs(0) {
$c->stash->{allBuilds} =
$c->stash->{jobset}->builds;
$c->stash->{channelBaseName} =
$c->stash->{curProject}->name . "-" . $c->stash->{jobset}->name;
$c->stash->{project}->name . "-" . $c->stash->{jobset}->name;
}

View file

@ -13,7 +13,7 @@ sub project : Chained('/') PathPart('project') CaptureArgs(1) {
my $project = $c->model('DB::Projects')->find($projectName)
or notFound($c, "Project $projectName doesn't exist.");
$c->stash->{curProject} = $project;
$c->stash->{project} = $project;
}
@ -22,14 +22,14 @@ sub view : Chained('project') PathPart('') Args(0) {
$c->stash->{template} = 'project.tt';
getBuildStats($c, scalar $c->stash->{curProject}->builds);
getBuildStats($c, scalar $c->stash->{project}->builds);
}
sub edit : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{curProject});
requireProjectOwner($c, $c->stash->{project});
$c->stash->{template} = 'project.tt';
$c->stash->{edit} = 1;
@ -39,12 +39,12 @@ sub edit : Chained('project') PathPart Args(0) {
sub submit : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{curProject});
requireProjectOwner($c, $c->stash->{project});
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
$c->model('DB')->schema->txn_do(sub {
updateProject($c, $c->stash->{curProject});
updateProject($c, $c->stash->{project});
});
$c->res->redirect($c->uri_for($self->action_for("view"), $c->req->captures));
@ -54,12 +54,12 @@ sub submit : Chained('project') PathPart Args(0) {
sub delete : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{curProject});
requireProjectOwner($c, $c->stash->{project});
error($c, "Request must be POSTed.") if $c->request->method ne "POST";
$c->model('DB')->schema->txn_do(sub {
$c->stash->{curProject}->delete;
$c->stash->{project}->delete;
});
$c->res->redirect($c->uri_for("/"));
@ -224,8 +224,8 @@ sub updateProject {
# Hydra::Base::Controller::ListBuilds needs this.
sub get_builds : Chained('project') PathPart('') CaptureArgs(0) {
my ($self, $c) = @_;
$c->stash->{allBuilds} = $c->stash->{curProject}->builds;
$c->stash->{channelBaseName} = $c->stash->{curProject}->name;
$c->stash->{allBuilds} = $c->stash->{project}->builds;
$c->stash->{channelBaseName} = $c->stash->{project}->name;
}

View file

@ -68,7 +68,7 @@ sub releasesets :Local {
my $project = $c->model('DB::Projects')->find($projectName);
notFound($c, "Project $projectName doesn't exist.") if !defined $project;
$c->stash->{curProject} = $project;
$c->stash->{project} = $project;
$c->stash->{releaseSets} = [$project->releasesets->all];
}
@ -79,7 +79,7 @@ sub getReleaseSet {
my $project = $c->model('DB::Projects')->find($projectName);
die "Project $projectName doesn't exist." if !defined $project;
$c->stash->{curProject} = $project;
$c->stash->{project} = $project;
(my $releaseSet) = $c->model('DB::ReleaseSets')->find($projectName, $releaseSetName);
die "Release set $releaseSetName doesn't exist." if !defined $releaseSet;
@ -175,7 +175,7 @@ sub create_releaseset :Local {
my $project = $c->model('DB::Projects')->find($projectName);
die "Project $projectName doesn't exist." if !defined $project;
$c->stash->{curProject} = $project;
$c->stash->{project} = $project;
requireProjectOwner($c, $project);

View file

@ -2,9 +2,9 @@
[% PROCESS common.tt %]
<h1>All Builds
[% IF jobName %]for Job [% curProject.name %]:[% jobset.name %]:[% jobName %]
[% ELSIF jobset %]for Jobset [% curProject.name %]:[% jobset.name %]
[% ELSIF curProject %] for Project <tt>[% curProject.name %]</tt>[% END %]</h1>
[% IF job %]for Job [% project.name %]:[% jobset.name %]:[% job.name %]
[% ELSIF jobset %]for Jobset [% project.name %]:[% jobset.name %]
[% ELSIF project %] for Project <tt>[% project.name %]</tt>[% END %]</h1>
<p>Showing builds [% (page - 1) * resultsPerPage + 1 %] - [% (page - 1) * resultsPerPage + builds.size %]
out of [% totalBuilds %] in order of descending timestamp.</p>

View file

@ -1,8 +1,8 @@
[% WRAPPER layout.tt title=(create ? "New Release Set" : "Release Set $curProject.name:$releaseSet.name") %]
[% WRAPPER layout.tt title=(create ? "New Release Set" : "Release Set $project.name:$releaseSet.name") %]
[% PROCESS common.tt %]
[% USE HTML %]
<h1>[% IF create %]New Release Set[% ELSE %]Release Set <tt>[% curProject.name %]:[% releaseSet.name %]</tt>[% END %]</h1>
<h1>[% IF create %]New Release Set[% ELSE %]Release Set <tt>[% project.name %]:[% releaseSet.name %]</tt>[% END %]</h1>
[% BLOCK renderJob %]
@ -21,7 +21,7 @@
[% END %]
<form action="[% IF create %][% c.uri_for('/create_releaseset' curProject.name 'submit') %][% ELSE %][% c.uri_for('/releases' curProject.name releaseSet.name 'submit') %][% END %]" method="post">
<form action="[% IF create %][% c.uri_for('/create_releaseset' project.name 'submit') %][% ELSE %][% c.uri_for('/releases' project.name releaseSet.name 'submit') %][% END %]" method="post">
<table class="layoutTable">
<tr>
@ -86,7 +86,7 @@
[% IF !create %]
<form action="[% c.uri_for('/releases' curProject.name releaseSet.name 'delete') %]" method="post">
<form action="[% c.uri_for('/releases' project.name releaseSet.name 'delete') %]" method="post">
<p><button id="delete-project" type="submit"><img src="/static/images/failure.gif" />Delete this release set</button></p>
</form>

View file

@ -1,7 +1,7 @@
[% WRAPPER layout.tt title="Job Status" %]
[% PROCESS common.tt %]
<h1>Job Status[% IF curProject %] of Project <tt>[% curProject.name %]</tt>[% END %]</h1>
<h1>Job Status[% IF project %] of Project <tt>[% project.name %]</tt>[% END %]</h1>
<p>Below are the latest builds for each job.</p>

View file

@ -99,10 +99,10 @@
<li>
<div class="title">Projects</div>
<ul class="submenu">
[% FOREACH project IN projects %]
<li [% IF curUri == c.uri_for('/project' project.name) %]class="active"[% END %]>
<div class="title"><a href="[% c.uri_for('/project' project.name) %]">[% HTML.escape(project.displayname) %]</a></div>
[% IF curProject.name == project.name %]
[% FOREACH project_ IN projects %]
<li [% IF curUri == c.uri_for('/project' project_.name) %]class="active"[% END %]>
<div class="title"><a href="[% c.uri_for('/project' project_.name) %]">[% HTML.escape(project_.displayname) %]</a></div>
[% IF project.name == project_.name %]
<ul class="subsubmenu">
[% INCLUDE makeLink uri = c.uri_for('/project' project.name 'jobstatus') title = "Job status" %]
[% INCLUDE makeLink uri = c.uri_for('/project' project.name 'all') title = "All builds" %]
@ -120,8 +120,6 @@
</ul>
[% END %]
[% END %]
[% INCLUDE makeLink uri = c.uri_for('/project' project.name 'edit') title = "Edit" %]
</ul>
[% END %]

View file

@ -1,4 +1,4 @@
[% WRAPPER layout.tt title=(edit ? (create ? "New Project" : "Editing Project $curProject.name") : "Project $curProject.name") %]
[% WRAPPER layout.tt title=(edit ? (create ? "New Project" : "Editing Project $project.name") : "Project $project.name") %]
[% PROCESS common.tt %]
[% USE HTML %]
@ -133,14 +133,14 @@
[% IF edit %]
<form action="[% IF create %][% c.uri_for('/create-project/submit') %][% ELSE %][% c.uri_for('/project' curProject.name 'submit') %][% END %]" method="post">
<form action="[% IF create %][% c.uri_for('/create-project/submit') %][% ELSE %][% c.uri_for('/project' project.name 'submit') %][% END %]" method="post">
[% END %]
[% IF create %]
<h1>New Project</h1>
[% ELSE %]
<h1>Project <tt>[% curProject.name %]</tt></h1>
<h1>Project <tt>[% project.name %]</tt></h1>
[% END %]
@ -150,25 +150,25 @@
[% IF edit %]
<tr>
<th>Identifier:</th>
<td><tt>[% INCLUDE maybeEditString param="name" value=curProject.name %]</tt></td>
<td><tt>[% INCLUDE maybeEditString param="name" value=project.name %]</tt></td>
</tr>
[% END %]
<tr>
<th>Display name:</th>
<td>[% INCLUDE maybeEditString param="displayname" value=curProject.displayname %]</td>
<td>[% INCLUDE maybeEditString param="displayname" value=project.displayname %]</td>
</tr>
<tr>
<th>Description:</th>
<td>[% INCLUDE maybeEditString param="description" value=curProject.description %]</td>
<td>[% INCLUDE maybeEditString param="description" value=project.description %]</td>
</tr>
<tr>
<th>Homepage:</th>
<td>
[% IF edit %]
[% INCLUDE maybeEditString param="homepage" value=curProject.homepage %]
[% INCLUDE maybeEditString param="homepage" value=project.homepage %]
[% ELSE %]
[% IF curProject.homepage %]
<a [% HTML.attributes(href => curProject.homepage) %]>[% HTML.escape(curProject.homepage) %]</a>
[% IF project.homepage %]
<a [% HTML.attributes(href => project.homepage) %]>[% HTML.escape(project.homepage) %]</a>
[% ELSE %]
<em>(not specified)</em>
[% END %]
@ -177,12 +177,12 @@
</tr>
<tr>
<th>Owner:</th>
<td><tt>[% INCLUDE maybeEditString param="owner" value=curProject.owner.username edit=(edit && c.check_user_roles('admin')) %]</tt></td>
<td><tt>[% INCLUDE maybeEditString param="owner" value=project.owner.username edit=(edit && c.check_user_roles('admin')) %]</tt></td>
</tr>
<tr>
<th>Enabled:</th>
<td>
[% INCLUDE renderSelection param="enabled" curValue=curProject.enabled options={"1" = "Yes", "0" = "No"} %]
[% INCLUDE renderSelection param="enabled" curValue=project.enabled options={"1" = "Yes", "0" = "No"} %]
</td>
</tr>
</table>
@ -199,7 +199,7 @@
<h2>Jobsets</h2>
[% IF curProject.jobsets && curProject.jobsets.size > 0 || edit %]
[% IF project.jobsets && project.jobsets.size > 0 || edit %]
[% IF edit %]
<p><button type="button" id="add-jobset">Add a new jobset</button></p>
@ -250,7 +250,7 @@
</script>
[% END %]
[% FOREACH jobset IN curProject.jobsets -%]
[% FOREACH jobset IN project.jobsets -%]
[% INCLUDE renderJobset jobset=jobset baseName=jobset.name %]
[% END -%]
@ -271,7 +271,7 @@
[% IF !create %]
<form action="[% c.uri_for('/project' curProject.name 'delete') %]" method="post">
<form action="[% c.uri_for('/project' project.name 'delete') %]" method="post">
<p><button id="delete-project" type="submit"><img src="/static/images/failure.gif" />Delete this project</button></p>
</form>

View file

@ -5,8 +5,8 @@
<h1>Release Set <tt>[% releaseSet.project.name %]:[% releaseSet.name %]</tt></h1>
<p>
[<a href="[% c.uri_for('/releases' curProject.name releaseSet.name "edit") %]">Edit</a>]
[<a href="[% c.uri_for('/release' curProject.name releaseSet.name "latest") %]">Latest</a>]
[<a href="[% c.uri_for('/releases' project.name releaseSet.name "edit") %]">Edit</a>]
[<a href="[% c.uri_for('/release' project.name releaseSet.name "latest") %]">Latest</a>]
</p>
<table class="tablesorter">

View file

@ -5,24 +5,24 @@
[% IF releaseSets.size > 0 %]
<p>Project <tt>[% curProject.name %]</tt> has the following release sets:</p>
<p>Project <tt>[% project.name %]</tt> has the following release sets:</p>
<ul>
[% FOREACH releaseSet IN releaseSets %]
<li>
<a href="[% c.uri_for('/releases' curProject.name releaseSet.name) %]"><tt>[% releaseSet.name %]</tt></a>
[<a href="[% c.uri_for('/releases' curProject.name releaseSet.name "edit") %]">Edit</a>]
<a href="[% c.uri_for('/releases' project.name releaseSet.name) %]"><tt>[% releaseSet.name %]</tt></a>
[<a href="[% c.uri_for('/releases' project.name releaseSet.name "edit") %]">Edit</a>]
</li>
[% END %]
</ul>
[% ELSE %]
<p>Project <tt>[% curProject.name %]</tt> has no release sets.</p>
<p>Project <tt>[% project.name %]</tt> has no release sets.</p>
[% END %]
<p>[<a href="[% c.uri_for('/create_releaseset' curProject.name) %]">Create a new release set</a>]</p>
<p>[<a href="[% c.uri_for('/create_releaseset' project.name) %]">Create a new release set</a>]</p>
[% END %]