aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/DefaultJRubyIssues.java7
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb5
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb33
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/issues/_list.html.erb7
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/DefaultJRubyIssuesTest.java6
5 files changed, 53 insertions, 5 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/DefaultJRubyIssues.java b/sonar-server/src/main/java/org/sonar/server/issue/DefaultJRubyIssues.java
index a4a36c35641..678cde67fab 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/DefaultJRubyIssues.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/DefaultJRubyIssues.java
@@ -23,6 +23,7 @@ import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
+import com.google.common.primitives.Ints;
import org.sonar.api.issue.IssueChange;
import org.sonar.api.issue.IssueFinder;
import org.sonar.api.issue.IssueQuery;
@@ -83,7 +84,7 @@ public class DefaultJRubyIssues implements JRubyIssues {
builder.createdAfter(toDate(props.get("createdAfter")));
builder.createdBefore(toDate(props.get("createdBefore")));
builder.limit(toInteger(props.get("limit")));
-// builder.offset(toInteger(props.get("offset")));
+ builder.page(toInteger(props.get("page")));
return builder.build();
}
@@ -158,6 +159,10 @@ public class DefaultJRubyIssues implements JRubyIssues {
if (o instanceof Integer) {
return (Integer) o;
}
+ if (o instanceof Long) {
+ return Ints.checkedCast((Long) o);
+ }
+
if (o instanceof String) {
return Integer.parseInt((String) o);
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
index 3d1a1acb1a2..18a9c7c13f0 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
@@ -21,7 +21,10 @@
class IssuesController < ApplicationController
def index
- @issues = find_issues({}).issues
+ page = params[:page_id] || 1
+ issues_result = find_issues({'limit' => 2, 'page' => page})
+ @pagination = issues_result.pagination
+ @issues = issues_result.issues.collect {|issue| issue}
end
protected
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 a03a4d8fe42..0b232a13089 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
@@ -535,6 +535,39 @@ module ApplicationHelper
end
#
+ # Creates a pagination section for the given array (items_array) if its size exceeds the pagination size (default: 20).
+ # Upon completion of this method, the HTML is returned and the given array contains only the selected elements.
+ #
+ # In any case, the HTML that is returned contains the message 'x results', where x is the total number of elements
+ # in the items_array object.
+ #
+ # === Optional parameters
+ # * page_size: the number of elements to display at the same time (= the pagination size)
+ #
+ def paginate_java(pagination)
+ size = pagination.size.to_i
+ page_id = pagination.page ? pagination.page.to_i : 1
+ page_size = pagination.limit.to_i || 20
+ page_count = pagination.pages.to_i
+
+ html = size.to_s + " " + message('results').downcase
+
+ if size > page_size
+ # render the pagination links
+ html += " | "
+ html += link_to_if page_id>1, message('paging_previous'), {:overwrite_params => {:page_id => page_id-1}}
+ html += " "
+ for index in 1..page_count
+ html += link_to_unless index==page_id, index.to_s, {:overwrite_params => {:page_id => index}}
+ html += " "
+ end
+ html += link_to_if page_id<page_count, message('paging_next'), {:overwrite_params => {:page_id => 1+page_id}}
+ end
+
+ html
+ end
+
+ #
# Used on the reviews listing page (http://localhost:9000/project_reviews)
# Prints a label for the given parameter that is used to filter the review list.
# The label has:
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_list.html.erb
index 9b5b4bd257d..a8b1f02f826 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_list.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issues/_list.html.erb
@@ -51,6 +51,13 @@
</th>
</tr>
</thead>
+ <tfoot>
+ <tr>
+ <td colspan="6">
+ <%= paginate_java(@pagination) -%>
+ </td>
+ </tr>
+ </tfoot>
<tbody>
<%
@issues.each do |issue|
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/DefaultJRubyIssuesTest.java b/sonar-server/src/test/java/org/sonar/server/issue/DefaultJRubyIssuesTest.java
index fefed446ddf..89c0433ac4a 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/DefaultJRubyIssuesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/DefaultJRubyIssuesTest.java
@@ -70,8 +70,8 @@ public class DefaultJRubyIssuesTest {
map.put("createdAfter", "2013-04-16T09:08:24+0200");
map.put("createdBefore", "2013-04-17T09:08:24+0200");
map.put("rules", "squid:AvoidCycle,findbugs:NullReference");
- map.put("limit", 10);
- map.put("offset", 50);
+ map.put("limit", 10l);
+ map.put("page", 50);
IssueQuery query = new DefaultJRubyIssues(finder, changes).toQuery(map);
assertThat(query.keys()).containsOnly("ABCDE1234");
@@ -86,7 +86,7 @@ public class DefaultJRubyIssuesTest {
assertThat(query.createdAfter()).isEqualTo(DateUtils.parseDateTime("2013-04-16T09:08:24+0200"));
assertThat(query.createdBefore()).isEqualTo(DateUtils.parseDateTime("2013-04-17T09:08:24+0200"));
assertThat(query.limit()).isEqualTo(10);
-// assertThat(query.offset()).isEqualTo(50);
+ assertThat(query.page()).isEqualTo(50);
}
@Test