Merge "Rewrite UI plugin action description API"
This commit is contained in:
commit
523738fb98
@ -2317,10 +2317,6 @@ the user hovers the mouse.
|
||||
If true the action is permitted at this time and the caller is
|
||||
likely allowed to execute it. This may change if state is updated
|
||||
at the server or permissions are modified. Not present if false.
|
||||
|`confirmation_message` |optional|
|
||||
Warning message to display to the user at the client side after
|
||||
the user has selected to use this action, but before the action
|
||||
request is sent to the server.
|
||||
|====================================
|
||||
|
||||
[[add-reviewer-result]]
|
||||
|
@ -21,5 +21,4 @@ public class UiCommandDetail {
|
||||
public String label;
|
||||
public String title;
|
||||
public boolean enabled;
|
||||
public String confirmationMessage;
|
||||
}
|
||||
|
@ -14,20 +14,20 @@
|
||||
|
||||
package com.google.gerrit.extensions.webui;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
/**
|
||||
* Internal implementation helper for Gerrit Code Review server.
|
||||
* <p>
|
||||
* Extensions and plugins should not invoke this class.
|
||||
*/
|
||||
public class PrivateInternals_UiActionDescription {
|
||||
public static void setMethod(UiAction.Description d, String method) {
|
||||
d.setMethod(method);
|
||||
}
|
||||
|
||||
import java.util.Set;
|
||||
public static void setId(UiAction.Description d, String id) {
|
||||
d.setId(id);
|
||||
}
|
||||
|
||||
public interface UiCommand<R extends RestResource> extends RestView<R> {
|
||||
public static enum Place {
|
||||
PATCHSET_ACTION_PANEL;
|
||||
};
|
||||
|
||||
Set<Place> getPlaces();
|
||||
String getLabel(R resource);
|
||||
String getTitle(R resource);
|
||||
boolean isVisible(R resource);
|
||||
boolean isEnabled(R resource);
|
||||
String getConfirmationMessage(R resource);
|
||||
private PrivateInternals_UiActionDescription() {
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
// 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.extensions.webui;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
|
||||
public interface UiAction<R extends RestResource> extends RestView<R> {
|
||||
/**
|
||||
* Get the description of the action customized for the resource.
|
||||
*
|
||||
* @param resource the resource the view would act upon if the action is
|
||||
* invoked by the client. Information from the resource can be used to
|
||||
* customize the description.
|
||||
* @return a description of the action. The server will populate the
|
||||
* {@code id} and {@code method} properties. If null the action will
|
||||
* assumed unavailable and not presented. This is usually the same as
|
||||
* {@code setVisible(false)}.
|
||||
*/
|
||||
public Description getDescription(R resource);
|
||||
|
||||
/** Describes an action invokable through the web interface. */
|
||||
public static class Description {
|
||||
private String method;
|
||||
private String id;
|
||||
private String label;
|
||||
private String title;
|
||||
private boolean visible = true;
|
||||
private boolean enabled = true;
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
/** {@code PrivateInternals_UiActionDescription.setMethod()} */
|
||||
void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/** {@code PrivateInternals_UiActionDescription.setId()} */
|
||||
void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
/** Set the label to appear on the button to activate this action. */
|
||||
public Description setLabel(String label) {
|
||||
this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/** Set the tool-tip text to appear when the mouse hovers on the button. */
|
||||
public Description setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the action's button is visible on screen for the current client.
|
||||
* If not visible the action description may not be sent to the client.
|
||||
*/
|
||||
public Description setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled && isVisible();
|
||||
}
|
||||
|
||||
/** Set if the button should be invokable (true), or greyed out (false). */
|
||||
public Description setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -14,13 +14,13 @@
|
||||
|
||||
package com.google.gerrit.client.change;
|
||||
|
||||
import com.google.gerrit.client.ConfirmationCallback;
|
||||
import com.google.gerrit.client.ConfirmationDialog;
|
||||
import com.google.gerrit.client.ErrorDialog;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.changes.ChangeApi;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.ActionInfo;
|
||||
import com.google.gerrit.client.rpc.NativeString;
|
||||
import com.google.gerrit.client.rpc.RestApi;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
@ -56,23 +56,6 @@ class ActionButton extends Button implements ClickHandler {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
if (action.confirmation_message() != null
|
||||
&& !action.confirmation_message().isEmpty()) {
|
||||
new ConfirmationDialog(
|
||||
action.title(),
|
||||
new SafeHtmlBuilder().append(action.confirmation_message()),
|
||||
new ConfirmationCallback() {
|
||||
@Override
|
||||
public void onOk() {
|
||||
send();
|
||||
}
|
||||
}).center();
|
||||
} else {
|
||||
send();
|
||||
}
|
||||
}
|
||||
|
||||
private void send() {
|
||||
setEnabled(false);
|
||||
|
||||
AsyncCallback<NativeString> cb = new AsyncCallback<NativeString>() {
|
||||
@ -86,9 +69,10 @@ class ActionButton extends Button implements ClickHandler {
|
||||
public void onSuccess(NativeString msg) {
|
||||
setEnabled(true);
|
||||
if (msg != null && !msg.asString().isEmpty()) {
|
||||
// TODO Support better UI on UiCommand results.
|
||||
// TODO Support better UI on UiAction results.
|
||||
Window.alert(msg.asString());
|
||||
}
|
||||
Gerrit.display(PageLinks.toChange2(changeId));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -243,7 +243,6 @@ public class ChangeInfo extends JavaScriptObject {
|
||||
public final native String label() /*-{ return this.label; }-*/;
|
||||
public final native String title() /*-{ return this.title; }-*/;
|
||||
public final native boolean enabled() /*-{ return this.enabled || false; }-*/;
|
||||
public final native String confirmation_message() /*-{ return this.confirmation_message; }-*/;
|
||||
|
||||
protected ActionInfo() {
|
||||
}
|
||||
|
@ -13,8 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
import com.google.gerrit.client.ConfirmationCallback;
|
||||
import com.google.gerrit.client.ConfirmationDialog;
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.ErrorDialog;
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
@ -53,11 +51,10 @@ import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.DisclosurePanel;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.InlineLabel;
|
||||
import com.google.gwt.user.client.ui.Panel;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
import com.google.gwtjsonrpc.common.VoidResult;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -559,24 +556,6 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
||||
b.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(final ClickEvent event) {
|
||||
if (cmd.confirmationMessage != null &&
|
||||
!cmd.confirmationMessage.isEmpty()) {
|
||||
ConfirmationDialog confirmationDialog = new ConfirmationDialog(
|
||||
cmd.title, new SafeHtmlBuilder().append(cmd.confirmationMessage),
|
||||
new ConfirmationCallback() {
|
||||
@Override
|
||||
public void onOk() {
|
||||
postProcessCommand(cmd, b);
|
||||
}
|
||||
});
|
||||
confirmationDialog.center();
|
||||
} else {
|
||||
postProcessCommand(cmd, b);
|
||||
}
|
||||
}
|
||||
|
||||
private void postProcessCommand(final UiCommandDetail cmd,
|
||||
final Button b) {
|
||||
b.setEnabled(false);
|
||||
AsyncCallback<NativeString> cb =
|
||||
new AsyncCallback<NativeString>() {
|
||||
@ -592,6 +571,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
||||
if (msg != null && !msg.asString().isEmpty()) {
|
||||
Window.alert(msg.asString());
|
||||
}
|
||||
Gerrit.display(PageLinks.toChange(patchSet.getId()));
|
||||
}
|
||||
};
|
||||
RestApi api = ChangeApi.revision(patchSet.getId()).view(cmd.id);
|
||||
|
@ -14,9 +14,13 @@
|
||||
|
||||
package com.google.gerrit.httpd.rpc.changedetail;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.PatchSetDetail;
|
||||
import com.google.gerrit.common.data.UiCommandDetail;
|
||||
import com.google.gerrit.common.errors.NoSuchEntityException;
|
||||
import com.google.gerrit.extensions.webui.UiCommand;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.httpd.rpc.Handler;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
@ -32,7 +36,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.RevisionResource;
|
||||
import com.google.gerrit.server.change.Revisions;
|
||||
import com.google.gerrit.server.extensions.webui.UiCommands;
|
||||
import com.google.gerrit.server.extensions.webui.UiActions;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
@ -49,7 +53,6 @@ import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -173,10 +176,22 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
||||
}
|
||||
}
|
||||
|
||||
detail.setCommands(UiCommands.sorted(UiCommands.plugins(UiCommands.from(
|
||||
revisions,
|
||||
new RevisionResource(new ChangeResource(control), patchSet),
|
||||
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL)))));
|
||||
detail.setCommands(Lists.newArrayList(Iterables.transform(
|
||||
UiActions.sorted(UiActions.plugins(UiActions.from(
|
||||
revisions,
|
||||
new RevisionResource(new ChangeResource(control), patchSet)))),
|
||||
new Function<UiAction.Description, UiCommandDetail>() {
|
||||
@Override
|
||||
public UiCommandDetail apply(UiAction.Description in) {
|
||||
UiCommandDetail r = new UiCommandDetail();
|
||||
r.method = in.getMethod();
|
||||
r.id = in.getId();
|
||||
r.label = in.getLabel();
|
||||
r.title = in.getTitle();
|
||||
r.enabled = in.isEnabled();
|
||||
return r;
|
||||
}
|
||||
})));
|
||||
return detail;
|
||||
}
|
||||
|
||||
|
@ -21,7 +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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@ -42,11 +42,9 @@ 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>,
|
||||
UiCommand<ChangeResource> {
|
||||
UiAction<ChangeResource> {
|
||||
private static final Logger log = LoggerFactory.getLogger(Abandon.class);
|
||||
|
||||
private final ChangeHooks hooks;
|
||||
@ -133,34 +131,11 @@ public class Abandon implements RestModifyView<ChangeResource, Input>,
|
||||
}
|
||||
|
||||
@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;
|
||||
public UiAction.Description getDescription(ChangeResource resource) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Abandon")
|
||||
.setVisible(resource.getChange().getStatus().isOpen()
|
||||
&& resource.getControl().canAbandon());
|
||||
}
|
||||
|
||||
private ChangeMessage newMessage(Input input, IdentifiedUser caller,
|
||||
|
@ -46,11 +46,10 @@ import com.google.gerrit.common.data.LabelValue;
|
||||
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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
@ -68,7 +67,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.extensions.webui.UiCommands;
|
||||
import com.google.gerrit.server.extensions.webui.UiActions;
|
||||
import com.google.gerrit.server.git.LabelNormalizer;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
@ -293,11 +292,10 @@ public class ChangeJson {
|
||||
|
||||
if (has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiCommandDetail c : UiCommands.from(
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
changes,
|
||||
new ChangeResource(control(cd)),
|
||||
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) {
|
||||
out.actions.put(c.id, new ActionInfo(c));
|
||||
new ChangeResource(control(cd)))) {
|
||||
out.actions.put(d.getId(), new ActionInfo(d));
|
||||
}
|
||||
}
|
||||
lastControl = null;
|
||||
@ -794,11 +792,10 @@ public class ChangeJson {
|
||||
|
||||
if (out.isCurrent && has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiCommandDetail c : UiCommands.from(
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
revisions,
|
||||
new RevisionResource(new ChangeResource(control(cd)), in),
|
||||
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) {
|
||||
out.actions.put(c.id, new ActionInfo(c));
|
||||
new RevisionResource(new ChangeResource(control(cd)), in))) {
|
||||
out.actions.put(d.getId(), new ActionInfo(d));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
@ -983,14 +980,12 @@ public class ChangeJson {
|
||||
String label;
|
||||
String title;
|
||||
Boolean enabled;
|
||||
String confirmationMessage;
|
||||
|
||||
ActionInfo(UiCommandDetail c) {
|
||||
method = c.method;
|
||||
label = c.label;
|
||||
title = c.title;
|
||||
enabled = c.enabled ? true : null;
|
||||
confirmationMessage = c.confirmationMessage;
|
||||
ActionInfo(UiAction.Description d) {
|
||||
method = d.getMethod();
|
||||
label = d.getLabel();
|
||||
title = d.getTitle();
|
||||
enabled = d.isEnabled() ? true : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@ -30,11 +30,8 @@ import com.google.gerrit.server.project.RefControl;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
UiCommand<RevisionResource> {
|
||||
UiAction<RevisionResource> {
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final Provider<CherryPickChange> cherryPickChange;
|
||||
private final ChangeJson json;
|
||||
@ -96,32 +93,10 @@ class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Place> getPlaces() {
|
||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(RevisionResource resource) {
|
||||
return "Cherry Pick To";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(RevisionResource resource) {
|
||||
return "Cherry pick change to a different branch";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(RevisionResource resource) {
|
||||
return isEnabled(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(RevisionResource resource) {
|
||||
return resource.getControl().getProjectControl().canUpload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfirmationMessage(RevisionResource resource) {
|
||||
return null;
|
||||
public UiAction.Description getDescription(RevisionResource resource) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Cherry Pick")
|
||||
.setTitle("Cherry pick change to a different branch")
|
||||
.setVisible(resource.getControl().getProjectControl().canUpload());
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@ -36,11 +36,9 @@ 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>,
|
||||
UiCommand<ChangeResource> {
|
||||
UiAction<ChangeResource> {
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final ChangeIndexer indexer;
|
||||
private final ChangeHooks hooks;
|
||||
@ -119,32 +117,9 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
}
|
||||
|
||||
@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;
|
||||
public UiAction.Description getDescription(ChangeResource resource) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Edit Topic")
|
||||
.setVisible(resource.getControl().canEditTopicName());
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.webui.UiCommand;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@ -35,11 +35,9 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Rebase implements RestModifyView<RevisionResource, Input>,
|
||||
UiCommand<RevisionResource> {
|
||||
UiAction<RevisionResource> {
|
||||
public static class Input {
|
||||
}
|
||||
|
||||
@ -81,35 +79,13 @@ public class Rebase implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Place> getPlaces() {
|
||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(RevisionResource resource) {
|
||||
return "Rebase";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(RevisionResource resource) {
|
||||
return "Rebase onto tip of branch or parent change";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(RevisionResource resource) {
|
||||
return isEnabled(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(RevisionResource resource) {
|
||||
return resource.getChange().getStatus().isOpen()
|
||||
&& resource.getControl().canRebase()
|
||||
&& rebaseChange.get().canRebase(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfirmationMessage(RevisionResource resource) {
|
||||
return null;
|
||||
public UiAction.Description getDescription(RevisionResource resource) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Rebase")
|
||||
.setTitle("Rebase onto tip of branch or parent change")
|
||||
.setVisible(resource.getChange().getStatus().isOpen()
|
||||
&& resource.getControl().canRebase()
|
||||
&& rebaseChange.get().canRebase(resource));
|
||||
}
|
||||
|
||||
public static class CurrentRevision implements
|
||||
|
@ -20,7 +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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
@ -42,11 +42,9 @@ 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>,
|
||||
UiCommand<ChangeResource> {
|
||||
UiAction<ChangeResource> {
|
||||
private static final Logger log = LoggerFactory.getLogger(Restore.class);
|
||||
|
||||
private final ChangeHooks hooks;
|
||||
@ -94,8 +92,8 @@ public class Restore implements RestModifyView<ChangeResource, Input>,
|
||||
new AtomicUpdate<Change>() {
|
||||
@Override
|
||||
public Change update(Change change) {
|
||||
if (change.getStatus() == Change.Status.ABANDONED) {
|
||||
change.setStatus(Change.Status.NEW);
|
||||
if (change.getStatus() == Status.ABANDONED) {
|
||||
change.setStatus(Status.NEW);
|
||||
ChangeUtil.updated(change);
|
||||
return change;
|
||||
}
|
||||
@ -132,34 +130,11 @@ public class Restore implements RestModifyView<ChangeResource, Input>,
|
||||
}
|
||||
|
||||
@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;
|
||||
public UiAction.Description getDescription(ChangeResource resource) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Restore")
|
||||
.setVisible(resource.getChange().getStatus() == Status.ABANDONED
|
||||
&& resource.getControl().canRestore());
|
||||
}
|
||||
|
||||
private ChangeMessage newMessage(Input input, IdentifiedUser caller,
|
||||
|
@ -20,7 +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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@ -41,11 +41,8 @@ import com.google.inject.Provider;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Revert implements RestModifyView<ChangeResource, Input>,
|
||||
UiCommand<ChangeResource> {
|
||||
UiAction<ChangeResource> {
|
||||
private final ChangeHooks hooks;
|
||||
private final RevertedSender.Factory revertedSenderFactory;
|
||||
private final CommitValidators.Factory commitValidatorsFactory;
|
||||
@ -113,34 +110,11 @@ 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;
|
||||
public UiAction.Description getDescription(ChangeResource resource) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Revert")
|
||||
.setVisible(resource.getChange().getStatus() == Status.MERGED
|
||||
&& resource.getControl().getRefControl().canUpload());
|
||||
}
|
||||
|
||||
private static String status(Change change) {
|
||||
|
@ -24,7 +24,7 @@ import com.google.gerrit.common.data.SubmitRecord;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
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.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
@ -50,12 +50,10 @@ import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Submit implements RestModifyView<RevisionResource, Input>,
|
||||
UiCommand<RevisionResource> {
|
||||
UiAction<RevisionResource> {
|
||||
public static class Input {
|
||||
public boolean waitForMerge;
|
||||
}
|
||||
@ -145,41 +143,15 @@ public class Submit implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Place> getPlaces() {
|
||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(RevisionResource resource) {
|
||||
return String.format(
|
||||
"Submit Patch Set %d",
|
||||
resource.getPatchSet().getPatchSetId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(RevisionResource resource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(RevisionResource resource) {
|
||||
public UiAction.Description getDescription(RevisionResource resource) {
|
||||
PatchSet.Id current = resource.getChange().currentPatchSetId();
|
||||
return resource.getChange().getStatus().isOpen()
|
||||
&& resource.getPatchSet().getId().equals(current)
|
||||
&& isEnabled(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(RevisionResource resource) {
|
||||
// Enable based on approximation. If the user has permission enable,
|
||||
// even if the change has not reached as submittable state according
|
||||
// to the project rules.
|
||||
return resource.getControl().canSubmit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfirmationMessage(RevisionResource resource) {
|
||||
return null;
|
||||
return new UiAction.Description()
|
||||
.setLabel(String.format(
|
||||
"Submit Revision %d",
|
||||
resource.getPatchSet().getPatchSetId()))
|
||||
.setVisible(resource.getChange().getStatus().isOpen()
|
||||
&& resource.getPatchSet().getId().equals(current)
|
||||
&& resource.getControl().canSubmit());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,82 +19,76 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
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.RestCollection;
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.extensions.webui.UiCommand;
|
||||
import com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class UiCommands {
|
||||
private static final Logger log = LoggerFactory.getLogger(UiCommands.class);
|
||||
public class UiActions {
|
||||
private static final Logger log = LoggerFactory.getLogger(UiActions.class);
|
||||
|
||||
public static Predicate<UiCommandDetail> enabled() {
|
||||
return new Predicate<UiCommandDetail>() {
|
||||
public static Predicate<UiAction.Description> enabled() {
|
||||
return new Predicate<UiAction.Description>() {
|
||||
@Override
|
||||
public boolean apply(UiCommandDetail input) {
|
||||
return input.enabled;
|
||||
public boolean apply(UiAction.Description input) {
|
||||
return input.isEnabled();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static List<UiCommandDetail> sorted(Iterable<UiCommandDetail> in) {
|
||||
List<UiCommandDetail> s = Lists.newArrayList(in);
|
||||
Collections.sort(s, new Comparator<UiCommandDetail>() {
|
||||
public static List<UiAction.Description> sorted(Iterable<UiAction.Description> in) {
|
||||
List<UiAction.Description> s = Lists.newArrayList(in);
|
||||
Collections.sort(s, new Comparator<UiAction.Description>() {
|
||||
@Override
|
||||
public int compare(UiCommandDetail a, UiCommandDetail b) {
|
||||
return a.id.compareTo(b.id);
|
||||
public int compare(UiAction.Description a, UiAction.Description b) {
|
||||
return a.getId().compareTo(b.getId());
|
||||
}
|
||||
});
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Iterable<UiCommandDetail> plugins(Iterable<UiCommandDetail> in) {
|
||||
public static Iterable<UiAction.Description> plugins(Iterable<UiAction.Description> in) {
|
||||
return Iterables.filter(in,
|
||||
new Predicate<UiCommandDetail>() {
|
||||
new Predicate<UiAction.Description>() {
|
||||
@Override
|
||||
public boolean apply(UiCommandDetail input) {
|
||||
return input.id.indexOf('~') > 0;
|
||||
public boolean apply(UiAction.Description input) {
|
||||
return input.getId().indexOf('~') > 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <R extends RestResource> Iterable<UiCommandDetail> from(
|
||||
public static <R extends RestResource> Iterable<UiAction.Description> from(
|
||||
RestCollection<?, R> collection,
|
||||
R resource,
|
||||
EnumSet<UiCommand.Place> places) {
|
||||
return from(collection.views(), resource, places);
|
||||
R resource) {
|
||||
return from(collection.views(), resource);
|
||||
}
|
||||
|
||||
public static <R extends RestResource> Iterable<UiCommandDetail> from(
|
||||
public static <R extends RestResource> Iterable<UiAction.Description> from(
|
||||
DynamicMap<RestView<R>> views,
|
||||
final R resource,
|
||||
final EnumSet<UiCommand.Place> places) {
|
||||
final R resource) {
|
||||
return Iterables.filter(
|
||||
Iterables.transform(
|
||||
views,
|
||||
new Function<DynamicMap.Entry<RestView<R>>, UiCommandDetail> () {
|
||||
new Function<DynamicMap.Entry<RestView<R>>, UiAction.Description> () {
|
||||
@Override
|
||||
@Nullable
|
||||
public UiCommandDetail apply(DynamicMap.Entry<RestView<R>> e) {
|
||||
public UiAction.Description apply(DynamicMap.Entry<RestView<R>> e) {
|
||||
int d = e.getExportName().indexOf('.');
|
||||
if (d < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String method = e.getExportName().substring(0, d);
|
||||
String name = e.getExportName().substring(d + 1);
|
||||
RestView<R> view;
|
||||
try {
|
||||
view = e.getProvider().get();
|
||||
@ -105,31 +99,31 @@ public class UiCommands {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(view instanceof UiCommand)) {
|
||||
if (!(view instanceof UiAction)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UiCommand<R> cmd = (UiCommand<R>) view;
|
||||
if (Sets.intersection(cmd.getPlaces(), places).isEmpty()
|
||||
|| !cmd.isVisible(resource)) {
|
||||
UiAction.Description dsc =
|
||||
((UiAction<R>) view).getDescription(resource);
|
||||
if (dsc == null || !dsc.isVisible()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UiCommandDetail dsc = new UiCommandDetail();
|
||||
dsc.id = "gerrit".equals(e.getPluginName())
|
||||
? name
|
||||
: e.getPluginName() + '~' + name;
|
||||
dsc.method = method;
|
||||
dsc.label = cmd.getLabel(resource);
|
||||
dsc.title = cmd.getTitle(resource);
|
||||
dsc.enabled = cmd.isEnabled(resource);
|
||||
dsc.confirmationMessage = cmd.getConfirmationMessage(resource);
|
||||
String name = e.getExportName().substring(d + 1);
|
||||
PrivateInternals_UiActionDescription.setMethod(
|
||||
dsc,
|
||||
e.getExportName().substring(0, d));
|
||||
PrivateInternals_UiActionDescription.setId(
|
||||
dsc,
|
||||
"gerrit".equals(e.getPluginName())
|
||||
? name
|
||||
: e.getPluginName() + '~' + name);
|
||||
return dsc;
|
||||
}
|
||||
}),
|
||||
Predicates.notNull());
|
||||
}
|
||||
|
||||
private UiCommands() {
|
||||
private UiActions() {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user