]> source.dussan.org Git - sonarqube.git/blob
145d39e37cd74d627b885a89e459a7b71773369f
[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']=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 = 'all' unless Severity::KEYS.include?(default_severity)
21 %>
22
23 <script type="text/javascript">
24   function showMostViolatedRules<%= widget.id -%>(severity) {
25     divs = $j('#block_<%= widget.id-%> div.hotspot');
26     for (i = 0; i < divs.size(); i++) {
27       divs[i].hide();
28     }
29     $j('#most-violated-rules-<%= widget.id -%>-' + severity).show();
30   }
31
32   function severityForLink() {
33     var severity = $F('select-severity_<%= widget.id -%>');
34     if (severity == 'all') {
35       return '';
36     } else {
37       return severity;
38     }
39   }
40 </script>
41
42 <div class="line-block">
43   <div style="float:right">
44     <a href="#" onclick="window.location.href='<%= url_for(:controller => 'drilldown', :action => 'issues') -%>/<%= @resource.id -%>?period=<%= dashboard_configuration.period_index -%>&severity=' + severityForLink() ">
45       <%= message('widget.hotspot_metric.more') -%>
46     </a>
47   </div>
48   <h3>
49     <%= message(dashboard_configuration.selected_period? ? 'widget.hotspot_most_violated_rules.name_when_period' : 'widget.hotspot_most_violated_rules.name') %>
50
51     <select class="small withIcons" style="margin-left: 20px" onchange="showMostViolatedRules<%= widget.id -%>(this.value);" id="select-severity_<%= widget.id -%>">
52       <option value="all" <%= 'selected' if default_severity=='all' -%>><%= message('widget.hotspot_most_violated_rules.any_severity') -%></option>
53       <% Severity::KEYS.each do |key| %>
54         <option class="sev_<%= key -%>" value="<%= key -%>" <%= 'selected' if default_severity==key -%>><%= message("severity.#{key}") -%></option>
55       <% end %>
56     </select>
57
58     <script>
59       $j(function() {
60         $j('#select-severity_<%= widget.id -%>').select2({ width: '130px' });
61       });
62     </script>
63   </h3>
64 </div>
65
66
67 <div>
68   <%
69      measures_by_severity.each do |severity, measures|
70        if measures.empty?
71   %>
72
73       <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot" style="padding-top:10px">
74         <span class="empty_widget"><%= message('widget.hotspot_most_violated_rules.no_violation_for_severity') -%></span>
75       </div>
76
77     <%
78        else
79     %>
80
81       <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot">
82         <table class="data">
83           <thead>
84           <tr>
85             <th colspan="3"></th>
86           </tr>
87           </thead>
88           <tbody>
89           <%
90              max_value = measures.first.send(value_column)
91              measures.each do |m|
92                rule = m.rule
93                value = m.send(value_column)
94           %>
95             <tr class="<%= cycle 'even', 'odd', :name => ("hotspot_most_violated_rules-#{widget.id}-#{severity}") -%>">
96               <td class="thin">
97                 <%= image_tag('priority/' + m.severity + '.png') -%>
98               </td>
99               <td>
100                 <%= h rule.name -%>
101               </td>
102               <td class="right nowrap">
103                 <a class="nolink" href="<%= url_for(:controller => 'drilldown', :action => 'issues', :id => @resource.key, :rule => rule.key, :rule_sev => m.severity, :period => dashboard_configuration.period_index) -%>">
104                   <%= dashboard_configuration.selected_period? ? format_variation(m) : format_measure(m) -%>
105                 </a>
106               </td>
107               <td class="barchart">
108                 <div class="barchart" style="width: <%= (value*100/max_value).round.to_i -%>%">
109                   <div style="width: 100%;background-color:#777;"></div>
110                 </div>
111               </td>
112             </tr>
113           <%
114              end
115           %>
116           </tbody>
117         </table>
118       </div>
119
120     <%
121        end
122        end
123     %>
124 </div>
125 <script type="text/javascript">
126   showMostViolatedRules<%= widget.id -%>("<%= default_severity -%>");
127 </script>