Allow users to control the number of results per page
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -26,6 +26,7 @@ public interface AccountConstants extends Constants {
|
||||
String accountId();
|
||||
|
||||
String defaultContextFieldLabel();
|
||||
String maximumPageSizeFieldLabel();
|
||||
String contextWholeFile();
|
||||
String showSiteHeader();
|
||||
String useFlashClipboard();
|
||||
|
@@ -8,6 +8,7 @@ accountId = Account ID
|
||||
showSiteHeader = Show Site Header
|
||||
useFlashClipboard = Use Flash Clipboard Widget
|
||||
defaultContextFieldLabel = Default Context:
|
||||
maximumPageSizeFieldLabel = Maximum Page Size:
|
||||
contextWholeFile = Whole File
|
||||
buttonSaveChanges = Save Changes
|
||||
|
||||
|
@@ -20,6 +20,7 @@ import java.util.Date;
|
||||
|
||||
public interface AccountMessages extends Messages {
|
||||
String lines(short cnt);
|
||||
String rowsPerPage(short cnt);
|
||||
String enterIAGREE(String iagree);
|
||||
String contactOnFile(Date lastDate);
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
lines = {0} lines
|
||||
rowsPerPage = {0} rows per page
|
||||
|
||||
enterIAGREE = (enter {0} in the box to the left)
|
||||
contactOnFile = Contact information last updated on {0,date,medium} at {0,time,short}.
|
||||
|
@@ -14,6 +14,12 @@
|
||||
|
||||
package com.google.gerrit.client.account;
|
||||
|
||||
import static com.google.gerrit.client.reviewdb.AccountGeneralPreferences.DEFAULT_CONTEXT;
|
||||
import static com.google.gerrit.client.reviewdb.AccountGeneralPreferences.DEFAULT_PAGESIZE;
|
||||
import static com.google.gerrit.client.reviewdb.AccountGeneralPreferences.CONTEXT_CHOICES;
|
||||
import static com.google.gerrit.client.reviewdb.AccountGeneralPreferences.PAGESIZE_CHOICES;
|
||||
import static com.google.gerrit.client.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.AccountGeneralPreferences;
|
||||
@@ -35,6 +41,7 @@ class PreferencePanel extends Composite {
|
||||
private CheckBox showSiteHeader;
|
||||
private CheckBox useFlashClipboard;
|
||||
private ListBox defaultContext;
|
||||
private ListBox maximumPageSize;
|
||||
private Button save;
|
||||
|
||||
PreferencePanel() {
|
||||
@@ -46,6 +53,12 @@ class PreferencePanel extends Composite {
|
||||
save.setEnabled(true);
|
||||
}
|
||||
};
|
||||
final ChangeHandler onChangeSave = new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(final ChangeEvent event) {
|
||||
save.setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
showSiteHeader = new CheckBox(Util.C.showSiteHeader());
|
||||
showSiteHeader.addClickHandler(onClickSave);
|
||||
@@ -53,22 +66,23 @@ class PreferencePanel extends Composite {
|
||||
useFlashClipboard = new CheckBox(Util.C.useFlashClipboard());
|
||||
useFlashClipboard.addClickHandler(onClickSave);
|
||||
|
||||
maximumPageSize = new ListBox();
|
||||
for (final short v : PAGESIZE_CHOICES) {
|
||||
maximumPageSize.addItem(Util.M.rowsPerPage(v), String.valueOf(v));
|
||||
}
|
||||
maximumPageSize.addChangeHandler(onChangeSave);
|
||||
|
||||
defaultContext = new ListBox();
|
||||
for (final short v : AccountGeneralPreferences.CONTEXT_CHOICES) {
|
||||
for (final short v : CONTEXT_CHOICES) {
|
||||
final String label;
|
||||
if (v == AccountGeneralPreferences.WHOLE_FILE_CONTEXT) {
|
||||
if (v == WHOLE_FILE_CONTEXT) {
|
||||
label = Util.C.contextWholeFile();
|
||||
} else {
|
||||
label = Util.M.lines(v);
|
||||
}
|
||||
defaultContext.addItem(label, String.valueOf(v));
|
||||
}
|
||||
defaultContext.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(final ChangeEvent event) {
|
||||
save.setEnabled(true);
|
||||
}
|
||||
});
|
||||
defaultContext.addChangeHandler(onChangeSave);
|
||||
|
||||
final int labelIdx, fieldIdx;
|
||||
if (LocaleInfo.getCurrentLocale().isRTL()) {
|
||||
@@ -78,7 +92,7 @@ class PreferencePanel extends Composite {
|
||||
labelIdx = 0;
|
||||
fieldIdx = 1;
|
||||
}
|
||||
final Grid formGrid = new Grid(3, 2);
|
||||
final Grid formGrid = new Grid(4, 2);
|
||||
|
||||
int row = 0;
|
||||
formGrid.setText(row, labelIdx, "");
|
||||
@@ -89,6 +103,10 @@ class PreferencePanel extends Composite {
|
||||
formGrid.setWidget(row, fieldIdx, useFlashClipboard);
|
||||
row++;
|
||||
|
||||
formGrid.setText(row, labelIdx, Util.C.maximumPageSizeFieldLabel());
|
||||
formGrid.setWidget(row, fieldIdx, maximumPageSize);
|
||||
row++;
|
||||
|
||||
formGrid.setText(row, labelIdx, Util.C.defaultContextFieldLabel());
|
||||
formGrid.setWidget(row, fieldIdx, defaultContext);
|
||||
row++;
|
||||
@@ -122,38 +140,45 @@ class PreferencePanel extends Composite {
|
||||
private void enable(final boolean on) {
|
||||
showSiteHeader.setEnabled(on);
|
||||
useFlashClipboard.setEnabled(on);
|
||||
maximumPageSize.setEnabled(on);
|
||||
defaultContext.setEnabled(on);
|
||||
}
|
||||
|
||||
private void display(final AccountGeneralPreferences p) {
|
||||
showSiteHeader.setValue(p.isShowSiteHeader());
|
||||
useFlashClipboard.setValue(p.isUseFlashClipboard());
|
||||
displayDefaultContext(p.getDefaultContext());
|
||||
setListBox(maximumPageSize, DEFAULT_PAGESIZE, p.getMaximumPageSize());
|
||||
setListBox(defaultContext, DEFAULT_CONTEXT, p.getDefaultContext());
|
||||
}
|
||||
|
||||
private void displayDefaultContext(final short lines) {
|
||||
for (int i = 0; i < AccountGeneralPreferences.CONTEXT_CHOICES.length; i++) {
|
||||
if (AccountGeneralPreferences.CONTEXT_CHOICES[i] == lines) {
|
||||
defaultContext.setSelectedIndex(i);
|
||||
private void setListBox(final ListBox f, final short defaultValue,
|
||||
final short currentValue) {
|
||||
final int n = f.getItemCount();
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (Short.parseShort(f.getValue(i)) == currentValue) {
|
||||
f.setSelectedIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
displayDefaultContext(AccountGeneralPreferences.DEFAULT_CONTEXT);
|
||||
if (currentValue != defaultValue) {
|
||||
setListBox(f, defaultValue, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
private short getDefaultContext() {
|
||||
final int idx = defaultContext.getSelectedIndex();
|
||||
private short getListBox(final ListBox f, final short defaultValue) {
|
||||
final int idx = f.getSelectedIndex();
|
||||
if (0 <= idx) {
|
||||
return Short.parseShort(defaultContext.getValue(idx));
|
||||
return Short.parseShort(f.getValue(idx));
|
||||
}
|
||||
return AccountGeneralPreferences.DEFAULT_CONTEXT;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private void doSave() {
|
||||
final AccountGeneralPreferences p = new AccountGeneralPreferences();
|
||||
p.setShowSiteHeader(showSiteHeader.getValue());
|
||||
p.setUseFlashClipboard(useFlashClipboard.getValue());
|
||||
p.setDefaultContext(getDefaultContext());
|
||||
p.setMaximumPageSize(getListBox(maximumPageSize, DEFAULT_PAGESIZE));
|
||||
p.setDefaultContext(getListBox(defaultContext, DEFAULT_CONTEXT));
|
||||
|
||||
enable(false);
|
||||
save.setEnabled(false);
|
||||
|
@@ -14,8 +14,10 @@
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.data.ChangeInfo;
|
||||
import com.google.gerrit.client.data.SingleListChangeInfo;
|
||||
import com.google.gerrit.client.reviewdb.AccountGeneralPreferences;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
@@ -32,7 +34,7 @@ public abstract class AllSingleListScreen extends Screen {
|
||||
protected static final String MIN_SORTKEY = "";
|
||||
protected static final String MAX_SORTKEY = "z";
|
||||
|
||||
protected static final int pageSize = 25;
|
||||
protected final int pageSize;
|
||||
private ChangeTable table;
|
||||
private ChangeTable.Section section;
|
||||
protected Hyperlink prev;
|
||||
@@ -48,6 +50,15 @@ public abstract class AllSingleListScreen extends Screen {
|
||||
anchorPrefix = anchorToken;
|
||||
useLoadPrev = positionToken.startsWith("p,");
|
||||
pos = positionToken.substring(2);
|
||||
|
||||
if (Gerrit.isSignedIn()) {
|
||||
final AccountGeneralPreferences p =
|
||||
Gerrit.getUserAccount().getGeneralPreferences();
|
||||
final short m = p.getMaximumPageSize();
|
||||
pageSize = 0 < m ? m : AccountGeneralPreferences.DEFAULT_PAGESIZE;
|
||||
} else {
|
||||
pageSize = AccountGeneralPreferences.DEFAULT_PAGESIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -58,7 +58,7 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
|
||||
}
|
||||
};
|
||||
|
||||
private static final int MAX_PER_PAGE = 50;
|
||||
private static final int MAX_PER_PAGE = 100;
|
||||
|
||||
private static int safePageSize(final int pageSize) {
|
||||
return 0 < pageSize && pageSize <= MAX_PER_PAGE ? pageSize : MAX_PER_PAGE;
|
||||
|
@@ -28,10 +28,20 @@ public final class AccountGeneralPreferences {
|
||||
public static final short[] CONTEXT_CHOICES =
|
||||
{3, 10, 25, 50, 75, 100, WHOLE_FILE_CONTEXT};
|
||||
|
||||
/** Default number of items to display per page. */
|
||||
public static final short DEFAULT_PAGESIZE = 25;
|
||||
|
||||
/** Valid choices for the page size. */
|
||||
public static final short[] PAGESIZE_CHOICES = {10, 25, 50, 100};
|
||||
|
||||
/** Default number of lines of context when viewing a patch. */
|
||||
@Column
|
||||
protected short defaultContext;
|
||||
|
||||
/** Number of changes to show in a screen. */
|
||||
@Column
|
||||
protected short maximumPageSize;
|
||||
|
||||
/** Should the site header be displayed when logged in ? */
|
||||
@Column
|
||||
protected boolean showSiteHeader;
|
||||
@@ -53,6 +63,14 @@ public final class AccountGeneralPreferences {
|
||||
defaultContext = s;
|
||||
}
|
||||
|
||||
public short getMaximumPageSize() {
|
||||
return maximumPageSize;
|
||||
}
|
||||
|
||||
public void setMaximumPageSize(final short s) {
|
||||
maximumPageSize = s;
|
||||
}
|
||||
|
||||
public boolean isShowSiteHeader() {
|
||||
return showSiteHeader;
|
||||
}
|
||||
@@ -71,6 +89,7 @@ public final class AccountGeneralPreferences {
|
||||
|
||||
public void resetToDefaults() {
|
||||
defaultContext = DEFAULT_CONTEXT;
|
||||
maximumPageSize = DEFAULT_PAGESIZE;
|
||||
showSiteHeader = true;
|
||||
useFlashClipboard = true;
|
||||
}
|
||||
|
@@ -6,4 +6,9 @@ UPDATE accounts SET use_flash_clipboard = 'Y';
|
||||
ALTER TABLE accounts ALTER COLUMN use_flash_clipboard SET DEFAULT 'N';
|
||||
ALTER TABLE accounts ALTER COLUMN use_flash_clipboard SET NOT NULL;
|
||||
|
||||
ALTER TABLE accounts ADD maximum_page_size SMALLINT;
|
||||
UPDATE accounts SET maximum_page_size = 25;
|
||||
ALTER TABLE accounts ALTER COLUMN maximum_page_size SET DEFAULT 0;
|
||||
ALTER TABLE accounts ALTER COLUMN maximum_page_size SET NOT NULL;
|
||||
|
||||
UPDATE schema_version SET version_nbr = 11;
|
||||
|
Reference in New Issue
Block a user