remove hash from first column name
[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
11 sub index {
12         my $self = shift;
13
14         my $max = $self->param('max') || 50;
15         my $action_regex = join('|', $self->param('action_filter'));
16         warn "# action_regex $action_regex\n";
17
18         my $actions;
19
20         my $stats;
21         foreach my $path ( sort { $b cmp $a } glob '/tmp/actions/*' ) {
22                 if ( $path =~ m{/((\d+\.\d+)\.data\.(.+))$} ) {
23                         my ( $uid, $t, $action ) = ( $1, $2, $3 );
24                         $stats->{$action}++;
25                         next if $action_regex && $action !~ m/^($action_regex)$/;
26                         push @$actions, { uid => $uid, t => $t, action => $action }
27                                 if $#$actions < $max;
28                 } else {
29                         warn "ignore: $path\n";
30                 }
31         }
32
33         # Render template "actions/index.html.ep" with message
34         $self->render(actions => $actions, stats => $stats );
35 }
36
37
38 sub view {
39         my $self = shift;
40         my $uid = $self->param('uid');
41         $self->render( change => retrieve( "/tmp/actions/$uid" ), uid => $uid );
42 }
43
44 1;