archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r675415 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main: java/org/apache/maven/archiva/web/action/ webapp/WEB-INF/jsp/ webapp/images/
Date Thu, 10 Jul 2008 02:17:04 GMT
Author: oching
Date: Wed Jul  9 19:17:04 2008
New Revision: 675415

URL: http://svn.apache.org/viewvc?rev=675415&view=rev
Log:
[MRM-861]
-added pagination to search results page

Added:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page.gif
  (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page_disabled.gif
  (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page.gif
  (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page_disabled.gif
  (with props)
Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java?rev=675415&r1=675414&r2=675415&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
Wed Jul  9 19:17:04 2008
@@ -45,7 +45,7 @@
  */
 public class SearchAction
     extends PlexusActionSupport
-{
+{   
     /**
      * Query string.
      */
@@ -76,6 +76,10 @@
     private static final String ARTIFACT = "artifact";
 
     private List databaseResults;
+    
+    private int currentPage = 0;
+    
+    private int totalPages;
 
     public String quickSearch()
         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
@@ -87,8 +91,8 @@
          */
 
         assert q != null && q.length() != 0;
-
-        SearchResultLimits limits = new SearchResultLimits( 0 );
+        
+        SearchResultLimits limits = new SearchResultLimits( currentPage );
         
         List<String> selectedRepos = getObservableRepos();
         if ( CollectionUtils.isEmpty( selectedRepos ) )
@@ -103,7 +107,9 @@
             addActionError( "No results found" );
             return INPUT;
         }
-
+        
+        totalPages = results.getTotalHits() / limits.getPageSize();
+        
         // TODO: filter / combine the artifacts by version? (is that even possible with non-artifact
hits?)
 
         /* I don't think that we should, as I expect us to utilize the 'score' system in
lucene in 
@@ -197,4 +203,24 @@
     {
         return databaseResults;
     }
+    
+    public void setCurrentPage( int page )
+    {
+        this.currentPage = page;
+    }
+    
+    public int getCurrentPage()
+    {
+        return currentPage;
+    }
+
+    public int getTotalPages()
+    {
+        return totalPages;
+    }
+
+    public void setTotalPages( int totalPages )
+    {
+        this.totalPages = totalPages;
+    }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp?rev=675415&r1=675414&r2=675415&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp
Wed Jul  9 19:17:04 2008
@@ -32,6 +32,11 @@
 
 <h1>Search</h1>
 
+<c:url var="imgNextPageUrl" value="/images/icon_next_page.gif"/>
+<c:url var="imgPrevPageUrl" value="/images/icon_prev_page.gif"/>
+<c:url var="imgPrevPageDisabledUrl" value="/images/icon_prev_page_disabled.gif"/>
+<c:url var="imgNextPageDisabledUrl" value="/images/icon_next_page_disabled.gif"/>
+
 <div id="contentArea">
   <div id="searchBox">
     <%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %>
@@ -44,13 +49,72 @@
 
       <%-- search was made from the indices --%>
       <c:when test="${databaseResults == null}">
-        <p>Hits: ${fn:length(results.hits)} of ${results.totalHits}</p>
-
+        <c:set var="hitsNum">${fn:length(results.hits) + (currentPage * 31)}</c:set>
+        <p>Hits: ${hitsNum - 30} to ${hitsNum} of ${results.totalHits}</p>
+        
         <c:choose>
           <c:when test="${empty results.hits}">
             <p>No results</p>
           </c:when>
           <c:otherwise>
+      	      	    
+      	  <%-- Pagination start --%>
+      	    <p>                       
+            <%-- Prev & Next icons --%>
+            <c:set var="prevPageUrl">
+              <ww:url action="quickSearch" namespace="/">
+                <ww:param name="q" value="%{'${q}'}"/>                
+                <ww:param name="currentPage" value="%{'${currentPage - 1}'}"/>
+              </ww:url>
+      	    </c:set>
+      	    <c:set var="nextPageUrl">
+              <ww:url action="quickSearch" namespace="/">
+                <ww:param name="q" value="%{'${q}'}"/>                
+                <ww:param name="currentPage" value="%{'${currentPage + 1}'}"/>
+              </ww:url>
+      	    </c:set>    
+            
+            <c:choose>
+              <c:when test="${currentPage == 0}">                               
+	            <img src="${imgPrevPageDisabledUrl}"/>
+	          </c:when>
+	          <c:otherwise>
+	            <a href="${prevPageUrl}">
+	              <img src="${imgPrevPageUrl}"/>
+	            </a>      
+	          </c:otherwise>
+            </c:choose>
+                         
+            <c:forEach var="i" begin="0" end="${totalPages - 1}">
+			  <c:choose>			    			    
+				<c:when test="${ (i != currentPage) }">
+				   <c:set var="specificPageUrl">
+		              <ww:url action="quickSearch" namespace="/">
+		                <ww:param name="q" value="%{'${q}'}"/>
+		                <ww:param name="currentPage" value="%{'${i}'}"/>
+		              </ww:url>
+		      	  </c:set>
+				  <a href="${specificPageUrl}">${i + 1}</a>
+				</c:when>
+				<c:otherwise>		
+					<b>${i + 1}</b>   
+				</c:otherwise>
+			  </c:choose> 
+			</c:forEach>
+			
+			<c:choose>
+			  <c:when test="${ currentPage eq ( totalPages - 1 ) }">
+			    <img src="${imgNextPageDisabledUrl}"/>
+              </c:when>
+              <c:otherwise>
+	            <a href="${nextPageUrl}">
+	              <img src="${imgNextPageUrl}"/>
+	            </a>
+	          </c:otherwise>   
+            </c:choose>
+            </p>    
+          <%-- Pagination end --%>
+            
             <c:forEach items="${results.hits}" var="record" varStatus="i">
               <c:choose>
                 <c:when test="${not empty (record.groupId)}">

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page.gif
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page.gif?rev=675415&view=auto
==============================================================================
Binary file - no diff available.

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page_disabled.gif
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page_disabled.gif?rev=675415&view=auto
==============================================================================
Binary file - no diff available.

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_next_page_disabled.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page.gif
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page.gif?rev=675415&view=auto
==============================================================================
Binary file - no diff available.

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page_disabled.gif
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page_disabled.gif?rev=675415&view=auto
==============================================================================
Binary file - no diff available.

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/images/icon_prev_page_disabled.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message