/[pub]/suikawiki/script/misc/plugins/BugTrack.wps
Suika

Contents of /suikawiki/script/misc/plugins/BugTrack.wps

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Sat Feb 14 10:53:48 2004 UTC (21 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
FILE REMOVED
Removed

1 wakaba 1.1 Name:
2     BugTrack
3     FullName:
4     Wiki BugTracking System
5     URI:
6 wakaba 1.2 IW:SuikaWiki:"SuikaWiki//Plugin//BugTrack"
7 wakaba 1.1 Require:
8     SuikaWiki::Markup::XML SuikaWiki::Plugin::WikiLinking main
9     Initialize:
10     my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
11    
12     {
13     Name:
14     wikiform_input/bt--bug-list
15     FullName:
16     Bug list
17     Format:
18     $p->{ns} ||= $o->{page};
19     $p->{ns} .= '//' if substr ($p->{ns}, -2) ne '//';
20 wakaba 1.2 my $db = $o->_database;
21     my @bugs;
22     for (grep m!//[0-9]+//$!, $db->list_items ({ns => $p->{ns}, type => 'namespace', recursive => 0})) {
23     push @bugs, map {m!//([0-9]+)//([0-9]+)$!; [$_, $1*100+$2]} grep m!//[0-9]+$!, $db->list_items ({ns => $_, type => 'key', recursive => 0})
24     }
25 wakaba 1.1 my $props = SuikaWiki::Plugin->resource ('Plugin:BugTrack:Table:Row');
26     my $fmt = $o->formatter ('bt--bug-table-header');
27     $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'table');
28     $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'thead')
29     ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr')
30     ->append_node ($fmt->replace ($props, $o, {formatter => $fmt}));
31     $r->append_text ("\n");
32     $r->set_attribute (class => 'bt--bugtrack');
33     $fmt = $o->formatter ('bt--bug-item');
34     my $tb = $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tbody');
35     my $weight = {
36     Priority => {high => 1, normal => 2, low => 3},
37     Status => {open => 1, reserved => 2, closed => 3},
38     };
39     for $_ (sort {
40     $weight->{Status}->{$a->{prop}->{Status}||'open'}
41     <=> $weight->{Status}->{$b->{prop}->{Status}||'open'}
42     || $weight->{Priority}->{$a->{prop}->{Priority}||'normal'}
43     <=> $weight->{Priority}->{$b->{prop}->{Priority}||'normal'}
44     || $b->{lm} <=> $a->{lm}
45     || $a->{prop}->{Category} cmp $b->{prop}->{Category}
46     || $b->{bug_no} <=> $a->{bug_no}
47     } map {{
48     bug_ns => $p->{ns},
49 wakaba 1.2 bug_page => $_->[0],
50     bug_no => $_->[1],
51     prop => __PACKAGE__->get_bug_properties ($_->[0]),
52     lm => SuikaWiki::Plugin->_database->mtime ($_->[0]),
53 wakaba 1.1 }} @bugs) {
54     $o->{bt__bug} = $_;
55     my @class;
56     ## TODO: ensure each class name is NMTOKEN
57     push @class, $o->{bt__bug}->{prop}->{Status}||'open';
58     push @class, $o->{bt__bug}->{prop}->{Priority}||'normal';
59     push @class, $o->{bt__bug}->{prop}->{Category};
60     my $tr = $tb->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr');
61     $tr->append_node ($fmt->replace ($props, $o, {formatter => $fmt}));
62     $tr->set_attribute (class => join ' ', @class);
63     $tb->append_text ("\n");
64     }
65     }
66    
67     {
68     Name:
69     wikibt--bug-table-header/no
70     wikibt--bug-table-header/subject
71     wikibt--bug-table-header/priority
72     wikibt--bug-table-header/status
73     wikibt--bug-table-header/category
74     wikibt--bug-table-header/last-modified
75     FullName:
76     Table heading cell
77     Format:
78     $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'th');
79     $r->append_node ($o->resource ('Plugin:BugTrack:Column:'.$p->{-rule_name}), node_or_text => 1);
80     $r->set_attribute (scope => 'cols');
81     $r->set_attribute (class => $p->{-rule_name});
82     }
83    
84     {
85     Name:
86     wikibt--bug-table-header/-bare-text
87     wikibt--bug-item/-bare-text
88     FullName:
89     #text
90     Format:
91     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $p->{-bare_text});
92     }
93    
94     {
95     Name:
96     wikibt--bug-item/no
97     FullName:
98     Bug number
99     Format:
100     $r = __PACKAGE__->make_cell ($o, $p, SuikaWiki::Plugin::WikiLinking->to_wikipage_in_html ({
101     label => qq'%link-to-it(label=>{$o->{bt__bug}->{bug_no}},description=>{%page-name(absolute);}p);',
102     }, {
103     base => $o->{bt_bug}->{bug_ns},
104     page_name_relative => $o->{bt__bug}->{bug_page},
105     }, {
106     o => $o,
107     }));
108     }
109    
110     {
111     Name:
112     wikibt--bug-item/subject
113     FullName:
114     Bug subject
115     Format:
116     $r = __PACKAGE__->make_cell ($o, $p, SuikaWiki::Plugin::WikiLinking->to_wikipage_in_html ({
117     label => qq'%link-to-it(label=>{$o->{bt__bug}->{prop}->{Subject}},description=>{%page-name(absolute);}p);',
118     }, {
119     base => $o->{bt_bug}->{bug_ns},
120     page_name_relative => $o->{bt__bug}->{bug_page},
121     _with_lm => 1,
122     }, {
123     o => $o,
124     }));
125     }
126    
127     {
128     Name:
129     wikibt--bug-item/category
130     FullName:
131     Bug category
132     Format:
133     $r = __PACKAGE__->make_cell ($o, $p, $o->resource ('Category:'.($o->{bt__bug}->{prop}->{Category}||'(default)'), ns => $o->{bt__bug}->{bug_ns}.'Options//'));
134     }
135     {
136     Name:
137     wikibt--bug-item/last-modified
138     FullName:
139     Bug last modified
140     Format:
141     ## TODO: custom date format (Message::Field::Date)
142     my @time = gmtime $o->{bt__bug}->{lm};
143     $r = __PACKAGE__->make_cell ($o, $p, sprintf '%04d-%02d-%02d %02d:%02d:%02d +00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0]);
144     }
145     {
146     Name:
147     wikibt--bug-item/status
148     FullName:
149     Bug status
150     Format:
151     $r = __PACKAGE__->make_cell ($o, $p, $o->resource ('Status:'.($o->{bt__bug}->{prop}->{Status}||'(default)'), ns => $o->{bt__bug}->{bug_ns}.'Options//'));
152     }
153     {
154     Name:
155     wikibt--bug-item/priority
156     FullName:
157     Bug priority
158     Format:
159     $r = __PACKAGE__->make_cell ($o, $p, $o->resource ('Priority:'.($o->{bt__bug}->{prop}->{Priority}||'(default)'), ns => $o->{bt__bug}->{bug_ns}.'Options//'));
160     }
161    
162     {
163     Name:
164     wikiview-resource/bt--bug-no
165     FullName:
166     Bug number
167     Format:
168     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{bt__bug}->{bug_no});
169     }
170    
171     {
172     Name:
173     wikiform-input/bt--create-new-bug
174     FullName:
175     Create a new bug page
176     Format:
177     $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'form');
178     $r->set_attribute (action => $o->uri ('wiki'));
179     $r->set_attribute (method => 'post');
180     $r->set_attribute ('accept-charset' => 'iso-2022-jp, utf-8');
181     $r->set_attribute (class => 'bt--create-bug');
182     for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'input')) {
183     $_->set_attribute (type => 'hidden');
184     $_->set_attribute (name => 'mode');
185     $_->set_attribute (value => 'bt--bug-create');
186     }
187     for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'input')) {
188     $_->set_attribute (type => 'hidden');
189     $_->set_attribute (name => 'mypage');
190     $_->set_attribute (value => ($p->{ns} || $o->{page}));
191     }
192     $r->append_node ($p->{content}, node_or_text => 1);
193     }
194    
195     {
196     Name:
197     wikiview/bt--create-new-bug
198     FullName:
199     Create a new bug page
200     Format:
201     my @page = ('#?SuikaWiki/0.9');
202     for (qw/Subject Priority Status Category/) {
203     push @page, '- ' . $_ . ': ' . $main::form{'wikiform__'.$_};
204     }
205     push @page, '- Creation-Date: ' . main::_rfc3339_date (time);
206     push @page, '';
207     push @page, '[1] ' . $main::form{'wikiform__body'};
208    
209     $p->{ns} ||= $o->{page};
210     $p->{ns} .= '//' if substr ($p->{ns}, -2) ne '//';
211 wakaba 1.2 my $bugno = __PACKAGE__->get_new_bug_number ($p->{ns});
212     my $page = sprintf '%s%d//%d', $p->{ns}, int ($bugno / 100), ($bugno % 100);
213 wakaba 1.1 $main::database{$page} = join "\n", @page;
214     $o->{bt__bug} = {
215     bug_ns => $p->{ns},
216     bug_page => $page,
217 wakaba 1.2 bug_no => $bugno,
218 wakaba 1.1 prop => __PACKAGE__->get_bug_properties ($page),
219     };
220     }
221    
222     MODULE:
223     sub get_bug_properties ($$) {
224     my (undef, $bug_page) = @_;
225     my (undef, $bug_info) = (SuikaWiki::Plugin->magic_and_content ($main::database{ $bug_page }));
226     my %bug_prop;
227     for (split /\n/, $bug_info) {
228     tr/\x0A\x0D//d;
229     if (/^-\s*([0-9A-Za-z-]+)\s*:\s*(\S.*\S)/) {
230     $bug_prop{$1} = $2;
231     } elsif (!/^-/) {
232     last;
233     }
234     }
235     \%bug_prop;
236     }
237    
238     sub make_cell ($$$$) {
239     my (undef, $o, $p, $content) = @_;
240     my $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'td');
241     if ($p->{is_header}) {
242     $r->local_name ('th');
243     $r->set_attribute (scope => 'rows');
244     }
245     $r->append_node ($content, node_or_text => 1);
246     $r->set_attribute (class => $p->{-rule_name});
247     $r;
248     }
249    
250     sub get_new_bug_number ($$) {
251     my (undef, $bug_ns) = @_;
252 wakaba 1.2 my ($no, $no2) = (0, 0);
253     for (SuikaWiki::Plugin->_database->list_items ({ns => $bug_ns, type => 'namespace', recursive => 0})) {
254     if (m!//([0-9]+)//$!) {
255     $no = 0+$1 if $1 > $no;
256     }
257     }
258     $no ||= 1;
259     for (SuikaWiki::Plugin->_database->list_items ({ns => $bug_ns.$no.'//', type => 'key', recursive => 0})) {
260 wakaba 1.1 if (m!//([0-9]+)$!) {
261 wakaba 1.2 $no2 = 0+$1 if $1 > $no2;
262 wakaba 1.1 }
263     }
264 wakaba 1.2 $no = $no * 100 + $no2 + 1;
265     $no += 1 if int ($no % 100) == 0;
266     $no;
267 wakaba 1.1 }
268    
269    
270     SuikaWiki::View->definition (bt__bug_create => {
271     media => {type => 'text/html', charset => 1, expires => 60},
272     xmedia => {type => 'application/xhtml+xml', charset => 1, expires => 60},
273     preprocess => sub {
274     my %o = @_;
275     my $fmt = SuikaWiki::Plugin->formatter ('view');
276     $fmt->replace (q(%bt--create-new-bug;), $o{o}, {formatter => $fmt});
277 wakaba 1.3 my $uri = SuikaWiki::Plugin->_uri_wiki_page ($o{o}->{bt__bug}->{bug_page}, absolute => 1);
278     require SuikaWiki::Output::HTTP;
279     my $output = SuikaWiki::Output::HTTP->new (wiki => $main::WIKI);
280     $output->set_redirect (uri => $uri, status_code => 303);
281     $output->output (output => 'http-cgi');
282 wakaba 1.1 0;
283     },
284     template => <<'EOH'});
285     %html-document(title=>{%res(name=>{Plugin:BugTrack:Created:WebPageTitle});}p,link-meta=>{%predefined-template(name=>links);%html-meta(name=>ROBOTS,content=>NOINDEX);}p,content=>{
286     %section(level=>1,add-to-toc=>0,type=>body,title=>{%page-name;}p,heading,content=>{
287     %section(id=>tools1,class=>tools,add-to-toc=>0,content=>{%predefined-template(name=>navbar);}p);
288     %section(level=>2,add-to-toc=>0,content=>{
289     %paragraph(content=>{%res(name=>{Plugin:BugTrack:Created:Message});}p);
290     }p);
291     %section(id=>footer,add-to-toc=>0,content=>{%predefined-template(name=>footer);}p);
292     }p);
293     }p);
294     EOH
295    
296    
297     POD:LICENSE:
298     Copyright 2003 Wakaba <w@suika.fam.cx>
299    
300     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24