The Unified and Autonomous Development Platform
pure
robin shine08aa4b96edee
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 2a9bb1ba8b..658cc9d1d7 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,6 +16,7 @@ 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;@@ -29,17 +30,21 @@ 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<Comment> commentModel,+ public BlobDiffPanel(String id, IModel<Repository> repoModel,+ IModel<PullRequest> requestModel, IModel<Comment> commentModel,BlobChange change, DiffMode diffMode) {super(id);this.repoModel = repoModel;+ this.requestModel = requestModel;this.commentModel = commentModel;this.change = change;this.diffMode = diffMode;@@ -68,7 +73,7 @@ public class BlobDiffPanel extends Panel {elseadd(newFragment("Empty file added.", false));} else {- add(new TextDiffPanel(CONTENT_ID, repoModel, commentModel, change, diffMode));+ add(new TextDiffPanel(CONTENT_ID, repoModel, requestModel, commentModel, change, diffMode));}} else if (blob.isPartial()) {add(newFragment("File is too large to be loaded.", true));@@ -103,7 +108,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, commentModel, change, diffMode));+ add(new TextDiffPanel(CONTENT_ID, repoModel, requestModel, commentModel, change, diffMode));}} else if (change.getOldBlob().isPartial() || change.getNewBlob().isPartial()) {add(newFragment("File is too large to be loaded.", true));@@ -132,6 +137,7 @@ 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 40519bb15b..55affeeca6 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,6 +71,8 @@ public class TextDiffPanel extends Panel {private final IModel<Repository> repoModel;+ private final IModel<PullRequest> requestModel;+private final IModel<Comment> commentModel;private final BlobChange change;@@ -85,25 +87,22 @@ public class TextDiffPanel extends Panel {protected List<CommentAndPos> load() {List<CommentAndPos> listOfCommentAndPos = new ArrayList<>();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);- }+ for (Comment comment: requestModel.getObject().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;}@@ -114,9 +113,9 @@ public class TextDiffPanel extends Panel {@Overrideprotected Boolean load() {- Comment comment = commentModel.getObject();- if (comment != null && comment.getRequest().getId() != null) {- List<String> commentables = comment.getRequest().getCommentables();+ PullRequest request = requestModel.getObject();+ if (request != null && request.getId() != null) {+ List<String> commentables = request.getCommentables();int oldCommitIndex = commentables.indexOf(change.getOldBlobIdent().revision);int newCommitIndex = commentables.indexOf(change.getNewBlobIdent().revision);return oldCommitIndex != -1 && newCommitIndex != -1 && oldCommitIndex < newCommitIndex;@@ -133,11 +132,12 @@ public class TextDiffPanel extends Panel {private RepeatingView commentRows;- public TextDiffPanel(String id, IModel<Repository> repoModel, IModel<Comment> commentModel,- BlobChange change, DiffMode diffMode) {+ public TextDiffPanel(String id, IModel<Repository> repoModel, IModel<PullRequest> requestModel,+ IModel<Comment> commentModel, BlobChange change, DiffMode diffMode) {super(id);this.repoModel = repoModel;+ this.requestModel = requestModel;this.commentModel = commentModel;this.change = change;this.diffMode = diffMode;@@ -153,9 +153,9 @@ public class TextDiffPanel extends Panel {Repository repo = repoModel.getObject();PageParameters params;- Comment comment = commentModel.getObject();- if (comment != null)- params = RepoFilePage.paramsOf(comment.getRequest(), change.getBlobIdent());+ PullRequest request = requestModel.getObject();+ if (request != null)+ params = RepoFilePage.paramsOf(request, change.getBlobIdent());elseparams = RepoFilePage.paramsOf(repo, change.getBlobIdent());@@ -260,7 +260,7 @@ public class TextDiffPanel extends Panel {InheritableThreadLocalData.set(new WebSocketRenderBehavior.PageId(getPage().getPageId()));try {comment = GitPlex.getInstance(CommentManager.class).addInline(- commentModel.getObject().getRequest(), commentAt, compareWith,+ requestModel.getObject(), commentAt, compareWith,lineNo, input.getModelObject());} finally {InheritableThreadLocalData.clear();@@ -658,8 +658,9 @@ public class TextDiffPanel extends Panel {@Overridepublic void renderHead(IHeaderResponse response) {super.renderHead(response);-- if (commentId.equals(commentModel.getObject().getId())) {++ Comment comment = commentModel.getObject();+ if (comment != null && commentId.equals(comment.getId())) {String script = String.format("$('#%s').closest('td').focus();", getMarkupId());response.render(OnDomReadyHeaderItem.forScript(script));}@@ -686,6 +687,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onDetach() {repoModel.detach();+ requestModel.detach();commentModel.detach();commentableModel.detach();listOfCommentAndPosModel.detach();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 8fbcd9566d..cb4892da41 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,6 +40,7 @@ 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;@@ -50,6 +51,8 @@ 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;@@ -166,12 +169,13 @@ public abstract class RevisionDiffPanel extends Panel {}};- public RevisionDiffPanel(String id, IModel<Repository> repoModel, 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<PullRequest> requestModel,+ 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;@@ -290,7 +294,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, commentModel, change, diffMode));+ item.add(new BlobDiffPanel("change", repoModel, requestModel, commentModel, change, diffMode));}});@@ -308,6 +312,7 @@ 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/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.javaindex 2183dd9f44..4f060577ac 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java@@ -87,8 +87,6 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private static final String PARAM_REVISION = "revision";- private static final String PARAM_COMMIT = "commit";-private static final String PARAM_PATH = "path";private static final String PARAM_BLAME = "blame";@@ -185,9 +183,6 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {blobIdent.mode = FileMode.TREE.getBits();}- String commitHash = params.get(PARAM_COMMIT).toString();- if (commitHash != null)- getRepository().cacheObjectId(blobIdent.revision, ObjectId.fromString(commitHash));blame = params.get(PARAM_BLAME).toBoolean(false);commentId = params.get(PARAM_COMMENT).toOptionalLong();requestId = params.get(PARAM_REQUEST).toOptionalLong();@@ -566,7 +561,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}private void pushState(AjaxRequestTarget target) {- PageParameters params = paramsOf(getRepository(), blobIdent.revision, null, blobIdent.path,+ PageParameters params = paramsOf(getRepository(), blobIdent.revision, blobIdent.path,blame, commentId, requestId);CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);HistoryState state = new HistoryState();@@ -596,24 +591,12 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}public static PageParameters paramsOf(PullRequest request, String commitHash, @Nullable String path) {- if (request.getSourceRepo() != null && commitHash.equals(request.getSource().getHead(false))) {- return paramsOf(request.getSourceRepo(), request.getSourceBranch(), commitHash,- path, false, null, request.getId());- } else {- return paramsOf(request.getTargetRepo(), commitHash, null, path, false, null, request.getId());- }+ return paramsOf(request.getTargetRepo(), commitHash, path, false, null, request.getId());}public static PageParameters paramsOf(Comment comment) {- String revision = comment.getBlobIdent().revision;- PullRequest request = comment.getRequest();- if (request.getSourceRepo() != null && revision.equals(request.getSource().getHead(false))) {- return paramsOf(request.getSourceRepo(), request.getSourceBranch(), revision,- comment.getBlobIdent().path, false, comment.getId(), null);- } else {- return paramsOf(comment.getRepository(), comment.getBlobIdent().revision, null,- comment.getBlobIdent().path, false, comment.getId(), null);- }+ return paramsOf(comment.getRepository(), comment.getBlobIdent().revision,+ comment.getBlobIdent().path, false, comment.getId(), null);}public static PageParameters paramsOf(Repository repository, BlobIdent blobIdent) {@@ -621,17 +604,14 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}public static PageParameters paramsOf(Repository repository, @Nullable String revision, @Nullable String path) {- return paramsOf(repository, revision, null, path, false, null, null);+ return paramsOf(repository, revision, path, false, null, null);}public static PageParameters paramsOf(Repository repository, @Nullable String revision,- @Nullable String commitHash, @Nullable String path, boolean blame,- @Nullable Long commentId, @Nullable Long requestId) {+ @Nullable String path, boolean blame, @Nullable Long commentId, @Nullable Long requestId) {PageParameters params = paramsOf(repository);if (revision != null)params.set(PARAM_REVISION, revision);- if (commitHash != null)- params.set(PARAM_COMMIT, commitHash);if (path != null)params.set(PARAM_PATH, path);if (blame)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 c7720ddd7f..3b9167ba57 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@@ -370,10 +370,8 @@ public class NewRequestPage extends PullRequestPage {String oldRev = request.getBaseCommitHash();String newRev = request.getLatestUpdate().getHeadCommitHash();- Comment comment = new Comment();- comment.setRequest(request);- RevisionDiffPanel diffPanel = new RevisionDiffPanel("revisionDiff", repoModel,- Model.of(comment), oldRev, newRev, path, null, diffOption.getLineProcessor(),+ RevisionDiffPanel diffPanel = new RevisionDiffPanel("revisionDiff", repoModel, requestModel,+ new Model<Comment>(null), oldRev, newRev, path, null, diffOption.getLineProcessor(),diffOption.getDiffMode()) {@Overridediff --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 e96d97deb8..d2776e225c 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@@ -528,7 +528,7 @@ public class RequestComparePage extends RequestDetailPage {}});- if (state.oldRev.equals(REV_INTEGRATION_PREVIEW) || state.newRev.equals(REV_INTEGRATION_PREVIEW)) {+ if (REV_INTEGRATION_PREVIEW.equals(state.oldRev) || REV_INTEGRATION_PREVIEW.equals(state.newRev)) {IntegrationPreview preview = getPullRequest().getIntegrationPreview();noIntegrationPreviewAlert.setVisible(preview == null || preview.getIntegrated() == null);} else {@@ -754,21 +754,8 @@ public class RequestComparePage extends RequestDetailPage {}private void newCompareResult(@Nullable AjaxRequestTarget target) {- 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,+ requestModel, commentModel, oldCommitHash, newCommitHash, path, comparePath,diffOption.getLineProcessor(), diffOption.getDiffMode()) {@Override