Scarab commit: svn commit: r11284 - branches/scarab_11079_legacy_with_ant_maven1/src: java/org/tigris/scarab/actions java/org/tigris/scarab/screens java/org/tigris/scarab/tools webapp/WEB-INF/templates/macros webapp/WEB-INF/templates/screens
[email protected] Sun, 10 Jun 2012 09:58:21 -0700 (PDT)
| Newsgroups | gmane.comp.java.scarab.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: dabbous
Date: 2012-06-10 09:58:20-0700
New Revision: 11284
Modified:
branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/actions/Search.java
branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/screens/IssueList.java
branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/tools/ScarabRequestTool.java
branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/macros/AdvancedQueryMacro.vm
branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/EditQuery.vm
branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/IssueList.vm
Log:
Fix: sorting for internal sort columns
Modified: branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/actions/Search.java
Url: http://scarab.tigris.org/source/browse/scarab/branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/actions/Search.java?view=diff&pathrev=11284&r1=11283&r2=11284
==============================================================================
--- branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/actions/Search.java (original)
+++ branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/actions/Search.java 2012-06-10 09:58:20-0700
@@ -813,11 +813,20 @@
String[] values = data.getParameters().getStrings(key);
for (int j=0; j<values.length; j++)
{
+ String fkey = key;
String value = values[j];
if (StringUtils.isNotEmpty(value))
- {
- buf.append('&').append(key);
+ {
+ if(key.startsWith("searchsai"))
+ {
+ if ("issueid".equals(value) || RModuleUserAttribute.isInternal(value, true))
+ {
+ fkey="sortinternal";
+ }
+ }
+ buf.append("&").append(fkey);
buf.append('=').append(ScarabUtil.urlEncode(value));
+
}
}
}
Modified: branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/screens/IssueList.java
Url: http://scarab.tigris.org/source/browse/scarab/branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/screens/IssueList.java?view=diff&pathrev=11284&r1=11283&r2=11284
==============================================================================
--- branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/screens/IssueList.java (original)
+++ branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/screens/IssueList.java 2012-06-10 09:58:20-0700
@@ -49,11 +49,15 @@
import java.util.List;
import org.apache.commons.lang.StringUtils;
+import org.apache.fulcrum.parser.ParameterParser;
+import org.apache.fulcrum.parser.StringValueParser;
import org.apache.turbine.RunData;
import org.apache.turbine.TemplateContext;
+import org.tigris.scarab.om.ScarabUser;
import org.tigris.scarab.tools.ScarabLocalizationTool;
import org.tigris.scarab.tools.ScarabRequestTool;
+import org.tigris.scarab.util.ScarabUtil;
/**
* The sole purpose of this class is to generate a page
@@ -72,11 +76,21 @@
}
- private void populateContextWithQueryResults(RunData data, TemplateContext context)
+ private void populateContextWithQueryResults(RunData data, TemplateContext context) throws Exception
{
- ScarabRequestTool scarabR = getScarabRequestTool(context);
+ ScarabRequestTool scarabR = getScarabRequestTool(context);
+
+ // =============================================
+ // Perform the search (or get it from the cache)
+ // =============================================
List searchResults = scarabR.getCurrentSearchResults();
+
+
+ // =============================================
+ // Prepare the display in IssueList.vm
+ // =============================================
+
int searchResultsSize = searchResults.size();
int resultsPerPage = data.getParameters().getInt("resultsPerPage", 25);
int pageNum = data.getParameters().getInt("pageNum", 1 );
@@ -95,6 +109,57 @@
context.put("isueListSize", new Integer(isueListSize));
context.put("paginated", new Boolean(paginated));
context.put("resultsPerPage", new Integer(resultsPerPage));
+
+ ScarabUser user = (ScarabUser)data.getUser();
+ String currentQueryString = user.getMostRecentQuery();
+ StringValueParser qp = ScarabUtil.parseURL(currentQueryString);
+
+ ParameterParser pp = data.getParameters();
+
+ // =======================================================
+ // Add Sort parameters for usage in the Velocity template:
+ //
+ // $sortInternal
+ // $sortColumn
+ // $sortPolarity
+ // =======================================================
+
+ String sortinternal = null;
+ if(pp.containsKey("sortcolumn"))
+ {
+ String sortcolumn = pp.get("sortcolumn");
+ if (sortcolumn == null || "null".equals(sortcolumn))
+ {
+ // for some reason sortintern is sometimes set to null
+ // this indicates the default behaviour: sort by IssueID
+ sortinternal = "issueid";
+ }
+ else
+ {
+ context.put("sortColumn", sortcolumn );
+ }
+ }
+ else
+ {
+ sortinternal = qp.get("sortinternal");
+ }
+ if(sortinternal != null) context.put("sortInternal", sortinternal );
+
+
+
+ String sortpolarity;
+ if(pp.containsKey("sortpolarity"))
+ {
+ sortpolarity = pp.get("sortpolarity");
+ }
+ else
+ {
+ // Not sure where searcsp is used and why it exists.
+ // Maybe related to Intake ?
+ sortpolarity = qp.get("searchsp");
+ }
+ if(sortpolarity != null) context.put("sortPolarity", sortpolarity);
+
}
/**
Modified: branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/tools/ScarabRequestTool.java
Url: http://scarab.tigris.org/source/browse/scarab/branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/tools/ScarabRequestTool.java?view=diff&pathrev=11284&r1=11283&r2=11284
==============================================================================
--- branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/tools/ScarabRequestTool.java (original)
+++ branches/scarab_11079_legacy_with_ant_maven1/src/java/org/tigris/scarab/tools/ScarabRequestTool.java 2012-06-10 09:58:20-0700
@@ -120,6 +120,7 @@
import org.tigris.scarab.om.RModuleIssueType;
import org.tigris.scarab.om.RModuleIssueTypePeer;
import org.tigris.scarab.om.RModuleOption;
+import org.tigris.scarab.om.RModuleUserAttribute;
import org.tigris.scarab.om.ROptionOption;
import org.tigris.scarab.om.ReportManager;
import org.tigris.scarab.om.ScarabUser;
@@ -1973,17 +1974,59 @@
}
}
- String sortColumn = data.getParameters().getString("sortColumn");
- if(isValidIssueSearchSortColumn(sortColumn))
+ // The query can be "modified" by URL Requests parameters:
+ // We can provide:
+ //
+ // sortcolumn The ID of a new sort column
+ // sortinternal The name of an internal sort column
+ // sortpolarity "asc" or "desc"
+ // searchsp "asc" or "desc" (not sure about what that is)
+ //
+ // There is one irregularity: sortcolumn can be existing and have the value "null"
+ // This means, that the sort shall use the IssueID as sort criterion (needs cleanup)
+ // Note, that if sortcolumn AND sortinternal are specified,
+ // then sortcolumn rules.
+
+
+ // Here we either get a modified sortColumn:
+ String sortColumn = getModifiedQueryParameter("sortColumn", data, parser);
+ if("null".equals(sortColumn))
+ {
+ // This is a sort by IssueId -> do nothing!
+ }
+ else
+ {
+ if(isValidIssueSearchSortColumn(sortColumn))
+ {
+ search.setSortAttributeId( Integer.valueOf(sortColumn) );
+ }
+
+ // or a modified sortInternal
+ else
+ {
+ String sortinternal = data.getParameters().getString("sortInternal");
+ if (!RModuleUserAttribute.isInternal(sortinternal, true))
+ {
+ sortinternal = parser.get("sortinternal");
+ }
+ if (sortinternal != null) search.setSortInternalAttribute(sortinternal);
+ }
+ }
+
+ String sortpolarity = data.getParameters().getString("sortPolarity");
+ if(sortpolarity == null)
{
- search.setSortAttributeId( Integer.valueOf(sortColumn) );
+ sortpolarity = parser.get("sortpolarity");
+ if(sortpolarity == null)
+ {
+ sortpolarity = parser.get("searchsp");
+ }
}
- search.setSortInternalAttribute(data.getParameters().getString("sortInternal"));
- search.setSortPolarity(data.getParameters().getString("sortPolarity"));
+ if(sortpolarity != null) search.setSortPolarity(sortpolarity);
return search;
- }
-
+ }
+
/**
* Check if a sortColumn is a sortColumn of an user-search (always a String)
* or a sortColumn of an issue-search (always an Integer)
@@ -2047,6 +2090,22 @@
return queryResults;
}
+ static public String getModifiedQueryParameter(String name, RunData theData, StringValueParser parser)
+ {
+ String result;
+ String vals[] = theData.getParameters().getStrings(name);
+ if (vals != null && vals.length > 0)
+ {
+ result = vals[0];
+ }
+ else
+ {
+ result = parser.get(name);
+ }
+ return result;
+ }
+
+
/**
* Gets the Result of the current query
* and caches it
@@ -2063,23 +2122,41 @@
// <scarabHost>/scarab/issues/query/<queryId>
//
// The queryId should be sufficient to setup the full query.
- // But i have seen a problem, when the user has only limitted
+ // But i have seen a problem, when the user has only limited
// module read permissions. In that case the LoginValve
- // forces a login before the query can be perfromed.
+ // forces a login before the query can be performed.
// Workaround: Also add the moduleId to the URL:
//
// <scarabHost>/scarab/issues/query/<queryId>/curmodule/<moduleId>
//
// The current solution always uses the default MITList, hence it will
- // not take care of user customized resultsets.
+ // not take care of user customized result sets.
// I am not sure, where to place this code and how to actually
- // control the search-Subsystem so that it will perfrom the correct
+ // control the search-Subsystem so that it will perform the correct
// search. Any help and advice for a better solution is heavily welcome!!!
-
+
+
+ // The query can be "modified" by URL Requests parameters:
+ // We can provide:
+ //
+ // sortcolumn The ID of a new sort column
+ // sortinternal The name of an internal sort column
+ // sortpolarity "asc" or "desc"
+ // searchsp "asc" or "desc" (not sure about what that is)
+ //
+ // There is one irregularity: sortcolumn can be existing and have the value "null"
+ // This means, that the sort shall use the IssueID as sort criterion (needs cleanup)
+ // Note, that if sortcolumn AND sortinternal are specified,
+ // then sortcolumn rules.
+
String currentQueryString = user.getMostRecentQuery();
- String sortColumn = data.getParameters().getString("sortColumn");
- String sortInternal=data.getParameters().getString("sortInternal");
- String sortPolarity = data.getParameters().getString("sortPolarity");
+ StringValueParser queryStringparser = ScarabUtil.parseURL(currentQueryString);
+
+ String sortColumn = getModifiedQueryParameter("sortColumn", data, queryStringparser);
+ String sortInternal = null;
+ if(sortColumn == null)
+ sortInternal = getModifiedQueryParameter("sortinternal", data, queryStringparser);
+ String sortPolarity = getModifiedQueryParameter("sortpolarity", data, queryStringparser);
String currentQueryAddition = "" + sortColumn + sortInternal + sortPolarity;
String cachedQueryAddition = (String)data.getUser().getTemp("queryAddition");
@@ -2088,9 +2165,11 @@
if (cachedQueryAddition==null || !cachedQueryAddition.equals(currentQueryAddition) || queryResult==null)
{
// currentQueryString gets lost if the session timed out. an empty search result is returned then.
- queryResult = null != currentQueryString
- ? getSearchResults(currentQueryString)
- : Collections.emptyList();
+ // This needs review. If session timed out, then we should not get here.
+ if (currentQueryString != null)
+ queryResult = getSearchResults(currentQueryString);
+ else
+ queryResult = Collections.emptyList();
data.getUser().setTemp("queryAddition", currentQueryAddition );
data.getUser().setTemp("queryResult", queryResult);
Modified: branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/macros/AdvancedQueryMacro.vm
Url: http://scarab.tigris.org/source/browse/scarab/branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/macros/AdvancedQueryMacro.vm?view=diff&pathrev=11284&r1=11283&r2=11284
==============================================================================
--- branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/macros/AdvancedQueryMacro.vm (original)
+++ branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/macros/AdvancedQueryMacro.vm 2012-06-10 09:58:20-0700
@@ -297,11 +297,20 @@
#set ( $issueType = $search.IssueType )
#end
<th width="120">$l10n.SortBy</th>
+
+#set ( $internalSort = $search.getSortInternalAttribute())
<td>
<select name="$searchGroup.SortAttributeId.Key">
<option value="">$l10n.Choose</option>
+ <option value="issueid" #if ($internalSort=="issueid") selected="selected" #end>Issue ID</option>
+ <option value="createddate" #if ($internalSort=="createddate") selected="selected" #end>Create Date</option>
+ <option value="modifieddate" #if ($internalSort=="modifieddate")selected="selected" #end>Change Date</option>
+ <option value="createdby" #if ($internalSort=="createdby") selected="selected" #end>Created by</option>
+ <option value="modifiedby" #if ($internalSort=="modifiedby") selected="selected" #end>Changed by</option>
+ <option class="select-dash" disabled="disabled">--------------------</option>
#foreach ($rmua in $scarabR.RModuleUserAttributes)
#set ($attribute = $rmua.Attribute)
+#if ( $attribute.AttributeId > 0 )
<option value="$attribute.AttributeId"
#if ($searchGroup.SortAttributeId.Value.equals($attribute.AttributeId))
selected="selected" #end>
@@ -312,7 +321,10 @@
#end
</option>
#end
+#end
</select> 
+
+#set ( $sortPolarity = $searchGroup.SortPolarity.Value )
<select name="$searchGroup.SortPolarity.Key">
<option value="asc"
#if ($searchGroup.SortPolarity.Value.equals("asc"))
Modified: branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/EditQuery.vm
Url: http://scarab.tigris.org/source/browse/scarab/branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/EditQuery.vm?view=diff&pathrev=11284&r1=11283&r2=11284
==============================================================================
--- branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/EditQuery.vm (original)
+++ branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/EditQuery.vm 2012-06-10 09:58:20-0700
@@ -23,7 +23,7 @@
<input type="submit" value="$l10n.Cancel" name="eventSubmit_doCancel" />
</div>
-<h3>$l10n.format("QueryAndName", $currentQuery.Name)</h3>
+<h3> $l10n.format("QueryAndName", $currentQuery.Name)</h3>
<div class="axial">
<table cellpadding="3" cellspacing="2" border="0" width="100%">
Modified: branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/IssueList.vm
Url: http://scarab.tigris.org/source/browse/scarab/branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/IssueList.vm?view=diff&pathrev=11284&r1=11283&r2=11284
==============================================================================
--- branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/IssueList.vm (original)
+++ branches/scarab_11079_legacy_with_ant_maven1/src/webapp/WEB-INF/templates/screens/IssueList.vm 2012-06-10 09:58:20-0700
@@ -90,8 +90,8 @@
</h3>
-#set ($sortColumn = $data.Parameters.getString('sortColumn'))
-#set ($sortInternal=$data.Parameters.getString('sortInternal'))
+#set ($sortColumn = $data.Parameters.getString('sortColumn'))
+#set ($sortInternal = $data.Parameters.getString('sortInternal'))
#set ($sortPolarity = $data.Parameters.getString('sortPolarity'))
#if ($sortColumn)
@@ -117,7 +117,7 @@
<th style="white-space:nowrap;">
## Issue ID column
#prepIssueListPageLink()
- #if ((!$sortColumn || $sortColumn == 'null') && !$sortInternal)
+ #if ( $sortInternal=="issueid" || (!$sortColumn || $sortColumn == 'null') && !$sortInternal)
## No sorting column is active, use issue ID
#if ($sortPolarity.equals('desc'))
#set ($sortLink = $link.setPathInfo('sortPolarity', 'asc').addPathInfo('sortColumn', 'null').addPathInfo('searchType', $searchType).addPathInfo("resultsPerPage","$resultsPerPage"))
@@ -151,7 +151,7 @@
#end
<th>
#prepIssueListPageLink()
- #if ($sortColumn.equals($pref.AttributeId.toString()) || $sortInternal.equals($pref.Name))
+ #if ($sortColumn.equals($pref.AttributeId.toString()) || $sortInternal.equalsIgnoreCase($pref.Name))
## This column is the one we are currently sorting on
#if ($sortPolarity.equals("desc"))
#set ($sortLink = $link.setPathInfo("sortPolarity", "asc").setPathInfo($sort, "$sortData").addPathInfo("searchType","$searchType").addPathInfo("resultsPerPage","$resultsPerPage").toString())
------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=2970194