Allow extra columns in group index, and split search columns
authorVincent Tondellier <tonton+hg@team1664.org>
Sun, 14 Feb 2016 22:42:29 +0100
changeset 100 4dae01f2beee
parent 99 0e40a68ba421
child 101 8e0a9f88fb47
Allow extra columns in group index, and split search columns
lib/CrashTest/Controller/CrashGroups.pm
lib/CrashTest/Plugin/Storage/Sql/Model/CrashGroup.pm
lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.pm
templates/groups/index.html.ep
--- a/lib/CrashTest/Controller/CrashGroups.pm	Sun Feb 14 22:39:01 2016 +0100
+++ b/lib/CrashTest/Controller/CrashGroups.pm	Sun Feb 14 22:42:29 2016 +0100
@@ -30,7 +30,7 @@
 
     $self->stash(crashs => $results);
     $self->stash(pager => $pager);
-    $self->stash(extra_columns => []);
+    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{GroupIndex});
 
     $self->render("groups/index");
 }
--- a/lib/CrashTest/Plugin/Storage/Sql/Model/CrashGroup.pm	Sun Feb 14 22:39:01 2016 +0100
+++ b/lib/CrashTest/Plugin/Storage/Sql/Model/CrashGroup.pm	Sun Feb 14 22:42:29 2016 +0100
@@ -38,7 +38,7 @@
     my ($self, $search_str) = @_;
     return $self->sql_utils->build_query_from_search_string(
         $search_str,
-        $self->app->config->{WebInterface}->{ExtraColumns}->{Index}, {
+        $self->app->config->{WebInterface}->{ExtraColumns}->{Search}, {
             user_id     => { name => 'crash_user.user_id' },
             product     => { name => 'product.name' },
             version     => { name => 'product.version' },
@@ -72,6 +72,12 @@
     $pager->entries_per_page($nperpage);
     $pager->current_page($pagen);
 
+    my @extra_cols;
+    foreach my $extra_col(@{$self->app->config->{WebInterface}->{ExtraColumns}->{GroupIndex}}) {
+        push @extra_cols, $extra_col->{db_column} . " AS " . $extra_col->{id};
+    }
+    my $extra_columns = join(",", @extra_cols);
+
     my $results = $self->db->query("
         SELECT crash_groups.uuid, title, group_by_count.*
         FROM crash_groups,
@@ -79,7 +85,7 @@
                     min(version) AS first_version,
                     max(version) AS last_version,
                     string_agg(distinct(name), ', ') AS product_names,
-                    string_agg(distinct(main_module), ', ') AS program_names,
+                    $extra_columns,
                     count(*) AS crash_count
                FROM crash_reports
                LEFT JOIN crash_users AS crash_user ON crash_reports.crash_user_id = crash_user.id
--- a/lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.pm	Sun Feb 14 22:39:01 2016 +0100
+++ b/lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.pm	Sun Feb 14 22:42:29 2016 +0100
@@ -42,7 +42,7 @@
     my ($self, $search_str) = @_;
     return $self->sql_utils->build_query_from_search_string(
         $search_str,
-        $self->app->config->{WebInterface}->{ExtraColumns}->{Index}, {
+        $self->app->config->{WebInterface}->{ExtraColumns}->{Search}, {
             user_id     => { name => 'crash_user.user_id' },
             product     => { name => 'product.name' },
             version     => { name => 'product.version' },
--- a/templates/groups/index.html.ep	Sun Feb 14 22:39:01 2016 +0100
+++ b/templates/groups/index.html.ep	Sun Feb 14 22:42:29 2016 +0100
@@ -8,6 +8,9 @@
     <th>First version seen</th>
     <th>Last version seen</th>
     <th>Products</th>
+    % foreach my $extra_col(@$extra_columns) {
+    %= t th => $extra_col->{name}
+    % }
   </tr>
 </thead>
 % foreach my $crash(@$crashs) {
@@ -19,6 +22,9 @@
     %= t td => $crash->{first_version}
     %= t td => $crash->{last_version}
     %= t td => $crash->{product_names}
+    % foreach my $extra_col(@$extra_columns) {
+    %= t td => $crash->{$extra_col->{id}}
+    % }
   % end
 % }
 % end