/[simile]/svn/index.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /svn/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (show annotations)
Tue Oct 28 19:10:16 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 6205 byte(s)
Unroll radio buttons into table by first letter of repository.

Much more readable and easier to navigate
1 #!/usr/bin/perl -w
2
3 # svn2js.pl
4 #
5 # 10/05/08 16:15:38 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6
7 use strict;
8 use XML::Simple;
9 use Data::Dump qw/dump/;
10 use JSON;
11 use CGI;
12 use File::Slurp;
13
14 my $debug = $ENV{'DEBUG'} || 0;
15
16 my $config_path = $0;
17 $config_path =~ s/.cgi/.js/;
18
19 my $hostname = `hostname -s`;
20 chomp($hostname);
21 $hostname .= '.js';
22 $config_path = $hostname if -e $hostname;
23
24 my $config = from_json( read_file( $config_path ) );
25 my $repository_dir = $config->{repository_dir} || die "no repository_dir in $config_path";
26 my $svnweb = $config->{svnweb} || die "no svnweb in $config_path";
27 die "no js URLs to Exhibit API and/or plugins" unless $config->{js};
28
29 my $limit = 1000;
30
31 # for older JSON
32 #sub encode_json { objToJson( @_ ) }
33
34 sub path_strip {
35 my $path = shift;
36 # $path =~ $strip_branch;
37 return $path;
38 }
39
40 opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!";
41 my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir);
42 closedir($dir);
43
44 our $q = CGI->new;
45 my $repository = $q->param('repository');
46 $repository = (grep { m/^\Q$repository\E$/ } @repositories )[0] if $repository;
47
48 warn "q = ",dump( $q );
49 warn "# limit: ", $q->param('limit');
50
51 sub select_repository {
52 my $onChange = qq{document.getElementById('current_repository').submit();};
53 # we want to activete javascript magic refresh after we hit submit for the first time, and not always
54 $onChange = '' unless $q->param('did_submit');
55 my $first_letter = substr($repositories[0],0,1);
56 return (
57 $q->start_form( -name => 'current_repository', -id => 'current_repository', -method => 'post' ),
58 "From repository ",
59 $q->param('did_submit') ?
60 $q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ) :
61 "<table><tr><th>$first_letter</th><td>" . join( '', map {
62 my $delimiter = '';
63 if ( substr($_,0,1) ne $first_letter ) {
64 $first_letter = substr($_,0,1);
65 $delimiter = "</td></tr>\n<tr><th>$first_letter</th><td>";
66 }
67 $delimiter . $q->radio_group( -name => 'repository', -values => [ $_ ] )
68 } @repositories ) . "<td></tr></table>",
69 #$q->radio_group( -name => 'repository', -values => [ map { "$_, " } @repositories ], -onChange => $onChange ), # , -linebreak => 'true' ),
70 " show ",
71 $q->popup_menu( -name => 'limit', -values => [ qw/100 500 1000 5000 10000/ ], -onChange => $onChange ),
72 " revisions and ",
73 $q->checkbox(-name=>'path', -checked=>1, -value=>'ON', -label=>'path modifications', -onChange => $onChange ),
74 " ",
75 $q->submit(-value=>'in Exhibit'),
76 $q->hidden(-name=>'did_submit', -value=>1),
77 $q->end_form
78 );
79 }
80
81 if ( ! $repository ) {
82 print $q->header,$q->start_html("Select repository"), select_repository;
83 exit;
84 } elsif ( ! $q->param('json') ) {
85 $repository ||= 'Select repository';
86 print $q->header, qq|
87 <html>
88 <head>
89 <title>$repository -- Exhibit SVN exhibit facet browsing</title>
90
91 <link rel="exhibit/data"
92 type="application/json"
93 href="|, $q->url( -query => 1 ), qq|&json=1" />
94
95 |, join("\n", map { qq|<script src="$_" type="text/javascript"></script>| } @{ $config->{js} } ), qq|
96
97 </head>
98 <body>
99 <div style="float: right">
100 <a href="http://stud05.technikum-wien.at/~tw05n126/exhibit/log/log.html">based on</a>,
101 <a href="http://simile.mit.edu/exhibit/">exhibit</a></div>
102 |, select_repository, qq|
103 <table width="100%" style="font-size: 0.8em">
104 <tr valign="top">
105 <td rowspan="2" width="25%">
106 <div ex:role="facet" ex:facetClass="TextSearch" ex:facetLabel="Search"></div>
107
108 <div ex:role="facet" ex:expression=".author" ex:facetLabel="Author"
109 ex:sortMode="count"></div>
110 |, $q->param('path') ?
111 qq|
112 <div ex:role="facet" ex:expression=".action" ex:facetLabel="Action"
113 ex:sortMode="count" ex:scroll="false"></div>
114 | : '',
115 qq|
116 <div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange"
117 ex:interval="20" ex:scroll="true"></div>
118 |, $q->param('path') ?
119 qq|
120 <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Count"
121 ex:sortMode="count"></div>
122 | : '',
123 qq|
124 </td>
125 <td>
126
127 <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Name"
128 ex:sortMode="value"></div>
129 </td>
130 </tr>
131 <tr valign="top">
132 <td ex:role="viewPanel">
133
134 <div ex:role="view" ex:viewClass="Timeline" ex:start=".date"
135 ex:colorKey=".author"
136 ex:topBandUnit="week" ex:topBandPixelsPerUnit="200"
137 ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25"
138 ex:timelineHeight="550" />
139
140 <div ex:role="view" ex:viewClass="Tabular"
141 ex:columns=".revision, .author, .date, .PATH, .action, .copyfrom-path, .copyfrom-rev, .msg"
142 />
143 </td>
144
145 </tr>
146 </table>
147
148 </body>
149 </html>
150 |;
151 exit;
152 }
153
154 my $json = {
155 properties => {
156 revision => {
157 valueType => "number",
158 },
159 'google-code-svn-link' => {
160 valueType => "url"
161 }
162 },
163 items => [],
164 };
165
166 my $log;
167 {
168 my $cmd = "svn log --xml --stop-on-copy -v --limit " . ( $q->param('limit') || $limit ) . " file://$repository_dir/$repository";
169 warn "cmd: $cmd\n";
170 open( my $log_fh, '-|', $cmd) || die "can't read svn log: $!";
171 local $/ = undef;
172 $log = <$log_fh>;
173 close( $log_fh );
174 }
175
176 my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
177
178 warn dump( $xml ) if $debug;
179
180 foreach my $e (@{$xml->{'logentry'}}) {
181
182 foreach my $p (@{$e->{'paths'}->{'path'}}) {
183 my $path = delete( $p->{'content'} );
184 my $label = $e->{'revision'} . ' - ' . path_strip( $path );
185 my $item = {
186 type => 'Item',
187 id => $label,
188 label => $label,
189 uri => sprintf($svnweb, $repository, $e->{'revision'}),
190 path_full => $path,
191 path => path_strip( $path ),
192 };
193
194 $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p;
195 $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e;
196
197 warn dump( $item ) if $debug;
198
199 push @{ $json->{items} }, $item;
200
201 last if ! $q->param('path');
202 }
203
204 }
205
206 print qq|Content-type: application/json\n\r\n\r|, encode_json( $json );
207

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26