implement tabbed search

This commit is contained in:
Oliver Gorwits
2012-01-07 02:21:19 +00:00
parent b9a11449a4
commit 3f500de477
11 changed files with 863 additions and 217 deletions

View File

@@ -1,13 +1,15 @@
package Netdisco;
use Dancer ':syntax';
use Dancer::Plugin::Ajax;
use Dancer::Plugin::Database;
use Digest::MD5 ();
hook 'before' => sub {
if (! session('user') && request->path !~ m{^/login}) {
var(requested_path => request->path);
request->path_info('/');
session(user => 'oliver'); # XXX
#var(requested_path => request->path);
#request->path_info('/');
}
};
@@ -15,6 +17,35 @@ get '/' => sub {
template 'index';
};
ajax '/ajax/content/search/:thing' => sub {
return '';
};
post '/search' => sub {
my $q = param('q');
if ($q and not param('tab')) {
# pick most likely tab for initial results
if ($q =~ m/^\d+$/) {
params->{'tab'} = 'vlan';
}
else {
params->{'tab'} = 'device';
}
}
elsif (not $q) {
redirect '/';
return;
}
# set up default search options for each type
if (param('tab') and param('tab') ne 'node') {
params->{'stamps'} = 'checked';
params->{'vendor'} = 'checked';
}
template 'search';
};
post '/login' => sub {
if (param('username') and param('password')) {
my $user = database->quick_select('users',
@@ -38,7 +69,9 @@ get '/logout' => sub {
};
any qr{.*} => sub {
redirect '/?notfound=1';
var('notfound' => true);
status 'not_found';
template 'index';
};
true;