]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
Bug listing page, rough first cut
authorIan Campbell <ijc@hellion.org.uk>
Wed, 31 Oct 2012 13:18:26 +0000 (14:18 +0100)
committerIan Campbell <ijc@hellion.org.uk>
Wed, 31 Oct 2012 13:18:43 +0000 (14:18 +0100)
Bugs/Bug.pm
Bugs/Message.pm
CGI/bug.pl [new file with mode: 0755]
control.pl
css/style.css [new file with mode: 0644]
thread-to-mbox.pl

index d3d8659db243ad9e908b641146f83081c648c78a..912de59cf2d510778d4706e2dfdbcf9008089f9c 100644 (file)
@@ -3,6 +3,8 @@ package Bugs::Bug;
 use warnings;
 use strict;
 
+use Bugs::Message;
+
 my $SELECT_FIELDS = "id,title";
 
 sub new {
@@ -21,6 +23,7 @@ sub new {
         ");
        $sth ->execute($args{ID}) or die "Failed to lookup bug";
        $row = $sth->fetchrow_arrayref;
+       return undef unless $row;
        $sth->finish;
     } else { die "Bugs::Bug->new needs ID or Fields"; }
 
@@ -47,7 +50,13 @@ sub create {
 
     my $bugid = $dbh->sqlite_last_insert_rowid();
 
-    return $class->new($dbh, ID => $bugid, Title=>$subj);
+    my $self = $class->new($dbh, ID => $bugid);
+
+    my $msg = Bugs::Message->lookup_msgid($dbh, $msgid, Insert => 1);
+    print "Self is ".$msg->{id}."\n";
+    $self->add_subthread($msg);
+
+    return $self;
 }
 
 sub set {
@@ -68,6 +77,7 @@ sub addremove_subthread {
     my $add = shift;
     my $m = shift;
 
+    print "addremove $add $m\n";
     my $sth = $self->{dbh}->prepare(q{
         INSERT INTO bug2message (include,bugid,messageid) VALUES (?,?,?)
     });
@@ -94,18 +104,21 @@ sub remove_subthread {
 sub messages {
     my $self = shift;
 
-    my %refs;
-
     my $sth = $self->{dbh}->prepare(q{
-        SELECT include,messageid FROM bug2message WHERE bugid = ?
+        SELECT include,messageid FROM bug2message WHERE bugid = ? ORDER BY id
     });
 
     $sth->execute($self->{id});
 
+    my %refs;
+
     while ( defined(my $row = $sth->fetch) ) {
        my ($inc,$msgid) = @$row;
-       print "$msgid, $inc\n";
+       my $m = Bugs::Message->lookup_id($self->{dbh}, $msgid);
+       #print "Subthread ".$m->{msgid}."\n";
+       $m->subthread($inc, \%refs);
     }
+    return \%refs;
 }
 
 sub listall ($$) {
index 88315996ff56d36841dfc5e24a2b6ec4c9387671..1231dd30c353656876d43d441a491b4160cfe687 100644 (file)
@@ -166,19 +166,19 @@ sub id {
 }
 
 sub _subthread {
-    my ($self,$refs) = @_;
+    my ($self,$inc,$refs) = @_;
 
     my $sth = $self->{dbh}->prepare(q{SELECT childid FROM refs WHERE parentid = ?});
 
-    $sth->execute($self->{id});
-    my $r;
-    while ( defined($r = $sth->fetch) ) {
+    $sth->execute($self->{id}) or die "Lookup subthread";
+    while ( defined(my $r = $sth->fetch) ) {
        my $id = $r->[0];
-       next if exists $refs->{$id};
-       $refs->{$id} = 1;
+       #print $refs->{$id} . " == $inc?\n" if exists $refs->{$id};
+       next if exists $refs->{$id} and $refs->{$id} eq $inc;
+       $refs->{$id} = $inc;
        my $m = Bugs::Message->lookup_id($self->{dbh}, $id);
        #print "REF: $id = " . $m->{msgid} . "\n";
-       $m->_subthread($refs)
+       $m->_subthread($inc,$refs)
     }
     $sth->finish;
 }
@@ -186,10 +186,12 @@ sub _subthread {
 sub subthread {
     my $self = shift;
     #my %args = @_;
-    my %refs;
-    $refs{$self->{id}} = 1;
-    $self->_subthread(\%refs);
-    return keys %refs;
+    my $inc = shift;
+    my $refs = shift || {};
+
+    $refs->{$self->{id}} = $inc;
+    $self->_subthread($inc,$refs);
+    return keys %$refs;
 }
 
 1;
diff --git a/CGI/bug.pl b/CGI/bug.pl
new file mode 100755 (executable)
index 0000000..f0eeda9
--- /dev/null
@@ -0,0 +1,76 @@
+#!/usr/bin/perl -I/home/ijc/devel/bugs
+
+use strict;
+use warnings;
+
+use CGI qw/:standard/;
+use CGI::Carp qw(fatalsToBrowser);
+
+use Bugs::Bug;
+use Bugs::Common;
+
+require 'common.pl';
+
+readconfig;
+my $dbh = opendb;
+
+my $bugid = param("id");
+my $bug = Bugs::Bug->new($dbh, ID => $bugid);
+
+if ( ! $bug ) {
+    print header;
+
+    print start_html(-title=>$c{TrackerName}.": #$bugid - Unknown Bug Number",
+                    -style  => { 'src' => '/css/style.css'});
+
+    print h1("#$bugid - Unknown Bug Number");
+    print p(["Ooops. This bug doesn't seem to exist."]);
+    print end_html;
+    exit (0);
+}
+
+print header;
+
+print start_html(-title=>$c{TrackerName}.": #$bugid - ".$bug->{title},
+                -style=>{'src' => '/css/style.css'});
+
+print h1("#$bugid - ".$bug->{title});
+
+print p(["Metadata goes here..."]),
+      hr;
+
+sub htmlsanit {
+    my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
+    my $in = shift || "";
+    $in =~ s/([<>&"])/\&$saniarray{$1};/g;
+    return $in;
+}
+
+our $msgs = $bug->messages;
+
+print "\n";
+foreach my $msgid ( keys $msgs ) {
+    my $m = Bugs::Message->lookup_id($dbh, $msgid);
+    my $body = $m->body;
+    my @body = <$body>;
+    print p({-class=>"message"},
+           [pre({-class=>"headers"},
+                join("\n", (b("From: ") . "Foo;",
+                            b("To: ") . "Bar;",
+                            b("Subject: ") . $m->{subject},
+                            b("Date: ") . "Baz"))),
+            pre({-class=>"body"}, join("\n",@body)),
+           ]);
+           print hr . "\n";
+}
+
+#print ul_start;
+#foreach my $msgid ( keys $msgs ) {
+#    my $m = Bugs::Message->lookup_id($dbh, $msgid);
+#    print li("$msgid = ".$m->{subject} . " (".$msgs->{$msgid}.") = ".htmlsanit(#$m->{msgid}));
+#}
+#print ul_end;
+
+print end_html;
+
+
index d1f12d1cf59f798fb09a2cef1b95ddbdf3b13679..63fedd1fc51129a91690d84ae39e6eef7996b2c6 100755 (executable)
@@ -98,7 +98,7 @@ sub cmd_prune {
     my $b = lookup_bugid $1;
     my $m = lookup_msgid $2;
     push @reply, "Prune `".$m->{msgid}."' from #".$b->{id};
-    $b->add_subthread($m);
+    $b->remove_subthread($m);
     return 1;
 }
 
@@ -108,7 +108,7 @@ sub cmd_graft {
     my $b = lookup_bugid $1;
     my $m = lookup_msgid $2;
     push @reply, "Graft `".$m->{msgid}."' onto #".$b->{id};
-    $b->remove_subthread($m);
+    $b->add_subthread($m);
     return 1;
 }
 
diff --git a/css/style.css b/css/style.css
new file mode 100644 (file)
index 0000000..32cf47d
--- /dev/null
@@ -0,0 +1,9 @@
+pre.headers {
+    font-family: sans-serif;
+    font-size: 95%;
+    color: #3c3c3c;
+    background-color: #f0f0f0;
+    padding: 2px;
+    border: #a7a7a7 1px solid;
+    line-height: 120%
+}
index 324defd42a3e8a8da311ae8a51e0c881c41d8ad9..63ca88cce211719688c76c9bb1a06b5948016b7a 100755 (executable)
@@ -15,7 +15,7 @@ our $msg = Bugs::Message->lookup_msgid($dbh, $msgid);
 our $id = $msg->id;
 
 print STDERR "Message is $id\n";
-our @msgs = $msg->subthread;
+our @msgs = $msg->subthread(1);
 
 for my $r ( @msgs  ) {
     my $m = Bugs::Message->lookup_id($dbh, $r);