Merge branch 'stable-2.8'
* stable-2.8: Bump SSHD version to 0.9.0.201311081 Add REST API to toggle starred change state Change-Id: Ic8d7a1802f6d6319f8f1012f9fe0c7f0c030f60a
This commit is contained in:
@@ -15,19 +15,23 @@
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.common.data.ToggleStarRequest;
|
||||
import com.google.gerrit.client.account.AccountApi;
|
||||
import com.google.gerrit.client.rpc.RestApi;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwtexpui.globalkey.client.KeyCommand;
|
||||
import com.google.gwtjsonrpc.common.VoidResult;
|
||||
import com.google.web.bindery.event.shared.Event;
|
||||
import com.google.web.bindery.event.shared.HandlerRegistration;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** Supports the star icon displayed on changes and tracking the status. */
|
||||
public class StarredChanges {
|
||||
private static final Event.Type<ChangeStarHandler> TYPE =
|
||||
@@ -105,57 +109,52 @@ public class StarredChanges {
|
||||
public static void toggleStar(
|
||||
final Change.Id changeId,
|
||||
final boolean newValue) {
|
||||
if (next == null) {
|
||||
next = new ToggleStarRequest();
|
||||
}
|
||||
next.toggle(changeId, newValue);
|
||||
pending.put(changeId, newValue);
|
||||
fireChangeStarEvent(changeId, newValue);
|
||||
if (!busy) {
|
||||
start();
|
||||
startRequest();
|
||||
}
|
||||
}
|
||||
|
||||
private static ToggleStarRequest next;
|
||||
private static boolean busy;
|
||||
private static final Map<Change.Id, Boolean> pending =
|
||||
new LinkedHashMap<Change.Id, Boolean>(4);
|
||||
|
||||
private static void start() {
|
||||
final ToggleStarRequest req = next;
|
||||
next = null;
|
||||
private static void startRequest() {
|
||||
busy = true;
|
||||
|
||||
Util.LIST_SVC.toggleStars(req, new GerritCallback<VoidResult>() {
|
||||
final Change.Id id = pending.keySet().iterator().next();
|
||||
final boolean starred = pending.remove(id);
|
||||
RestApi call = AccountApi.self().view("starred.changes").id(id.get());
|
||||
AsyncCallback<JavaScriptObject> cb = new AsyncCallback<JavaScriptObject>() {
|
||||
@Override
|
||||
public void onSuccess(VoidResult result) {
|
||||
if (next != null) {
|
||||
start();
|
||||
} else {
|
||||
public void onSuccess(JavaScriptObject none) {
|
||||
if (pending.isEmpty()) {
|
||||
busy = false;
|
||||
} else {
|
||||
startRequest();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
rollback(req);
|
||||
if (next != null) {
|
||||
rollback(next);
|
||||
next = null;
|
||||
if (!starred && RestApi.isStatus(caught, 404)) {
|
||||
onSuccess(null);
|
||||
return;
|
||||
}
|
||||
busy = false;
|
||||
super.onFailure(caught);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void rollback(ToggleStarRequest req) {
|
||||
if (req.getAddSet() != null) {
|
||||
for (Change.Id id : req.getAddSet()) {
|
||||
fireChangeStarEvent(id, false);
|
||||
}
|
||||
}
|
||||
if (req.getRemoveSet() != null) {
|
||||
for (Change.Id id : req.getRemoveSet()) {
|
||||
fireChangeStarEvent(id, true);
|
||||
fireChangeStarEvent(id, !starred);
|
||||
for (Map.Entry<Change.Id, Boolean> e : pending.entrySet()) {
|
||||
fireChangeStarEvent(e.getKey(), !e.getValue());
|
||||
}
|
||||
pending.clear();
|
||||
busy = false;
|
||||
}
|
||||
};
|
||||
if (starred) {
|
||||
call.put(cb);
|
||||
} else {
|
||||
call.delete(cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.common.data.ChangeDetailService;
|
||||
import com.google.gerrit.common.data.ChangeListService;
|
||||
import com.google.gerrit.common.data.ChangeManageService;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
@@ -27,7 +26,6 @@ public class Util {
|
||||
public static final ChangeResources R = GWT.create(ChangeResources.class);
|
||||
|
||||
public static final ChangeDetailService DETAIL_SVC;
|
||||
public static final ChangeListService LIST_SVC;
|
||||
public static final ChangeManageService MANAGE_SVC;
|
||||
|
||||
private static final int SUBJECT_MAX_LENGTH = 80;
|
||||
@@ -38,9 +36,6 @@ public class Util {
|
||||
DETAIL_SVC = GWT.create(ChangeDetailService.class);
|
||||
JsonUtil.bind(DETAIL_SVC, "rpc/ChangeDetailService");
|
||||
|
||||
LIST_SVC = GWT.create(ChangeListService.class);
|
||||
JsonUtil.bind(LIST_SVC, "rpc/ChangeListService");
|
||||
|
||||
MANAGE_SVC = GWT.create(ChangeManageService.class);
|
||||
JsonUtil.bind(MANAGE_SVC, "rpc/ChangeManageService");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user