ChangeScreen: Use submit type from ChangeInfo
Avoids an extra request to /revisions/current/submit_type. Change-Id: Iefc1531f3b2b64a8ecf58007d8f2e47df0771ca9
This commit is contained in:
		| @@ -19,6 +19,7 @@ import com.google.gerrit.client.rpc.NativeString; | |||||||
| import com.google.gerrit.client.rpc.Natives; | import com.google.gerrit.client.rpc.Natives; | ||||||
| import com.google.gerrit.common.data.LabelValue; | import com.google.gerrit.common.data.LabelValue; | ||||||
| import com.google.gerrit.common.data.SubmitRecord; | import com.google.gerrit.common.data.SubmitRecord; | ||||||
|  | import com.google.gerrit.extensions.client.SubmitType; | ||||||
| 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.client.Project; | import com.google.gerrit.reviewdb.client.Project; | ||||||
| @@ -139,6 +140,15 @@ public class ChangeInfo extends JavaScriptObject { | |||||||
|   public final native boolean _more_changes() |   public final native boolean _more_changes() | ||||||
|   /*-{ return this._more_changes ? true : false; }-*/; |   /*-{ return this._more_changes ? true : false; }-*/; | ||||||
|  |  | ||||||
|  |   public final SubmitType submitType() { | ||||||
|  |     String submitType = _submitType(); | ||||||
|  |     if (submitType == null) { | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |     return SubmitType.valueOf(submitType); | ||||||
|  |   } | ||||||
|  |   private final native String _submitType() /*-{ return this.submit_type; }-*/; | ||||||
|  |  | ||||||
|   public final boolean submittable() { |   public final boolean submittable() { | ||||||
|     init(); |     init(); | ||||||
|     return _submittable(); |     return _submittable(); | ||||||
|   | |||||||
| @@ -45,7 +45,6 @@ import com.google.gerrit.client.projects.ConfigInfoCache.Entry; | |||||||
| import com.google.gerrit.client.rpc.CallbackGroup; | import com.google.gerrit.client.rpc.CallbackGroup; | ||||||
| import com.google.gerrit.client.rpc.GerritCallback; | import com.google.gerrit.client.rpc.GerritCallback; | ||||||
| import com.google.gerrit.client.rpc.NativeMap; | import com.google.gerrit.client.rpc.NativeMap; | ||||||
| import com.google.gerrit.client.rpc.NativeString; |  | ||||||
| import com.google.gerrit.client.rpc.Natives; | import com.google.gerrit.client.rpc.Natives; | ||||||
| import com.google.gerrit.client.rpc.RestApi; | import com.google.gerrit.client.rpc.RestApi; | ||||||
| import com.google.gerrit.client.rpc.ScreenLoadCallback; | import com.google.gerrit.client.rpc.ScreenLoadCallback; | ||||||
| @@ -1055,33 +1054,16 @@ public class ChangeScreen extends Screen { | |||||||
|         })); |         })); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private void loadSubmitType(final Change.Status status, final boolean canSubmit) { |   private void renderSubmitType(Change.Status status, boolean canSubmit, | ||||||
|     if (canSubmit) { |       SubmitType submitType) { | ||||||
|       if (status == Change.Status.NEW) { |     if (canSubmit && status == Change.Status.NEW) { | ||||||
|         statusText.setInnerText(Util.C.readyToSubmit()); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     ChangeApi.revision(changeId.get(), revision) |  | ||||||
|       .view("submit_type") |  | ||||||
|       .get(new AsyncCallback<NativeString>() { |  | ||||||
|         @Override |  | ||||||
|         public void onSuccess(NativeString result) { |  | ||||||
|           if (canSubmit) { |  | ||||||
|             if (status == Change.Status.NEW) { |  | ||||||
|       statusText.setInnerText(changeInfo.mergeable() |       statusText.setInnerText(changeInfo.mergeable() | ||||||
|           ? Util.C.readyToSubmit() |           ? Util.C.readyToSubmit() | ||||||
|           : Util.C.mergeConflict()); |           : Util.C.mergeConflict()); | ||||||
|     } |     } | ||||||
|           } |  | ||||||
|     setVisible(notMergeable, !changeInfo.mergeable()); |     setVisible(notMergeable, !changeInfo.mergeable()); | ||||||
|  |     submitActionText.setInnerText( | ||||||
|           renderSubmitType(result.asString()); |         com.google.gerrit.client.admin.Util.toLongString(submitType)); | ||||||
|         } |  | ||||||
|  |  | ||||||
|         @Override |  | ||||||
|         public void onFailure(Throwable caught) { |  | ||||||
|         } |  | ||||||
|       }); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private RevisionInfo resolveRevisionToDisplay(ChangeInfo info) { |   private RevisionInfo resolveRevisionToDisplay(ChangeInfo info) { | ||||||
| @@ -1243,7 +1225,7 @@ public class ChangeScreen extends Screen { | |||||||
|  |  | ||||||
|     if (current && info.status().isOpen()) { |     if (current && info.status().isOpen()) { | ||||||
|       quickApprove.set(info, revision, replyAction); |       quickApprove.set(info, revision, replyAction); | ||||||
|       loadSubmitType(info.status(), isSubmittable(info)); |       renderSubmitType(info.status(), isSubmittable(info), info.submitType()); | ||||||
|     } else { |     } else { | ||||||
|       quickApprove.setVisible(false); |       quickApprove.setVisible(false); | ||||||
|     } |     } | ||||||
| @@ -1348,16 +1330,6 @@ public class ChangeScreen extends Screen { | |||||||
|     return sb.toString(); |     return sb.toString(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private void renderSubmitType(String action) { |  | ||||||
|     try { |  | ||||||
|       SubmitType type = SubmitType.valueOf(action); |  | ||||||
|       submitActionText.setInnerText( |  | ||||||
|           com.google.gerrit.client.admin.Util.toLongString(type)); |  | ||||||
|     } catch (IllegalArgumentException e) { |  | ||||||
|       submitActionText.setInnerText(action); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   private void renderActionTextDate(ChangeInfo info) { |   private void renderActionTextDate(ChangeInfo info) { | ||||||
|     String action; |     String action; | ||||||
|     if (info.created().equals(info.updated())) { |     if (info.created().equals(info.updated())) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dave Borowitz
					Dave Borowitz