+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.plugins.core.widgets;
-
-import org.sonar.api.web.WidgetCategory;
-import org.sonar.api.web.WidgetProperties;
-import org.sonar.api.web.WidgetProperty;
-import org.sonar.api.web.WidgetPropertyType;
-
-@WidgetCategory("Hotspots")
-@WidgetProperties(
-{
- @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5"),
- @WidgetProperty(key = "defaultSeverity", type = WidgetPropertyType.SINGLE_SELECT_LIST, defaultValue = "", options = {"INFO", "MINOR", "MAJOR", "CRITICAL", "BLOCKER"})
-})
-public class HotspotMostViolatedRulesWidget extends CoreWidget {
- public HotspotMostViolatedRulesWidget() {
- super("hotspot_most_violated_rules", "Most violated rules", "/org/sonar/plugins/core/widgets/hotspots/hotspot_most_violated_rules.html.erb");
- }
-}
+++ /dev/null
-<%
- limit = widget_properties["numberOfLines"]
- metric_prefix = dashboard_configuration.selected_period? ? 'new_' : ''
- value_column = (dashboard_configuration.selected_period? ? "variation_value_#{dashboard_configuration.period_index}" : 'value')
- measures_by_severity = {}
- all_measures=[]
-
- Severity::KEYS.each do |key|
- rule_measures = @snapshot.rule_measures(Metric.by_key("#{metric_prefix}#{key.downcase}_violations"))
- sorted_measures = rule_measures.select { |a|
- val = a.send(value_column)
- val && val>0
- }.sort { |a, b| b.send(value_column) <=> a.send(value_column) }[0...limit]
- measures_by_severity[key] = sorted_measures
- all_measures.concat(sorted_measures)
- end
- measures_by_severity['all']=all_measures.sort { |a, b| b.send(value_column) <=> a.send(value_column) }[0...limit]
-
- default_severity = widget_properties['defaultSeverity']
- default_severity = 'all' unless Severity::KEYS.include?(default_severity)
-%>
-
-<script type="text/javascript">
- function showMostViolatedRules<%= widget.id -%>(severity) {
- $j('#block_<%= widget.id-%> div.hotspot').hide();
- $j('#most-violated-rules-<%= widget.id -%>-' + severity).show();
- }
-
- function severityForLink() {
- var severity = $j('#select-severity_<%= widget.id -%>').val();
- if (severity == 'all') {
- return '';
- } else {
- return severity;
- }
- }
-</script>
-
-<div class="line-block">
- <div style="float:right">
- <a class="underlined-link" href="#" onclick="window.location.href='<%= url_for(:controller => 'drilldown', :action => 'issues') -%>/<%= @resource.id -%>?period=<%= dashboard_configuration.period_index -%>&severity=' + severityForLink() ">
- <%= message('widget.hotspot_metric.more') -%>
- </a>
- </div>
- <h3>
- <%= message(dashboard_configuration.selected_period? ? 'widget.hotspot_most_violated_rules.name_when_period' : 'widget.hotspot_most_violated_rules.name') %>
-
- <select class="small withIcons" style="margin-left: 20px" onchange="showMostViolatedRules<%= widget.id -%>(this.value);" id="select-severity_<%= widget.id -%>">
- <option value="all" <%= 'selected' if default_severity=='all' -%>><%= message('widget.hotspot_most_violated_rules.any_severity') -%></option>
- <% Severity::KEYS.each do |key| %>
- <option class="sev_<%= key -%>" value="<%= key -%>" <%= 'selected' if default_severity==key -%>><%= message("severity.#{key}") -%></option>
- <% end %>
- </select>
-
- <script>
- $j(function() {
- $j('#select-severity_<%= widget.id -%>').select2({ width: '130px' });
- });
- </script>
- </h3>
-</div>
-
-
-<div>
- <%
- measures_by_severity.each do |severity, measures|
- if measures.empty?
- %>
-
- <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot" style="padding-top:10px">
- <span class="empty_widget"><%= message('widget.hotspot_most_violated_rules.no_violation_for_severity') -%></span>
- </div>
-
- <%
- else
- %>
-
- <div id="most-violated-rules-<%= widget.id -%>-<%= severity -%>" class="hotspot">
- <table class="data">
- <thead>
- <tr>
- <th colspan="3"></th>
- </tr>
- </thead>
- <tbody>
- <%
- max_value = measures.first.send(value_column)
- measures.each do |m|
- rule = m.rule
- value = m.send(value_column)
- %>
- <tr class="<%= cycle 'even', 'odd', :name => ("hotspot_most_violated_rules-#{widget.id}-#{severity}") -%>">
- <td class="thin">
- <i class="icon-severity-<%= m.severity.downcase -%>"></i>
- </td>
- <td>
- <%= h rule.name -%>
- </td>
- <td class="right nowrap">
- <a class="underlined-link <%= widget.key %>_<%= rule.key.parameterize %>" href="<%= url_for(:controller => 'drilldown', :action => 'issues', :id => @resource.key, :rule => rule.key, :rule_sev => m.severity, :period => dashboard_configuration.period_index) -%>">
- <%= dashboard_configuration.selected_period? ? format_variation(m) : format_measure(m) -%>
- </a>
- </td>
- <td class="barchart">
- <div class="barchart" style="width: <%= (value*100/max_value).round.to_i -%>%">
- <div style="width: 100%;"></div>
- </div>
- </td>
- </tr>
- <%
- end
- %>
- </tbody>
- </table>
- </div>
-
- <%
- end
- end
- %>
-</div>
-<script type="text/javascript">
- showMostViolatedRules<%= widget.id -%>("<%= default_severity -%>");
-</script>
widget.hotspot_metric.property.metric.name=Metric
widget.hotspot_metric.property.numberOfLines.name=Number of lines
-widget.hotspot_most_violated_rules.name=Most Violated Rules
-widget.hotspot_most_violated_rules.name_when_period=Most new violated rules
-widget.hotspot_most_violated_rules.description=Shows the rules that are the most violated.
-widget.hotspot_most_violated_rules.no_violation_for_severity=No result
-widget.hotspot_most_violated_rules.any_severity=Any severity
-widget.hotspot_most_violated_rules.property.numberOfLines.name=Number of lines
-widget.hotspot_most_violated_rules.property.defaultSeverity.name=Default severity
-widget.hotspot_most_violated_rules.property.defaultSeverity.desc=If selected, severity used to initialize the dropdown list of widget
-
widget.my_reviews.name=My Unresolved Issues
widget.my_reviews.description=Shows unresolved issues assigned to the current user.
widget.my_reviews.property.numberOfLines.name=Number of lines