From 45605291eff0216a8d0b4e1d22dde4a3d69cbb15 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Mon, 24 Jan 2011 20:53:24 +0100 Subject: load tasks and display them on the dashboard --- lib/jitterbug.pm | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'lib/jitterbug.pm') diff --git a/lib/jitterbug.pm b/lib/jitterbug.pm index c876cb6..2da9e09 100644 --- a/lib/jitterbug.pm +++ b/lib/jitterbug.pm @@ -9,9 +9,16 @@ our $VERSION = '0.1'; load_app 'jitterbug::Hook', prefix => '/hook'; load_app 'jitterbug::Project', prefix => '/project'; load_app 'jitterbug::WebService', prefix => '/api'; -#load_app 'jitterbug::Task', prefix => '/task'; +load_app 'jitterbug::Task', prefix => '/task'; get '/' => sub { + my $projects = _get_projects(); + my ( $builds, $runnings ) = _get_builds(); + + template 'index', { projects => $projects, builds => $builds }; +}; + +sub _get_projects { my @projects = (); @@ -41,7 +48,25 @@ get '/' => sub { sort { $b->{last_build}->{timestamp} cmp $a->{last_build}->{timestamp} } @projects; - template 'index', {projects => \@projects}; -}; + return \@projects; +} + +sub _get_builds { + + my @builds = (); + my @runnings = (); + + my $builds = schema->resultset('Task')->search(); + while ( my $build = $builds->next ) { + my $build_desc = { + project => $build->project->name, + id => $build->id, + running => $build->running, + }; + $build->running ? push @runnings, $build_desc : push @builds, + $build_desc; + } + return ( \@builds, \@runnings ); +} true; -- cgit 1.4.1