sub index {
my $self = shift;
- my $max = $self->param('max') || 10;
+ my $max = $self->param('max') || 50;
+ my $action_regex = join('|', $self->param('action_filter'));
+ warn "# action_regex $action_regex\n";
+
+ my $actions;
my $changes;
foreach my $path ( sort { $b cmp $a } glob '/tmp/changes/*' ) {
if ( $path =~ m{/((\d+\.\d+)\.data\.(.+))$} ) {
- push @$changes, { uid => $1, t => $2, action => $3 };
- last if $#$changes >= $max;
+ my ( $uid, $t, $action ) = ( $1, $2, $3 );
+ $actions->{$action}++;
+ next if $action_regex && $action !~ m/^($action_regex)$/;
+ push @$changes, { uid => $uid, t => $t, action => $action }
+ if $#$changes < $max;
} else {
warn "ignore: $path\n";
}
}
# Render template "changes/index.html.ep" with message
- $self->render(message => 'Latest Changes', changes => $changes );
+ $self->render(message => 'Latest Changes', changes => $changes, actions => $actions );
}
% layout 'default';
<h2><%= $message %></h2>
+<form class=action_filter>
+<input type=submit value="Filter changes">
+<ul>
+% foreach my $type ( sort keys %$actions ) {
+<li><label>
+<input type=checkbox name=action_filter value="<%= $type %>">
+<%= $type %><span class=count><%= $actions->{$type} %></span>
+</label>
+% }
+</ul>
+<input type=submit value="Filter changes">
+</form>
+
<ul>
% foreach my $change ( @$changes ) {
<li>
% my $more = ( $#$changes ) * 10;
Show <a href="<%= url_for( controller => 'changes', action => 'index' )->query( max => $more ) %>"><%= $more %> changes</a>
+