aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-09 17:47:32 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-09 17:47:32 +0000
commit5acd5df8c512088a26b591c90866e4f3d085d6a7 (patch)
tree3fa0186d45633aa656efc8d74dcaed144b6131a3 /sonar-server
parenteecf9fb412f17004649312b26882383af2d0ea35 (diff)
downloadsonarqube-5acd5df8c512088a26b591c90866e4f3d085d6a7.tar.gz
sonarqube-5acd5df8c512088a26b591c90866e4f3d085d6a7.zip
SONAR-1956 Add a dropdown list on the top right of all Filters to support the differential views
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/filters/Filter.java52
-rw-r--r--sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/filter_result.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/filters/_customize_list.html.erb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb25
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb24
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_variations_to_filters.rb31
-rw-r--r--sonar-server/src/main/webapp/images/trend-up.pngbin0 -> 3073 bytes
11 files changed, 156 insertions, 26 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/filters/Filter.java b/sonar-server/src/main/java/org/sonar/server/filters/Filter.java
index 7e1e6eb2e3a..4b3a456a8a4 100644
--- a/sonar-server/src/main/java/org/sonar/server/filters/Filter.java
+++ b/sonar-server/src/main/java/org/sonar/server/filters/Filter.java
@@ -19,12 +19,12 @@
*/
package org.sonar.server.filters;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.resources.Resource;
-import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -46,10 +46,11 @@ public class Filter {
private boolean isViewContext = false;
// filters on measures
- private List<MeasureCriterion> measureCriteria = new ArrayList<MeasureCriterion>();
+ private List<MeasureCriterion> measureCriteria = Lists.newLinkedList();
// sorting
private Integer sortedMetricId;
+ private int sortedVariationIndex = 0; // >0 only when sortedMetricId not null
private boolean sortedByLanguage;
private boolean sortedByName;
private boolean sortedByDate;
@@ -57,13 +58,15 @@ public class Filter {
private boolean useMeasureValueToSort = true; // only if sortedMetricId is not null
private boolean ascendingSort = true;
+
+
public Filter setPath(Integer rootSnapshotId, Integer snapshotId, String snapshotPath, boolean isViewContext) {
this.baseSnapshotId = snapshotId;
- if (rootSnapshotId==null) {
+ if (rootSnapshotId == null) {
this.rootSnapshotId = snapshotId;
} else {
this.rootSnapshotId = rootSnapshotId;
- }
+ }
this.baseSnapshotPath = snapshotPath;
this.isViewContext = isViewContext;
return this;
@@ -134,7 +137,7 @@ public class Filter {
}
public boolean hasLanguages() {
- return languages!=null && !languages.isEmpty();
+ return languages != null && !languages.isEmpty();
}
public Filter setLanguages(Set<String> languages) {
@@ -152,7 +155,7 @@ public class Filter {
}
public boolean hasFavouriteIds() {
- return favouriteIds!=null && !favouriteIds.isEmpty();
+ return favouriteIds != null && !favouriteIds.isEmpty();
}
public Filter setFavouriteIds(Set<Integer> favouriteIds) {
@@ -261,7 +264,7 @@ public class Filter {
}
protected boolean hasMeasureCriteriaOnMetric(Integer metricId) {
- if (metricId!=null) {
+ if (metricId != null) {
for (MeasureCriterion criterion : measureCriteria) {
if (metricId.equals(criterion.getMetricId())) {
return true;
@@ -316,9 +319,42 @@ public class Filter {
return this;
}
+ public int getSortedVariationIndex() {
+ return sortedVariationIndex;
+ }
+
+ public Filter setSortedVariationIndex(int i) {
+ this.sortedVariationIndex = i;
+ return this;
+ }
+
+ static String getVariationColumn(int variationIndex) {
+ switch (variationIndex) {
+ case 1:
+ return "variation_value_1";
+ case 2:
+ return "variation_value_2";
+ case 3:
+ return "variation_value_3";
+ case 4:
+ return "variation_value_4";
+ case 5:
+ return "variation_value_5";
+ }
+ return null;
+ }
+
+ String getColumnToSort() {
+ String col = "text_value";
+ if (useMeasureValueToSort()) {
+ col = (sortedVariationIndex>0 ? getVariationColumn (sortedVariationIndex) : "value");
+ }
+ return col;
+ }
+
@Override
public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
public static Filter createForAllQualifiers() {
diff --git a/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java b/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java
index dd6b88e1e24..874838d1bbc 100644
--- a/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java
+++ b/sonar-server/src/main/java/org/sonar/server/filters/FilterExecutor.java
@@ -90,7 +90,7 @@ public class FilterExecutor implements ServerComponent {
sql.append(", MAX(CASE WHEN pm.metric_id=");
sql.append(filter.getSortedMetricId());
sql.append(" THEN ");
- sql.append(filter.useMeasureValueToSort() ? "value" : "text_value");
+ sql.append(filter.getColumnToSort());
sql.append(" ELSE NULL END) AS sortvalue");
sql.append(" ");
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb
index 7396fbb9d5b..5315af9b5ef 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb
@@ -51,8 +51,8 @@ class FiltersController < ApplicationController
load_filter_from_params(@filter, params)
@filter.columns.build(:family => 'name', :order_index => 1, :sort_direction => 'ASC')
- @filter.columns.build(:family => 'metric', :kee => 'ncloc', :order_index => 2)
- @filter.columns.build(:family => 'metric', :kee => 'violations_density', :order_index => 3)
+ @filter.columns.build(:family => 'metric', :kee => 'ncloc', :order_index => 2, :variation => @filter.default_period?)
+ @filter.columns.build(:family => 'metric', :kee => 'violations_density', :order_index => 3, :variation => @filter.default_period?)
@filter.columns.build(:family => 'date', :order_index => 4)
column_index=0
@@ -85,7 +85,8 @@ class FiltersController < ApplicationController
unless editable_filter?(@filter)
return access_denied
end
-
+
+ @variation_index=params[:var].to_i
@data=execute_filter(@filter, current_user, params)
render :action => 'new'
end
@@ -237,7 +238,7 @@ class FiltersController < ApplicationController
fields=params[:column].split(',')
family=fields[0]
if family=='metric'
- filter.columns.create(:family => fields[0], :kee => Metric.by_id(fields[1]).name, :order_index => filter.columns.size + 1)
+ filter.columns.create(:family => fields[0], :kee => Metric.by_id(fields[1]).name, :order_index => filter.columns.size + 1, :variation => params[:column_type]=='variation')
elsif family.present?
filter.columns.create(:family => family, :order_index => filter.columns.size + 1)
end
@@ -420,6 +421,7 @@ class FiltersController < ApplicationController
filter.favourites=params[:favourites].present?
filter.resource_id=(params[:path_id].present? ? Project.by_key(params[:path_id]).id : nil)
filter.user_id=current_user.id
+ filter.variation_index=params[:variation_index].to_i
filter.criteria=[]
filter.criteria<<Criterion.new_for_qualifiers(params['qualifiers'])
filter.criteria<<Criterion.new(:family => 'date', :operator => params['date_operator'], :value => params['date_value']) if params['date_operator'].present?
@@ -475,6 +477,7 @@ class FiltersController < ApplicationController
end
@filter=nil
+ @variation_index=params[:var].to_i
if @active
@filter=@active.filter
unless @filter.ajax_loading?
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb
index c92e12f8ad0..3aefd4295f9 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb
@@ -96,6 +96,10 @@ module FiltersHelper
java_filter.setAscendingSort(filter.sorted_column.ascending?)
+ #----- VARIATION
+ variation_index = (options[:var] ? options[:var].to_i : filter.variation_index)
+ java_filter.setSortedVariationIndex(variation_index)
+
#----- EXECUTION
java_result=java_facade.execute_filter(java_filter)
snapshot_ids=extract_snapshot_ids(java_result.getRows())
@@ -115,6 +119,10 @@ module FiltersHelper
else
html=h(column.display_name)
end
+ if column.variation
+ html="<img src='#{ApplicationController.root_context}/images/trend-up.png'></img> #{html}"
+ end
+
if filter.sorted_column==column
html << (column.ascending? ? image_tag("asc12.png") : image_tag("desc12.png"))
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb
index 20872c7eeb6..1809b9c7d43 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb
@@ -125,10 +125,22 @@ class Filter < ActiveRecord::Base
def advanced_search?
@advanced_search ||=
begin
- !(criterion('language').nil?) || favourites || !(criterion('name').nil?) || !(criterion('key').nil?) || !(criterion('date').nil?)
+ !(criterion('language').nil?) || favourites || !(criterion('name').nil?) || !(criterion('key').nil?) || !(criterion('date').nil?) || default_period?
end
end
+ def variation_index=(vi)
+ if vi && vi>0
+ write_attribute(:variation_index, vi)
+ else
+ write_attribute(:variation_index, nil)
+ end
+ end
+
+ def default_period?
+ variation_index && variation_index>0
+ end
+
protected
def before_validation
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/filter_result.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/filter_result.rb
index c3332f4ba3b..0a165acaedf 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/filter_result.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/filter_result.rb
@@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class FilterResult
- attr_accessor :page_size, :page_id, :security_exclusions, :filter
+ attr_accessor :page_size, :page_id, :security_exclusions, :filter, :variation_index
def initialize(filter, options={})
@filter = filter
@@ -28,6 +28,7 @@
@page_sids=[]
@security_exclusions=options[:security_exclusions]
@metric_ids=(options[:metric_ids] || @filter.columns.map{|col| col.metric ? col.metric.id : nil}.compact.uniq)
+ @variation_index = (options[:var].blank? ? filter.variation_index : options[:var].to_i)
from=(@page_id-1) * @page_size
to=(@page_id*@page_size)-1
@@ -124,4 +125,7 @@
@security_exclusions==true
end
+ def variation?
+ @variation_index && @variation_index>0
+ end
end \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_customize_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_customize_list.html.erb
index 75e18bb634b..d899960b1eb 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_customize_list.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_customize_list.html.erb
@@ -4,12 +4,17 @@
</td>
<td>
<form id="add_column_form" action="<%= url_for :action => 'add_column', :id => @filter.id -%>" method="post">
+ <select name="column_type" id="select_column_type">
+ <option value="value" selected>Value</option>
+ <option value="variation">Variation</option>
+ </select>
+
<select name="column" id="select_column">
<option value="" selected></option>
<% Metric.domains.each do |domain| %>
<optgroup label="<%= domain -%>">
<% Metric.by_domain(domain).each do |metric| %>
- <% if metric.display? && !(@filter.column('metric',metric.name)) %><option value="metric,<%= metric.id -%>"><%= metric.short_name -%></option><% end %>
+ <% if metric.display? %><option value="metric,<%= metric.id -%>"><%= metric.short_name -%></option><% end %>
<% end %>
<% if domain=='General' %>
<% unless @filter.column('date') %><option value="date">Build date</option><% end %>
@@ -35,7 +40,7 @@
default_sorted_column=@filter.sorted_column
@filter.columns.each do |column|
%>
- <option value="<%= column.id -%>" <%= 'selected' if column==default_sorted_column -%>><%= column.name -%></option>
+ <option value="<%= column.id -%>" <%= 'selected' if column==default_sorted_column -%>><%= 'Variation of ' if column.variation -%><%= column.name -%></option>
<% end %>
</select>
<select name="sort">
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb
index 0fe32f99f49..b1a93540f36 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb
@@ -1,5 +1,15 @@
<% filter=data.filter %>
<div>
+Periods:
+<form action="<%= url_for :overwrite_params => {:var => nil} -%>" style="display: inline" method="get">
+ <select name="var" onchange="submit()" class="small">
+ <option value="">None</option>
+ <option value="1" <%= 'selected' if data.variation_index==1 -%>>Period 1</option>
+ <option value="2" <%= 'selected' if data.variation_index==2 -%>>Period 2</option>
+ <option value="3" <%= 'selected' if data.variation_index==3 -%>>Period 3</option>
+ </select>
+</form>
+
<table class="data nowrap width100" id="results">
<thead id="results-head">
<tr>
@@ -70,8 +80,19 @@
<td><% if logged_in? %><%= link_to_favourite(snapshot.project) -%><% end %></td>
<% filter.columns.each do |column| %>
<td class="<%= column_align(column) -%>">
- <% if column.on_metric? %>
- <%= html_measure(data.measure(snapshot, column.metric), nil, true, nil, nil, true, false) %>
+ <% if column.on_metric?
+ measure = data.measure(snapshot, column.metric)
+ %>
+ <% if column.variation %>
+ <%= format_variation(measure, :index => data.variation_index) -%>
+ <% else %>
+ <%= format_measure(measure) -%>
+ <% if data.variation? %>
+ <%= format_variation(measure, :index => data.variation_index) -%>
+ <% else %>
+ <%= trend_icon(measure, :empty => true) -%>
+ <% end %>
+ <% end %>
<% elsif column.on_name? %>
<%= qualifier_icon(snapshot) %> <%= link_to_resource(snapshot.project, snapshot.project.name(true), {:dashboard => true, :title => snapshot.project.key}) %>
<% elsif column.on_version? %><%= h snapshot.version %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb
index e0fc7476949..5678afe6d69 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb
@@ -16,7 +16,6 @@ table#columns td {
}
</script>
<div class="tabs-panel">
-<h1>Settings</h1>
<div class="admin">
<form id="filter_form" name="filter_form" action="<%= url_for :action => (@filter.id ? 'update' : 'create'), :id => @filter.id -%>" method="post">
<input type="hidden" name="preview" value="" />
@@ -46,7 +45,7 @@ table#columns td {
</td>
</tr>
<tr>
- <td class="first">Type:</td>
+ <td class="first">Search for:</td>
<td>
<% qualifiers=(@filter.criterion('qualifier') ? @filter.criterion('qualifier').text_values : []) %>
@@ -77,19 +76,19 @@ table#columns td {
<tr>
<td class="first">Criteria:</td>
<td>
- <%= render :partial => 'filters/criterion', :locals => {:id => '0', :criterion => (@filter.measure_criteria.size>0 ? @filter.measure_criteria[0] : nil)} %>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <%= render :partial => 'filters/criterion', :locals => {:id => '0', :criterion => (@filter.measure_criteria.size>0 ? @filter.measure_criteria[0] : nil)} %>
</td>
</tr>
<tr>
- <td class="first">and: </td>
+ <td class="first"></td>
<td>
- <%= render :partial => 'filters/criterion', :locals => {:id => '1', :criterion => (@filter.measure_criteria.size>1 ? @filter.measure_criteria[1] : nil) } %>
+ and <%= render :partial => 'filters/criterion', :locals => {:id => '1', :criterion => (@filter.measure_criteria.size>1 ? @filter.measure_criteria[1] : nil) } %>
</td>
</tr>
<tr>
- <td class="first">and: </td>
+ <td class="first"></td>
<td>
- <%= render :partial => 'filters/criterion', :locals => {:id => '2', :criterion => (@filter.measure_criteria.size>2 ? @filter.measure_criteria[2] : nil) } %>
+ and <%= render :partial => 'filters/criterion', :locals => {:id => '2', :criterion => (@filter.measure_criteria.size>2 ? @filter.measure_criteria[2] : nil) } %>
</td>
</tr>
<% unless @filter.advanced_search? %>
@@ -101,6 +100,17 @@ table#columns td {
</tbody>
<tbody id="advanced-search" style="<%= 'display: none' unless @filter.advanced_search? -%>">
<tr>
+ <td class="first">Default period:</td>
+ <td>
+ <select id="variation_index" name="variation_index">
+ <option value="">None</option>
+ <option value="1" <%= 'selected' if @filter.variation_index==1 -%>>Period 1</value>
+ <option value="2" <%= 'selected' if @filter.variation_index==2 -%>>Period 2</value>
+ <option value="3" <%= 'selected' if @filter.variation_index==3 -%>>Period 3</value>
+ </select>
+ </td>
+ </tr>
+ <tr>
<td class="first">Language:</td>
<td>
<% languages=(@filter.criterion('language') ? @filter.criterion('language').text_values : []) %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_variations_to_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_variations_to_filters.rb
new file mode 100644
index 00000000000..34a703a19b7
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_variations_to_filters.rb
@@ -0,0 +1,31 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2009 SonarSource SA
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 2.5
+#
+class AddVariationsToFilters < ActiveRecord::Migration
+
+ def self.up
+ add_column :filters, :variation_index, :integer, :null => true
+ add_column :filter_columns, :variation, :boolean, :null => true
+ end
+
+end
diff --git a/sonar-server/src/main/webapp/images/trend-up.png b/sonar-server/src/main/webapp/images/trend-up.png
new file mode 100644
index 00000000000..4c8be2ecb77
--- /dev/null
+++ b/sonar-server/src/main/webapp/images/trend-up.png
Binary files differ