The Unified and Autonomous Development Platform
Add permanent link of comment in source view panel
robin shine79961aea9369
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.javaindex 3d5a46d386..bba01afe1a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java@@ -6,7 +6,6 @@ import java.util.List;import javax.annotation.Nullable;import org.apache.wicket.ajax.AjaxRequestTarget;-import org.eclipse.jgit.lib.ObjectId;import org.eclipse.jgit.revwalk.RevCommit;import com.pmease.commons.git.BlobIdent;@@ -33,7 +32,9 @@ public interface BlobViewContext extends Serializable {@NullableMark getMark();- String getMarkUrl(ObjectId commitId, Mark mark);+ void onMark(AjaxRequestTarget target, @Nullable Mark mark);++ String getMarkUrl(Mark mark);Mode getMode();@@ -51,6 +52,8 @@ public interface BlobViewContext extends Serializable {void onEdit(AjaxRequestTarget target, @Nullable String viewState);+ void onOpenComment(AjaxRequestTarget target, @Nullable CodeComment comment);+@NullableCodeComment getComment();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.htmlindex 682ca2f54c..dee0418d36 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html@@ -7,6 +7,7 @@<span class="pull-left">Comment</span><a wicket:id="close" class="pull-right close" title="Hide comment"><i class="fa fa-times"></i></a><a wicket:id="locate" class="pull-right locate close" title="Locate marked text of this comment"><i class="fa fa-hand-o-right"></i></a>+ <a wicket:id="permanent" class="pull-right permanent close" title="Permanent link of this comment"><i class="fa fa-link"></i></a></div><div wicket:id="body" class="body"></div></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.javaindex 4d4c335fc1..429172abf2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java@@ -253,6 +253,7 @@ public class SourceViewPanel extends BlobViewPanel {@Overridepublic void onClick(AjaxRequestTarget target) {mark(target, context.getComment().getMark(), true);+ context.onMark(target, context.getComment().getMark());target.appendJavaScript(String.format("$('#%s').blur();", getMarkupId()));}@@ -263,6 +264,28 @@ public class SourceViewPanel extends BlobViewPanel {}});+++ // use this instead of permanent link as we want to get the link+ // updated whenever we re-render the comment container+ AttributeAppender appender = AttributeAppender.append("href", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ if (context.getComment() != null) {+ DepotFilePage.HistoryState state = new DepotFilePage.HistoryState();+ state.blobIdent = new BlobIdent(context.getBlobIdent());+ state.blobIdent.revision = context.getCommit().name();+ state.commentId = context.getComment().getId();+ state.mark = context.getComment().getMark();+ return urlFor(DepotFilePage.class, DepotFilePage.paramsOf(context.getDepot(), state)).toString();+ } else {+ return "";+ }+ }++ });+ commentContainer.add(new WebMarkupContainer("permanent").add(appender));commentContainer.add(new AjaxLink<Void>("close") {@Override@@ -274,6 +297,7 @@ public class SourceViewPanel extends BlobViewPanel {@Overridepublic void onClick(AjaxRequestTarget target) {hideComment(target);+ context.onOpenComment(target, null);}});@@ -313,13 +337,10 @@ public class SourceViewPanel extends BlobViewPanel {case "openSelectionPopup":Mark mark = getMark(params, "param1", "param2", "param3", "param4");String script = String.format("gitplex.sourceview.openSelectionPopup(%s, '%s', %s);",- mark.toJson(), context.getMarkUrl(context.getCommit(), mark),+ mark.toJson(), context.getMarkUrl(mark),SecurityUtils.getAccount()!=null);target.appendJavaScript(script);break;- case "mark":- mark = getMark(params, "param1", "param2", "param3", "param4");- break;case "addComment":Preconditions.checkNotNull(SecurityUtils.getAccount());@@ -406,6 +427,7 @@ public class SourceViewPanel extends BlobViewPanel {comment.getMark().getBeginLine(),getJsonOfComment(comment));target.appendJavaScript(script);+ context.onOpenComment(target, comment);}});@@ -440,6 +462,7 @@ public class SourceViewPanel extends BlobViewPanel {script = String.format("gitplex.sourceview.onOpenComment(%s);",getJsonOfComment(commentModel.getObject()));target.appendJavaScript(script);+ context.onOpenComment(target, commentModel.getObject());break;}}@@ -614,6 +637,7 @@ public class SourceViewPanel extends BlobViewPanel {String script = String.format("gitplex.sourceview.onCommentDeleted(%d, %d);",comment.getMark().getBeginLine(), comment.getId());target.appendJavaScript(script);+ context.onOpenComment(target, null);}private void hideComment(AjaxRequestTarget target) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.cssindex 417107f969..5b22ad63f8 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css@@ -12,6 +12,11 @@margin-right: 8px;font-size: 20px;}+.source-view>.comment>.content>.head .permanent {+ margin-top: 2px;+ margin-right: 8px;+ font-size: 18px;+}.source-view>.comment>.ui-resizable-handle {position: absolute;border-right: 1px solid #CCC;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.jsindex 2768b21b9e..9aea98199b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js@@ -1,10 +1,10 @@gitplex.sourceview = {init: function(fileContent, filePath, mark, symbolTooltipId,- revision, blameInfos, commentInfos, sourceCllback, viewState, loggedIn) {+ revision, blameInfos, commentInfos, sourceCallback, viewState, loggedIn) {var cm;var $sourceView = $(".source-view");- $sourceView.data("sourceCllback", sourceCllback);+ $sourceView.data("sourceCallback", sourceCallback);var $code = $sourceView.children(".code");$sourceView.closest(".content").css("overflow", "hidden");@@ -116,7 +116,7 @@ gitplex.sourceview = {var from = cm.getCursor("from");var to = cm.getCursor("to");if (from.line != to.line || from.ch != to.ch) {- sourceCllback("openSelectionPopup", from.line, from.ch, to.line, to.ch);+ sourceCallback("openSelectionPopup", from.line, from.ch, to.line, to.ch);} else {$("#selection-popup").hide();}@@ -140,10 +140,8 @@ gitplex.sourceview = {}});cm.setSize($code.width(), $code.height());- if (mark) {- $sourceView.data("mark", mark);+ if (mark)pmease.commons.codemirror.mark(cm, mark, true);- }if (initState)pmease.commons.codemirror.initState(cm, viewState);cm.on("scroll", function() {@@ -209,8 +207,19 @@ gitplex.sourceview = {});},restoreMark: function() {- var mark = $(".source-view").data("mark");- if (mark) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var uri = new URI(window.location.href);+ var markStr = uri.search(true).mark;+ if (markStr) {+ var splitted = markStr.split("-");+ var fromInfo = splitted[0].split(".");+ var toInfo = splitted[1].split(".");+ var mark = {+ beginLine: parseInt(fromInfo[0])-1,+ beginChar: parseInt(fromInfo[1]),+ endLine: parseInt(toInfo[0])-1,+ endChar: parseInt(toInfo[1])+ }pmease.commons.codemirror.mark(cm, mark, false);} else {pmease.commons.codemirror.clearMark(cm);@@ -218,7 +227,7 @@ gitplex.sourceview = {},addCommentGutter: function(line, commentInfos) {var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var sourceCllback = $(".source-view").data("sourceCllback");+ var sourceCallback = $(".source-view").data("sourceCallback");var $gutter = $(document.createElement("div"));$gutter.addClass("CodeMirror-comment");@@ -254,7 +263,7 @@ gitplex.sourceview = {return;}var commentInfo = commentInfos[$(this).index()];- sourceCllback("openComment", commentInfo.id);+ sourceCallback("openComment", commentInfo.id);});});gitplex.sourceview.highlightCommentTrigger();@@ -274,7 +283,7 @@ gitplex.sourceview = {&& !confirm("There are unsaved changes, discard and continue?")) {return;}- sourceCllback("openComment", commentInfo.id);+ sourceCallback("openComment", commentInfo.id);});}cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);@@ -282,7 +291,7 @@ gitplex.sourceview = {openSelectionPopup: function(mark, markUrl, loggedIn) {var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;var $sourceView = $(".source-view");- var sourceCllback = $sourceView.data("sourceCllback");+ var sourceCallback = $sourceView.data("sourceCallback");var ch = (mark.beginChar + mark.endChar)/2;var position = cm.charCoords({line:mark.beginLine, ch:ch});var permanentLinkCallback = function($permanentLink) {@@ -299,8 +308,7 @@ gitplex.sourceview = {$("#selection-popup").hide();pmease.commons.codemirror.clearSelection(cm);pmease.commons.codemirror.mark(cm, mark, false);- $sourceView.data("mark", mark);- sourceCllback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);+ sourceCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);});} else {$commentLink.html("Log in to comment on selection");@@ -311,7 +319,7 @@ gitplex.sourceview = {},onCommentAdded: function(line, commentInfo) {var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var sourceCllback = $(".source-view").data("sourceCllback");+ var sourceCallback = $(".source-view").data("sourceCallback");var lineInfo = cm.lineInfo(line);var gutter;if (lineInfo.gutterMarkers)@@ -328,7 +336,7 @@ gitplex.sourceview = {},onCommentDeleted: function(line, commentId) {var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var sourceCllback = $(".source-view").data("sourceCllback");+ var sourceCallback = $(".source-view").data("sourceCallback");var lineInfo = cm.lineInfo(line);var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);var commentInfos = $gutter.data("commentInfos");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 2e116460ae..86735c7492 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@@ -65,6 +65,7 @@ import com.pmease.commons.wicket.behavior.inputassist.InputAssistBehavior;import com.pmease.commons.wicket.component.menu.MenuItem;import com.pmease.commons.wicket.component.menu.MenuLink;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.web.Constants;@@ -503,6 +504,7 @@ public abstract class RevisionDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {hideComment(target);+ onOpenComment(target, null);}});@@ -610,22 +612,6 @@ public abstract class RevisionDiffPanel extends Panel {setOutputMarkupId(true);}- protected String getPathFilter() {- return pathFilter;- }-- protected WhitespaceOption getWhitespaceOption() {- return whitespaceOption;- }-- protected Long getCommentId() {- return commentId;- }-- protected DiffMark getMark() {- return mark;- }-private void hideComment(AjaxRequestTarget target) {commentContainer.replace(new WebMarkupContainer("body"));commentContainer.setVisible(false);@@ -660,6 +646,8 @@ public abstract class RevisionDiffPanel extends Panel {protected abstract void onWhitespaceOptionChange(AjaxRequestTarget target,WhitespaceOption whitespaceOption);+ protected abstract void onOpenComment(AjaxRequestTarget target, @Nullable CodeComment comment);+private static class ChangesAndCount {private final List<BlobChange> changes;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.javaindex d7e0a21b8c..bb5f132522 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java@@ -42,6 +42,7 @@ import com.pmease.commons.git.GitUtils;import com.pmease.commons.lang.diff.WhitespaceOption;import com.pmease.commons.wicket.assets.oneline.OnelineResourceReference;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.manager.AuxiliaryManager;@@ -316,6 +317,12 @@ public class CommitDetailPage extends DepotPage {pushState(target);}+ @Override+ protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ state.commentId = CodeComment.idOf(comment);+ pushState(target);+ }+};revisionDiff.setOutputMarkupId(true);if (target != null) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.javaindex 2eabb7a0f9..1ae72cf3da 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java@@ -32,6 +32,7 @@ import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;import com.pmease.commons.wicket.component.tabbable.Tab;import com.pmease.commons.wicket.component.tabbable.Tabbable;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.entity.component.DepotAndBranch;@@ -412,6 +413,16 @@ public class RevisionComparePage extends DepotPage {pushState(target);}+ @Override+ protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ state.commentId = CodeComment.idOf(comment);+ if (comment != null) {+ boolean leftSide = comment.getCommit().equals(mergeBaseModel.getObject());+ state.mark = new DiffMark(comment.getPath(), leftSide, comment.getMark());+ }+ pushState(target);+ }+};commitsTab.setSelected(false);filesTab.setSelected(true);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.javaindex 6a572e9179..f9285fabc7 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java@@ -834,9 +834,16 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {}@Override- public String getMarkUrl(ObjectId commitId, Mark mark) {+ public void onMark(AjaxRequestTarget target, Mark mark) {+ this.mark = mark;+ pushState(target);+ }++ @Override+ public String getMarkUrl(Mark mark) {HistoryState state = getState();- state.blobIdent.revision = commitId.name();+ state.blobIdent.revision = resolvedRevision.name();+ state.commentId = null;state.mark = mark;PageParameters params = paramsOf(getDepot(), state);return RequestCycle.get().urlFor(DepotFilePage.class, params).toString();@@ -917,6 +924,14 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {resizeWindow(target);}+ @Override+ public void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ commentId = CodeComment.idOf(comment);+ if (comment != null)+ mark = comment.getMark();+ pushState(target);+ }+private void resolveRevision() {/** a hack to reset resolved revision to null to disable getObjectIdCache()diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.javaindex ba9097ab49..2b60767c37 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java@@ -47,6 +47,7 @@ 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.entity.Account;+import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;@@ -341,6 +342,10 @@ public class NewRequestPage extends PullRequestPage {WhitespaceOption whitespaceOption) {}+ @Override+ protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ }+};diffPanel.setOutputMarkupId(true);return diffPanel;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.javaindex 38692f059f..1e726fa69e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/compare/RequestComparePage.java@@ -44,6 +44,7 @@ import com.pmease.commons.wicket.component.floating.AlignPlacement;import com.pmease.commons.wicket.component.floating.FloatingPanel;import com.pmease.commons.wicket.component.menu.MenuItem;import com.pmease.commons.wicket.component.menu.MenuLink;+import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.entity.PullRequestUpdate;@@ -669,6 +670,12 @@ public class RequestComparePage extends RequestDetailPage {pushState(target);}+ @Override+ protected void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ commentId = state.commentId = CodeComment.idOf(comment);+ pushState(target);+ }+};revisionDiff.setOutputMarkupId(true);if (partialPageRequestHandler != null) {