Merge "Display avatar and a link to change the avatar in the profile screen"
This commit is contained in:
@@ -257,6 +257,28 @@ The response redirects to the URL of the avatar image.
|
|||||||
Location: https://profiles/avatar/john_doe.jpeg?s=20x20
|
Location: https://profiles/avatar/john_doe.jpeg?s=20x20
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[[get-avatar-change-url]]
|
||||||
|
Get Avatar Change URL
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
[verse]
|
||||||
|
'GET /accounts/link:#account-id[\{account-id\}]/avatar.change.url'
|
||||||
|
|
||||||
|
Retrieves the URL where the user can change the avatar image.
|
||||||
|
|
||||||
|
.Request
|
||||||
|
----
|
||||||
|
GET /a/accounts/self/avatar.change.url HTTP/1.0
|
||||||
|
----
|
||||||
|
|
||||||
|
.Response
|
||||||
|
----
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Content-Disposition: attachment
|
||||||
|
Content-Type: text/plain;charset=UTF-8
|
||||||
|
|
||||||
|
https://profiles/pictures/john.doe
|
||||||
|
----
|
||||||
|
|
||||||
[[get-diff-preferences]]
|
[[get-diff-preferences]]
|
||||||
Get Diff Preferences
|
Get Diff Preferences
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@@ -29,6 +29,9 @@ import com.google.gwt.user.client.ui.UIObject;
|
|||||||
|
|
||||||
public class AvatarImage extends Image {
|
public class AvatarImage extends Image {
|
||||||
|
|
||||||
|
public AvatarImage() {
|
||||||
|
}
|
||||||
|
|
||||||
/** A default sized avatar image. */
|
/** A default sized avatar image. */
|
||||||
public AvatarImage(AccountInfo account) {
|
public AvatarImage(AccountInfo account) {
|
||||||
this(account, 0);
|
this(account, 0);
|
||||||
@@ -57,7 +60,11 @@ public class AvatarImage extends Image {
|
|||||||
* avatar image
|
* avatar image
|
||||||
*/
|
*/
|
||||||
public AvatarImage(AccountInfo account, int size, boolean addPopup) {
|
public AvatarImage(AccountInfo account, int size, boolean addPopup) {
|
||||||
super(isGerritServer(account) ? getGerritServerAvatarUrl() :
|
setAccount(account, size, addPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccount(AccountInfo account, int size, boolean addPopup) {
|
||||||
|
setUrl(isGerritServer(account) ? getGerritServerAvatarUrl() :
|
||||||
url(account.email(), size));
|
url(account.email(), size));
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@ public interface GerritCss extends CssResource {
|
|||||||
String approvalhint();
|
String approvalhint();
|
||||||
String approvalrole();
|
String approvalrole();
|
||||||
String approvalscore();
|
String approvalscore();
|
||||||
|
String avatarInfoPanel();
|
||||||
String blockHeader();
|
String blockHeader();
|
||||||
String bottomheader();
|
String bottomheader();
|
||||||
String cAPPROVAL();
|
String cAPPROVAL();
|
||||||
|
@@ -19,6 +19,7 @@ import com.google.gwt.i18n.client.Constants;
|
|||||||
public interface AccountConstants extends Constants {
|
public interface AccountConstants extends Constants {
|
||||||
String settingsHeading();
|
String settingsHeading();
|
||||||
|
|
||||||
|
String changeAvatar();
|
||||||
String fullName();
|
String fullName();
|
||||||
String preferredEmail();
|
String preferredEmail();
|
||||||
String registeredOn();
|
String registeredOn();
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
settingsHeading = Settings
|
settingsHeading = Settings
|
||||||
|
|
||||||
|
changeAvatar = Change Avatar
|
||||||
fullName = Full Name
|
fullName = Full Name
|
||||||
preferredEmail = Email Address
|
preferredEmail = Email Address
|
||||||
registeredOn = Registered
|
registeredOn = Registered
|
||||||
|
@@ -16,13 +16,23 @@ package com.google.gerrit.client.account;
|
|||||||
|
|
||||||
import static com.google.gerrit.client.FormatUtil.mediumFormat;
|
import static com.google.gerrit.client.FormatUtil.mediumFormat;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.AvatarImage;
|
||||||
|
import com.google.gerrit.client.FormatUtil;
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
|
import com.google.gerrit.client.rpc.NativeString;
|
||||||
|
import com.google.gerrit.client.rpc.RestApi;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gwt.i18n.client.LocaleInfo;
|
import com.google.gwt.i18n.client.LocaleInfo;
|
||||||
|
import com.google.gwt.user.client.ui.Anchor;
|
||||||
import com.google.gwt.user.client.ui.Grid;
|
import com.google.gwt.user.client.ui.Grid;
|
||||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||||
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
public class MyProfileScreen extends SettingsScreen {
|
public class MyProfileScreen extends SettingsScreen {
|
||||||
|
private AvatarImage avatar;
|
||||||
|
private Anchor changeAvatar;
|
||||||
private int labelIdx, fieldIdx;
|
private int labelIdx, fieldIdx;
|
||||||
private Grid info;
|
private Grid info;
|
||||||
|
|
||||||
@@ -30,6 +40,18 @@ public class MyProfileScreen extends SettingsScreen {
|
|||||||
protected void onInitUI() {
|
protected void onInitUI() {
|
||||||
super.onInitUI();
|
super.onInitUI();
|
||||||
|
|
||||||
|
HorizontalPanel h = new HorizontalPanel();
|
||||||
|
add(h);
|
||||||
|
|
||||||
|
VerticalPanel v = new VerticalPanel();
|
||||||
|
v.addStyleName(Gerrit.RESOURCES.css().avatarInfoPanel());
|
||||||
|
h.add(v);
|
||||||
|
avatar = new AvatarImage();
|
||||||
|
v.add(avatar);
|
||||||
|
changeAvatar = new Anchor(Util.C.changeAvatar(), "", "_blank");
|
||||||
|
changeAvatar.setVisible(false);
|
||||||
|
v.add(changeAvatar);
|
||||||
|
|
||||||
if (LocaleInfo.getCurrentLocale().isRTL()) {
|
if (LocaleInfo.getCurrentLocale().isRTL()) {
|
||||||
labelIdx = 1;
|
labelIdx = 1;
|
||||||
fieldIdx = 0;
|
fieldIdx = 0;
|
||||||
@@ -41,7 +63,7 @@ public class MyProfileScreen extends SettingsScreen {
|
|||||||
info = new Grid((Gerrit.getConfig().siteHasUsernames() ? 1 : 0) + 4, 2);
|
info = new Grid((Gerrit.getConfig().siteHasUsernames() ? 1 : 0) + 4, 2);
|
||||||
info.setStyleName(Gerrit.RESOURCES.css().infoBlock());
|
info.setStyleName(Gerrit.RESOURCES.css().infoBlock());
|
||||||
info.addStyleName(Gerrit.RESOURCES.css().accountInfoBlock());
|
info.addStyleName(Gerrit.RESOURCES.css().accountInfoBlock());
|
||||||
add(info);
|
h.add(info);
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
if (Gerrit.getConfig().siteHasUsernames()) {
|
if (Gerrit.getConfig().siteHasUsernames()) {
|
||||||
@@ -72,6 +94,16 @@ public class MyProfileScreen extends SettingsScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void display(final Account account) {
|
void display(final Account account) {
|
||||||
|
avatar.setAccount(FormatUtil.asInfo(account), 93, false);
|
||||||
|
new RestApi("/accounts/").id("self").view("avatar.change.url")
|
||||||
|
.get(new GerritCallback<NativeString>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(NativeString changeUrl) {
|
||||||
|
changeAvatar.setHref(changeUrl.asString());
|
||||||
|
changeAvatar.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
if (Gerrit.getConfig().siteHasUsernames()) {
|
if (Gerrit.getConfig().siteHasUsernames()) {
|
||||||
info.setWidget(row++, fieldIdx, new UsernameField());
|
info.setWidget(row++, fieldIdx, new UsernameField());
|
||||||
|
@@ -971,6 +971,13 @@ a:hover {
|
|||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.avatarInfoPanel {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
.avatarInfoPanel td {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.infoBlock {
|
.infoBlock {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
border-spacing: 0;
|
border-spacing: 0;
|
||||||
|
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (C) 2013 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.server.account;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||||
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
|
import com.google.gerrit.server.avatar.AvatarProvider;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
public class GetAvatarChangeUrl implements RestReadView<AccountResource> {
|
||||||
|
private final DynamicItem<AvatarProvider> avatarProvider;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
GetAvatarChangeUrl(DynamicItem<AvatarProvider> avatarProvider) {
|
||||||
|
this.avatarProvider = avatarProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(AccountResource rsrc)
|
||||||
|
throws ResourceNotFoundException {
|
||||||
|
AvatarProvider impl = avatarProvider.get();
|
||||||
|
if (impl == null) {
|
||||||
|
throw new ResourceNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = impl.getChangeAvatarUrl(rsrc.getUser());
|
||||||
|
if (Strings.isNullOrEmpty(url)) {
|
||||||
|
throw new ResourceNotFoundException();
|
||||||
|
} else {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -31,6 +31,7 @@ public class Module extends RestApiModule {
|
|||||||
|
|
||||||
get(ACCOUNT_KIND).to(GetAccount.class);
|
get(ACCOUNT_KIND).to(GetAccount.class);
|
||||||
get(ACCOUNT_KIND, "avatar").to(GetAvatar.class);
|
get(ACCOUNT_KIND, "avatar").to(GetAvatar.class);
|
||||||
|
get(ACCOUNT_KIND, "avatar.change.url").to(GetAvatarChangeUrl.class);
|
||||||
child(ACCOUNT_KIND, "capabilities").to(Capabilities.class);
|
child(ACCOUNT_KIND, "capabilities").to(Capabilities.class);
|
||||||
get(ACCOUNT_KIND, "groups").to(GetGroups.class);
|
get(ACCOUNT_KIND, "groups").to(GetGroups.class);
|
||||||
get(ACCOUNT_KIND, "preferences.diff").to(GetDiffPreferences.class);
|
get(ACCOUNT_KIND, "preferences.diff").to(GetDiffPreferences.class);
|
||||||
|
Reference in New Issue
Block a user