Clean up account dashboard owner:"Full Name" link

The code to format an operator like owner:$NAME already mostly exists
to support other types of queries, like projects. Reuse that code in
PageLinks rather than building it from scratch again.

Update the rules in PageLinks about what strings must be quoted to be
the exact character class used by Query.g to parse the string. A bare
operator can be any sequence of characters not in the NON_WORD class.

Delete some now unused code related to the old AccountDashboard link.

Default the owner link to status:open. This is faster for servers to
answer, as the set of open changes is often much smaller than all
changes owned by a user. Its also indexed through byOwnerOpen(). Users
that want to see the closed, merged or abandoned changes by the owner
should update the query string to specify what they want to view.

Change-Id: I697cac913e264ade70b314e37317b76e26283b02
This commit is contained in:
Shawn O. Pearce
2012-05-18 07:23:15 -07:00
parent 35b8e533ae
commit 9637774986
5 changed files with 34 additions and 33 deletions

View File

@@ -14,13 +14,11 @@
package com.google.gerrit.common;
import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gwtorm.client.KeyUtil;
public class PageLinks {
@@ -60,15 +58,8 @@ public class PageLinks {
}
public static String toAccountQuery(final String fullname) {
return "/q/owner:\"" + KeyUtil.encode(fullname) + "\"," + TOP;
}
public static String toAccountDashboard(final AccountInfo acct) {
return toAccountDashboard(acct.getId());
}
public static String toAccountDashboard(final Account.Id acct) {
return "/dashboard/" + acct.toString();
String query = op("owner", fullname) + " status:open";
return toChangeQuery(query, TOP);
}
public static String toChangeQuery(final String query) {
@@ -76,8 +67,7 @@ public class PageLinks {
}
public static String toChangeQuery(String query, String page) {
query = KeyUtil.encode(query).replaceAll("%3[Aa]", ":");
return "/q/" + query + "," + page;
return "/q/" + KeyUtil.encode(query) + "," + page;
}
public static String projectQuery(Project.NameKey proj, Status status) {
@@ -95,11 +85,18 @@ public class PageLinks {
}
}
public static String op(String name, String value) {
if (value.indexOf(' ') >= 0) {
return name + ":\"" + value + "\"";
public static String op(String op, String value) {
if (isSingleWord(value)) {
return op + ":" + value;
}
return name + ":" + value;
return op + ":\"" + value + "\"";
}
private static boolean isSingleWord(String value) {
if (value.startsWith("-")) {
return false;
}
return value.matches("[^\u0000-\u0020!\"#$%&'():;?\\[\\]{}~]+");
}
protected PageLinks() {