Merge branch 'change-screen-deps'

* change-screen-deps:
  Add change level actions map to ChangeInfo
  Automatically refresh GWT UI on each page load
  Make parts of SubmitInfo and SubmitFailureDialog public
  Add no-arg constructor for CopyableLabel
  Fix visible length of CopyableLabel on Change-Id
  Support ListChangesOption in ChangeApi.detail() calls
  Add ChangeApi method to invoke rebase
  Add KeyDownHandler for escape to close popups
  Extract ReviewInput to top level class
  Add NativeMap.create() as a utility

Change-Id: Ic1cbc9fd51cde4a6b0fc748ce9488a9d2259f01b
This commit is contained in:
Shawn Pearce 2013-07-14 18:55:08 -07:00
commit ed061f502a
17 changed files with 311 additions and 49 deletions

View File

@ -2406,6 +2406,10 @@ Not set for merged changes.
|`owner` ||
The owner of the change as an link:rest-api-accounts.html#account-info[
AccountInfo] entity.
|`actions` |optional|
Actions the caller might be able to perform on this revision. The
information is a map of view name to link:#action-info[ActionInfo]
entities.
|`labels` |optional|
The labels of the change as a map that maps the label names to
link:#label-info[LabelInfo] entries. +
@ -2886,12 +2890,12 @@ The `RevisionInfo` entity contains information about a patch set.
Information about how to fetch this patch set. The fetch information is
provided as a map that maps the protocol name ("`git`", "`http`",
"`ssh`") to link:#fetch-info[FetchInfo] entities.
|`commit` ||The commit of the patch set as
|`commit` |optional|The commit of the patch set as
link:#commit-info[CommitInfo] entity.
|`files` ||
|`files` |optional|
The files of the patch set as a map that maps the file names to
link:#file-info[FileInfo] entities.
|`actions` ||
|`actions` |optional|
Actions the caller might be able to perform on this revision. The
information is a map of view name to link:#action-info[ActionInfo]
entities.

View File

