InlineEdit: Add UiActions support for change edits

Change-Id: I69989cfb3d4ddc29de8f308095d0c44536401716
This commit is contained in:
David Ostrovsky 2014-08-03 14:03:13 +02:00
parent 23f74b39b2
commit cdda331099
9 changed files with 105 additions and 8 deletions

View File

@ -168,7 +168,7 @@ on a button associated with a server side `UiAction`.
self.onAction(type, view_name, callback);
----
* type: `'change'`, `'revision'`, `'project'`, or `'branch'`
* type: `'change'`, `'edit'`, `'revision'`, `'project'`, or `'branch'`
indicating which type of resource the `UiAction` was bound to
in the server.
@ -838,8 +838,8 @@ on a button associated with a server side `UiAction`.
Gerrit.onAction(type, view_name, callback);
----
* type: `'change'`, `'revision'`, `'project'` or `'branch'` indicating
what sort of resource the `UiAction` was bound to in the server.
* type: `'change'`, `'edit'`, `'revision'`, `'project'` or `'branch'`
indicating what sort of resource the `UiAction` was bound to in the server.
* view_name: string appearing in URLs to name the view. This is the
second argument of the `get()`, `post()`, `put()`, and `delete()`

View File

@ -3819,6 +3819,10 @@ The `EditInfo` entity contains information about a change edit.
|Field Name ||Description
|`commit` ||The commit of change edit as
link:#commit-info[CommitInfo] entity.
|`actions` ||
Actions the caller might be able to perform on this change edit. The
information is a map of view name to link:#action-info[ActionInfo]
entities.
|`files` |optional|
The files of the change edit as a map that maps the file names to
link:#file-info[FileInfo] entities.

View File

@ -18,5 +18,6 @@ import java.util.Map;
public class EditInfo {
public CommitInfo commit;
public Map<String, ActionInfo> actions;
public Map<String, FileInfo> files;
}

View File

