Rewrite UI plugin action description API
Using methods on an interface that plugins/extensions implement makes for a very brittle API. We cannot safely add a new method without breaking all existing code or introducing another interface for plugins to implement. Change the UI action description to be a single method interface that returns an instance of a concrete description object. Plugins can populate the fields they know about and need for their use case, and the server will do its best to honor what the plugin has given. New methods can be added to the description without affecting the API versioning, enabling Gerrit to add more features in the future. The confirmation message feature has been removed. In the near future plugins will have the ability to register JavaScript code to be executed client-side when the button is activated and before the RPC is started. This will allow plugins to perform more custom logic, such as obtaining additional input. Looking even further ahead plugins may register their own JS handler to render a button, allowing the plugin to use a more complex widget. The UiAction.Description type may need to be extended to allow server side view code to pass custom data to the UI rendering logic. Change-Id: If5e0e6b42d6d1e8a111a2d304ce54b9d8834688a
This commit is contained in:
parent
3600951d0b
commit
3d57549a1d
@ -2317,10 +2317,6 @@ the user hovers the mouse.
|
|||||||
If true the action is permitted at this time and the caller is
|
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
|
likely allowed to execute it. This may change if state is updated
|
||||||
at the server or permissions are modified. Not present if false.
|
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]]
|
[[add-reviewer-result]]
|
||||||
|
@ -21,5 +21,4 @@ public class UiCommandDetail {
|
|||||||
public String label;
|
public String label;
|
||||||
public String title;
|
public String title;
|
||||||
public boolean enabled;
|
public boolean enabled;
|
||||||
public String confirmationMessage;
|
|
||||||
}
|
}
|
||||||
|
@ -14,20 +14,20 @@
|
|||||||
|
|
||||||
package com.google.gerrit.extensions.webui;
|
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>
|
||||||
import java.util.Set;
|
* Extensions and plugins should not invoke this class.
|
||||||
|
*/
|
||||||
public interface UiCommand<R extends RestResource> extends RestView<R> {
|
public class PrivateInternals_UiActionDescription {
|
||||||
public static enum Place {
|
public static void setMethod(UiAction.Description d, String method) {
|
||||||
PATCHSET_ACTION_PANEL;
|
d.setMethod(method);
|
||||||
};
|
}
|
||||||
|
|
||||||
Set<Place> getPlaces();
|
public static void setId(UiAction.Description d, String id) {
|
||||||
String getLabel(R resource);
|
d.setId(id);
|
||||||
String getTitle(R resource);
|
}
|
||||||
boolean isVisible(R resource);
|
|
||||||
boolean isEnabled(R resource);
|
private PrivateInternals_UiActionDescription() {
|
||||||
String getConfirmationMessage(R resource);
|
}
|
||||||
}
|
}
|
@ -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;
|
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.ErrorDialog;
|
||||||
|
import com.google.gerrit.client.Gerrit;
|
||||||
import com.google.gerrit.client.changes.ChangeApi;
|
import com.google.gerrit.client.changes.ChangeApi;
|
||||||
import com.google.gerrit.client.changes.ChangeInfo.ActionInfo;
|
import com.google.gerrit.client.changes.ChangeInfo.ActionInfo;
|
||||||
import com.google.gerrit.client.rpc.NativeString;
|
import com.google.gerrit.client.rpc.NativeString;
|
||||||
import com.google.gerrit.client.rpc.RestApi;
|
import com.google.gerrit.client.rpc.RestApi;
|
||||||
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gwt.core.client.JavaScriptObject;
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
@ -56,23 +56,6 @@ class ActionButton extends Button implements ClickHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(ClickEvent event) {
|
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);
|
setEnabled(false);
|
||||||
|
|
||||||
AsyncCallback<NativeString> cb = new AsyncCallback<NativeString>() {
|
AsyncCallback<NativeString> cb = new AsyncCallback<NativeString>() {
|
||||||
@ -86,9 +69,10 @@ class ActionButton extends Button implements ClickHandler {
|
|||||||
public void onSuccess(NativeString msg) {
|
public void onSuccess(NativeString msg) {
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
if (msg != null && !msg.asString().isEmpty()) {
|
if (msg != null && !msg.asString().isEmpty()) {
|
||||||
// TODO Support better UI on UiCommand results.
|
// TODO Support better UI on UiAction results.
|
||||||
Window.alert(msg.asString());
|
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 label() /*-{ return this.label; }-*/;
|
||||||
public final native String title() /*-{ return this.title; }-*/;
|
public final native String title() /*-{ return this.title; }-*/;
|
||||||
public final native boolean enabled() /*-{ return this.enabled || false; }-*/;
|
public final native boolean enabled() /*-{ return this.enabled || false; }-*/;
|
||||||
public final native String confirmation_message() /*-{ return this.confirmation_message; }-*/;
|
|
||||||
|
|
||||||
protected ActionInfo() {
|
protected ActionInfo() {
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package com.google.gerrit.client.changes;
|
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.Dispatcher;
|
||||||
import com.google.gerrit.client.ErrorDialog;
|
import com.google.gerrit.client.ErrorDialog;
|
||||||
import com.google.gerrit.client.FormatUtil;
|
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.DisclosurePanel;
|
||||||
import com.google.gwt.user.client.ui.FlowPanel;
|
import com.google.gwt.user.client.ui.FlowPanel;
|
||||||
import com.google.gwt.user.client.ui.Grid;
|
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.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.InlineLabel;
|
||||||
import com.google.gwt.user.client.ui.Panel;
|
import com.google.gwt.user.client.ui.Panel;
|
||||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
|
||||||
import com.google.gwtjsonrpc.common.VoidResult;
|
import com.google.gwtjsonrpc.common.VoidResult;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -559,24 +556,6 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
|||||||
b.addClickHandler(new ClickHandler() {
|
b.addClickHandler(new ClickHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final ClickEvent event) {
|
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);
|
b.setEnabled(false);
|
||||||
AsyncCallback<NativeString> cb =
|
AsyncCallback<NativeString> cb =
|
||||||
new AsyncCallback<NativeString>() {
|
new AsyncCallback<NativeString>() {
|
||||||
@ -592,6 +571,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
|||||||
if (msg != null && !msg.asString().isEmpty()) {
|
if (msg != null && !msg.asString().isEmpty()) {
|
||||||
Window.alert(msg.asString());
|
Window.alert(msg.asString());
|
||||||
}
|
}
|
||||||
|
Gerrit.display(PageLinks.toChange(patchSet.getId()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
RestApi api = ChangeApi.revision(patchSet.getId()).view(cmd.id);
|
RestApi api = ChangeApi.revision(patchSet.getId()).view(cmd.id);
|
||||||
|
@ -14,9 +14,13 @@
|
|||||||
|
|
||||||
package com.google.gerrit.httpd.rpc.changedetail;
|
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.PatchSetDetail;
|
||||||
|
import com.google.gerrit.common.data.UiCommandDetail;
|
||||||
import com.google.gerrit.common.errors.NoSuchEntityException;
|
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.httpd.rpc.Handler;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
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.ChangeResource;
|
||||||
import com.google.gerrit.server.change.RevisionResource;
|
import com.google.gerrit.server.change.RevisionResource;
|
||||||
import com.google.gerrit.server.change.Revisions;
|
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.PatchList;
|
||||||
import com.google.gerrit.server.patch.PatchListCache;
|
import com.google.gerrit.server.patch.PatchListCache;
|
||||||
import com.google.gerrit.server.patch.PatchListKey;
|
import com.google.gerrit.server.patch.PatchListKey;
|
||||||
@ -49,7 +53,6 @@ import org.eclipse.jgit.lib.ObjectId;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -173,10 +176,22 @@ class PatchSetDetailFactory extends Handler<PatchSetDetail> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
detail.setCommands(UiCommands.sorted(UiCommands.plugins(UiCommands.from(
|
detail.setCommands(Lists.newArrayList(Iterables.transform(
|
||||||
|
UiActions.sorted(UiActions.plugins(UiActions.from(
|
||||||
revisions,
|
revisions,
|
||||||
new RevisionResource(new ChangeResource(control), patchSet),
|
new RevisionResource(new ChangeResource(control), patchSet)))),
|
||||||
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL)))));
|
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;
|
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.DefaultInput;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@ -42,11 +42,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Collections;
|
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> {
|
UiAction<ChangeResource> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Abandon.class);
|
private static final Logger log = LoggerFactory.getLogger(Abandon.class);
|
||||||
|
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
@ -133,34 +131,11 @@ public class Abandon implements RestModifyView<ChangeResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(ChangeResource resource) {
|
||||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
return new UiAction.Description()
|
||||||
}
|
.setLabel("Abandon")
|
||||||
|
.setVisible(resource.getChange().getStatus().isOpen()
|
||||||
@Override
|
&& resource.getControl().canAbandon());
|
||||||
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,
|
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.Permission;
|
||||||
import com.google.gerrit.common.data.PermissionRange;
|
import com.google.gerrit.common.data.PermissionRange;
|
||||||
import com.google.gerrit.common.data.SubmitRecord;
|
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.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.restapi.RestView;
|
import com.google.gerrit.extensions.restapi.RestView;
|
||||||
import com.google.gerrit.extensions.restapi.Url;
|
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.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
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.account.AccountInfo;
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
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.git.LabelNormalizer;
|
||||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||||
@ -293,11 +292,10 @@ public class ChangeJson {
|
|||||||
|
|
||||||
if (has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
|
if (has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
|
||||||
out.actions = Maps.newTreeMap();
|
out.actions = Maps.newTreeMap();
|
||||||
for (UiCommandDetail c : UiCommands.from(
|
for (UiAction.Description d : UiActions.from(
|
||||||
changes,
|
changes,
|
||||||
new ChangeResource(control(cd)),
|
new ChangeResource(control(cd)))) {
|
||||||
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) {
|
out.actions.put(d.getId(), new ActionInfo(d));
|
||||||
out.actions.put(c.id, new ActionInfo(c));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastControl = null;
|
lastControl = null;
|
||||||
@ -794,11 +792,10 @@ public class ChangeJson {
|
|||||||
|
|
||||||
if (out.isCurrent && has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
|
if (out.isCurrent && has(CURRENT_ACTIONS) && user instanceof IdentifiedUser) {
|
||||||
out.actions = Maps.newTreeMap();
|
out.actions = Maps.newTreeMap();
|
||||||
for (UiCommandDetail c : UiCommands.from(
|
for (UiAction.Description d : UiActions.from(
|
||||||
revisions,
|
revisions,
|
||||||
new RevisionResource(new ChangeResource(control(cd)), in),
|
new RevisionResource(new ChangeResource(control(cd)), in))) {
|
||||||
EnumSet.of(UiCommand.Place.PATCHSET_ACTION_PANEL))) {
|
out.actions.put(d.getId(), new ActionInfo(d));
|
||||||
out.actions.put(c.id, new ActionInfo(c));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
@ -983,14 +980,12 @@ public class ChangeJson {
|
|||||||
String label;
|
String label;
|
||||||
String title;
|
String title;
|
||||||
Boolean enabled;
|
Boolean enabled;
|
||||||
String confirmationMessage;
|
|
||||||
|
|
||||||
ActionInfo(UiCommandDetail c) {
|
ActionInfo(UiAction.Description d) {
|
||||||
method = c.method;
|
method = d.getMethod();
|
||||||
label = c.label;
|
label = d.getLabel();
|
||||||
title = c.title;
|
title = d.getTitle();
|
||||||
enabled = c.enabled ? true : null;
|
enabled = d.isEnabled() ? true : null;
|
||||||
confirmationMessage = c.confirmationMessage;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
|||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
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.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
class CherryPick implements RestModifyView<RevisionResource, Input>,
|
class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||||
UiCommand<RevisionResource> {
|
UiAction<RevisionResource> {
|
||||||
private final Provider<ReviewDb> dbProvider;
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final Provider<CherryPickChange> cherryPickChange;
|
private final Provider<CherryPickChange> cherryPickChange;
|
||||||
private final ChangeJson json;
|
private final ChangeJson json;
|
||||||
@ -96,32 +93,10 @@ class CherryPick implements RestModifyView<RevisionResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(RevisionResource resource) {
|
||||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
return new UiAction.Description()
|
||||||
}
|
.setLabel("Cherry Pick")
|
||||||
|
.setTitle("Cherry pick change to a different branch")
|
||||||
@Override
|
.setVisible(resource.getControl().getProjectControl().canUpload());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import com.google.gerrit.extensions.restapi.DefaultInput;
|
|||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.Response;
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@ -36,11 +36,9 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import java.util.Collections;
|
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> {
|
UiAction<ChangeResource> {
|
||||||
private final Provider<ReviewDb> dbProvider;
|
private final Provider<ReviewDb> dbProvider;
|
||||||
private final ChangeIndexer indexer;
|
private final ChangeIndexer indexer;
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
@ -119,32 +117,9 @@ class PutTopic implements RestModifyView<ChangeResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(ChangeResource resource) {
|
||||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
return new UiAction.Description()
|
||||||
}
|
.setLabel("Edit Topic")
|
||||||
|
.setVisible(resource.getControl().canEditTopicName());
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
|||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@ -35,11 +35,9 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Rebase implements RestModifyView<RevisionResource, Input>,
|
public class Rebase implements RestModifyView<RevisionResource, Input>,
|
||||||
UiCommand<RevisionResource> {
|
UiAction<RevisionResource> {
|
||||||
public static class Input {
|
public static class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,35 +79,13 @@ public class Rebase implements RestModifyView<RevisionResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(RevisionResource resource) {
|
||||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
return new UiAction.Description()
|
||||||
}
|
.setLabel("Rebase")
|
||||||
|
.setTitle("Rebase onto tip of branch or parent change")
|
||||||
@Override
|
.setVisible(resource.getChange().getStatus().isOpen()
|
||||||
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()
|
&& resource.getControl().canRebase()
|
||||||
&& rebaseChange.get().canRebase(resource);
|
&& rebaseChange.get().canRebase(resource));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getConfirmationMessage(RevisionResource resource) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CurrentRevision implements
|
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.DefaultInput;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
@ -42,11 +42,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Collections;
|
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> {
|
UiAction<ChangeResource> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Restore.class);
|
private static final Logger log = LoggerFactory.getLogger(Restore.class);
|
||||||
|
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
@ -94,8 +92,8 @@ public class Restore implements RestModifyView<ChangeResource, Input>,
|
|||||||
new AtomicUpdate<Change>() {
|
new AtomicUpdate<Change>() {
|
||||||
@Override
|
@Override
|
||||||
public Change update(Change change) {
|
public Change update(Change change) {
|
||||||
if (change.getStatus() == Change.Status.ABANDONED) {
|
if (change.getStatus() == Status.ABANDONED) {
|
||||||
change.setStatus(Change.Status.NEW);
|
change.setStatus(Status.NEW);
|
||||||
ChangeUtil.updated(change);
|
ChangeUtil.updated(change);
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
@ -132,34 +130,11 @@ public class Restore implements RestModifyView<ChangeResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(ChangeResource resource) {
|
||||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
return new UiAction.Description()
|
||||||
}
|
.setLabel("Restore")
|
||||||
|
.setVisible(resource.getChange().getStatus() == Status.ABANDONED
|
||||||
@Override
|
&& resource.getControl().canRestore());
|
||||||
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,
|
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.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
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.PersonIdent;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Revert implements RestModifyView<ChangeResource, Input>,
|
public class Revert implements RestModifyView<ChangeResource, Input>,
|
||||||
UiCommand<ChangeResource> {
|
UiAction<ChangeResource> {
|
||||||
private final ChangeHooks hooks;
|
private final ChangeHooks hooks;
|
||||||
private final RevertedSender.Factory revertedSenderFactory;
|
private final RevertedSender.Factory revertedSenderFactory;
|
||||||
private final CommitValidators.Factory commitValidatorsFactory;
|
private final CommitValidators.Factory commitValidatorsFactory;
|
||||||
@ -113,34 +110,11 @@ public class Revert implements RestModifyView<ChangeResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(ChangeResource resource) {
|
||||||
return EnumSet.of(Place.PATCHSET_ACTION_PANEL);
|
return new UiAction.Description()
|
||||||
}
|
.setLabel("Revert")
|
||||||
|
.setVisible(resource.getChange().getStatus() == Status.MERGED
|
||||||
@Override
|
&& resource.getControl().getRefControl().canUpload());
|
||||||
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) {
|
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.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
@ -50,12 +50,10 @@ import java.io.IOException;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Submit implements RestModifyView<RevisionResource, Input>,
|
public class Submit implements RestModifyView<RevisionResource, Input>,
|
||||||
UiCommand<RevisionResource> {
|
UiAction<RevisionResource> {
|
||||||
public static class Input {
|
public static class Input {
|
||||||
public boolean waitForMerge;
|
public boolean waitForMerge;
|
||||||
}
|
}
|
||||||
@ -145,41 +143,15 @@ public class Submit implements RestModifyView<RevisionResource, Input>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Place> getPlaces() {
|
public UiAction.Description getDescription(RevisionResource resource) {
|
||||||
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) {
|
|
||||||
PatchSet.Id current = resource.getChange().currentPatchSetId();
|
PatchSet.Id current = resource.getChange().currentPatchSetId();
|
||||||
return resource.getChange().getStatus().isOpen()
|
return new UiAction.Description()
|
||||||
|
.setLabel(String.format(
|
||||||
|
"Submit Revision %d",
|
||||||
|
resource.getPatchSet().getPatchSetId()))
|
||||||
|
.setVisible(resource.getChange().getStatus().isOpen()
|
||||||
&& resource.getPatchSet().getId().equals(current)
|
&& resource.getPatchSet().getId().equals(current)
|
||||||
&& isEnabled(resource);
|
&& resource.getControl().canSubmit());
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,82 +19,76 @@ import com.google.common.base.Predicate;
|
|||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
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.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.restapi.RestCollection;
|
import com.google.gerrit.extensions.restapi.RestCollection;
|
||||||
import com.google.gerrit.extensions.restapi.RestResource;
|
import com.google.gerrit.extensions.restapi.RestResource;
|
||||||
import com.google.gerrit.extensions.restapi.RestView;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class UiCommands {
|
public class UiActions {
|
||||||
private static final Logger log = LoggerFactory.getLogger(UiCommands.class);
|
private static final Logger log = LoggerFactory.getLogger(UiActions.class);
|
||||||
|
|
||||||
public static Predicate<UiCommandDetail> enabled() {
|
public static Predicate<UiAction.Description> enabled() {
|
||||||
return new Predicate<UiCommandDetail>() {
|
return new Predicate<UiAction.Description>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(UiCommandDetail input) {
|
public boolean apply(UiAction.Description input) {
|
||||||
return input.enabled;
|
return input.isEnabled();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<UiCommandDetail> sorted(Iterable<UiCommandDetail> in) {
|
public static List<UiAction.Description> sorted(Iterable<UiAction.Description> in) {
|
||||||
List<UiCommandDetail> s = Lists.newArrayList(in);
|
List<UiAction.Description> s = Lists.newArrayList(in);
|
||||||
Collections.sort(s, new Comparator<UiCommandDetail>() {
|
Collections.sort(s, new Comparator<UiAction.Description>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(UiCommandDetail a, UiCommandDetail b) {
|
public int compare(UiAction.Description a, UiAction.Description b) {
|
||||||
return a.id.compareTo(b.id);
|
return a.getId().compareTo(b.getId());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Iterable<UiCommandDetail> plugins(Iterable<UiCommandDetail> in) {
|
public static Iterable<UiAction.Description> plugins(Iterable<UiAction.Description> in) {
|
||||||
return Iterables.filter(in,
|
return Iterables.filter(in,
|
||||||
new Predicate<UiCommandDetail>() {
|
new Predicate<UiAction.Description>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(UiCommandDetail input) {
|
public boolean apply(UiAction.Description input) {
|
||||||
return input.id.indexOf('~') > 0;
|
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,
|
RestCollection<?, R> collection,
|
||||||
R resource,
|
R resource) {
|
||||||
EnumSet<UiCommand.Place> places) {
|
return from(collection.views(), resource);
|
||||||
return from(collection.views(), resource, places);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R extends RestResource> Iterable<UiCommandDetail> from(
|
public static <R extends RestResource> Iterable<UiAction.Description> from(
|
||||||
DynamicMap<RestView<R>> views,
|
DynamicMap<RestView<R>> views,
|
||||||
final R resource,
|
final R resource) {
|
||||||
final EnumSet<UiCommand.Place> places) {
|
|
||||||
return Iterables.filter(
|
return Iterables.filter(
|
||||||
Iterables.transform(
|
Iterables.transform(
|
||||||
views,
|
views,
|
||||||
new Function<DynamicMap.Entry<RestView<R>>, UiCommandDetail> () {
|
new Function<DynamicMap.Entry<RestView<R>>, UiAction.Description> () {
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public UiCommandDetail apply(DynamicMap.Entry<RestView<R>> e) {
|
public UiAction.Description apply(DynamicMap.Entry<RestView<R>> e) {
|
||||||
int d = e.getExportName().indexOf('.');
|
int d = e.getExportName().indexOf('.');
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String method = e.getExportName().substring(0, d);
|
|
||||||
String name = e.getExportName().substring(d + 1);
|
|
||||||
RestView<R> view;
|
RestView<R> view;
|
||||||
try {
|
try {
|
||||||
view = e.getProvider().get();
|
view = e.getProvider().get();
|
||||||
@ -105,31 +99,31 @@ public class UiCommands {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(view instanceof UiCommand)) {
|
if (!(view instanceof UiAction)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UiCommand<R> cmd = (UiCommand<R>) view;
|
UiAction.Description dsc =
|
||||||
if (Sets.intersection(cmd.getPlaces(), places).isEmpty()
|
((UiAction<R>) view).getDescription(resource);
|
||||||
|| !cmd.isVisible(resource)) {
|
if (dsc == null || !dsc.isVisible()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UiCommandDetail dsc = new UiCommandDetail();
|
String name = e.getExportName().substring(d + 1);
|
||||||
dsc.id = "gerrit".equals(e.getPluginName())
|
PrivateInternals_UiActionDescription.setMethod(
|
||||||
|
dsc,
|
||||||
|
e.getExportName().substring(0, d));
|
||||||
|
PrivateInternals_UiActionDescription.setId(
|
||||||
|
dsc,
|
||||||
|
"gerrit".equals(e.getPluginName())
|
||||||
? name
|
? name
|
||||||
: 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);
|
|
||||||
return dsc;
|
return dsc;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Predicates.notNull());
|
Predicates.notNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
private UiCommands() {
|
private UiActions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user