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']=all_measures.sort { |a, b| b.send(value_column) <=> a.send(value_column) }[0...limit]
19 default_severity = widget_properties['defaultSeverity']
20 default_severity = 'all' unless Severity::KEYS.include?(default_severity)
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++) {
29 $j('#most-violated-rules-<%= widget.id -%>-' + severity).show();
32 function severityForLink() {
33 var severity = $F('select-severity_<%= widget.id -%>');
34 if (severity == 'all') {
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') -%>
49 <%= message(dashboard_configuration.selected_period? ? 'widget.hotspot_most_violated_rules.name_when_period' : 'widget.hotspot_most_violated_rules.name') %>
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>
60 $j('#select-severity_<%= widget.id -%>').select2({ width: '130px' });
69 measures_by_severity.each do |severity, measures|
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>
81 <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot">
90 max_value = measures.first.send(value_column)
93 value = m.send(value_column)
95 <tr class="<%= cycle 'even', 'odd', :name => ("hotspot_most_violated_rules-#{widget.id}-#{severity}") -%>">
97 <%= image_tag('priority/' + m.severity + '.png') -%>
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) -%>
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>
125 <script type="text/javascript">
126 showMostViolatedRules<%= widget.id -%>("<%= default_severity -%>");