Name: BugTrack FullName: Wiki BugTracking System URI: IW:SuikaWiki:"SuikaWiki//BugTrack" Require: SuikaWiki::Markup::XML SuikaWiki::Plugin::WikiLinking main Initialize: my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml'; { Name: wikiform_input/bt--bug-list FullName: Bug list Format: $p->{ns} ||= $o->{page}; $p->{ns} .= '//' if substr ($p->{ns}, -2) ne '//'; my @bugs = grep m!//[0-9]+$!, $o->_database->list_items ({ns => $p->{ns}, type => 'key', recursive => 0}); my $props = SuikaWiki::Plugin->resource ('Plugin:BugTrack:Table:Row'); my $fmt = $o->formatter ('bt--bug-table-header'); $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'table'); $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'thead') ->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr') ->append_node ($fmt->replace ($props, $o, {formatter => $fmt})); $r->append_text ("\n"); $r->set_attribute (class => 'bt--bugtrack'); $fmt = $o->formatter ('bt--bug-item'); my $tb = $r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tbody'); my $weight = { Priority => {high => 1, normal => 2, low => 3}, Status => {open => 1, reserved => 2, closed => 3}, }; for $_ (sort { $weight->{Status}->{$a->{prop}->{Status}||'open'} <=> $weight->{Status}->{$b->{prop}->{Status}||'open'} || $weight->{Priority}->{$a->{prop}->{Priority}||'normal'} <=> $weight->{Priority}->{$b->{prop}->{Priority}||'normal'} || $b->{lm} <=> $a->{lm} || $a->{prop}->{Category} cmp $b->{prop}->{Category} || $b->{bug_no} <=> $a->{bug_no} } map {{ bug_ns => $p->{ns}, bug_page => $_, bug_no => do {$_ =~ m!//([0-9]+)$!; $1}, prop => __PACKAGE__->get_bug_properties ($_), lm => SuikaWiki::Plugin->_database->mtime ($_), }} @bugs) { $o->{bt__bug} = $_; my @class; ## TODO: ensure each class name is NMTOKEN push @class, $o->{bt__bug}->{prop}->{Status}||'open'; push @class, $o->{bt__bug}->{prop}->{Priority}||'normal'; push @class, $o->{bt__bug}->{prop}->{Category}; my $tr = $tb->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'tr'); $tr->append_node ($fmt->replace ($props, $o, {formatter => $fmt})); $tr->set_attribute (class => join ' ', @class); $tb->append_text ("\n"); } } { Name: wikibt--bug-table-header/no wikibt--bug-table-header/subject wikibt--bug-table-header/priority wikibt--bug-table-header/status wikibt--bug-table-header/category wikibt--bug-table-header/last-modified FullName: Table heading cell Format: $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'th'); $r->append_node ($o->resource ('Plugin:BugTrack:Column:'.$p->{-rule_name}), node_or_text => 1); $r->set_attribute (scope => 'cols'); $r->set_attribute (class => $p->{-rule_name}); } { Name: wikibt--bug-table-header/-bare-text wikibt--bug-item/-bare-text FullName: #text Format: $r = SuikaWiki::Markup::XML->new (type => '#text', value => $p->{-bare_text}); } { Name: wikibt--bug-item/no FullName: Bug number Format: $r = __PACKAGE__->make_cell ($o, $p, SuikaWiki::Plugin::WikiLinking->to_wikipage_in_html ({ label => qq'%link-to-it(label=>{$o->{bt__bug}->{bug_no}},description=>{%page-name(absolute);}p);', }, { base => $o->{bt_bug}->{bug_ns}, page_name_relative => $o->{bt__bug}->{bug_page}, }, { o => $o, })); } { Name: wikibt--bug-item/subject FullName: Bug subject Format: $r = __PACKAGE__->make_cell ($o, $p, SuikaWiki::Plugin::WikiLinking->to_wikipage_in_html ({ label => qq'%link-to-it(label=>{$o->{bt__bug}->{prop}->{Subject}},description=>{%page-name(absolute);}p);', }, { base => $o->{bt_bug}->{bug_ns}, page_name_relative => $o->{bt__bug}->{bug_page}, _with_lm => 1, }, { o => $o, })); } { Name: wikibt--bug-item/category FullName: Bug category Format: $r = __PACKAGE__->make_cell ($o, $p, $o->resource ('Category:'.($o->{bt__bug}->{prop}->{Category}||'(default)'), ns => $o->{bt__bug}->{bug_ns}.'Options//')); } { Name: wikibt--bug-item/last-modified FullName: Bug last modified Format: ## TODO: custom date format (Message::Field::Date) my @time = gmtime $o->{bt__bug}->{lm}; $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]); } { Name: wikibt--bug-item/status FullName: Bug status Format: $r = __PACKAGE__->make_cell ($o, $p, $o->resource ('Status:'.($o->{bt__bug}->{prop}->{Status}||'(default)'), ns => $o->{bt__bug}->{bug_ns}.'Options//')); } { Name: wikibt--bug-item/priority FullName: Bug priority Format: $r = __PACKAGE__->make_cell ($o, $p, $o->resource ('Priority:'.($o->{bt__bug}->{prop}->{Priority}||'(default)'), ns => $o->{bt__bug}->{bug_ns}.'Options//')); } { Name: wikiview-resource/bt--bug-no FullName: Bug number Format: $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{bt__bug}->{bug_no}); } { Name: wikiform-input/bt--create-new-bug FullName: Create a new bug page Format: $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'form'); $r->set_attribute (action => $o->uri ('wiki')); $r->set_attribute (method => 'post'); $r->set_attribute ('accept-charset' => 'iso-2022-jp, utf-8'); $r->set_attribute (class => 'bt--create-bug'); for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'input')) { $_->set_attribute (type => 'hidden'); $_->set_attribute (name => 'mode'); $_->set_attribute (value => 'bt--bug-create'); } for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'input')) { $_->set_attribute (type => 'hidden'); $_->set_attribute (name => 'mypage'); $_->set_attribute (value => ($p->{ns} || $o->{page})); } $r->append_node ($p->{content}, node_or_text => 1); } { Name: wikiview/bt--create-new-bug FullName: Create a new bug page Format: my @page = ('#?SuikaWiki/0.9'); for (qw/Subject Priority Status Category/) { push @page, '- ' . $_ . ': ' . $main::form{'wikiform__'.$_}; } push @page, '- Creation-Date: ' . main::_rfc3339_date (time); push @page, ''; push @page, '[1] ' . $main::form{'wikiform__body'}; $p->{ns} ||= $o->{page}; $p->{ns} .= '//' if substr ($p->{ns}, -2) ne '//'; my $page = $p->{ns} . __PACKAGE__->get_new_bug_number ($p->{ns}); $main::database{$page} = join "\n", @page; $o->{bt__bug} = { bug_ns => $p->{ns}, bug_page => $page, bug_no => do {$page =~ m!//([0-9]+)$!; $1}, prop => __PACKAGE__->get_bug_properties ($page), }; } MODULE: sub get_bug_properties ($$) { my (undef, $bug_page) = @_; my (undef, $bug_info) = (SuikaWiki::Plugin->magic_and_content ($main::database{ $bug_page })); my %bug_prop; for (split /\n/, $bug_info) { tr/\x0A\x0D//d; if (/^-\s*([0-9A-Za-z-]+)\s*:\s*(\S.*\S)/) { $bug_prop{$1} = $2; } elsif (!/^-/) { last; } } \%bug_prop; } sub make_cell ($$$$) { my (undef, $o, $p, $content) = @_; my $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'td'); if ($p->{is_header}) { $r->local_name ('th'); $r->set_attribute (scope => 'rows'); } $r->append_node ($content, node_or_text => 1); $r->set_attribute (class => $p->{-rule_name}); $r; } sub get_new_bug_number ($$) { my (undef, $bug_ns) = @_; my $no = 0; for (SuikaWiki::Plugin->_database->list_items ({ns => $bug_ns, type => 'key', recursive => 0})) { if (m!//([0-9]+)$!) { $no = 0+$1 if $1 > $no; } } ++$no; } SuikaWiki::View->definition (bt__bug_create => { media => {type => 'text/html', charset => 1, expires => 60}, xmedia => {type => 'application/xhtml+xml', charset => 1, expires => 60}, preprocess => sub { my %o = @_; my $fmt = SuikaWiki::Plugin->formatter ('view'); $fmt->replace (q(%bt--create-new-bug;), $o{o}, {formatter => $fmt}); main::_http_see_other (page => $o{o}->{bt__bug}->{bug_page}, o => $o{o}, alternate_view => 'bt__bug_create'); 0; }, template => <<'EOH'}); %html-document(title=>{%res(name=>{Plugin:BugTrack:Created:WebPageTitle});}p,link-meta=>{%predefined-template(name=>links);%html-meta(name=>ROBOTS,content=>NOINDEX);}p,content=>{ %section(level=>1,add-to-toc=>0,type=>body,title=>{%page-name;}p,heading,content=>{ %section(id=>tools1,class=>tools,add-to-toc=>0,content=>{%predefined-template(name=>navbar);}p); %section(level=>2,add-to-toc=>0,content=>{ %paragraph(content=>{%res(name=>{Plugin:BugTrack:Created:Message});}p); }p); %section(id=>footer,add-to-toc=>0,content=>{%predefined-template(name=>footer);}p); }p); }p); EOH POD:LICENSE: Copyright 2003 Wakaba %%GNUGPL2%%