]> source.dussan.org Git - sonarqube.git/blob
09a42b4d6bd4c9431bd41c4ce186fbdca55aea37
[sonarqube.git] /
1 <%
2    metric = widget_properties["metric"] || Metric.by_key('ncloc')
3
4    if measure(metric)
5
6      limit = widget_properties["numberOfLines"]
7      title = widget_properties["title"]
8      title = message('widget.hotspot_metric.hotspots_by_x', :params => metric.short_name) if title.blank?
9
10      snapshots = nil
11      if metric.numeric? && !@snapshot.leaves_qualifiers.empty?
12        snapshots_conditions=["snapshots.qualifier in (:qualifiers)", "snapshots.islast=:islast", "snapshots.status = 'P'"]
13        snapshots_values={:qualifiers => @snapshot.leaves_qualifiers, :islast => true}
14        snapshots_conditions << '(snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))'
15        snapshots_values[:sid]=@snapshot.id
16        snapshots_values[:root_sid] = (@snapshot.root_snapshot_id || @snapshot.id)
17        snapshots_values[:path]="#{@snapshot.path}#{@snapshot.id}.%"
18
19        measures_conditions = ["project_measures.rule_id IS NULL", "project_measures.characteristic_id IS NULL", "project_measures.person_id IS NULL"]
20        measures_values = {}
21        measures_conditions << "project_measures.metric_id = :m_id"
22        measures_values[:m_id] = metric.id
23
24        measures=ProjectMeasure.find(:all,
25                                     :joins => :snapshot,
26                                     :conditions => [(snapshots_conditions + measures_conditions).join(' AND '), snapshots_values.merge(measures_values)],
27                                     :order => "project_measures.value #{'DESC' if metric.direction<0}",
28                                     :limit => limit)
29
30        snapshots=Snapshot.find(measures.map { |m| m.snapshot_id }, :include => 'project')
31        snapshots_by_id = {}
32        snapshots.each do |s|
33          snapshots_by_id[s.id]=s
34        end
35      end
36
37      unless snapshots && !snapshots.empty? %>
38     <h3><%= title -%></h3>
39     <span class="empty_widget"><%= message('no_results') -%></span>
40   <% else %>
41
42     <div class="line-block">
43       <div style="float:right">
44         <a href="<%= url_for_drilldown(metric) -%>"><%= message('widget.hotspot_metric.more') -%></a>
45       </div>
46       <h3><%= title -%></h3>
47     </div>
48
49     <table id="hotspots-<%= metric.name -%>-<%= widget.id -%>" class="data">
50       <thead>
51       <tr>
52         <th colspan="3"/>
53       </tr>
54       </thead>
55       <tbody>
56       <%
57          if metric.direction > 0
58            metric_max_value = measures.last.value
59          else
60            metric_max_value = measures.first.value
61          end
62          measures.each do |measure|
63            resource = snapshots_by_id[measure.snapshot_id].resource
64       %>
65         <tr class="<%= cycle 'even', 'odd', :name => ('hotspot_metric' + widget.id.to_s) -%>">
66           <td>
67             <%= link_to_resource(resource, h(resource.name), {:metric => metric.name}) -%>
68           </td>
69           <td class="right nowrap">
70             <%= format_measure(measure) -%>
71           </td>
72           <td class="barchart">
73             <div class="barchart" style="width: <%= (measure.value*100/metric_max_value).round.to_i -%>%">
74               <div style="width: 100%;background-color:#777;"></div>
75             </div>
76           </td>
77         </tr>
78       <%
79          end
80       %>
81       </tbody>
82     </table>
83
84   <% end %>
85
86 <% end %>