This allows searching for projects, jobsets or jobs by name or description.
UICHT2PSN2QOCHP6MGY5QQJUDU4IF6FBIOJLBA55QBJDK6ST566AC
VH5ZABDRP565VZIG55YHNYYPST53NQ2J6YM362NSLXCAHI5WPH4AC
HRAFVVOEGQJQS4XQNZSMNYN2SUZGKEGPSJUDZUBMI2IN32WFNQ4QC
J5UVLXOK6EDIL5I7VKWH4V2QDS4DPD7FHRK6XBWSXFRQS4JKXFZQC
OEPUOUNBNTHTFZVDXREGBQCKFRCWMVP2MDVK4OA47VK2DBKEWVYAC
G4X5IUYJHZSEXAGFG5DRIJEHFBSQDQ2UTIJ4FCILIPZAUHGQ3GTQC
SBMOICGVH2B2FBFHL2D767XC4LC2Y6SF4TYGY3I6TSNMLYV27GUQC
D5QIOJGPKQJIYBUCSC3MFJ3TXLPNZ2XMI37GXMFRVRFWWR2VMTFAC
7ZQAHJQMEEREYP3PZAPO5JUMEDX4CNNJCCHTFQNEPOZZUJCIOVHQC
QL55ECJ6KMMBUOWQ6LKSOVN7L43CH4S6SPE2AQ3VX3KSGC32RP4AC
JZVRK5QJGPDT7HNQLC2UOJRG6V6QO4NJJ5V5QEMQ6VUTUIQWHG5AC
}
sub search :Local Args(0) {
my ($self, $c) = @_;
$c->stash->{template} = 'search.tt';
my $query = trim $c->request->params->{"query"};
error($c, "Query is empty.") if $query eq "";
error($c, "Invalid character in query.")
unless $query =~ /^[a-zA-Z0-9_\-]+$/;
$c->stash->{projects} = [ $c->model('DB::Projects')->search(
{ -or => [ name => { ilike => "%$query%" }, displayName => { ilike => "%$query%" }, description => { ilike => "%$query%" } ] },
{ order_by => ["name"] } ) ];
$c->stash->{jobsets} = [ $c->model('DB::Jobsets')->search(
{ -or => [ name => { ilike => "%$query%" }, description => { ilike => "%$query%" } ] },
{ order_by => ["project", "name"] } ) ];
$c->stash->{jobs} = [ $c->model('DB::Jobs')->search(
{ name => { ilike => "%$query%" } },
{ order_by => ["project", "jobset", "name"] } ) ];
[% WRAPPER layout.tt title="Search results" %]
[% PROCESS common.tt %]
[% IF projects.size > 0; matched = 1 %]
<p>The following projects match your query:</p>
<table class="table table-striped table-condensed">
<thead>
<tr><th>Project</th><th>Description</th></tr>
</thead>
<tbody>
[% FOREACH p IN projects %]
<tr>
<td>[% INCLUDE renderProjectName project=p.name %]</td>
<td>[% HTML.escape(p.description) %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF jobsets.size > 0; matched = 1 %]
<p>The following jobsets match your query:</p>
<table class="table table-striped table-condensed">
<thead>
<tr><th>Jobset</th><th>Description</th></tr>
</thead>
<tbody>
[% FOREACH j IN jobsets %]
<tr>
<td>[% INCLUDE renderFullJobsetName project=j.get_column('project') jobset=j.name %]</td>
<td>[% HTML.escape(j.description) %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF jobs.size > 0; matched = 1 %]
<p>The following jobs match your query:</p>
<table class="table table-striped table-condensed">
<thead>
<tr><th>Job</th></tr>
</thead>
<tbody>
[% FOREACH j IN jobs %]
<tr>
<td>[% INCLUDE renderFullJobName project=j.get_column('project') jobset=j.get_column('jobset') job=j.name %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]
[% IF !matched %]
<div class="alert alert-warn">Sorry! Nothing matches your
query.</div>
[% END %]
[% END %]
[% IF c.user_exists %]
[% INCLUDE makeLink uri = c.uri_for(c.controller('Root').action_for('logout')) title = "Sign out" %]
[% ELSE %]
[% INCLUDE makeLink uri = c.uri_for(c.controller('Root').action_for('login')) title = "Sign in" %]
[% END %]
<div class="pull-right">
</ul>
<form class="navbar-search" action="[% c.uri_for('/search') %]">
<input name="query" type="text" class="search-query span2" placeholder="Search"></input>
</form>
<ul class="nav" id="top-menu">
[% IF c.user_exists %]
[% INCLUDE makeLink uri = c.uri_for(c.controller('Root').action_for('logout')) title = "Sign out" %]
[% ELSE %]
[% INCLUDE makeLink uri = c.uri_for(c.controller('Root').action_for('login')) title = "Sign in" %]
[% END %]
</ul>
</div>