summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-02-16 08:31:43 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-02-16 08:31:51 +0100
commit2e7a3f43642e9ccd975170f225b7676a718e883c (patch)
treefb676323abc6c0cd4f166f80a6bf0b492c2a14c5 /sonar-server
parent1cf94058093d6c235d108298dfc4a22d921e384b (diff)
downloadsonarqube-2e7a3f43642e9ccd975170f225b7676a718e883c.tar.gz
sonarqube-2e7a3f43642e9ccd975170f225b7676a718e883c.zip
SONAR-3208 drilldown from views to files
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/drilldown2.rb176
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/project.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb17
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb19
6 files changed, 194 insertions, 33 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
index a194e70a31b..22fbcd9e739 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
@@ -53,13 +53,8 @@ class DrilldownController < ApplicationController
options[:period]=@period
end
- if params[:committer]
- @committer=params[:committer]
- options[:committer]=@committer
- end
-
# load data
- @drilldown = Drilldown.new(@project, @metric, selected_rids, options)
+ @drilldown = Drilldown2.new(@project, @metric, selected_rids, options)
access_denied unless has_role?(:user, @snapshot)
@highlighted_resource=@drilldown.highlighted_resource
@@ -111,7 +106,7 @@ class DrilldownController < ApplicationController
end
# load data
- @drilldown = Drilldown.new(@project, @metric, @selected_rids, options)
+ @drilldown = Drilldown2.new(@project, @metric, @selected_rids, options)
access_denied unless has_role?(:user, @snapshot)
@highlighted_resource=@drilldown.highlighted_resource
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
index 3d69c422203..03de08a5dfd 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
@@ -42,9 +42,9 @@ module ApplicationHelper
qualifier=(object.respond_to?('qualifier') ? object.qualifier : object.to_s)
if qualifier
definition = Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceDefinition(qualifier)
- image_tag(definition.getIconPath(), :alt => message("qualifier.#{qualifier}"))
+ image_tag definition.getIconPath(), :alt => '', :size => '16x16'
else
- image_tag('e16.gif')
+ image_tag 'e16.gif'
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown2.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown2.rb
new file mode 100644
index 00000000000..d7f86154f8d
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown2.rb
@@ -0,0 +1,176 @@
+#
+# Sonar, open source software quality management tool.
+# Copyright (C) 2008-2012 SonarSource
+# 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
+#
+class Drilldown2
+
+ DEFAULT=[['TRK'], ['BRC'], ['DIR', 'PAC'], ['FIL', 'CLA', 'UTS']]
+ VIEWS=[['VW'], ['SVW'], ['TRK']]
+ PERSONS=[['PERSON'], ['PERSON_PRJ']]
+ TREES=[DEFAULT, VIEWS, PERSONS]
+
+ def self.qualifier_children(q)
+ return [] if q==nil
+ TREES.each do |tree|
+ tree.each_with_index do |qualifiers, index|
+ if qualifiers==q || qualifiers.include?(q)
+ return index+1<tree.size ? tree[index+1] : []
+ end
+ end
+ end
+ []
+ end
+
+
+ attr_reader :resource, :metric, :selected_resource_ids
+ attr_reader :snapshot, :columns, :highlighted_resource, :highlighted_snapshot
+
+ def initialize(resource, metric, selected_resource_ids, options={})
+ @resource=resource
+ @selected_resource_ids=selected_resource_ids||[]
+ @metric=metric
+ @snapshot=resource.last_snapshot
+ @columns=[]
+
+ if @snapshot
+ column=DrilldownColumn2.new(self, nil)
+ while column.valid?
+ column.init_measures(options)
+ @columns<<column if column.display?
+ column=DrilldownColumn2.new(self, column)
+ end
+ end
+ end
+
+ def display_value?
+ ProjectMeasure.exists?(["snapshot_id=? and metric_id=? and value is not null", @snapshot.id, @metric.id])
+ end
+
+ def display_period?(period_index)
+ ProjectMeasure.exists?(["snapshot_id=? and metric_id=? and variation_value_#{period_index.to_i} is not null", @snapshot.id, @metric.id])
+ end
+end
+
+
+class DrilldownColumn2
+
+ attr_reader :measures, :base_snapshot, :selected_snapshot, :qualifiers, :person_id
+
+ def initialize(drilldown, previous_column)
+ @drilldown = drilldown
+
+ if previous_column
+ @base_snapshot=(previous_column.selected_snapshot || previous_column.base_snapshot)
+ @person_id=(previous_column.person_id || @base_snapshot.resource.person_id)
+ else
+ @base_snapshot=drilldown.snapshot
+ @person_id=@base_snapshot.resource.person_id
+ end
+
+ # switch
+ if @base_snapshot.resource.copy
+ @base_snapshot=@base_snapshot.resource.copy.last_snapshot
+ @qualifiers = Drilldown2.qualifier_children(@base_snapshot.qualifier)
+
+ elsif previous_column
+ @qualifiers=Drilldown2.qualifier_children(previous_column.qualifiers)
+
+ else
+ @qualifiers=Drilldown2.qualifier_children(drilldown.snapshot.qualifier)
+ end
+
+ @resource_per_sid={}
+ end
+
+ def init_measures(options)
+ value_column = (options[:period] ? "variation_value_#{options[:period]}" : 'value')
+ order="project_measures.#{value_column}"
+ if @drilldown.metric.direction<0
+ order += ' DESC'
+ end
+
+ conditions="snapshots.root_snapshot_id=:root_sid AND snapshots.islast=:islast AND snapshots.qualifier in (:qualifiers) " +
+ " AND snapshots.path LIKE :path AND project_measures.metric_id=:metric_id AND project_measures.#{value_column} IS NOT NULL"
+ condition_values={
+ :root_sid => (@base_snapshot.root_snapshot_id || @base_snapshot.id),
+ :islast => true,
+ :qualifiers => @qualifiers,
+ :metric_id => @drilldown.metric.id,
+ :path => "#{@base_snapshot.path}#{@base_snapshot.id}.%"}
+
+ if value_column=='value' && @drilldown.metric.best_value
+ conditions<<' AND project_measures.value<>:best_value'
+ condition_values[:best_value]=@drilldown.metric.best_value
+ end
+
+ if options[:exclude_zero_value]
+ conditions += " AND project_measures.#{value_column}<>0"
+ end
+
+ if options[:rule_id]
+ conditions += ' AND project_measures.rule_id=:rule'
+ condition_values[:rule]=options[:rule_id]
+ else
+ conditions += ' AND project_measures.rule_id IS NULL '
+ end
+
+ if options[:characteristic]
+ conditions += ' AND project_measures.characteristic_id=:characteristic_id'
+ condition_values[:characteristic_id]=options[:characteristic].id
+ else
+ conditions += ' AND project_measures.characteristic_id IS NULL'
+ end
+
+ if @person_id
+ conditions += ' AND project_measures.person_id=:person_id'
+ condition_values[:person_id]=@person_id
+ else
+ conditions += ' AND project_measures.person_id IS NULL'
+ end
+
+ @measures=ProjectMeasure.find(:all,
+ :select => "project_measures.id,project_measures.metric_id,project_measures.#{value_column},project_measures.text_value,project_measures.alert_status,project_measures.alert_text,project_measures.snapshot_id",
+ :joins => :snapshot,
+ :conditions => [conditions, condition_values],
+ :order => order,
+ :limit => 200)
+
+ @resource_per_sid={}
+ sids=@measures.map { |m| m.snapshot_id }.compact.uniq
+ unless sids.empty?
+ Snapshot.find(:all, :include => :project, :conditions => {'snapshots.id' => sids}).each do |snapshot|
+ @resource_per_sid[snapshot.id]=snapshot.project
+ if @drilldown.selected_resource_ids.include?(snapshot.project_id)
+ @selected_snapshot=snapshot
+ end
+ end
+ end
+ end
+
+ def resource(measure)
+ @resource_per_sid[measure.snapshot_id]
+ end
+
+ def display?
+ @measures && !@measures.empty?
+ end
+
+ def valid?
+ @base_snapshot && @qualifiers && !@qualifiers.empty?
+ end
+end \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
index 14c9c288ec4..299c71c1e0d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb
@@ -30,6 +30,8 @@ class Project < ActiveRecord::Base
has_many :group_roles, :foreign_key => 'resource_id'
has_many :manual_measures, :foreign_key => 'resource_id'
belongs_to :root, :class_name => 'Project', :foreign_key => 'root_id'
+ belongs_to :copy, :class_name => 'Project', :foreign_key => 'copy_resource_id'
+ belongs_to :person, :class_name => 'Project', :foreign_key => 'person_id'
def self.by_key(k)
begin
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
index 4542b0651d1..3e7317852e6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
@@ -57,26 +57,21 @@
@drilldown.columns.each_with_index do |column, index|
%>
<td class="column <%= 'first' if index==0 -%>" nowrap>
- <div class="scrollable" id="col_<%= column.scope -%>">
+ <div class="scrollable" id="col_<%= index -%>">
<table class="spaced">
<% column.measures.each do |measure|
resource=column.resource(measure)
selected = column.selected_snapshot && column.selected_snapshot.project_id==resource.id
- clazz = cycle("even", "odd", :name => "col_#{column.scope}")
+ clazz = cycle("even", "odd", :name => "col_#{index}")
clazz = clazz + ' selected' if selected
%>
<tr class="<%= clazz -%>">
<td nowrap>
<%
- if resource.entity?
- if resource.copy_resource_id %>
- <%= qualifier_icon(resource) -%>
- <%= link_to(resource.name, {:only_path => true, :overwrite_params => {:rids => nil, :id => resource.copy_resource_id}}) -%>
- <% else %>
+ if !resource.display_dashboard? %>
<%= qualifier_icon(resource) -%>
<a href="#" onclick="d(<%= resource.id -%>)" alt="<%= resource.name(true) -%>" title="<%= resource.name(true) -%>"><%= resource.name(false) -%></a>
- <% end
- else %>
+ <% else %>
<%= link_to(image_tag('zoom.png'), {:id => resource.id, :metric => @metric.id}, {:class => 'nolink'}) -%>
<%= qualifier_icon(resource) -%>
<%= link_to(resource.name, {:only_path => true, :overwrite_params => {:rids => (selected ? rids-[resource.id] : rids+[resource.id])}}) -%>
@@ -97,8 +92,8 @@
</tr>
</table>
<script>
- <% @drilldown.columns.each do |column| %>
- $$('#col_<%= column.scope -%> tr.selected').each(function (item) {
+ <% for i in 0...@drilldown.columns.size do %>
+ $$('#col_<%= i -%> tr.selected').each(function (item) {
item.scrollIntoView(true);
});
<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
index 3e4232c3633..ba7ddfcbb38 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
@@ -125,12 +125,12 @@
@drilldown.columns.each_with_index do |column, index|
%>
<td class="column <%= 'first' if index==0 -%>" nowrap width="<%= column_width -%>%">
- <div class="scrollable" id="col_<%= column.scope -%>">
+ <div class="scrollable" id="col_<%= index -%>">
<table class="spaced">
<%
column.measures.each do |measure|
resource=column.resource(measure)
- clazz = cycle('even', 'odd', :name => "col_#{column.scope}")
+ clazz = cycle('even', 'odd', :name => "col_#{index}")
selected = column.selected_snapshot && column.selected_snapshot.project_id==resource.id
if selected
clazz += ' selected'
@@ -139,17 +139,10 @@
%>
<tr class="<%= clazz -%>">
<td nowrap>
- <%
- if resource.entity?
- if resource.copy_resource_id %>
- <%= qualifier_icon(resource) -%>
- <%= link_to(h(resource.name), {:only_path => true, :overwrite_params => {:rids => nil, :id => resource.copy_resource_id}}) -%>
- <% else %>
+ <% if !resource.display_dashboard? %>
<%= qualifier_icon(resource) -%>
<a href="#" onclick="d(<%= resource.id -%>, '<%= @period_index -%>', '<%= @rule ? @rule.key : @severity -%>');" alt="<%= resource.name(true) -%>" title="<%= resource.name(true) -%>"><%= resource.name(false) %></a>
- <%
- end
- else %>
+ <% else %>
<%= link_to(image_tag('zoom.png'), {:id => resource.id}, {:class => 'nolink'}) %>
<%= qualifier_icon(resource) %>
<%= link_to(h(resource.name), {:only_path => true, :overwrite_params => {:rids => (selected ? rids-[resource.id] : rids+[resource.id])}}) -%>
@@ -173,8 +166,8 @@
$$('#col_rules tr.selected').each(function (item) {
item.scrollIntoView(true);
});
- <% @drilldown.columns.each do |column| %>
- $$('#col_<%= column.scope -%> tr.selected').each(function (item) {
+ <% for i in 0...@drilldown.columns.size do %>
+ $$('#col_<%= i -%> tr.selected').each(function (item) {
item.scrollIntoView(true);
});
<% end %>