move /changes to root
[MojoFacets.git] / lib / MojoFacets / Actions.pm
1 package MojoFacets::Actions;
2
3 use strict;
4 use warnings;
5
6 use base 'Mojolicious::Controller';
7
8 use Storable;
9 use Data::Dump qw(dump);
10 use MojoFacets::Data;
11
12 sub index {
13         my $self = shift;
14
15         my $max = $self->param('max') || 50;
16         my $action_regex = join('|', $self->param('action_filter'));
17         warn "# action_regex $action_regex\n";
18
19         my $actions;
20
21         my $stats;
22         foreach my $path ( sort { $b cmp $a } glob '/tmp/actions/*' ) {
23                 if ( $path =~ m{/((\d+\.\d+)\.data\.(.+))$} ) {
24                         my ( $uid, $t, $action ) = ( $1, $2, $3 );
25                         $stats->{$action}++;
26                         next if $action_regex && $action !~ m/^($action_regex)$/;
27                         push @$actions, { uid => $uid, t => $t, action => $action }
28                                 if $#$actions < $max;
29                 } else {
30                         warn "ignore: $path\n";
31                 }
32         }
33
34         # Render template "actions/index.html.ep" with message
35         $self->render(actions => $actions, stats => $stats );
36 }
37
38
39 sub view {
40         my $self = shift;
41         my $uid = $self->param('uid');
42         $self->render( change => retrieve( "/tmp/actions/$uid" ), uid => $uid );
43 }
44
45 1;