Populate 'My' menu from user preferences
Instead of hard coding the 'My' menu on client side the menu will now be populated from the user preferences which are returned from the server. On server side the menu items are still hard coded, but follow-up changes will make it configurable per user. The idea is that users should be able to configure custom dashboards that they want to link under the 'My' menu. Change-Id: I6aec34045777114027e5f3f3d37102f67b1036ed Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
committed by
Shawn Pearce
parent
1724b8d2cc
commit
7941a187c3
@@ -18,8 +18,10 @@ import static com.google.gerrit.common.data.GlobalCapability.ADMINISTRATE_SERVER
|
||||
import static com.google.gerrit.common.data.GlobalCapability.CREATE_GROUP;
|
||||
import static com.google.gerrit.common.data.GlobalCapability.CREATE_PROJECT;
|
||||
|
||||
import com.google.gerrit.client.account.AccountApi;
|
||||
import com.google.gerrit.client.account.AccountCapabilities;
|
||||
import com.google.gerrit.client.account.AccountInfo;
|
||||
import com.google.gerrit.client.account.Preferences;
|
||||
import com.google.gerrit.client.admin.ProjectScreen;
|
||||
import com.google.gerrit.client.api.ApiGlue;
|
||||
import com.google.gerrit.client.api.PluginLoader;
|
||||
@@ -70,6 +72,7 @@ import com.google.gwt.user.client.Cookies;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.Window.Location;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.FocusPanel;
|
||||
@@ -585,14 +588,21 @@ public class Gerrit implements EntryPoint {
|
||||
menuLeft.add(m, C.menuAll());
|
||||
|
||||
if (signedIn) {
|
||||
m = new LinkMenuBar();
|
||||
final LinkMenuBar myBar = new LinkMenuBar();
|
||||
menuBars.put(GerritTopMenu.MY.menuName, m);
|
||||
addLink(m, C.menuMyChanges(), PageLinks.MINE);
|
||||
addLink(m, C.menuMyDrafts(), PageLinks.toChangeQuery("is:draft"));
|
||||
addLink(m, C.menuMyDraftComments(), PageLinks.toChangeQuery("has:draft"));
|
||||
addLink(m, C.menuMyWatchedChanges(), PageLinks.toChangeQuery("is:watched status:open"));
|
||||
addLink(m, C.menuMyStarredChanges(), PageLinks.toChangeQuery("is:starred"));
|
||||
menuLeft.add(m, C.menuMine());
|
||||
AccountApi.self().view("preferences").get(new AsyncCallback<Preferences>() {
|
||||
@Override
|
||||
public void onSuccess(Preferences prefs) {
|
||||
for (TopMenuItem item : Natives.asList(prefs.my())) {
|
||||
addExtensionLink(myBar, item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
}
|
||||
});
|
||||
menuLeft.add(myBar, C.menuMine());
|
||||
menuLeft.selectTab(1);
|
||||
} else {
|
||||
menuLeft.selectTab(0);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.account;
|
||||
|
||||
import com.google.gerrit.client.extensions.TopMenuItem;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
|
||||
public class Preferences extends JavaScriptObject {
|
||||
|
||||
public final native JsArray<TopMenuItem> my() /*-{ return this.my; }-*/;
|
||||
|
||||
protected Preferences() {
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.account;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.webui.TopMenu;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ChangeScreen;
|
||||
@@ -32,6 +33,9 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GetPreferences implements RestReadView<AccountResource> {
|
||||
private final Provider<CurrentUser> self;
|
||||
private final Provider<ReviewDb> db;
|
||||
@@ -74,6 +78,7 @@ public class GetPreferences implements RestReadView<AccountResource> {
|
||||
CommentVisibilityStrategy commentVisibilityStrategy;
|
||||
DiffView diffView;
|
||||
ChangeScreen changeScreen;
|
||||
List<TopMenu.MenuItem> my;
|
||||
|
||||
PreferenceInfo(AccountGeneralPreferences p) {
|
||||
changesPerPage = p.getMaximumPageSize();
|
||||
@@ -91,6 +96,17 @@ public class GetPreferences implements RestReadView<AccountResource> {
|
||||
commentVisibilityStrategy = p.getCommentVisibilityStrategy();
|
||||
diffView = p.getDiffView();
|
||||
changeScreen = p.getChangeScreen();
|
||||
my = my();
|
||||
}
|
||||
|
||||
private List<TopMenu.MenuItem> my() {
|
||||
List<TopMenu.MenuItem> my = new ArrayList<>();
|
||||
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", ""));
|
||||
return my;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user