implement changes filter
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 May 2010 17:59:03 +0000 (19:59 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 23 May 2010 17:59:03 +0000 (19:59 +0200)
lib/MojoFacets/Changes.pm
public/mojo_facets.css
templates/changes/index.html.ep

index 752b709..9c07764 100644 (file)
@@ -10,20 +10,27 @@ use Storable;
 sub index {
        my $self = shift;
 
 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\.(.+))$} ) {
 
        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
                } 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 );
 }
 
 
 }
 
 
index 6a1a959..ab09c72 100644 (file)
@@ -140,3 +140,7 @@ span.d {
 .saved {
        background: #ffe;
 }
 .saved {
        background: #ffe;
 }
+
+form.action_filter {
+       float: right;
+}
index 464d0d4..1550bbf 100644 (file)
@@ -1,6 +1,19 @@
 % layout 'default';
 <h2><%= $message %></h2>
 
 % 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>
 <ul>
 % foreach my $change ( @$changes ) {
 <li>
@@ -11,3 +24,4 @@
 
 % my $more = ( $#$changes ) * 10;
 Show <a href="<%= url_for( controller => 'changes', action => 'index' )->query( max => $more ) %>"><%= $more %> changes</a>
 
 % my $more = ( $#$changes ) * 10;
 Show <a href="<%= url_for( controller => 'changes', action => 'index' )->query( max => $more ) %>"><%= $more %> changes</a>
+