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