aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-04-05 14:43:14 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-04-05 14:43:14 +0200
commit15bf42ed9dfdc29b47a47e7d7860787641074809 (patch)
tree4b7672a8c1250a6dac73f011021a199a1e878e46
parent1402404355b2bed1f8c53dbcdf116c2064dede7b (diff)
downloadsonarqube-15bf42ed9dfdc29b47a47e7d7860787641074809.tar.gz
sonarqube-15bf42ed9dfdc29b47a47e7d7860787641074809.zip
SONAR-3384 Do not display hotspot widgets when related metric is not available
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb146
1 files changed, 74 insertions, 72 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb
index 38137a1446c..6166d150842 100644
--- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb
+++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb
@@ -1,84 +1,86 @@
<%
- metric = widget_properties["metric"]
- metric = Metric.by_key('ncloc') unless metric
- limit = widget_properties["numberOfLines"]
- title = widget_properties["title"]
- title = message('widget.hotspot_metric.hotspots_by_x', :params => metric.short_name) if title.blank?
+ metric = widget_properties["metric"] || Metric.by_key('ncloc')
- snapshots = nil
- if metric.numeric? && !@snapshot.leaves_qualifiers.empty?
- snapshots_conditions=["snapshots.qualifier in (:qualifiers)", "snapshots.islast=:islast", "snapshots.status = 'P'"]
- snapshots_values={:qualifiers => @snapshot.leaves_qualifiers, :islast => true}
- snapshots_conditions << '(snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))'
- snapshots_values[:sid]=@snapshot.id
- snapshots_values[:root_sid] = (@snapshot.root_snapshot_id || @snapshot.id)
- snapshots_values[:path]="#{@snapshot.path}#{@snapshot.id}.%"
+ if measure(metric)
- measures_conditions = ["project_measures.rule_id IS NULL", "project_measures.characteristic_id IS NULL", "project_measures.person_id IS NULL"]
- measures_values = {}
- measures_conditions << "project_measures.metric_id = :m_id"
- measures_values[:m_id] = metric.id
+ limit = widget_properties["numberOfLines"]
+ title = widget_properties["title"]
+ title = message('widget.hotspot_metric.hotspots_by_x', :params => metric.short_name) if title.blank?
- measures=ProjectMeasure.find(:all,
- :joins => :snapshot,
- :conditions => [(snapshots_conditions + measures_conditions).join(' AND '), snapshots_values.merge(measures_values)],
- :order => "project_measures.value #{'DESC' if metric.direction<0}",
- :limit => limit)
+ snapshots = nil
+ if metric.numeric? && !@snapshot.leaves_qualifiers.empty?
+ snapshots_conditions=["snapshots.qualifier in (:qualifiers)", "snapshots.islast=:islast", "snapshots.status = 'P'"]
+ snapshots_values={:qualifiers => @snapshot.leaves_qualifiers, :islast => true}
+ snapshots_conditions << '(snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))'
+ snapshots_values[:sid]=@snapshot.id
+ snapshots_values[:root_sid] = (@snapshot.root_snapshot_id || @snapshot.id)
+ snapshots_values[:path]="#{@snapshot.path}#{@snapshot.id}.%"
- snapshots=Snapshot.find(measures.map { |m| m.snapshot_id }, :include => 'project')
- snapshots_by_id = {}
- snapshots.each do |s|
- snapshots_by_id[s.id]=s
- end
- end
-%>
+ measures_conditions = ["project_measures.rule_id IS NULL", "project_measures.characteristic_id IS NULL", "project_measures.person_id IS NULL"]
+ measures_values = {}
+ measures_conditions << "project_measures.metric_id = :m_id"
+ measures_values[:m_id] = metric.id
+ measures=ProjectMeasure.find(:all,
+ :joins => :snapshot,
+ :conditions => [(snapshots_conditions + measures_conditions).join(' AND '), snapshots_values.merge(measures_values)],
+ :order => "project_measures.value #{'DESC' if metric.direction<0}",
+ :limit => limit)
-<% unless snapshots && !snapshots.empty? %>
- <h3><%= title -%></h3>
- <span class="empty_widget"><%= message('no_results') -%></span>
-<% else %>
+ snapshots=Snapshot.find(measures.map { |m| m.snapshot_id }, :include => 'project')
+ snapshots_by_id = {}
+ snapshots.each do |s|
+ snapshots_by_id[s.id]=s
+ end
+ end
- <div class="line-block">
- <div style="float:right">
- <a href="<%= url_for_drilldown(metric) -%>"><%= message('widget.hotspot_metric.more') -%></a>
- </div>
+ unless snapshots && !snapshots.empty? %>
<h3><%= title -%></h3>
- </div>
+ <span class="empty_widget"><%= message('no_results') -%></span>
+ <% else %>
- <table id="hotspots-<%= metric.name -%>-<%= widget.id -%>" class="data">
- <thead>
- <tr>
- <th colspan="3"/>
- </tr>
- </thead>
- <tbody>
- <%
- if metric.direction > 0
- metric_max_value = measures.last.value
- else
- metric_max_value = measures.first.value
- end
- measures.each do |measure|
- resource = snapshots_by_id[measure.snapshot_id].resource
- %>
- <tr class="<%= cycle 'even', 'odd', :name => ('hotspot_metric' + widget.id.to_s) -%>">
- <td>
- <%= link_to_resource(resource, resource.name, {:metric => metric.name}) -%>
- </td>
- <td class="right nowrap">
- <%= format_measure(measure) -%>
- </td>
- <td class="barchart">
- <div class="barchart" style="width: <%= (measure.value*100/metric_max_value).round.to_i -%>%">
- <div style="width: 100%;background-color:#777;"></div>
- </div>
- </td>
+ <div class="line-block">
+ <div style="float:right">
+ <a href="<%= url_for_drilldown(metric) -%>"><%= message('widget.hotspot_metric.more') -%></a>
+ </div>
+ <h3><%= title -%></h3>
+ </div>
+
+ <table id="hotspots-<%= metric.name -%>-<%= widget.id -%>" class="data">
+ <thead>
+ <tr>
+ <th colspan="3"/>
</tr>
- <%
- end
- %>
- </tbody>
- </table>
+ </thead>
+ <tbody>
+ <%
+ if metric.direction > 0
+ metric_max_value = measures.last.value
+ else
+ metric_max_value = measures.first.value
+ end
+ measures.each do |measure|
+ resource = snapshots_by_id[measure.snapshot_id].resource
+ %>
+ <tr class="<%= cycle 'even', 'odd', :name => ('hotspot_metric' + widget.id.to_s) -%>">
+ <td>
+ <%= link_to_resource(resource, resource.name, {:metric => metric.name}) -%>
+ </td>
+ <td class="right nowrap">
+ <%= format_measure(measure) -%>
+ </td>
+ <td class="barchart">
+ <div class="barchart" style="width: <%= (measure.value*100/metric_max_value).round.to_i -%>%">
+ <div style="width: 100%;background-color:#777;"></div>
+ </div>
+ </td>
+ </tr>
+ <%
+ end
+ %>
+ </tbody>
+ </table>
+
+ <% end %>
-<% end %>
+<% end %> \ No newline at end of file