Make the index columns configurable
authorVincent Tondellier <tonton@team1664.org>
Sat, 09 May 2015 23:17:47 +0200
changeset 67 9e95be0b1b8c
parent 66 ca4fa5dc09da
child 68 c810480b2c37
Make the index columns configurable
CrashTest.conf
CrashTest.pl
lib/CrashTest/StackFilters/FileLink.pm
lib/CrashTest/Storage/Sql.pm
templates/index.html.ep
--- a/CrashTest.conf	Fri May 08 22:29:20 2015 +0200
+++ b/CrashTest.conf	Sat May 09 23:17:47 2015 +0200
@@ -9,7 +9,7 @@
 #  },
   Storage => {
       Type => "CrashTest::Storage::Sql",
-      DSN => "dbi:SQLite:dbname=data/db.sqlite",
+      DSN => "dbi:Pg:dbname=crashreports",
       DataDir => 'data/',
   },
   DecodeQueue => {
@@ -19,7 +19,15 @@
 #      Type => "CrashTest::Decode::Queue::Gearman",
 #      GearmanServers => [ 'localhost:4730' ],
 #  },
-  ScmLinks => {
-    "svn:svn.example.org/testproject" => 'https://redmine.example.org/projects/testproject/repository/entry/<%= $scmpath =%>?rev=<%= $rev =%>#L<%= $line =%>',
+  WebInterface => {
+      ScmLinks => {
+          "svn:svn.example.org/testproject" => 'https://redmine.example.org/projects/testproject/repository/entry/<%= $scmpath =%>?rev=<%= $rev =%>#L<%= $line =%>',
+      },
+      ExtraColumns => {
+          Index => [
+              { id => 'os', db_column => "crash_user.os", name => 'Operating System' },
+          ],
+      },
   },
 };
+# vim:ft=perl:
--- a/CrashTest.pl	Fri May 08 22:29:20 2015 +0200
+++ b/CrashTest.pl	Sat May 09 23:17:47 2015 +0200
@@ -32,7 +32,10 @@
         die ref $e ? "Exception: $e" : 'Not found!';
     }
 
-    return $storage_class->new(config => $self->app->config->{Storage});
+    return $storage_class->new(
+        config => $self->app->config->{Storage},
+        extra_columns => $self->app->config->{WebInterface}->{ExtraColumns},
+    );
 });
 
 app->attr(decode_queue => sub {
@@ -67,6 +70,7 @@
 
     $self->stash(files => $result->{crashs});
     $self->stash(pager => $result->{pager});
+    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{Index});
     $self->render('index');
 } => 'index';
 
--- a/lib/CrashTest/StackFilters/FileLink.pm	Fri May 08 22:29:20 2015 +0200
+++ b/lib/CrashTest/StackFilters/FileLink.pm	Sat May 09 23:17:47 2015 +0200
@@ -42,7 +42,7 @@
         my $filename = File::Spec->splitpath($scmpath);
         my $scmrepo = "$scm:$repo";
         my $mt = Mojo::Template->new;
-        my $config = $self->config->{ScmLinks};
+        my $config = $self->config->{WebInterface}->{ScmLinks};
 
         # and we have a browser configured for this repository
         if(exists($config->{$scmrepo})) {
--- a/lib/CrashTest/Storage/Sql.pm	Fri May 08 22:29:20 2015 +0200
+++ b/lib/CrashTest/Storage/Sql.pm	Sat May 09 23:17:47 2015 +0200
@@ -18,6 +18,8 @@
 use CrashTest::Storage::Sql::Schema;
 use Search::Query;
 
+has [ qw/extra_columns/ ];
+
 sub new {
     my $self = shift->SUPER::new(@_);
 
@@ -50,11 +52,25 @@
         }
     }
 
+    my @select = ();
+    my @sel_as = ();
+    my @extra_ids = ();
+
+    if($self->extra_columns) {
+        foreach my $extra_col(@{$self->extra_columns->{Index}}) {
+            push @select, $extra_col->{db_column};
+            push @sel_as, $extra_col->{id};
+            push @extra_ids, $extra_col->{id};
+        }
+    }
+
     my $dbcrashs = $self->{schema}->resultset('CrashReport')->search_rs(
         $dbic_query,
         {
-            prefetch    => [ 'product', 'crash_user' ],
-            join        => 'crash_data',
+            prefetch    => 'product',
+            join        => [ qw/crash_user crash_data/ ],
+            '+select'   => \@select,
+            '+as'       => \@sel_as,
             order_by    => { -desc => 'crash_time' },
             page        => $page,
             rows        => $nperpage,
@@ -65,16 +81,23 @@
         pager   => $dbcrashs->pager,
         crashs  => [],
     };
+
     for my $crash($dbcrashs->all) {
         my $filename = File::Spec->catfile($self->{data_path}, $crash->uuid);
-        push @{$results->{crashs}}, {
+
+        my $result = {
             file        => $filename,
             uuid        => $crash->uuid,
             product     => $crash->product->name,
             version     => $crash->product->version,
-            user        => $crash->crash_user->user_id,
             date        => $crash->crash_time,
+        };
+
+        foreach (@extra_ids) {
+            $result->{$_} = $crash->get_column($_);
         }
+
+        push @{$results->{crashs}}, $result;
     }
 
     return $results;
@@ -141,7 +164,6 @@
 sub get_processed_data {
     my ($self, $uuid) = @_;
 
-
     my $crash = $self->{schema}->resultset('CrashReport')->search(
         { uuid => $uuid },
         { prefetch => 'crash_data' }
--- a/templates/index.html.ep	Fri May 08 22:29:20 2015 +0200
+++ b/templates/index.html.ep	Sat May 09 23:17:47 2015 +0200
@@ -5,8 +5,10 @@
   <tr>
     <th>Product</th>
     <th>Version</th>
-    <th>UserID</th>
     <th>UUID</th>
+    % foreach my $extra_col(@$extra_columns) {
+      %= t th => $extra_col->{name}
+    % }
     <th>Date</th>
   </tr>
 </thead>
@@ -14,11 +16,13 @@
   %= t tr => begin
     %= t td => $crash->{product}
     %= t td => $crash->{version}
-    %= t td => $crash->{user}
     %= t td => (style => "font-family:monospace;") => begin
       %= link_to $crash->{uuid} => url_for('report', uuid => $crash->{uuid})
     % end
-    %= t td => $crash->{date}->strftime("%F %T")
+    % foreach my $extra_col(@$extra_columns) {
+      %= t td => $crash->{$extra_col->{id}}
+    % }
+    %= t td => $crash->{date}->set_time_zone('UTC')->set_time_zone('local')->strftime("%F %T")
   % end
 % }
 % end