[Bps-public-commit] r9101 - in SVKUI: . trunk/lib/SVKUI/View

clsung at bestpractical.com clsung at bestpractical.com
Thu Sep 20 04:27:55 EDT 2007


Author: clsung
Date: Thu Sep 20 04:27:53 2007
New Revision: 9101

Added:
   SVKUI/trunk/lib/SVKUI/View/
   SVKUI/trunk/lib/SVKUI/View/browse.pm
Modified:
   SVKUI/   (props changed)
   SVKUI/trunk/lib/SVKUI/Dispatcher.pm
   SVKUI/trunk/lib/SVKUI/View.pm

Log:
 r9176 at going04:  clsung | 2007-09-20 16:27:47 +0800
 - seperate output of list/annotate command to browse.pm
 - Jifty learned => import_templates


Modified: SVKUI/trunk/lib/SVKUI/Dispatcher.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI/Dispatcher.pm	(original)
+++ SVKUI/trunk/lib/SVKUI/Dispatcher.pm	Thu Sep 20 04:27:53 2007
@@ -99,6 +99,17 @@
     show '/sync/view';
 };
 
+on qr'^/browse/([^/]+)(?:/([^/]+)/?)?$' => run {
+    my $name    = $1;
+    my $cmd     = $2 || 'list';
+
+    $name = URI::Escape::uri_unescape($name);
+
+    set command => $cmd;
+    set proj_name => $name;
+    show '/browse';
+};
+
 on qr'^/ia2/([^/]+)(?:/([^/]+)/?)?$' => run {
     my $name    = $1;
     my $cmd     = $2 || '';

Modified: SVKUI/trunk/lib/SVKUI/View.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI/View.pm	(original)
+++ SVKUI/trunk/lib/SVKUI/View.pm	Thu Sep 20 04:27:53 2007
@@ -7,7 +7,6 @@
 
 use SVK::XD;
 use SVK;
-use Data::Dumper;
 
 template 'about' => page {
     title { _('About SVKUI') };
@@ -269,4 +268,33 @@
     }
 };
 
+require SVKUI::View::browse;
+import_templates SVKUI::View::browse under '/browse';
+
+template 'browse' => page {
+    title { _('Browse SVKUI projects') };
+    my $proj_name = get('proj_name');
+    my $cmd = get('command') || 'list';
+    my $relpath = get ('path') || '';
+    my $proj = SVKUI::Model::Project->new();
+    $proj->load_by_cols( name => $proj_name );
+    if (!$proj->id or ($cmd ne 'list' and $cmd ne 'annotate')) {  # project record not found
+        redirect '/';
+    }
+
+    my $command = SVKUI::Model::Command->new();
+    my $ret;
+
+    my $rootpath = Jifty->config->app('checkoutroot')."/".$proj->name;
+    my $args = $cmd eq 'list' ? '-v' : '-x';
+    $ret = $command->cmd($cmd, $args, $rootpath.'/'.$relpath);
+    if ($ret) {
+	set proj => $proj;
+	show '/__jifty/error/command_failed';
+    } else {
+	set ( output_raw => $command->output_raw, proj_name => $proj_name, relpath => $relpath );
+	show ('browse/'.$cmd);
+    }
+};
+
 1;

Added: SVKUI/trunk/lib/SVKUI/View/browse.pm
==============================================================================
--- (empty file)
+++ SVKUI/trunk/lib/SVKUI/View/browse.pm	Thu Sep 20 04:27:53 2007
@@ -0,0 +1,84 @@
+package SVKUI::View::browse;
+use utf8;
+use strict;
+use warnings;
+use Jifty::View::Declare -base;
+
+template annotate => sub {
+    my $self = shift;
+    my $output_raw = get('output_raw');
+    my @lines = split /\n/, $output_raw;
+    my $last_rev = -1;
+    my $line_no = 0;
+    my @styles = ( '#e0e0e0', '#f7f7f7' );
+    my $index_style = 0;
+    table { {class is 'listing' } { id is 'dirlist' } {summary is 'Browse Listing'} 
+	thead { 
+	    row {
+		th { 'Line #' }
+		th { {class is 'chgset' } 'Revision' }
+		th { {class is 'author' } 'Author' }
+		th {}
+	    }
+	}
+	tbody {
+	for my $_line (@lines) {
+	    my ($_rev, $_author, $_time, $_content) = ($_line =~ m/^ *(\d+)\t+\( *(\w+) ([\d-]+)\):\t+(.*)$/);
+	    next unless defined ($_rev);
+	    $index_style = ($index_style + 1) % 2 if ($last_rev != $_rev);
+	    row {
+		cell { $line_no };
+		cell { {class is 'chgset'} $_rev if ($last_rev != $_rev) };
+		cell { {class is 'author', align is 'center'} $_author };
+		cell { {style is "white-space: pre; background: $styles[$index_style];" } $_content }
+	    }
+	    $line_no++;
+	    $last_rev = $_rev;
+	} # for
+	};
+    };
+};
+
+template list => sub {
+    my $self = shift;
+    warn "hihihi";
+    my $proj_name = get('proj_name');
+    my $relpath = get('relpath');
+    my $output_raw = get('output_raw');
+    my @relpaths = split /\n/, $output_raw;
+    table { {class is 'listing' } { id is 'dirlist' } {summary is 'Browse Listing'} 
+	thead { 
+	    row {
+		th { {class is 'name' } 'Name' }
+		th { {class is 'rev' } 'Revision' }
+		th { {class is 'size' } 'Size' }
+		th { {class is 'age' } 'Age' }
+		th { {class is 'change' } 'Last Change' }
+	    }
+	}
+	tbody {
+	for my $_relpath (@relpaths) {
+	    my (undef, $_rev, $_last, $_size, $_mon, $_day, $_time, $_name) = split / {1,12}/, $_relpath;
+	    row {
+		if ($_relpath =~ m#/$#m) {
+		cell { {class is 'name'}
+		    Jifty->web->link (url => '/browse/'.$proj_name."/list?path=$relpath/$_name", 
+			label => $_name, class => 'dir');
+		};
+		} else {
+		cell {
+		    Jifty->web->link (url => '/browse/'.$proj_name."/annotate?path=$relpath/$_name", 
+			label => $_name, class => 'file');
+		};
+		}
+		cell { {class is 'rev'} $_rev };
+		cell { {class is 'size'} $_size };
+		cell { {class is 'age'} 'N/A' };
+		cell { {class is 'change'} $_last };
+	    } # row
+	} # for
+	};
+    };
+};
+
+1;



More information about the Bps-public-commit mailing list