Allow users to reset the 'My' menu entries to the server defaults
Change-Id: I42bbca895e29ca8825a569d0c0bff20342dcbc54 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -232,6 +232,7 @@ public interface GerritCss extends CssResource {
|
||||
String sshHostKeyPanelKnownHostEntry();
|
||||
String sshKeyPanelEncodedKey();
|
||||
String sshKeyPanelInvalid();
|
||||
String stringListPanelButtons();
|
||||
String topMostCell();
|
||||
String topmenu();
|
||||
String topmenuMenuLeft();
|
||||
|
||||
@@ -40,10 +40,11 @@ import java.util.List;
|
||||
|
||||
public class StringListPanel extends FlowPanel {
|
||||
private final StringListTable t;
|
||||
private final Button deleteButton;
|
||||
private final HorizontalPanel titlePanel;
|
||||
protected final HorizontalPanel buttonPanel;
|
||||
private final Button deleteButton;
|
||||
private Image info;
|
||||
private FocusWidget widget;
|
||||
protected FocusWidget widget;
|
||||
|
||||
public StringListPanel(String title, List<String> fieldNames, FocusWidget w,
|
||||
boolean autoSort) {
|
||||
@@ -56,9 +57,10 @@ public class StringListPanel extends FlowPanel {
|
||||
t = new StringListTable(fieldNames, autoSort);
|
||||
add(t);
|
||||
|
||||
buttonPanel = new HorizontalPanel();
|
||||
buttonPanel.setStyleName(Gerrit.RESOURCES.css().stringListPanelButtons());
|
||||
deleteButton = new Button(Gerrit.C.stringListPanelDelete());
|
||||
deleteButton.setEnabled(false);
|
||||
add(deleteButton);
|
||||
deleteButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
@@ -66,6 +68,8 @@ public class StringListPanel extends FlowPanel {
|
||||
t.deleteChecked();
|
||||
}
|
||||
});
|
||||
buttonPanel.add(deleteButton);
|
||||
add(buttonPanel);
|
||||
}
|
||||
|
||||
public void display(List<List<String>> values) {
|
||||
|
||||
@@ -43,6 +43,7 @@ public interface AccountConstants extends Constants {
|
||||
String myMenuInfo();
|
||||
String myMenuName();
|
||||
String myMenuUrl();
|
||||
String myMenuReset();
|
||||
|
||||
String changeScreenOldUi();
|
||||
String changeScreenNewUi();
|
||||
|
||||
@@ -23,6 +23,7 @@ myMenu = My Menu
|
||||
myMenuInfo = Menu Items for the 'My' top level menu.
|
||||
myMenuName = Name
|
||||
myMenuUrl = URL
|
||||
myMenuReset = Reset
|
||||
|
||||
changeScreenOldUi = Old Screen
|
||||
changeScreenNewUi = New Screen
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.PAGESI
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.StringListPanel;
|
||||
import com.google.gerrit.client.config.ConfigServerApi;
|
||||
import com.google.gerrit.client.extensions.TopMenuItem;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.Natives;
|
||||
@@ -27,6 +28,7 @@ import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.OnEditEnabler;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.CommentVisibilityStrategy;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
@@ -208,10 +210,7 @@ public class MyPreferencesScreen extends SettingsScreen {
|
||||
}
|
||||
});
|
||||
|
||||
myMenus = new StringListPanel(Util.C.myMenu(),
|
||||
Arrays.asList(Util.C.myMenuName(), Util.C.myMenuUrl()),
|
||||
save, false);
|
||||
myMenus.setInfo(Util.C.myMenuInfo());
|
||||
myMenus = new MyMenuPanel(save);
|
||||
add(myMenus);
|
||||
|
||||
add(save);
|
||||
@@ -282,9 +281,12 @@ public class MyPreferencesScreen extends SettingsScreen {
|
||||
setListBox(diffView,
|
||||
AccountGeneralPreferences.DiffView.SIDE_BY_SIDE,
|
||||
p.diffView());
|
||||
display(p.my());
|
||||
}
|
||||
|
||||
private void display(JsArray<TopMenuItem> items) {
|
||||
List<List<String>> values = new ArrayList<>();
|
||||
for (TopMenuItem item : Natives.asList(p.my())) {
|
||||
for (TopMenuItem item : Natives.asList(items)) {
|
||||
values.add(Arrays.asList(item.getName(), item.getUrl()));
|
||||
}
|
||||
myMenus.display(values);
|
||||
@@ -409,4 +411,28 @@ public class MyPreferencesScreen extends SettingsScreen {
|
||||
return ui.name();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyMenuPanel extends StringListPanel {
|
||||
MyMenuPanel(Button save) {
|
||||
super(Util.C.myMenu(), Arrays.asList(Util.C.myMenuName(),
|
||||
Util.C.myMenuUrl()), save, false);
|
||||
|
||||
setInfo(Util.C.myMenuInfo());
|
||||
|
||||
Button resetButton = new Button(Util.C.myMenuReset());
|
||||
resetButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
ConfigServerApi.defaultPreferences(new GerritCallback<Preferences>() {
|
||||
@Override
|
||||
public void onSuccess(Preferences p) {
|
||||
MyPreferencesScreen.this.display(p.my());
|
||||
widget.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
buttonPanel.add(resetButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.client.config;
|
||||
|
||||
import com.google.gerrit.client.account.Preferences;
|
||||
import com.google.gerrit.client.extensions.TopMenuList;
|
||||
import com.google.gerrit.client.rpc.NativeMap;
|
||||
import com.google.gerrit.client.rpc.RestApi;
|
||||
@@ -32,4 +33,8 @@ public class ConfigServerApi {
|
||||
public static void topMenus(AsyncCallback<TopMenuList> cb) {
|
||||
new RestApi("/config/server/top-menus").get(cb);
|
||||
}
|
||||
|
||||
public static void defaultPreferences(AsyncCallback<Preferences> cb) {
|
||||
new RestApi("/config/server/preferences").get(cb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1628,3 +1628,13 @@ a:hover.downloadLink {
|
||||
padding-top: 5px;
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
/* StringListPanel */
|
||||
.stringListPanelButtons {
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
.stringListPanelButtons .gwt-Button {
|
||||
margin-right: 2em;
|
||||
font-size: 7pt;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user