]> source.dussan.org Git - sonarqube.git/blob
f9697b58ab2087b26edf96f16ef47570feecd5da
[sonarqube.git] /
1 <%
2    limit = widget_properties["numberOfLines"]
3    metric = Metric.by_key('weighted_violations')
4
5    snapshots_conditions=["snapshots.qualifier in (:qualifiers)", "snapshots.islast=:islast", "snapshots.status = 'P'"]
6    snapshots_values={:qualifiers => @snapshot.leaves_qualifiers, :islast => true}
7    snapshots_conditions << '(snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path)'
8    snapshots_values[:root_sid] = (@snapshot.root_snapshot_id || @snapshot.id)
9    snapshots_values[:path]="#{@snapshot.path}#{@snapshot.id}.%"
10
11    measures_conditions = ["project_measures.rule_id IS NULL AND project_measures.characteristic_id IS NULL AND project_measures.person_id IS NULL"]
12    measures_values = {}
13    measures_conditions << "project_measures.metric_id = :m_id"
14    measures_values[:m_id] = metric.id
15
16    measures=ProjectMeasure.find(:all,
17                                 :joins => :snapshot,
18                                 :conditions => [(snapshots_conditions + measures_conditions).join(' AND '), snapshots_values.merge(measures_values)],
19                                 :order => "project_measures.value #{'DESC' if metric.direction<0}",
20                                 :limit => limit)
21    measures=measures.select{|m| m.text_value.present?}
22
23    snapshots=Snapshot.find(measures.map { |m| m.snapshot_id }, :include => 'project')
24    snapshots_by_id = {}
25    snapshots.each do |s|
26      snapshots_by_id[s.id]=s
27    end
28    
29    title = message('widget.hotspot_most_violated_resources.name')
30    
31    if measures.empty?
32 %>
33
34 <h3><%= title -%></h3>
35 <span class="empty_widget"><%= message('widget.hotspot_most_violated_resources.no_resource') -%></span>
36
37 <%
38    else
39 %>
40
41 <div class="line-block">
42   <div style="float:right">
43     <a href="<%= url_for_drilldown(metric) -%>"><%= message('widget.hotspot_metric.more') -%></a>
44   </div>
45   <h3><%= title -%></h3>
46 </div>
47
48 <table id="most-violated-resources-<%= widget.id -%>" class="data">
49   <thead>
50   <tr>
51     <th colspan="11"></th>
52   </tr>
53   </thead>
54   <tbody>
55   <%
56      measures.each do |measure|
57        resource = snapshots_by_id[measure.snapshot_id].resource
58        violations_per_severity={}
59        measure.text_value.split(';').each do |part|
60          fields=part.split('=')
61          violations_per_severity[fields[0]]=fields[1]
62        end
63   %>
64     <tr class="<%= cycle 'even', 'odd', :name => ('hotspot_most_violated_resources' + widget.id.to_s) -%>">
65       <td>
66         <%= link_to_resource(resource, h(resource.name), {:tab => :violations}) -%>
67       </td>
68       <td class="small right">
69         <i class="icon-severity-blocker"></i>
70       </td>
71       <td class="small left">
72         <%= violations_per_severity["BLOCKER"] ? violations_per_severity["BLOCKER"].to_s : "0" -%>
73       </td>
74       <td class="small right">
75         <i class="icon-severity-critical"></i>
76       </td>
77       <td class="small left">
78         <%= violations_per_severity["CRITICAL"] ? violations_per_severity["CRITICAL"].to_s : "0" -%>
79       </td>
80       <td class="small right">
81         <i class="icon-severity-major"></i>
82       </td>
83       <td class="small left">
84         <%= violations_per_severity["MAJOR"] ? violations_per_severity["MAJOR"].to_s : "0" -%>
85       </td>
86       <td class="small right">
87         <i class="icon-severity-minor"></i>
88       </td>
89       <td class="small left">
90         <%= violations_per_severity["MINOR"] ? violations_per_severity["MINOR"].to_s : "0" -%>
91       </td>
92       <td class="small right">
93         <i class="icon-severity-info"></i>
94       </td>
95       <td class="small left">
96         <%= violations_per_severity["INFO"] ? violations_per_severity["INFO"].to_s : "0" -%>
97       </td>
98     </tr>
99   <%
100      end
101   %>
102   </tbody>
103 </table>
104
105 <% end %>