Merge topic 'my-menu'

* changes:
  Handle internal extension menu items like built in items
  My menu targets should be null not empty string
This commit is contained in:
Shawn Pearce
2014-03-28 17:05:42 +00:00
committed by Gerrit Code Review
3 changed files with 45 additions and 20 deletions

View File

@@ -899,15 +899,26 @@ public class Gerrit implements EntryPoint {
}
private static void addExtensionLink(LinkMenuBar m, TopMenuItem item) {
Anchor atag = anchor(item.getName(), isAbsolute(item.getUrl())
? item.getUrl()
: selfRedirect(item.getUrl()));
atag.setTarget(item.getTarget());
if (item.getId() != null) {
atag.getElement().setAttribute("id", item.getId());
if (item.getUrl().startsWith("#")
&& (item.getTarget() == null || item.getTarget().isEmpty())) {
LinkMenuItem a =
new LinkMenuItem(item.getName(), item.getUrl().substring(1));
if (item.getId() != null) {
a.getElement().setAttribute("id", item.getId());
}
m.add(a);
} else {
Anchor atag = anchor(item.getName(), isAbsolute(item.getUrl())
? item.getUrl()
: selfRedirect(item.getUrl()));
if (item.getTarget() != null && !item.getTarget().isEmpty()) {
atag.setTarget(item.getTarget());
}
if (item.getId() != null) {
atag.getElement().setAttribute("id", item.getId());
}
m.add(atag);
}
m.add(atag);
}
private static boolean isAbsolute(String url) {

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.account;
import com.google.common.base.Strings;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
@@ -121,11 +122,11 @@ public class GetPreferences implements RestReadView<AccountResource> {
my = my(allUsers, RefNames.REFS_USER + "default");
}
if (my.isEmpty()) {
my.add(new TopMenu.MenuItem("Changes", "#/", ""));
my.add(new TopMenu.MenuItem("Drafts", "#/q/is:draft", ""));
my.add(new TopMenu.MenuItem("Draft Comments", "#/q/has:draft", ""));
my.add(new TopMenu.MenuItem("Watched Changes", "#/q/is:watched+is:open", ""));
my.add(new TopMenu.MenuItem("Starred Changes", "#/q/is:starred", ""));
my.add(new TopMenu.MenuItem("Changes", "#/", null));
my.add(new TopMenu.MenuItem("Drafts", "#/q/is:draft", null));
my.add(new TopMenu.MenuItem("Draft Comments", "#/q/has:draft", null));
my.add(new TopMenu.MenuItem("Watched Changes", "#/q/is:watched+is:open", null));
my.add(new TopMenu.MenuItem("Starred Changes", "#/q/is:starred", null));
}
return my;
}
@@ -134,16 +135,20 @@ public class GetPreferences implements RestReadView<AccountResource> {
List<TopMenu.MenuItem> my = new ArrayList<>();
Config cfg = allUsers.getConfig(PREFERENCES, ref).get();
for (String subsection : cfg.getSubsections(MY)) {
my.add(new TopMenu.MenuItem(subsection, my(cfg, subsection, KEY_URL, "#/"),
my(cfg, subsection, KEY_TARGET, null), my(cfg, subsection, KEY_ID, null)));
String url = my(cfg, subsection, KEY_URL, "#/");
String target = my(cfg, subsection, KEY_TARGET,
url.startsWith("#") ? null : "_blank");
my.add(new TopMenu.MenuItem(
subsection, url, target,
my(cfg, subsection, KEY_ID, null)));
}
return my;
}
private static String my(Config cfg, String subsection, String key,
String defaultValue) {
String value = cfg.getString(MY, subsection, key);
return value != null ? value : defaultValue;
String val = cfg.getString(MY, subsection, key);
return !Strings.isNullOrEmpty(val) ? val : defaultValue;
}
}
}

View File

@@ -20,6 +20,7 @@ import static com.google.gerrit.server.account.GetPreferences.KEY_URL;
import static com.google.gerrit.server.account.GetPreferences.MY;
import static com.google.gerrit.server.account.GetPreferences.PREFERENCES;
import com.google.common.base.Strings;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestModifyView;
@@ -179,9 +180,9 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
if (my != null) {
unsetSection(cfg, MY);
for (TopMenu.MenuItem item : my) {
cfg.setString(MY, item.name, KEY_URL, item.url);
cfg.setString(MY, item.name, KEY_TARGET, item.target);
cfg.setString(MY, item.name, KEY_ID, item.id);
set(cfg, item.name, KEY_URL, item.url);
set(cfg, item.name, KEY_TARGET, item.target);
set(cfg, item.name, KEY_ID, item.id);
}
}
MetaDataUpdate md =
@@ -190,6 +191,14 @@ public class SetPreferences implements RestModifyView<AccountResource, Input> {
prefsCfg.commit(md);
}
private static void set(Config cfg, String section, String key, String val) {
if (Strings.isNullOrEmpty(val)) {
cfg.unset(MY, section, key);
} else {
cfg.setString(MY, section, key, val);
}
}
private static void unsetSection(Config cfg, String section) {
cfg.unsetSection(section, null);
for (String subsection: cfg.getSubsections(section)) {