aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-gwt
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-16 17:47:59 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-16 17:47:59 +0000
commitdcbf1fc1630fa311fdbbe883e4e286d2fa74bd76 (patch)
treeded787ce0bb23b63d67818f75904431cccdb2ba8 /plugins/sonar-core-gwt
parent4b756e42a163a02f2bf29dca930295cfd3c5f0ea (diff)
downloadsonarqube-dcbf1fc1630fa311fdbbe883e4e286d2fa74bd76.tar.gz
sonarqube-dcbf1fc1630fa311fdbbe883e4e286d2fa74bd76.zip
SONAR-1941 add a period filter on violations tab
Diffstat (limited to 'plugins/sonar-core-gwt')
-rw-r--r--plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java11
-rw-r--r--plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsViewer.java82
-rw-r--r--plugins/sonar-core-gwt/src/main/resources/org/sonar/plugins/core/violationsviewer/public/test.html20
3 files changed, 84 insertions, 29 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>