]> source.dussan.org Git - sonarqube.git/blob
988f6c606c6c7631181689705e1988409d0d3f73
[sonarqube.git] /
1 <%
2    limit = widget_properties["numberOfLines"]
3    metric_prefix = dashboard_configuration.selected_period? ? 'new_' : ''
4    value_column = (dashboard_configuration.selected_period? ? "variation_value_#{dashboard_configuration.period_index}" : 'value')
5    measures_by_severity = {}
6    all_measures=[]
7
8    Severity::KEYS.each do |key|
9      rule_measures = @snapshot.rule_measures(Metric.by_key("#{metric_prefix}#{key.downcase}_violations"))
10      sorted_measures = rule_measures.select { |a|
11        val = a.send(value_column)
12        val && val>0
13      }.sort { |a, b| b.send(value_column) <=> a.send(value_column) }[0...limit]
14      measures_by_severity[key] = sorted_measures
15      all_measures.concat(sorted_measures)
16    end
17    measures_by_severity['']=all_measures.sort { |a, b| b.send(value_column) <=> a.send(value_column) }[0...limit]
18
19    default_severity = widget_properties['defaultSeverity']
20    default_severity = '' unless Severity::KEYS.include?(default_severity)
21 %>
22
23 <script type="text/javascript">
24   function showMostViolatedRules<%= widget.id -%>(severity) {
25     divs = $$('#widget-<%= widget.id-%> div.hotspot');
26     for (i = 0; i < divs.size(); i++) {
27       divs[i].hide();
28     }
29     $('most-violated-rules-<%= widget.id -%>-' + severity).show();
30   }
31 </script>
32
33 <div class="line-block">
34   <div style="float:right">
35     <a href="#" onclick="window.location.href='<%= url_for(:controller => 'drilldown', :action => 'violations') -%>?id=<%= @resource.key -%>&period=<%= dashboard_configuration.period_index -%>&severity=' + $F('select-severity_<%= widget.id -%>') ">
36       <%= message('widget.hotspot_metric.more') -%>
37     </a>
38   </div>
39   <h3>
40     <%= message(dashboard_configuration.selected_period? ? 'widget.hotspot_most_violated_rules.name_when_period' : 'widget.hotspot_most_violated_rules.name') -%>
41
42     <select class="small withIcons" style="margin-left: 20px" onchange="showMostViolatedRules<%= widget.id -%>(this.value);" id="select-severity_<%= widget.id -%>">
43       <option value="" <%= 'selected' if default_severity=='' -%>><%= message('widget.hotspot_most_violated_rules.any_severity') -%></option>
44       <% Severity::KEYS.each do |key| %>
45         <option class="sev_<%= key -%>" value="<%= key -%>" <%= 'selected' if default_severity==key -%>><%= message("severity.#{key}") -%></option>
46       <% end %>
47     </select>
48   </h3>
49 </div>
50
51
52 <div id="widget-<%= widget.id -%>">
53   <%
54      measures_by_severity.each do |severity, measures|
55        if measures.empty?
56   %>
57
58       <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot" style="padding-top:10px">
59         <span class="empty_widget"><%= message('widget.hotspot_most_violated_rules.no_violation_for_severity') -%></span>
60       </div>
61
62     <%
63        else
64     %>
65
66       <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot">
67         <table class="data">
68           <thead>
69           <tr>
70             <th colspan="3"></th>
71           </tr>
72           </thead>
73           <tbody>
74           <%
75              max_value = measures.first.send(value_column)
76              measures.each do |m|
77                rule = m.rule
78                value = m.send(value_column)
79           %>
80             <tr class="<%= cycle 'even', 'odd', :name => ("hotspot_most_violated_rules-#{widget.id}-#{severity}") -%>">
81               <td class="thin">
82                 <%= image_tag('priority/' + m.severity + '.png') -%>
83               </td>
84               <td>
85                 <a href="<%= url_for(:controller => 'drilldown', :action => 'violations', :id => @resource.key, :rule => rule.key, :rule_sev => m.severity, :period => dashboard_configuration.period_index) -%>">
86                   <%= h rule.name -%>
87                 </a>
88               </td>
89               <td class="right">
90                 <%= dashboard_configuration.selected_period? ? format_variation(m) : format_measure(m) -%>
91               </td>
92               <td class="barchart">
93                 <div class="barchart" style="width: <%= (value*100/max_value).round.to_i -%>%">
94                   <div style="width: 100%;background-color:#777;"></div>
95                 </div>
96               </td>
97             </tr>
98           <%
99              end
100           %>
101           </tbody>
102         </table>
103       </div>
104
105     <%
106        end
107        end
108     %>
109 </div>
110 <script type="text/javascript">
111   showMostViolatedRules<%= widget.id -%>("<%= default_severity -%>");
112 </script>