The Unified and Autonomous Development Platform
midwork
robin shine41636a2d719f
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.javaindex fd77b73937..2a9bb1ba8b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/BlobDiffPanel.java@@ -16,7 +16,6 @@ import com.pmease.commons.git.BlobChange;import com.pmease.commons.lang.diff.DiffUtils;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.model.Comment;-import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.Constants;import com.pmease.gitplex.web.component.diff.blob.text.TextDiffPanel;@@ -30,20 +29,17 @@ public class BlobDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final IModel<PullRequest> requestModel;-private final IModel<Comment> commentModel;private final BlobChange change;private final DiffMode diffMode;- public BlobDiffPanel(String id, IModel<Repository> repoModel, IModel<PullRequest> requestModel,- IModel<Comment> commentModel, BlobChange change, DiffMode diffMode) {+ public BlobDiffPanel(String id, IModel<Repository> repoModel, IModel<Comment> commentModel,+ BlobChange change, DiffMode diffMode) {super(id);this.repoModel = repoModel;- this.requestModel = requestModel;this.commentModel = commentModel;this.change = change;this.diffMode = diffMode;@@ -72,7 +68,7 @@ public class BlobDiffPanel extends Panel {elseadd(newFragment("Empty file added.", false));} else {- add(new TextDiffPanel(CONTENT_ID, repoModel, requestModel, commentModel, change, diffMode));+ add(new TextDiffPanel(CONTENT_ID, repoModel, commentModel, change, diffMode));}} else if (blob.isPartial()) {add(newFragment("File is too large to be loaded.", true));@@ -107,7 +103,7 @@ public class BlobDiffPanel extends Panel {} else if (change.getAdditions() + change.getDeletions() == 0) {add(newFragment("File is identical if " + change.getLineProcessor().getName().toLowerCase() + ".", false));} else {- add(new TextDiffPanel(CONTENT_ID, repoModel, requestModel, commentModel, change, diffMode));+ add(new TextDiffPanel(CONTENT_ID, repoModel, commentModel, change, diffMode));}} else if (change.getOldBlob().isPartial() || change.getNewBlob().isPartial()) {add(newFragment("File is too large to be loaded.", true));@@ -136,7 +132,6 @@ public class BlobDiffPanel extends Panel {protected void onDetach() {repoModel.detach();- requestModel.detach();commentModel.detach();super.onDetach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex 597eef3be1..40519bb15b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java@@ -71,8 +71,6 @@ public class TextDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final IModel<PullRequest> requestModel;-private final IModel<Comment> commentModel;private final BlobChange change;@@ -86,31 +84,48 @@ public class TextDiffPanel extends Panel {@Overrideprotected List<CommentAndPos> load() {List<CommentAndPos> listOfCommentAndPos = new ArrayList<>();- PullRequest request = requestModel.getObject();- if (request != null) {- for (Comment comment: request.getComments()) {- if (comment.getInlineInfo() != null) {- GitPlex.getInstance(CommentManager.class).updateInlineInfo(comment);- CommentAndPos commentAndPos = getCommentAndPos(comment);- if (commentAndPos != null)- listOfCommentAndPos.add(commentAndPos);+ if (commentableModel.getObject()) {+ PullRequest request = commentModel.getObject().getRequest();+ if (request != null) {+ for (Comment comment: request.getComments()) {+ if (comment.getInlineInfo() != null) {+ GitPlex.getInstance(CommentManager.class).updateInlineInfo(comment);+ CommentAndPos commentAndPos = getCommentAndPos(comment);+ if (commentAndPos != null)+ listOfCommentAndPos.add(commentAndPos);+ }}+ Collections.sort(listOfCommentAndPos, new Comparator<CommentAndPos>() {++ @Override+ public int compare(CommentAndPos commentAndPos1, CommentAndPos commentAndPos2) {+ return commentAndPos1.comment.getDate().compareTo(commentAndPos2.comment.getDate());+ }++ });}- Collections.sort(listOfCommentAndPos, new Comparator<CommentAndPos>() {-- @Override- public int compare(CommentAndPos commentAndPos1, CommentAndPos commentAndPos2) {- return commentAndPos1.comment.getDate().compareTo(commentAndPos2.comment.getDate());- }-- });}return listOfCommentAndPos;}};- private final boolean commentable;+ private final IModel<Boolean> commentableModel = new LoadableDetachableModel<Boolean>() {++ @Override+ protected Boolean load() {+ Comment comment = commentModel.getObject();+ if (comment != null && comment.getRequest().getId() != null) {+ List<String> commentables = comment.getRequest().getCommentables();+ int oldCommitIndex = commentables.indexOf(change.getOldBlobIdent().revision);+ int newCommitIndex = commentables.indexOf(change.getNewBlobIdent().revision);+ return oldCommitIndex != -1 && newCommitIndex != -1 && oldCommitIndex < newCommitIndex;+ } else {+ return false;+ }+ }++ };private AbstractDefaultAjaxBehavior addCommentBehavior;@@ -118,26 +133,14 @@ public class TextDiffPanel extends Panel {private RepeatingView commentRows;- public TextDiffPanel(String id, IModel<Repository> repoModel, IModel<PullRequest> requestModel,- IModel<Comment> commentModel, BlobChange change, DiffMode diffMode) {+ public TextDiffPanel(String id, IModel<Repository> repoModel, IModel<Comment> commentModel,+ BlobChange change, DiffMode diffMode) {super(id);this.repoModel = repoModel;this.commentModel = commentModel;- this.requestModel = requestModel;this.change = change;this.diffMode = diffMode;-- PullRequest request = requestModel.getObject();- if (request != null) {- List<String> commentables = request.getCommentables();- int oldCommitIndex = commentables.indexOf(change.getOldBlobIdent().revision);- int newCommitIndex = commentables.indexOf(change.getNewBlobIdent().revision);- commentable = oldCommitIndex != -1 && newCommitIndex != -1 && oldCommitIndex < newCommitIndex;- } else {- commentable = false;- }-}@Override@@ -150,9 +153,9 @@ public class TextDiffPanel extends Panel {Repository repo = repoModel.getObject();PageParameters params;- PullRequest request = requestModel.getObject();- if (request != null)- params = RepoFilePage.paramsOf(request, change.getBlobIdent());+ Comment comment = commentModel.getObject();+ if (comment != null)+ params = RepoFilePage.paramsOf(comment.getRequest(), change.getBlobIdent());elseparams = RepoFilePage.paramsOf(repo, change.getBlobIdent());@@ -257,7 +260,8 @@ public class TextDiffPanel extends Panel {InheritableThreadLocalData.set(new WebSocketRenderBehavior.PageId(getPage().getPageId()));try {comment = GitPlex.getInstance(CommentManager.class).addInline(- requestModel.getObject(), commentAt, compareWith, lineNo, input.getModelObject());+ commentModel.getObject().getRequest(), commentAt, compareWith,+ lineNo, input.getModelObject());} finally {InheritableThreadLocalData.clear();}@@ -436,7 +440,7 @@ public class TextDiffPanel extends Panel {}private void appendAddComment(StringBuilder builder, int oldLineNo, int newLineNo) {- if (commentable) {+ if (commentableModel.getObject()) {builder.append("<span class='add-comment'>");String script = String.format("document.getElementById('%s').addComment(%d, %d);",getMarkupId(), oldLineNo, newLineNo);@@ -655,8 +659,7 @@ public class TextDiffPanel extends Panel {public void renderHead(IHeaderResponse response) {super.renderHead(response);- Comment comment = commentModel.getObject();- if (comment != null && commentId.equals(comment.getId())) {+ if (commentId.equals(commentModel.getObject().getId())) {String script = String.format("$('#%s').closest('td').focus();", getMarkupId());response.render(OnDomReadyHeaderItem.forScript(script));}@@ -683,8 +686,8 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onDetach() {repoModel.detach();- requestModel.detach();commentModel.detach();+ commentableModel.detach();listOfCommentAndPosModel.detach();super.onDetach();}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.javaindex 99cd09e252..8fbcd9566d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java@@ -40,7 +40,6 @@ import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;import com.pmease.commons.wicket.ajaxlistener.IndicateLoadingListener;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.model.Comment;-import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.Constants;import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;@@ -51,8 +50,6 @@ public abstract class RevisionDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final IModel<PullRequest> requestModel;-private final IModel<Comment> commentModel;private final String oldRev;@@ -169,13 +166,12 @@ public abstract class RevisionDiffPanel extends Panel {}};- public RevisionDiffPanel(String id, IModel<Repository> repoModel, IModel<PullRequest> requestModel,- IModel<Comment> commentModel, String oldRev, String newRev, @Nullable String path,- @Nullable String comparePath, LineProcessor lineProcessor, DiffMode diffMode) {+ public RevisionDiffPanel(String id, IModel<Repository> repoModel, IModel<Comment> commentModel,+ String oldRev, String newRev, @Nullable String path, @Nullable String comparePath,+ LineProcessor lineProcessor, DiffMode diffMode) {super(id);this.repoModel = repoModel;- this.requestModel = requestModel;this.commentModel = commentModel;this.oldRev = oldRev;this.newRev = newRev;@@ -294,7 +290,7 @@ public abstract class RevisionDiffPanel extends Panel {BlobChange change = item.getModelObject();item.setMarkupId("diff-" + change.getPath());item.setOutputMarkupId(true);- item.add(new BlobDiffPanel("change", repoModel, requestModel, commentModel, change, diffMode));+ item.add(new BlobDiffPanel("change", repoModel, commentModel, change, diffMode));}});@@ -312,7 +308,6 @@ public abstract class RevisionDiffPanel extends Panel {protected void onDetach() {changesAndCountModel.detach();repoModel.detach();- requestModel.detach();commentModel.detach();super.onDetach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.javaindex 2f60109b6c..c7720ddd7f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.java@@ -31,7 +31,6 @@ import org.apache.wicket.model.Model;import org.apache.wicket.model.PropertyModel;import org.apache.wicket.request.mapper.parameter.PageParameters;import org.apache.wicket.request.resource.CssResourceReference;-import org.eclipse.jgit.lib.ObjectId;import com.google.common.base.Preconditions;import com.pmease.commons.git.Commit;@@ -47,11 +46,11 @@ import com.pmease.commons.wicket.component.tabbable.Tabbable;import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.manager.PullRequestManager;+import com.pmease.gitplex.core.model.Comment;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequest.CloseStatus;import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;import com.pmease.gitplex.core.model.PullRequest.Status;-import com.pmease.gitplex.core.model.Comment;import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.core.model.RepoAndBranch;import com.pmease.gitplex.core.model.Repository;@@ -369,20 +368,13 @@ public class NewRequestPage extends PullRequestPage {protected RevisionDiffPanel newRevDiffPanel() {PullRequest request = getPullRequest();String oldRev = request.getBaseCommitHash();- String newRev = request.getSourceBranch();-- /*- * pass branch ref instead of commit hash to revision diff panel in order- * to make the file editable online, and to make revision diff panel- * displays changes consistently when doing actions such as changing path- * filter, changing diff mode, we need to cache the commit hash against- * the branch ref- */- getRepository().cacheObjectId(newRev, ObjectId.fromString(request.getLatestUpdate().getHeadCommitHash()));+ String newRev = request.getLatestUpdate().getHeadCommitHash();+ Comment comment = new Comment();+ comment.setRequest(request);RevisionDiffPanel diffPanel = new RevisionDiffPanel("revisionDiff", repoModel,- new Model<PullRequest>(null), new Model<Comment>(null), oldRev, newRev,- path, null, diffOption.getLineProcessor(), diffOption.getDiffMode()) {+ Model.of(comment), oldRev, newRev, path, null, diffOption.getLineProcessor(),+ diffOption.getDiffMode()) {@Overrideprotected void onClearPath(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.javaindex 38121db0e4..e96d97deb8 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java@@ -754,7 +754,20 @@ public class RequestComparePage extends RequestDetailPage {}private void newCompareResult(@Nullable AjaxRequestTarget target) {- compareResult = new RevisionDiffPanel("compareResult", repoModel, requestModel,+ IModel<Comment> commentModel = new LoadableDetachableModel<Comment>() {++ @Override+ protected Comment load() {+ Comment comment = RequestComparePage.this.commentModel.getObject();+ if (comment == null) {+ comment = new Comment();+ comment.setRequest(getPullRequest());+ }+ return comment;+ }++ };+ compareResult = new RevisionDiffPanel("compareResult", repoModel,commentModel, oldCommitHash, newCommitHash, path, comparePath,diffOption.getLineProcessor(), diffOption.getDiffMode()) {