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 = {}
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)
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)
17 measures_by_severity['']=all_measures.sort { |a, b| b.send(value_column) <=> a.send(value_column) }[0...limit]
19 default_severity = widget_properties['defaultSeverity']
20 default_severity = '' unless Severity::KEYS.include?(default_severity)
23 <script type="text/javascript">
24 function showMostViolatedRules<%= widget.id -%>(severity) {
25 divs = $$('#block_<%= widget.id-%> div.hotspot');
26 for (i = 0; i < divs.size(); i++) {
29 $('most-violated-rules-<%= widget.id -%>-' + severity).show();
33 <div class="line-block">
34 <div style="float:right">
35 <a href="#" onclick="window.location.href='<%= url_for(:controller => 'drilldown', :action => 'violations') -%>/<%= @resource.id -%>?period=<%= dashboard_configuration.period_index -%>&severity=' + $F('select-severity_<%= widget.id -%>') ">
36 <%= message('widget.hotspot_metric.more') -%>
40 <%= message(dashboard_configuration.selected_period? ? 'widget.hotspot_most_violated_rules.name_when_period' : 'widget.hotspot_most_violated_rules.name') -%>
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>
54 measures_by_severity.each do |severity, measures|
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>
66 <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot">
75 max_value = measures.first.send(value_column)
78 value = m.send(value_column)
80 <tr class="<%= cycle 'even', 'odd', :name => ("hotspot_most_violated_rules-#{widget.id}-#{severity}") -%>">
82 <%= image_tag('priority/' + m.severity + '.png') -%>
85 <a href="<%= url_for(:controller => 'drilldown', :action => 'violations', :id => @resource.key, :rule => rule.key, :rule_sev => m.severity, :period => dashboard_configuration.period_index) -%>">
89 <td class="right nowrap">
90 <%= dashboard_configuration.selected_period? ? format_variation(m) : format_measure(m) -%>
93 <div class="barchart" style="width: <%= (value*100/max_value).round.to_i -%>%">
94 <div style="width: 100%;background-color:#777;"></div>
110 <script type="text/javascript">
111 showMostViolatedRules<%= widget.id -%>("<%= default_severity -%>");