@ -16,9 +16,11 @@ package com.google.gerrit.client.actions;
import com.google.gerrit.client.api.ActionContext;
import com.google.gerrit.client.api.ChangeGlue;
import com.google.gerrit.client.api.EditGlue;
import com.google.gerrit.client.api.ProjectGlue;
import com.google.gerrit.client.api.RevisionGlue;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.changes.ChangeInfo.EditInfo;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.projects.BranchInfo;
import com.google.gerrit.reviewdb.client.Project;
@ -31,30 +33,37 @@ public class ActionButton extends Button implements ClickHandler {
private final Project.NameKey project;
private final BranchInfo branch;
private final ChangeInfo change;
private final EditInfo edit;
private final RevisionInfo revision;
private final ActionInfo action;
private ActionContext ctx;
public ActionButton(Project.NameKey project, ActionInfo action) {
this(project, null, null, null, action);
this(project, null, null, null, null, action);
}
public ActionButton(Project.NameKey project, BranchInfo branch,
ActionInfo action) {
this(project, branch, null, null, action);
this(project, branch, null, null, null, action);
}
public ActionButton(ChangeInfo change, ActionInfo action) {
this(change, null, action);
this(null, null, change, null, null, action);
}
public ActionButton(ChangeInfo change, RevisionInfo revision,
ActionInfo action) {
this(null, null, change, revision, action);
this(null, null, change, null, revision, action);
}
public ActionButton(ChangeInfo change, EditInfo edit,
ActionInfo action) {
this(null, null, change, edit, null, action);
}
private ActionButton(Project.NameKey project, BranchInfo branch,
ChangeInfo change, RevisionInfo revision, ActionInfo action) {
ChangeInfo change, EditInfo edit, RevisionInfo revision,
ActionInfo action) {
super(new SafeHtmlBuilder()
.openDiv()
.append(action.label())
@ -67,6 +76,7 @@ public class ActionButton extends Button implements ClickHandler {
this.project = project;
this.branch = branch;
this.change = change;
this.edit = edit;
this.revision = revision;
this.action = action;
}
@ -81,6 +91,8 @@ public class ActionButton extends Button implements ClickHandler {
if (revision != null) {
RevisionGlue.onAction(change, revision, action, this);
} else if (edit != null) {
EditGlue.onAction(change, edit, action, this);
} else if (change != null) {
ChangeGlue.onAction(change, action, this);
} else if (branch != null) {

View File

@ -17,6 +17,7 @@ package com.google.gerrit.client.api;
import com.google.gerrit.client.actions.ActionButton;
import com.google.gerrit.client.actions.ActionInfo;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.changes.ChangeInfo.EditInfo;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.projects.BranchInfo;
import com.google.gerrit.client.rpc.GerritCallback;
@ -137,6 +138,7 @@ public class ActionContext extends JavaScriptObject {
final native void set(ActionInfo a) /*-{ this.action=a; }-*/;
final native void set(ChangeInfo c) /*-{ this.change=c; }-*/;
final native void set(EditInfo e) /*-{ this.edit=e; }-*/;
final native void set(Project.NameKey p) /*-{ this.project=p; }-*/;
final native void set(BranchInfo b) /*-{ this.branch=b }-*/;
final native void set(RevisionInfo r) /*-{ this.revision=r; }-*/;

View File

@ -41,6 +41,7 @@ public class ApiGlue {
plugins: {},
screens: {},
change_actions: {},
edit_actions: {},
revision_actions: {},
project_actions: {},
branch_actions: {},
@ -71,6 +72,7 @@ public class ApiGlue {
_onAction: function (p,t,n,c) {
var i = p+'~'+n;
if ('change' == t) this.change_actions[i]=c;
else if ('edit' == t) this.edit_actions[i]=c;
else if ('revision' == t) this.revision_actions[i]=c;
else if ('project' == t) this.project_actions[i]=c;
else if ('branch' == t) this.branch_actions[i]=c;

View File

@ -0,0 +1,54 @@
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.api;
import com.google.gerrit.client.actions.ActionButton;
import com.google.gerrit.client.actions.ActionInfo;
import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.changes.ChangeInfo.EditInfo;
import com.google.gerrit.client.rpc.RestApi;
import com.google.gwt.core.client.JavaScriptObject;
public class EditGlue {
public static void onAction(
ChangeInfo change,
EditInfo edit,
ActionInfo action,
ActionButton button) {
RestApi api = ChangeApi.edit(
change.legacy_id().get())
.view(action.id());
JavaScriptObject f = get(action.id());
if (f != null) {
ActionContext c = ActionContext.create(api);
c.set(action);
c.set(change);
c.set(edit);
c.button(button);
ApiGlue.invoke(f, c);
} else {
DefaultActions.invoke(change, action, api);
}
}
private static final native JavaScriptObject get(String id) /*-{
return $wnd.Gerrit.edit_actions[id];
}-*/;
private EditGlue() {
}
}

View File

@ -19,6 +19,7 @@ import com.google.gerrit.client.actions.ActionButton;
import com.google.gerrit.client.actions.ActionInfo;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.changes.ChangeInfo.CommitInfo;
import com.google.gerrit.client.changes.ChangeInfo.EditInfo;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.reviewdb.client.Change;
@ -84,6 +85,7 @@ class Actions extends Composite {
initChangeActions(info, hasUser);
initRevisionActions(info, revInfo, hasUser);
initEditActions(info, info.edit(), hasUser);
}
private void initChangeActions(ChangeInfo info, boolean hasUser) {
@ -103,6 +105,23 @@ class Actions extends Composite {
}
}
private void initEditActions(ChangeInfo info, EditInfo editInfo,
boolean hasUser) {
if (!info.has_edit() || !info.current_revision().equals(editInfo.name())) {
return;
}
NativeMap<ActionInfo> actions = editInfo.has_actions()
? editInfo.actions()
: NativeMap.<ActionInfo> create();
actions.copyKeysIntoChildren("id");
if (hasUser) {
for (String id : filterNonCore(actions)) {
add(new ActionButton(info, editInfo, actions.get(id)));
}
}
}
private void initRevisionActions(ChangeInfo info, RevisionInfo revInfo,
boolean hasUser) {
NativeMap<ActionInfo> actions = revInfo.has_actions()

View File

@ -214,6 +214,9 @@ public class ChangeInfo extends JavaScriptObject {
public final native String set_name(String n) /*-{ this.name = n; }-*/;
public final native CommitInfo commit() /*-{ return this.commit; }-*/;
public final native boolean has_actions() /*-{ return this.hasOwnProperty('actions') }-*/;
public final native NativeMap<ActionInfo> actions() /*-{ return this.actions; }-*/;
public final native boolean has_files() /*-{ return this.hasOwnProperty('files') }-*/;
public final native NativeMap<FileInfo> files() /*-{ return this.files; }-*/;