[Jifty-commit] r6978 - in wifty/trunk/lib/Wifty: .

Jifty commits jifty-commit at lists.jifty.org
Mon May 11 16:19:27 EDT 2009


Author: ruz
Date: Mon May 11 16:19:26 2009
New Revision: 6978

Added:
   wifty/trunk/lib/Wifty/View/Users.pm
Modified:
   wifty/trunk/lib/Wifty/Dispatcher.pm
   wifty/trunk/lib/Wifty/View.pm

Log:
* add Users' stats I had in the checkout for months

Modified: wifty/trunk/lib/Wifty/Dispatcher.pm
==============================================================================
--- wifty/trunk/lib/Wifty/Dispatcher.pm	(original)
+++ wifty/trunk/lib/Wifty/Dispatcher.pm	Mon May 11 16:19:26 2009
@@ -11,6 +11,13 @@
     $top->child( Home   => url => "/",                 label => _("Home") );
     $top->child( Recent => url => "/recent/changes",   label => _("Recent Changes") );
     $top->child( New    => url => "/recent/additions", label => _("New") );
+    if ( Jifty->web->current_user->id ) {
+        $top->child(
+            Stats => url =>
+            "/user/". Jifty->web->escape_uri(Jifty->web->current_user->username),
+            label => _("Stats"),
+        );
+    }
     $top->child( Search => url => "/search",           label => _("Search") );
 };
 
@@ -127,6 +134,14 @@
     show('/feeds/atom/pages');
 };
 
+on 'user/*' => run {
+    my $user = Wifty::Model::User->load_by_cols( name => URI::Escape::uri_unescape($1) );
+    abort(404) unless $user && $user->id;
+
+    set(user => $user);
+    show('/user/stats');
+};
+
 sub setup_page_nav {
     my ($prefix, $page, $rev) = @_;
 

Modified: wifty/trunk/lib/Wifty/View.pm
==============================================================================
--- wifty/trunk/lib/Wifty/View.pm	(original)
+++ wifty/trunk/lib/Wifty/View.pm	Mon May 11 16:19:26 2009
@@ -7,6 +7,9 @@
 require Wifty::View::Feeds;
 alias Wifty::View::Feeds under 'feeds/';
 
+require Wifty::View::Users;
+alias Wifty::View::Users under 'user/';
+
 template 'robots.txt' => sub {
 outs_raw('User-agent: *
 Disallow: /history
@@ -102,7 +105,9 @@
                 label => $rev->created,
                 url   => '/view/' . $page->name . '/' . $rev->id
             );
-            outs( ' (' . $rev->created_by->friendly_name . ')' );
+            outs(' (');
+            user($rev->created_by);
+            outs(')');
             outs( ' ', _('%1 bytes', length $rev->content ) );
             render_region(
                 'revision-'. $rev->id .'-diff',
@@ -228,23 +233,48 @@
 };
 
 private template page_list => sub {
-    my ( $pages, $id ) = get(qw(pages id));
-    dl {{ id is $id, class is "pagelist" }
-        while ( my $page = $pages->next ) {
-            dt {
-                hyperlink(
-                    label => $page->name,
-                    url   => '/view/' . $page->name
-                );
-            };
-            dd {
-                outs( $page->updated );
-                outs( ' - ('. $page->updated_by->friendly_name .')' );
-            };
-        }
+    my ($pages, $id, $hide) = get(qw(pages id hide));
+    my %hide = map {$_ => 1} @{ $hide || [] };
+
+    table { attr { id => $id, class => "pagelist" };
+        unless ( $hide{'header'} ) { row {
+            th {_('Page')};
+            th {_('Updated')} unless $hide{'updated'};
+            th {_('Created')} unless $hide{'created'};
+        } }
+        while ( my $page = $pages->next ) { row {
+            cell { hyperlink(
+                label => $page->name,
+                url   => '/view/' . $page->name
+            ) };
+            unless ( $hide{'updated'} ) {
+                cell { date_user( $page->updated, $page->updated_by ) }
+            }
+            unless ( $hide{'created'} ) {
+                cell { date_user( $page->created, $page->created_by ) }
+            }
+        } }
     };
 };
 
+sub date_user {
+    my ($date, $user) = @_;
+    return outs( _('%1 by %2', $date, $user->friendly_name ) )
+        unless $user->id;
+
+    return a { attr { href => '/user/'. $user->name };
+        _('%1 by %2', $date, $user->friendly_name)
+    }
+}
+
+sub user {
+    my $user = shift;
+    return $user->friendly_name unless $user->id;
+    return a { attr { href => '/user/'. $user->name };
+        $user->friendly_name
+    }
+}
+
 template 'helpers/diff' => sub {
     my ($from, $to, $show) = get(qw(from to show));
     hyperlink

Added: wifty/trunk/lib/Wifty/View/Users.pm
==============================================================================
--- (empty file)
+++ wifty/trunk/lib/Wifty/View/Users.pm	Mon May 11 16:19:26 2009
@@ -0,0 +1,31 @@
+use warnings;
+use strict;
+
+package Wifty::View::Users;
+use Jifty::View::Declare -base;
+
+template stats => page {
+    my ($user) = get('user');
+    page_title is _('Statistics of user %1', $user->friendly_name );
+
+    set(type => 'updated'); show('recently');
+    set(type => 'created'); show('recently');
+};
+
+private template recently => sub {
+    my ($user, $type) = get('user', 'type');
+    
+    my $method = 'recently_'. $type;
+    my $pages = Wifty::Model::PageCollection->$method;
+    $pages->limit( column => $type .'_by', value => $user->id );
+
+    h1 { $type eq 'updated'? _('Recenly updated') : _('Recently created') };
+    set(
+        pages => $pages,
+        id => 'recent-user-updates',
+        hide => [$type],
+    );
+    show('/page_list');
+};
+
+1;


More information about the Jifty-commit mailing list