diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-16 17:47:59 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-16 17:47:59 +0000 |
commit | dcbf1fc1630fa311fdbbe883e4e286d2fa74bd76 (patch) | |
tree | ded787ce0bb23b63d67818f75904431cccdb2ba8 | |
parent | 4b756e42a163a02f2bf29dca930295cfd3c5f0ea (diff) | |
download | sonarqube-dcbf1fc1630fa311fdbbe883e4e286d2fa74bd76.tar.gz sonarqube-dcbf1fc1630fa311fdbbe883e4e286d2fa74bd76.zip |
SONAR-1941 add a period filter on violations tab
9 files changed, 133 insertions, 65 deletions
diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java index 8f2f85acabd..42b63b4b87f 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.core.violationsviewer.client; +import com.google.gwt.user.client.Window; import org.sonar.gwt.Links; import org.sonar.gwt.Utils; import org.sonar.gwt.ui.Icons; @@ -37,9 +38,9 @@ public class ViolationsPanel extends SourcePanel { private Map<Integer, List<Violation>> filteredViolationsByLine = new HashMap<Integer, List<Violation>>(); private final static Date now = new Date(); - public ViolationsPanel(Resource resource, String filter) { + public ViolationsPanel(Resource resource, String filter, Date fromDate) { super(resource); - loadViolations(resource, filter, null); + loadViolations(resource, filter, fromDate); } protected void loadViolations(final Resource resource, final String filter, final Date fromDate) { @@ -65,7 +66,11 @@ public class ViolationsPanel extends SourcePanel { public void filter(String filter, Date fromDate) { filteredViolationsByLine.clear(); for (Violation violation : violations) { - if (filter == null || filter.equals("") || violation.getRuleKey().equals(filter) || violation.getSeverity().equals(filter) || violation.isCreatedAfter(fromDate)) { + if (// check text filter + (filter == null || filter.equals("") || violation.getRuleKey().equals(filter) || violation.getSeverity().equals(filter)) && + + // check date filter + (fromDate == null || violation.isCreatedAfter(fromDate))) { Integer line = 0; if (violation.getLine() != null) { line = violation.getLine(); diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsViewer.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsViewer.java index 35e00a660d7..804b143edb8 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsViewer.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsViewer.java @@ -26,6 +26,7 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.gen2.table.override.client.Grid; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Configuration; +import org.sonar.gwt.JsonUtils; import org.sonar.gwt.Metrics; import org.sonar.gwt.ui.Icons; import org.sonar.gwt.ui.Loading; @@ -36,8 +37,7 @@ import org.sonar.wsclient.services.Measure; import org.sonar.wsclient.services.Resource; import org.sonar.wsclient.services.ResourceQuery; -import java.util.Collections; -import java.util.Comparator; +import java.util.*; public class ViolationsViewer extends Page { public static final String GWT_ID = "org.sonar.plugins.core.violationsviewer.ViolationsViewer"; @@ -49,6 +49,7 @@ public class ViolationsViewer extends Page { // header private Grid header = null; private ListBox filterBox = null, periodBox = null; + private List<Date> dateFilters = new ArrayList<Date>(); private CheckBox expandCheckbox = null; private String defaultFilter; @@ -70,26 +71,11 @@ public class ViolationsViewer extends Page { header.setStylePrimaryName("gwt-ViewerHeader"); header.getCellFormatter().setStyleName(0, 0, "thin left"); - initDefaultFilter(); - sourcePanel = new ViolationsPanel(resource, defaultFilter); header.getCellFormatter().setStyleName(0, 1, "right"); - filterBox = new ListBox(); - filterBox.addItem(I18nConstants.INSTANCE.noFilters(), ""); - filterBox.setStyleName("small"); - filterBox.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - String filter = filterBox.getValue(filterBox.getSelectedIndex()); - loadSources(); - sourcePanel.filter(filter, null); - sourcePanel.refresh(); - } - }); - - periodBox = new ListBox(); - periodBox.addItem(I18nConstants.INSTANCE.noFilters(), ""); - periodBox.setStyleName("small"); + initDefaultFilter(); + initFilterBoxes(); header.setWidget(0, 1, periodBox); header.getCellFormatter().setStyleName(0, 1, "thin cell right"); @@ -111,10 +97,68 @@ public class ViolationsViewer extends Page { header.setWidget(0, 4, expandCheckbox); header.getCellFormatter().setStyleName(0, 4, "thin cell left"); + sourcePanel = new ViolationsPanel(resource, getCurrentRuleFilter(), getCurrentDateFilter()); + loadRuleSeverities(); return mainPanel; } + private void initFilterBoxes() { + initFilterBox(); + initPeriodBox(); + + ChangeHandler changeHandler = new ChangeHandler() { + public void onChange(ChangeEvent event) { + loadSources(); + sourcePanel.filter(getCurrentRuleFilter(), getCurrentDateFilter()); + sourcePanel.refresh(); + } + }; + filterBox.addChangeHandler(changeHandler); + periodBox.addChangeHandler(changeHandler); + } + + private void initFilterBox() { + filterBox = new ListBox(); + filterBox.addItem(I18nConstants.INSTANCE.noFilters(), ""); + filterBox.setStyleName("small"); + } + + private void initPeriodBox() { + periodBox = new ListBox(); + periodBox.setStyleName("small"); + periodBox.addItem(I18nConstants.INSTANCE.noFilters()); + + initPeriod(1); + initPeriod(2); + initPeriod(3); + initPeriod(4); + initPeriod(5); + } + + private void initPeriod(int periodIndex) { + String period = Configuration.getParameter("period" + periodIndex); + if (period != null) { + Date date = JsonUtils.parseDateTime(Configuration.getParameter("period" + periodIndex + "_date")); + if (date != null) { + periodBox.addItem(period); + dateFilters.add(date); + } + } + } + + private Date getCurrentDateFilter() { + Date dateFilter = null; + if (periodBox.getSelectedIndex() > 0) { + dateFilter = dateFilters.get(periodBox.getSelectedIndex() - 1); + } + return dateFilter; + } + + private String getCurrentRuleFilter() { + return filterBox.getValue(filterBox.getSelectedIndex()); + } + private void initDefaultFilter() { defaultFilter = Configuration.getRequestParameter("rule"); if (defaultFilter == null) { diff --git a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/violationsviewer/public/test.html b/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/violationsviewer/public/test.html index 7c0a06d111e..dd3e877e5bd 100644 --- a/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/violationsviewer/public/test.html +++ b/plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/violationsviewer/public/test.html @@ -5,19 +5,23 @@ <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Violations</title> - <link href="http://localhost:9000/dev/stylesheets/yui-2.6.0.css" media="all" rel="Stylesheet" type="text/css"/> - <link href="http://localhost:9000/dev/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/> - <script src="http://localhost:9000/dev/javascripts/application.js" type="text/javascript"></script> - <script src="http://localhost:9000/dev/javascripts/prototype.js" type="text/javascript"></script> - <script src="http://localhost:9000/dev/javascripts/scriptaculous.js" type="text/javascript"></script> + <link href="http://localhost:9000/stylesheets/yui-2.6.0.css" media="all" rel="Stylesheet" type="text/css"/> + <link href="http://localhost:9000/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css"/> + <script src="http://localhost:9000/javascripts/application.js" type="text/javascript"></script> + <script src="http://localhost:9000/javascripts/prototype.js" type="text/javascript"></script> + <script src="http://localhost:9000/javascripts/scriptaculous.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> var registeredTabs = []; + var modules={}; var config = { - "sonar_url": "http://localhost:9000/dev", - "viewer_resource_key": "org.sonar.tests:reference:org.sonar.samples.PrivateClass" + "sonar_url": "http://localhost:9000", + "resource":[{"id": 369, "key":"org.sonar.tests:violations-timemachine:org.sonar.tests.violationstimemachine.Hello","scope": "FIL", "qualifier": "CLA", "name": "Hello", "lang":"java"}], + "viewer_resource_key": "org.sonar.tests:violations-timemachine:org.sonar.tests.violationstimemachine.Hello", + "period1" : "Violations created after previous analysis", + "period1_date" : "2010-11-03T00:01:00+0200" }; var request_parameters = {"priority": "BLOCKER"} </script> @@ -33,6 +37,8 @@ <div id="resource_viewers"> </div> +<div id="gwtpage"> +</div> <script type="text/javascript" language="javascript" src="org.sonar.plugins.core.violationsviewer.ViolationsViewer.nocache.js"></script> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index 242be6bc1f5..916064adc1e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -75,6 +75,26 @@ module ApplicationHelper params['configuring']=='true' end + def period_label(snapshot, period_index) + return nil if snapshot.nil? || snapshot.project_snapshot.nil? + mode=snapshot.project_snapshot.send "period#{period_index}_mode" + mode_param=snapshot.project_snapshot.send "period#{period_index}_param" + + label='' + if mode + if mode=='days' + label = "%s previous days" % mode_param + elsif mode=='version' + label = "Version %s" % mode_param + elsif mode=='previous_analysis' + label = "Previous analysis (%s)" % localize(Date.parse(mode_param)) + elsif mode=='date' + label = "Date: #{localize(Date.parse(mode_param))}" + end + end + label + end + def html_measure(measure, metric_name=nil, show_alert_status=true, url=nil, suffix='', small=true, no_tendency_img=false) html='' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb index f49827b46cb..b6473f95dee 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb @@ -29,24 +29,10 @@ module DashboardHelper end def period_select_options(snapshot, index) - return nil if snapshot.nil? || snapshot.project_snapshot.nil? - mode=snapshot.project_snapshot.send "period#{index}_mode" - mode_param=snapshot.project_snapshot.send "period#{index}_param" - - if mode - if mode=='days' - label = "Compare to %s previous days" % mode_param - elsif mode=='version' - label = "Compare to version %s" % mode_param - elsif mode=='previous_analysis' - label = "Compare to previous analysis (%s)" % localize(Date.parse(mode_param)) - elsif mode=='date' - label = "Compare to #{localize(Date.parse(mode_param))}" - end - if label - selected=(params[:period]==index.to_s ? 'selected' : '') - "<option value='#{index}' #{selected}>#{label}</option>" - end + label=period_label(snapshot, index) + if label + selected=(params[:period]==index.to_s ? 'selected' : '') + "<option value='#{index}' #{selected}>#{label}</option>" else nil end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb index da1002c6288..9a0c9fb913e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/filters_helper.rb @@ -171,14 +171,14 @@ module FiltersHelper def period_name(property) if property=='previous_analysis' - "Since previous analysis" + "Compare to previous analysis" elsif property =~ /^[\d]+(\.[\d]+){0,1}$/ # is integer - "Previous #{property} days" + "Compare to previous #{property} days" elsif property =~ /\d{4}-\d{2}-\d{2}/ - "Since #{property}" + "Compare to #{property}" elsif !property.blank? - "Since version #{property}" + "Compare to version #{property}" else nil end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb index f608d3a7da9..fd245d00529 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/_list.html.erb @@ -1,14 +1,17 @@ <% filter=@filter_context.filter %> <div> -Period: -<form action="<%= url_for :overwrite_params => {:period => nil} -%>" style="display: inline" method="get"> - <select name="period" onchange="submit()" class="small"> - <option value="">None</option> - <% period_names.each_with_index do |name, index| %> - <option value="<%= index+1 -%>" <%= 'selected' if @filter_context.period_index==index+1 -%>><%= name -%></value> - <% end %> - </select> -</form> + <div class="line-block"> + <div class="operations"> + <form action="<%= url_for :overwrite_params => {:period => nil} -%>" style="display: inline" method="get"> + <select name="period" onchange="submit()" class="small"> + <option value="">Trends</option> + <% period_names.each_with_index do |name, index| %> + <option value="<%= index+1 -%>" <%= 'selected' if @filter_context.period_index==index+1 -%>><%= name -%></value> + <% end %> + </select> + </form> + </div> + </div> <table class="data nowrap width100" id="results"> <thead id="results-head"> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb index 4f57e2112ff..eaa8e3d7636 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb @@ -13,23 +13,23 @@ <% end %> <% if @snapshot %> <% if @snapshot.project_snapshot.period1_mode %> - ,"period1": "<%= @snapshot.project_snapshot.period1_mode -%>" + ,"period1": "<%= period_label(@snapshot, 1) -%>" ,"period1_date": "<%= @snapshot.project_snapshot.period1_date.strftime("%Y-%m-%dT%H:%M:%S%z") -%>" <% end if @snapshot.project_snapshot.period2_mode %> - ,"period2": "<%= @snapshot.project_snapshot.period2_mode -%>" + ,"period2": "<%= period_label(@snapshot, 2) -%>" ,"period2_date": "<%= @snapshot.project_snapshot.period2_date.strftime("%Y-%m-%dT%H:%M:%S%z") -%>" <% end if @snapshot.project_snapshot.period3_mode %> - ,"period3": "<%= @snapshot.project_snapshot.period3_mode -%>" + ,"period3": "<%= period_label(@snapshot, 3) -%>" ,"period3_date": "<%= @snapshot.project_snapshot.period3_date.strftime("%Y-%m-%dT%H:%M:%S%z") -%>" <% end if @snapshot.project_snapshot.period4_mode %> - ,"period4": "<%= @snapshot.project_snapshot.period4_mode -%>" + ,"period4": "<%= period_label(@snapshot, 4) -%>" ,"period4_date": "<%= @snapshot.project_snapshot.period4_date.strftime("%Y-%m-%dT%H:%M:%S%z") -%>" <% end if @snapshot.project_snapshot.period5_mode %> - ,"period5": "<%= @snapshot.project_snapshot.period5_mode -%>" + ,"period5": "<%= period_label(@snapshot, 5) -%>" ,"period5_date": "<%= @snapshot.project_snapshot.period5_date.strftime("%Y-%m-%dT%H:%M:%S%z") -%>" <% end %> <% end %> diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index c63c1a72527..98b72c1a42b 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -571,6 +571,10 @@ table.form td img { display: inline-block; width: 100%; } +div.operations { + float: right; + margin: 0; +} ul.operations { float: right; list-style-type: none; |