--- svn/svn2js.cgi 2008/10/05 18:45:10 14 +++ svn/index.cgi 2008/10/06 17:09:17 16 @@ -8,13 +8,119 @@ use XML::Simple; use Data::Dump qw/dump/; use JSON; +use CGI; my $debug = 0; my $max_items = 500; -my $repository = 'file:///home/dpavlin/.svk/strix4/'; -my $svnweb = 'http://localhost/svnweb/svk/index.cgi/strix4/revision?rev='; +my $repository_dir = '/srv/svn'; +my $svnweb = 'https://svn-strix.carnet.hr/private/svnweb/index.cgi/%s/revision?rev=%d'; +my $strip_branch = s!^/(branches/)?[^/]+/!/!; + +# my local config for development +$repository_dir = '/home/dpavlin/private/svn'; +$svnweb = 'http://localhost/svnweb/index.cgi/%s/revision?rev=%d'; +$strip_branch = s!!!; + +# for older JSON +#sub encode_json { objToJson( @_ ) } + +sub path_strip { + my $path = shift; + $path =~ $strip_branch; + return $path; +} + +opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!"; +my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir); +closedir($dir); + +our $q = CGI->new; +my $repository = $q->param('repository'); +$repository = (grep { m/^\Q$repository\E$/ } @repositories )[0]; + +sub select_repository { + $q->start_form( -name => 'current_repository', -id => 'current_repository' ), + "Select repository: ", + $q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => qq{document.getElementById('current_repository').submit();} ), + $q->submit, + $q->end_form; +} + +if ( ! $repository ) { + print $q->header,$q->start_html("Select repository"), select_repository; + exit; +} elsif ( ! $q->param('json') ) { + $repository ||= 'Select repository'; + print $q->header, qq| + +
++ + + + + + + + + + + | ++ + + | +
+ + + + + | + +