/[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.1 - (hide annotations) (download)
Sun Jun 1 07:01:58 2003 UTC (22 years, 7 months ago) by wakaba
Branch: MAIN
New

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24