@ -71,6 +71,10 @@ public class CopyableLabel extends Composite implements HasText {
private TextBox textBox;
private Element swf;
public CopyableLabel() {
this("");
}
/**
* Create a new label
*
@ -117,7 +121,6 @@ public class CopyableLabel extends Composite implements HasText {
public void setPreviewText(final String text) {
if (textLabel != null) {
textLabel.setText(text);
visibleLen = text.length();
}
}

View File

@ -15,6 +15,8 @@
package com.google.gwtexpui.globalkey.client;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
@ -92,6 +94,14 @@ public class GlobalKey {
active = new State(panel);
active.add(new HidePopupPanelCommand(0, KeyCodes.KEY_ESCAPE, panel));
panel.addCloseHandler(restoreGlobal);
panel.addDomHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
panel.hide();
}
}
}, KeyDownEvent.getType());
}
public static HandlerRegistration addApplication(final Widget widget,

View File

@ -16,10 +16,13 @@ package com.google.gerrit.client.changes;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.common.changes.ListChangesOption;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.EnumSet;
/**
* A collection of static methods which work on the Gerrit REST API for specific
* changes.
@ -62,7 +65,20 @@ public class ChangeApi {
}
public static void detail(int id, AsyncCallback<ChangeInfo> cb) {
call(id, "detail").get(cb);
detail(id).get(cb);
}
public static void detail(int id, EnumSet<ListChangesOption> options,
AsyncCallback<ChangeInfo> cb) {
RestApi call = detail(id);
if (!options.isEmpty()) {
ChangeList.addOptions(call, options);
}
call.get(cb);
}
private static RestApi detail(int id) {
return call(id, "detail");
}
public static RestApi revision(int id, String revision) {
@ -100,6 +116,12 @@ public class ChangeApi {
call(id, commit, "submit").post(in, cb);
}
/** Rebase a revision onto the branch tip. */
public static void rebase(int id, String commit, AsyncCallback<ChangeInfo> cb) {
JavaScriptObject in = JavaScriptObject.createObject();
call(id, commit, "rebase").post(in, cb);
}
private static class Input extends JavaScriptObject {
final native void topic(String t) /*-{ if(t)this.topic=t; }-*/;
final native void message(String m) /*-{ if(m)this.message=m; }-*/;

View File

@ -66,7 +66,7 @@ public class ChangeList extends JsArray<ChangeInfo> {
call.get(callback);
}
static void addOptions(RestApi call, EnumSet<ListChangesOption> s) {
public static void addOptions(RestApi call, EnumSet<ListChangesOption> s) {
call.addParameterRaw("O", Integer.toHexString(ListChangesOption.toBits(s)));
}

View File

@ -36,7 +36,6 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@ -402,7 +401,6 @@ public class PublishCommentScreen extends AccountScreen implements
private void onSend2(final boolean submit) {
ReviewInput data = ReviewInput.create();
data.message(ChangeApi.emptyToNull(message.getText().trim()));
data.init();
for (final ValueRadioButton b : approvalButtons) {
if (b.getValue()) {
data.label(b.label.name(), b.parseValue());
@ -432,23 +430,6 @@ public class PublishCommentScreen extends AccountScreen implements
});
}
private static class ReviewInput extends JavaScriptObject {
static ReviewInput create() {
return (ReviewInput) createObject();
}
final native void message(String m) /*-{ if(m)this.message=m; }-*/;
final native void label(String n, short v) /*-{ this.labels[n]=v; }-*/;
final native void init() /*-{
this.labels = {};
this.strict_labels = true;
this.drafts = 'PUBLISH';
}-*/;
protected ReviewInput() {
}
}
private void submit() {
ChangeApi.submit(patchSetId.getParentKey().get(), revision,
new GerritCallback<SubmitInfo>() {

View File

@ -0,0 +1,37 @@
// 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.client.changes;
import com.google.gwt.core.client.JavaScriptObject;
public class ReviewInput extends JavaScriptObject {
public static ReviewInput create() {
ReviewInput r = createObject().cast();
r.init();
return r;
}
public final native void message(String m) /*-{ if(m)this.message=m; }-*/;
public final native void label(String n, short v) /*-{ this.labels[n]=v; }-*/;
private final native void init() /*-{
this.labels = {};
this.strict_labels = true;
this.drafts = 'PUBLISH';
}-*/;
protected ReviewInput() {
}
}

View File

@ -18,13 +18,13 @@ import com.google.gerrit.client.ErrorDialog;
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
import com.google.gwtjsonrpc.client.RemoteJsonException;
class SubmitFailureDialog extends ErrorDialog {
static boolean isConflict(Throwable err) {
public class SubmitFailureDialog extends ErrorDialog {
public static boolean isConflict(Throwable err) {
return err instanceof RemoteJsonException
&& 409 == ((RemoteJsonException) err).getCode();
}
SubmitFailureDialog(String msg) {
public SubmitFailureDialog(String msg) {
super(new SafeHtmlBuilder().append(msg.trim()).wikify());
setText(Util.C.submitFailed());
}

View File

@ -17,7 +17,7 @@ package com.google.gerrit.client.changes;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwt.core.client.JavaScriptObject;
class SubmitInfo extends JavaScriptObject {
public class SubmitInfo extends JavaScriptObject {
final Change.Status status() {
return Change.Status.valueOf(statusRaw());
}

View File

@ -22,6 +22,10 @@ import java.util.Set;
/** A map of native JSON objects, keyed by a string. */
public class NativeMap<T extends JavaScriptObject> extends JavaScriptObject {
public static <T extends JavaScriptObject> NativeMap<T> create() {
return createObject().cast();
}
/**
* Loop through the result map's entries and copy the key strings into the
* "name" property of the corresponding child object. This only runs on the

View File

@ -77,6 +77,12 @@ import java.util.zip.ZipFile;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
@Singleton
public class JettyServer {
@ -343,7 +349,7 @@ public class JettyServer {
// need to unpack them into yet another temporary directory prior to
// serving to clients.
//
app.setBaseResource(getBaseResource());
app.setBaseResource(getBaseResource(app));
// HTTP front-end filter to be used as surrogate of Apache HTTP
// reverse-proxy filtering.
@ -397,13 +403,14 @@ public class JettyServer {
return app;
}
private Resource getBaseResource() throws IOException {
private Resource getBaseResource(ServletContextHandler app)
throws IOException {
if (baseResource == null) {
try {
baseResource = unpackWar(GerritLauncher.getDistributionArchive());
} catch (FileNotFoundException err) {
if (err.getMessage() == GerritLauncher.NOT_ARCHIVED) {
baseResource = useDeveloperBuild();
baseResource = useDeveloperBuild(app);
} else {
throw err;
}
@ -412,7 +419,13 @@ public class JettyServer {
return baseResource;
}
private Resource unpackWar(File srcwar) throws IOException {
private static Resource unpackWar(File srcwar) throws IOException {
File dstwar = makeWarTempDir();
unpack(srcwar, dstwar);
return Resource.newResource(dstwar.toURI());
}
private static File makeWarTempDir() throws IOException {
// Obtain our local temporary directory, but it comes back as a file
// so we have to switch it to be a directory post creation.
//
@ -425,11 +438,13 @@ public class JettyServer {
// a security feature. Try to resolve out any symlinks in the path.
//
try {
dstwar = dstwar.getCanonicalFile();
return dstwar.getCanonicalFile();
} catch (IOException e) {
dstwar = dstwar.getAbsoluteFile();
return dstwar.getAbsoluteFile();
}
}
private static void unpack(File srcwar, File dstwar) throws IOException {
final ZipFile zf = new ZipFile(srcwar);
try {
final Enumeration<? extends ZipEntry> e = zf.entries();
@ -466,11 +481,9 @@ public class JettyServer {
} finally {
zf.close();
}
return Resource.newResource(dstwar.toURI());
}
private void mkdir(final File dir) throws IOException {
private static void mkdir(File dir) throws IOException {
if (!dir.isDirectory()) {
mkdir(dir.getParentFile());
if (!dir.mkdir())
@ -479,7 +492,8 @@ public class JettyServer {
}
}
private Resource useDeveloperBuild() throws IOException {
private Resource useDeveloperBuild(ServletContextHandler app)
throws IOException {
// Find ourselves in the CLASSPATH. We should be a loose class file.
//
URL u = getClass().getResource(getClass().getSimpleName() + ".class");
@ -510,12 +524,44 @@ public class JettyServer {
dir = dir.getParentFile(); // pop classes
if ("buck-out".equals(dir.getName())) {
final File dstwar = makeWarTempDir();
String pkg = "gerrit-gwtui";
String target = targetForBrowser(System.getProperty("gerrit.browser"));
File gen = new File(dir, "gen");
final File gen = new File(dir, "gen");
String out = new File(new File(gen, pkg), target).getAbsolutePath();
build(dir.getParentFile(), gen, "//" + pkg + ":" + target);
return unpackWar(new File(out + ".zip"));
final File zip = new File(out + ".zip");
final File root = dir.getParentFile();
final String name = "//" + pkg + ":" + target;
File ui = new File(dstwar, "gerrit_ui");
File p = new File(ui, "permutations");
mkdir(ui);
p.createNewFile();
p.deleteOnExit();
app.addFilter(new FilterHolder(new Filter() {
private long last;
@Override
public void doFilter(ServletRequest request, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
build(root, gen, name);
if (last != zip.lastModified()) {
last = zip.lastModified();
unpack(zip, dstwar);
}
chain.doFilter(req, res);
}
@Override
public void init(FilterConfig config) {
}
@Override
public void destroy() {
}
}), "/", EnumSet.of(DispatcherType.REQUEST));
return Resource.newResource(dstwar.toURI());
} else if ("target".equals(dir.getName())) {
return useMavenDeveloperBuild(dir);
} else {

View File

@ -21,6 +21,7 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiCommand;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.server.ReviewDb;
@ -41,8 +42,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public class Abandon implements RestModifyView<ChangeResource, Input> {
public class Abandon implements RestModifyView<ChangeResource, Input>,
UiCommand<ChangeResource> {
private static final Logger log = LoggerFactory.getLogger(Abandon.class);
private final ChangeHooks hooks;
@ -128,6 +132,37 @@ public class Abandon implements RestModifyView<ChangeResource, Input> {
return json.format(change);
}
@Override
public Set<Place> getPlaces() {
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
}
@Override
public String getLabel(ChangeResource resource) {
return "Abandon";
}
@Override
public String getTitle(ChangeResource resource) {
return null;
}
@Override
public boolean isVisible(ChangeResource resource) {
return isEnabled(resource);
}
@Override
public boolean isEnabled(ChangeResource resource) {
return resource.getChange().getStatus().isOpen()
&& resource.getControl().canAbandon();
}
@Override
public String getConfirmationMessage(ChangeResource resource) {
return null;
}
private ChangeMessage newMessage(Input input, IdentifiedUser caller,
Change change) throws OrmException {
StringBuilder msg = new StringBuilder();

View File

@ -47,6 +47,8 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRange;
import com.google.gerrit.common.data.SubmitRecord;
import com.google.gerrit.common.data.UiCommandDetail;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.extensions.webui.UiCommand;
import com.google.gerrit.reviewdb.client.Account;
@ -129,6 +131,7 @@ public class ChangeJson {
private final AccountInfo.Loader.Factory accountLoaderFactory;
private final Provider<String> urlProvider;
private final Urls urls;
private final DynamicMap<RestView<ChangeResource>> changes;
private final Revisions revisions;
private ChangeControl.Factory changeControlUserFactory;
@ -150,6 +153,7 @@ public class ChangeJson {
AccountInfo.Loader.Factory ailf,
@CanonicalWebUrl Provider<String> curl,
Urls urls,
DynamicMap<RestView<ChangeResource>> changes,
Revisions revisions) {
this.db = db;
this.labelNormalizer = ln;
@ -162,6 +166,7 @@ public class ChangeJson {
this.accountLoaderFactory = ailf;
this.urlProvider = curl;
this.urls = urls;
this.changes = changes;
this.revisions = revisions;
options = EnumSet.noneOf(ListChangesOption.class);
@ -286,6 +291,15 @@ public class ChangeJson {
}
}
if (has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
out.actions = Maps.newTreeMap();
for (UiCommandDetail c : UiCommands.from(
changes,
new ChangeResource(control(cd)),
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) {
out.actions.put(c.id, new ActionInfo(c));
}
}
lastControl = null;
return out;
}
@ -870,6 +884,7 @@ public class ChangeJson {
AccountInfo owner;
Map<String, ActionInfo> actions;
Map<String, LabelInfo> labels;
Map<String, Collection<String>> permitted_labels;
Collection<AccountInfo> removable_reviewers;

View File

@ -19,9 +19,10 @@ import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiCommand;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.server.ReviewDb;
@ -35,8 +36,11 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
class PutTopic implements RestModifyView<ChangeResource, Input> {
class PutTopic implements RestModifyView<ChangeResource, Input>,
UiCommand<ChangeResource> {
private final Provider<ReviewDb> dbProvider;
private final ChangeIndexer indexer;
private final ChangeHooks hooks;
@ -113,4 +117,34 @@ class PutTopic implements RestModifyView<ChangeResource, Input> {
? Response.none()
: newTopicName;
}
@Override
public Set<Place> getPlaces() {
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
}
@Override
public String getLabel(ChangeResource resource) {
return "Edit Topic";
}
@Override
public String getTitle(ChangeResource resource) {
return null;
}
@Override
public boolean isVisible(ChangeResource resource) {
return isEnabled(resource);
}
@Override
public boolean isEnabled(ChangeResource resource) {
return resource.getControl().canEditTopicName();
}
@Override
public String getConfirmationMessage(ChangeResource resource) {
return null;
}
}

View File

@ -20,6 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiCommand;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.client.ChangeMessage;
@ -41,8 +42,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public class Restore implements RestModifyView<ChangeResource, Input> {
public class Restore implements RestModifyView<ChangeResource, Input>,
UiCommand<ChangeResource> {
private static final Logger log = LoggerFactory.getLogger(Restore.class);
private final ChangeHooks hooks;
@ -127,6 +131,37 @@ public class Restore implements RestModifyView<ChangeResource, Input> {
return json.format(change);
}
@Override
public Set<Place> getPlaces() {
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
}
@Override
public String getLabel(ChangeResource resource) {
return "Restore";
}
@Override
public String getTitle(ChangeResource resource) {
return null;
}
@Override
public boolean isVisible(ChangeResource resource) {
return isEnabled(resource);
}
@Override
public boolean isEnabled(ChangeResource resource) {
return resource.getChange().getStatus() == Change.Status.ABANDONED
&& resource.getControl().canRestore();
}
@Override
public String getConfirmationMessage(ChangeResource resource) {
return null;
}
private ChangeMessage newMessage(Input input, IdentifiedUser caller,
Change change) throws OrmException {
StringBuilder msg = new StringBuilder();

View File

@ -20,6 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiCommand;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.server.ReviewDb;
@ -40,7 +41,11 @@ import com.google.inject.Provider;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
public class Revert implements RestModifyView<ChangeResource, Input> {
import java.util.EnumSet;
import java.util.Set;
public class Revert implements RestModifyView<ChangeResource, Input>,
UiCommand<ChangeResource> {
private final ChangeHooks hooks;
private final RevertedSender.Factory revertedSenderFactory;
private final CommitValidators.Factory commitValidatorsFactory;
@ -107,6 +112,37 @@ public class Revert implements RestModifyView<ChangeResource, Input> {
}
}
@Override
public Set<Place> getPlaces() {
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
}
@Override
public String getLabel(ChangeResource resource) {
return "Revert";
}
@Override
public String getTitle(ChangeResource resource) {
return null;
}
@Override
public boolean isVisible(ChangeResource resource) {
return isEnabled(resource);
}
@Override
public boolean isEnabled(ChangeResource resource) {
return resource.getChange().getStatus() == Change.Status.MERGED
&& resource.getControl().getRefControl().canUpload();
}
@Override
public String getConfirmationMessage(ChangeResource resource) {
return null;
}
private static String status(Change change) {
return change != null ? change.getStatus().name().toLowerCase() : "deleted";
}

View File

@ -22,7 +22,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gerrit.common.data.UiCommandDetail;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.ChildCollection;
import com.google.gerrit.extensions.restapi.RestCollection;
import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.extensions.webui.UiCommand;
@ -71,7 +71,7 @@ public class UiCommands {
}
public static <R extends RestResource> Iterable<UiCommandDetail> from(
ChildCollection<?, R> collection,
RestCollection<?, R> collection,
R resource,
EnumSet<UiCommand.Place> places) {
return from(collection.views(), resource, places);