Web: Fixed filtering by tags in "Results" page
"Results" page not allow for filtering by tags.
* If both, configuration and tags are specified, only reports
for specified configurations AND with at least one of the
specified tags are shown.
* If only tags are specified, then all reports on all configurations
having at keast one of specified tags are shown.
Kudos to Jan Kurs for forcing me to fix this :-)
--- a/web/app/models/results_filter.rb Fri Mar 18 19:36:12 2016 +0000
+++ b/web/app/models/results_filter.rb Fri Mar 18 22:41:49 2016 +0000
@@ -14,17 +14,38 @@
BenchmarkConfiguration.where(id: benchmark_configurations.compact)
end
+ # Return benchmark reports (batches in webapp) based on criterie.
+ # The filtering works as folloeing:
+ # * if selected configurations and selected benchmarks are BOTH ARE EMPTYy,
+ # return an empty list.
+ # * if selected CONFIGURATIONS ARE EMPTY, then filter by selected tags.
+ # * if selected TAGS ARE EMPTY, then filter by selected configrations
+ # * if BOTH ARE NON-EMPTY, then return only those having one of the
+ # selected configurations and one of the tags
def filtered_batches
- BenchmarkBatch.
- includes(
- :tags,
- :benchmark_configuration,
- benchmark_results: [
- :benchmark_durations,
- :benchmark_info
- ]).
- where(benchmark_configuration_id: benchmark_configurations.compact).
- order("performed_at desc")
+ benchmark_configurations.compact!
+ benchmark_configurations.reject! { | e | e.empty? }
+ tags.compact!
+ tags.reject! { | e | e.empty? }
+
+ if benchmark_configurations.empty? and tags.empty? then
+ return []
+ end
+ batches = BenchmarkBatch.includes(
+ :tags,
+ :benchmark_configuration,
+ benchmark_results: [
+ :benchmark_durations,
+ :benchmark_info
+ ])
+ if not benchmark_configurations.empty? then
+ batches = batches.where(benchmark_configuration_id: benchmark_configurations)
+ end
+ if not tags.empty? then
+ batches = batches.joins(:tags).where(tags: { id: tags})
+ end
+ batches = batches.order("performed_at desc")
+ return batches
end
end
--- a/web/app/views/results/index.html.erb Fri Mar 18 19:36:12 2016 +0000
+++ b/web/app/views/results/index.html.erb Fri Mar 18 22:41:49 2016 +0000
@@ -28,60 +28,66 @@
<% end %>
</div>
-<% @results_filter.benchmark_configurations_relation.each do |configuration| %>
- <div class="row">
- <% panel_id = "panel-for-configuration-#{configuration.id}" %>
- <% panel_body_id = "panel-body-for-configuration-#{configuration.id}" %>
- <div id="<%= panel_id %>" class="panel-group col-xs-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- <%= link_to configuration.name,
- "#" + panel_body_id,
- data: { toggle: "collapse",
- parent: "#" + panel_id } %>
- </div>
- <div id="<%= panel_body_id %>" class="panel-collapse">
- <div class="panel-body">
- <%= render "index/timeline_table", benchmark_configuration: configuration %>
+<% filtered_batches = @results_filter.filtered_batches() %>
+<% if not filtered_batches.empty? %>
+ <% @results_filter.benchmark_configurations_relation.each do |configuration| %>
+ <div class="row">
+ <% panel_id = "panel-for-configuration-#{configuration.id}" %>
+ <% panel_body_id = "panel-body-for-configuration-#{configuration.id}" %>
+ <div id="<%= panel_id %>" class="panel-group col-xs-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <%= link_to configuration.name,
+ "#" + panel_body_id,
+ data: { toggle: "collapse",
+ parent: "#" + panel_id } %>
+ </div>
+ <div id="<%= panel_body_id %>" class="panel-collapse">
+ <div class="panel-body">
+ <%= render "index/timeline_table", benchmark_configuration: configuration %>
+ </div>
</div>
</div>
</div>
</div>
- </div>
-<% end %>
-
-<div class="row">
+ <% end %>
- <% @results_filter.filtered_batches.each do |batch| %>
- <% panel_id = "benchmark-batch-#{batch.id}" %>
- <% panel_body_id = "benchmark-batch-details-#{batch.id}" %>
- <div id="<%= panel_id %>" class="panel-group col-xs-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- <div class="row">
- <div class="col-xs-4">
- <%= link_to l(batch.performed_at),
- "#" + panel_body_id,
- data: { toggle: "collapse",
- parent: "#" + panel_id } %>
+ <div class="row">
+ <% filtered_batches.each do |batch| %>
+ <% panel_id = "benchmark-batch-#{batch.id}" %>
+ <% panel_body_id = "benchmark-batch-details-#{batch.id}" %>
+ <div id="<%= panel_id %>" class="panel-group col-xs-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <div class="row">
+ <div class="col-xs-4">
+ <%= link_to l(batch.performed_at),
+ "#" + panel_body_id,
+ data: { toggle: "collapse",
+ parent: "#" + panel_id } %>
+ </div>
+ <div class="col-xs-6">
+ <%= batch.benchmark_configuration.name %>
+ <%= batch.tags.map(&:name).join(", ") %>
+ </div>
+ <div class="col-xs-2 pull-right text-right">
+ <%= link_to('[json]', archive_path(batch.id, format: 'json')) %>
+ <%= link_to('[csv]', archive_path(batch.id, format: 'csv')) %>
+ </div>
</div>
- <div class="col-xs-6">
- <%= batch.benchmark_configuration.name %>
- <%= batch.tags.map(&:name).join(", ") %>
- </div>
- <div class="col-xs-2 pull-right text-right">
- <%= link_to('[json]', archive_path(batch.id, format: 'json')) %>
- <%= link_to('[csv]', archive_path(batch.id, format: 'csv')) %>
+ </div>
+ <div id="<%= panel_body_id %>" class="panel-collapse collapse">
+ <div class="panel-body">
+ <%= render "index/benchmarks_table", batch: batch %>
</div>
</div>
</div>
- <div id="<%= panel_body_id %>" class="panel-collapse collapse">
- <div class="panel-body">
- <%= render "index/benchmarks_table", batch: batch %>
- </div>
- </div>
</div>
- </div>
- <% end %>
-</div>
+ <% end %>
+ </div>
+<% else %>
+ <div>
+ <p>Sorry, no benchmark reports match the above criterie</p>
+ </div>
+<% end %>
\ No newline at end of file