Skip to content

The Unified and Autonomous Development Platform

Draft implementation of selection popover jquery plugin.

robin shine9c50d43db0e8
diff --git a/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java b/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java
index fb53115819..120ed70ae1 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/RangeUtils.java
@@ -11,7 +11,7 @@ public class RangeUtils {
sorted.sort((o1, o2) -> o1.getFrom() - o2.getFrom());
List<Range> merged = new ArrayList<>();
Range current = null;
- for (Range range: ranges) {
+ for (Range range: sorted) {
if (current == null) {
current = range;
} else if (range.getFrom() <= current.getTo()) {
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
index 1ad097d46c..42692e030a 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
@@ -9,24 +9,26 @@ pmease.commons.codemirror = {
cm.setCursor(cm.getCursor("from"));
},
mark: function(cm, mark, scroll) {
- if (scroll) {
- var top = cm.charCoords({line: mark.beginLine, ch: 0}, "local").top;
- var bottom = cm.charCoords({line: mark.endLine, ch: 0}, "local").bottom;
-
- var markHeight = bottom - top;
- var clientHeight = cm.getScrollInfo().clientHeight;
- if (clientHeight <= markHeight) {
- cm.scrollTo(null, top - 50);
- } else {
- cm.scrollTo(null, (top+bottom-clientHeight)/2);
- }
- }
-
pmease.commons.codemirror.clearMark(cm);
cm.markText(
{line: mark.beginLine, ch: mark.beginChar},
{line: mark.endLine, ch: mark.endChar},
{className: "CodeMirror-mark"});
+ if (scroll) {
+ // use a timer to scroll after possible view port resize
+ setTimeout(function() {
+ var top = cm.charCoords({line: mark.beginLine, ch: 0}, "local").top;
+ var bottom = cm.charCoords({line: mark.endLine, ch: 0}, "local").bottom;
+
+ var markHeight = bottom - top;
+ var clientHeight = cm.getScrollInfo().clientHeight;
+ if (clientHeight <= markHeight) {
+ cm.scrollTo(null, top - 50);
+ } else {
+ cm.scrollTo(null, (top+bottom-clientHeight)/2);
+ }
+ }, 0);
+ }
},
setMode: function(cm, filePath) {
var modeInfo = CodeMirror.findModeByFileName(filePath);
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/SelectionPopoverResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/SelectionPopoverResourceReference.java
new file mode 100644
index 0000000000..993653e22d
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/SelectionPopoverResourceReference.java
@@ -0,0 +1,33 @@
+package com.pmease.commons.wicket.assets.selectionpopover;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.HeaderItem;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+
+import com.pmease.commons.wicket.assets.align.AlignResourceReference;
+
+public class SelectionPopoverResourceReference extends JavaScriptResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final SelectionPopoverResourceReference INSTANCE = new SelectionPopoverResourceReference();
+
+ private SelectionPopoverResourceReference() {
+ super(SelectionPopoverResourceReference.class, "jquery.selectionpopover.js");
+ }
+
+ @Override
+ public List<HeaderItem> getDependencies() {
+ List<HeaderItem> dependencies = new ArrayList<>();
+ dependencies.add(JavaScriptHeaderItem.forReference(AlignResourceReference.INSTANCE));
+ dependencies.add(CssHeaderItem.forReference(new CssResourceReference(
+ SelectionPopoverResourceReference.class, "jquery.selectionpopover.css")));
+ return dependencies;
+ }
+
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.css
new file mode 100644
index 0000000000..73430a2f67
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.css
@@ -0,0 +1,27 @@
+.selection-popover {
+ z-index: 10000;
+ position: absolute;
+ display: none;
+}
+.selection-popover>.content {
+ background: #333;
+ border-radius: 6px;
+ padding: 12px;
+}
+.selection-popover>.content a {
+ color: white;
+ display: block;
+ white-space: nowrap;
+}
+.selection-popover>.content>a.permanent {
+ margin-bottom: 8px;
+}
+.selection-popover>.triangle {
+ position: relative;
+ left: 50%;
+ width: 0;
+ height: 0;
+ border-left: 6px solid transparent;
+ border-right: 6px solid transparent;
+ border-top: 6px solid #333;
+}
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.js
new file mode 100644
index 0000000000..d73a07e36d
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.js
@@ -0,0 +1,52 @@
+(function ( $ ) {
+
+ $.fn.selectionPopover = function(callback) {
+ var $container = jQuery(this);
+
+ function popover(options) {
+ var popover = $container.data("selectionPopover");
+ if (popover && jQuery.contains(document, popover)) {
+ $(popover).remove();
+ }
+ if (options) {
+ var $popover = $("" +
+ "<div class='selection-popover'>" +
+ "<div class='content'></div>" +
+ "<div class='triangle'></div>" +
+ "</div>");
+ $popover.append(options.content);
+
+ $("body").append($popover);
+
+ var alignment = {
+ target: {left: options.position.left, top: options.position.top, width: 0, height: 0},
+ placement: {x: 50, y: 100, targetX: 0, targetY: 0}};
+ $popover.children(".triangle").show();
+ $popover.show().align(alignment);
+ if (Math.abs($popover.offset().top+$popover.outerHeight() - position.top)>10) {
+ $popover.children(".triangle").hide();
+ }
+ /*
+ Wicket.Event.subscribe('/ajax/call/complete', function() {
+ if (!jQuery.contains(document, $container[0])) {
+ $popover.remove();
+ }
+ });
+ */
+ $container.data("selectionPopover", $popover[0]);
+ }
+ }
+
+ $container.on("mouseup", function() {
+ popover(callback());
+ });
+ $container.on("keyup", function(e) {
+ if (e.which == 37 || e.which == 38 || e.which == 39 || e.which == 40) {
+ popover(callback());
+ }
+ });
+
+ return this;
+ };
+
+}( jQuery ));
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java
index 613b762fb2..12f17f51d5 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java
@@ -41,9 +41,9 @@ public class Mark implements Serializable {
tokenPos.getLine(), tokenPos.getRange().getTo());
}
- public Mark(String str) {
- String begin = StringUtils.substringBefore(str, "-");
- String end = StringUtils.substringAfter(str, "-");
+ public Mark(String markStr) {
+ String begin = StringUtils.substringBefore(markStr, "-");
+ String end = StringUtils.substringAfter(markStr, "-");
beginLine = Integer.parseInt(StringUtils.substringBefore(begin, "."))-1;
beginChar = Integer.parseInt(StringUtils.substringAfter(begin, "."));
endLine = Integer.parseInt(StringUtils.substringBefore(end, "."))-1;
@@ -103,6 +103,13 @@ public class Mark implements Serializable {
return null;
}
+ public static @Nullable Mark of(@Nullable String markStr) {
+ if (markStr != null)
+ return new Mark(markStr);
+ else
+ return null;
+ }
+
public String toJson() {
try {
return GitPlex.getInstance(ObjectMapper.class).writeValueAsString(this);
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.java
index d2131b5394..849f35b6bb 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
@@ -238,7 +238,7 @@ public class SourceViewPanel extends BlobViewPanel {
protected void onInitialize() {
super.onInitialize();
- commentContainer = new WebMarkupContainer("comment") {
+ commentContainer = new WebMarkupContainer("comment", Model.of((Mark)null)) {
@Override
public void renderHead(IHeaderResponse response) {
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.js
index ddfa63ceb7..ca9cbb6988 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
@@ -14,17 +14,17 @@ gitplex.sourceview = {
var $code = $sourceView.children(".code");
$sourceView.closest(".content").css("overflow", "hidden");
- function alignCommentPopovers() {
+ function repositionCommentPopovers() {
$(".comment-popover:visible").each(function() {
var $popover = $(this);
var lineInfo = cm.lineInfo($popover.data("line"));
if (lineInfo.gutterMarkers) {
var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
if (gutter) {
- var $commentLink = $(gutter).children("a");
+ var $indicator = $(gutter).children("a");
$popover.css({
- "left": $commentLink.offset().left + $commentLink.outerWidth() - $sourceView.offset().left,
- "top": $commentLink.offset().top + ($commentLink.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top
+ "left": $indicator.offset().left + $indicator.outerWidth() - $sourceView.offset().left,
+ "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top
});
}
}
@@ -151,13 +151,13 @@ gitplex.sourceview = {
pmease.commons.codemirror.initState(cm, viewState);
cm.on("scroll", function() {
gitplex.mouseState.moved = false;
- alignCommentPopovers(cm);
+ repositionCommentPopovers(cm);
});
} else {
cm.setSize($code.width(), $code.height());
if (cm.getOption("fullScreen"))
cm.setOption("fullScreen", false);
- alignCommentPopovers(cm);
+ repositionCommentPopovers(cm);
}
});
},
@@ -231,22 +231,28 @@ gitplex.sourceview = {
$gutter.addClass("CodeMirror-comment");
$gutter.data("comments", comments);
if (comments.length != 1) {
+ /*
+ * when there are multiple comments starts with the same line, we should
+ * display a comment indicator which will display a comment popover with
+ * list of comment triggers upon click, user can then click one of the
+ * trigger link to display the actual comment content
+ */
$gutter.append("<a><i class='fa fa-comments'></i></a>");
- var $commentLink = $gutter.children("a");
+ var $indicator = $gutter.children("a");
var content = "";
for (var i in comments) {
var comment = comments[i];
var index = parseInt(i) + 1;
content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + index + "</a>";
}
- $commentLink.popover({
+ $indicator.popover({
html: true,
container: ".source-view",
- placement: "right auto",
+ placement: "right",
template: "<div data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",
content: content
});
- $commentLink.on('shown.bs.popover', function () {
+ $indicator.on('shown.bs.popover', function () {
$(".comment-popover[data-line='" + line + "'] a").each(function() {
$(this).mouseover(function() {
var comment = comments[$(this).index()];
@@ -269,14 +275,14 @@ gitplex.sourceview = {
} else {
var comment = comments[0];
$gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");
- var $commentLink = $gutter.children("a");
- $commentLink.mouseover(function() {
+ var $indicator = $gutter.children("a");
+ $indicator.mouseover(function() {
pmease.commons.codemirror.mark(cm, comment.mark, false);
});
- $commentLink.mouseout(function() {
+ $indicator.mouseout(function() {
gitplex.sourceview.restoreMark();
});
- $commentLink.click(function() {
+ $indicator.click(function() {
if ($(".source-view form.dirty").length != 0
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
@@ -298,6 +304,7 @@ gitplex.sourceview = {
var commentLinkCallback = function($commentLink) {
$commentLink.off("click");
if (loggedIn) {
+ $commentLink.html("<i class='fa fa-comment'></i> Add comment of this selection");
$commentLink.click(function() {
if ($sourceView.find("form.dirty").length != 0
&& !confirm("There are unsaved changes, discard and continue?")) {
@@ -332,6 +339,7 @@ gitplex.sourceview = {
comments.push(comment);
gitplex.sourceview.addCommentGutter(line, comments);
gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
},
onCommentDeleted: function(comment) {
var $sourceView = $(".source-view");
@@ -355,6 +363,11 @@ gitplex.sourceview = {
gitplex.sourceview.addCommentGutter(line, comments);
}
gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+ var mark = $sourceView.data("mark");
+ if (mark) {
+ gitplex.sourceview.mark(mark, true);
+ }
},
onLayoutChange: function() {
$sourceView = $('.source-view');
@@ -368,24 +381,27 @@ gitplex.sourceview = {
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
pmease.commons.codemirror.clearSelection(cm);
- pmease.commons.codemirror.mark(cm, mark, false);
-
- gitplex.sourceview.highlightCommentTrigger();
gitplex.sourceview.onLayoutChange();
+ pmease.commons.codemirror.mark(cm, mark, true);
+ gitplex.sourceview.highlightCommentTrigger();
},
onOpenComment: function(comment) {
var $sourceView = $(".source-view");
$sourceView.data("openComment", comment);
$sourceView.data("mark", comment.mark);
gitplex.sourceview.highlightCommentTrigger();
- gitplex.sourceview.mark(comment.mark, false);
gitplex.sourceview.onLayoutChange();
+ gitplex.sourceview.mark(comment.mark, true);
},
onCloseComment: function() {
var $sourceView = $(".source-view");
$sourceView.removeData("openComment");
gitplex.sourceview.highlightCommentTrigger();
gitplex.sourceview.onLayoutChange();
+ var mark = $sourceView.data("mark");
+ if (mark) {
+ gitplex.sourceview.mark(mark, true);
+ }
},
onToggleOutline: function() {
gitplex.sourceview.onLayoutChange();
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.java
index 2abdbd0f03..d0b9c6c0f5 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
@@ -31,7 +31,7 @@ import com.pmease.gitplex.web.component.diff.revision.DiffMark;
import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;
@SuppressWarnings("serial")
-public class BlobDiffPanel extends Panel implements CommentAware {
+public class BlobDiffPanel extends Panel implements MarkAware {
private static final String CONTENT_ID = "content";
@@ -151,45 +151,45 @@ public class BlobDiffPanel extends Panel implements CommentAware {
@Override
public void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
Component content = get(CONTENT_ID);
- if (content instanceof CommentAware) {
- CommentAware commentAware = (CommentAware) content;
- commentAware.onCommentDeleted(target, comment);
+ if (content instanceof MarkAware) {
+ MarkAware markAware = (MarkAware) content;
+ markAware.onCommentDeleted(target, comment);
}
}
@Override
public void onCommentClosed(AjaxRequestTarget target, CodeComment comment) {
Component content = get(CONTENT_ID);
- if (content instanceof CommentAware) {
- CommentAware commentAware = (CommentAware) content;
- commentAware.onCommentClosed(target, comment);
+ if (content instanceof MarkAware) {
+ MarkAware markAware = (MarkAware) content;
+ markAware.onCommentClosed(target, comment);
}
}
@Override
public void onCommentAdded(AjaxRequestTarget target, CodeComment comment) {
Component content = get(CONTENT_ID);
- if (content instanceof CommentAware) {
- CommentAware commentAware = (CommentAware) content;
- commentAware.onCommentAdded(target, comment);
+ if (content instanceof MarkAware) {
+ MarkAware markAware = (MarkAware) content;
+ markAware.onCommentAdded(target, comment);
}
}
@Override
public void mark(AjaxRequestTarget target, DiffMark mark) {
Component content = get(CONTENT_ID);
- if (content instanceof CommentAware) {
- CommentAware commentAware = (CommentAware) content;
- commentAware.mark(target, mark);
+ if (content instanceof MarkAware) {
+ MarkAware markAware = (MarkAware) content;
+ markAware.mark(target, mark);
}
}
@Override
public void clearMark(AjaxRequestTarget target) {
Component content = get(CONTENT_ID);
- if (content instanceof CommentAware) {
- CommentAware commentAware = (CommentAware) content;
- commentAware.clearMark(target);
+ if (content instanceof MarkAware) {
+ MarkAware markAware = (MarkAware) content;
+ markAware.clearMark(target);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/CommentAware.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/MarkAware.java
similarity index 94%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/CommentAware.java
rename to gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/MarkAware.java
index 572f72ec1c..5ddfce63e0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/CommentAware.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/MarkAware.java
@@ -5,7 +5,7 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.web.component.diff.revision.DiffMark;
-public interface CommentAware {
+public interface MarkAware {
void onCommentDeleted(AjaxRequestTarget target, CodeComment comment);
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.java
index 1edb039f1c..aac4319a85 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
@@ -54,7 +54,7 @@ import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.web.Constants;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;
-import com.pmease.gitplex.web.component.diff.blob.CommentAware;
+import com.pmease.gitplex.web.component.diff.blob.MarkAware;
import com.pmease.gitplex.web.component.diff.blob.text.MarkAwareDiffBlock.Type;
import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
import com.pmease.gitplex.web.component.diff.difftitle.BlobDiffTitle;
@@ -67,7 +67,7 @@ import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
@SuppressWarnings("serial")
-public class TextDiffPanel extends Panel implements CommentAware {
+public class TextDiffPanel extends Panel implements MarkAware {
private final IModel<Depot> depotModel;
@@ -182,8 +182,12 @@ public class TextDiffPanel extends Panel implements CommentAware {
break;
case "addComment":
Preconditions.checkNotNull(SecurityUtils.getAccount());
+
mark = getMark(params, "param1", "param2", "param3", "param4", "param5");
markSupport.onAddComment(target, mark);
+ script = String.format("gitplex.textdiff.onAddComment($('#%s'), %s);",
+ getMarkupId(), mark.toJson());
+ target.appendJavaScript(script);
break;
case "openComment":
Long commentId = params.getParameterValue("param1").toLong();
@@ -836,7 +840,11 @@ public class TextDiffPanel extends Panel implements CommentAware {
@Override
public void clearMark(AjaxRequestTarget target) {
- String script = String.format("gitplex.textdiff.clearMark($('#%s'));", getMarkupId());
+ String script = String.format(""
+ + "var $container = $('#%s');"
+ + "gitplex.textdiff.clearMark($container);"
+ + "$container.removeData('mark');",
+ getMarkupId());
target.appendJavaScript(script);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
index 4fa2db26e7..7f878fad71 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
@@ -1,6 +1,5 @@
.text-diff {
border: 1px solid #D8D8D8;
- z-index: 10;
position: relative;
}
.text-diff>.head {
@@ -132,6 +131,28 @@
.text-diff>.body>tbody>tr>td.content>span.content-mark.delete {
background: #FF88FF;
}
+
+.text-diff>.body>tbody>tr>td.number>.comment-indicator {
+ margin: 0 4px;
+ color: #999;
+}
+.text-diff>.body>tbody>tr>td.number>.comment-indicator:hover {
+ color: #333;
+}
+.comment-popover a {
+ display: block;
+ color: #999;
+ text-decoration: none;
+}
+.comment-popover a:hover {
+ color: #333;
+}
+.text-diff>.body>tbody>tr>td.number>.comment-trigger.active,
+.comment-popover .comment-trigger.active {
+ font-size: 16px;
+ color: #333;
+}
+
.diff-tokentooltip {
background-color: infobackground;
border: 1px solid black;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
index 1f71b2498d..1e33f77fa9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
@@ -3,7 +3,7 @@ gitplex.textdiff = {
init: function(containerId, symbolTooltipId, oldRev, newRev, scroll, callback,
markSupport, mark, openComment, oldComments, newComments, dirtyContainerId) {
var $container = $("#" + containerId);
- $container.data("dirtyContainer", $("#" + dirtyContainerId));
+ $container.data("dirtyContainerId", dirtyContainerId);
$container.data("callback", callback);
$container.data("symbolHover", function() {
var revision;
@@ -339,7 +339,7 @@ gitplex.textdiff = {
endRect = startRect;
}
var position = {
- left: Math.round((startRect.left + endRect.right)/2),
+ left: (startRect.left + endRect.right)/2,
top: startRect.top
};
position.left += $(window).scrollLeft();
@@ -431,10 +431,10 @@ gitplex.textdiff = {
var endCursor = getCursor($end, endOffset);
if (startCursor.newLine && endCursor.newLine) {
- callback("openSelectionPopup", position.left, position.top, false,
+ callback("openSelectionPopup", Math.round(position.left), Math.round(position.top), false,
startCursor.newLine-1, startCursor.newCh, endCursor.newLine-1, endCursor.newCh);
} else if (startCursor.oldLine && endCursor.oldLine) {
- callback("openSelectionPopup", position.left, position.top, true,
+ callback("openSelectionPopup", Math.round(position.left), Math.round(position.top), true,
startCursor.oldLine-1, startCursor.oldCh, endCursor.oldLine-1, endCursor.oldCh);
} else {
showInvalidSelection();
@@ -443,14 +443,8 @@ gitplex.textdiff = {
}, 100);
});
- if (mark) {
- $container.data("mark", mark);
- gitplex.textdiff.mark($container, mark);
- if (scroll)
- gitplex.textdiff.scroll($container, mark);
- }
if (openComment) {
- $container.data("comment", openComment);
+ $container.data("openComment", openComment);
}
for (var line in oldComments) {
if (oldComments.hasOwnProperty(line)) {
@@ -465,23 +459,12 @@ gitplex.textdiff = {
gitplex.textdiff.highlightCommentTrigger($container);
- function alignCommentPopovers() {
- $container.find(".comment-popover:visible").each(function() {
- var $popover = $(this);
- var leftSide = $popover.hasClass("old");
- var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, $popover.data("line")).children(".comment-indicator");
- if ($indicator.length != 0) {
- $popover.css({
- "left": $indicator.offset().left + $indicator.outerWidth() - $container.offset().left,
- "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $container.offset().top
- });
- }
- });
+ if (mark) {
+ $container.data("mark", mark);
+ gitplex.textdiff.mark($container, mark);
+ if (scroll)
+ gitplex.textdiff.scroll($container, mark);
}
- $(window).on("resize scroll", function(e) {
- e.preventDefault();
- alignCommentPopovers();
- });
},
openSelectionPopup: function(containerId, position, mark, markUrl, loggedIn) {
var $container = $("#" + containerId);
@@ -491,26 +474,15 @@ gitplex.textdiff = {
};
var commentLinkCallback = function($commentLink) {
+ $commentLink.html("<i class='fa fa-comment'></i> Add comment of this selection");
$commentLink.off("click");
+ $commentLink.attr("href", "javascript:void(0);");
if (loggedIn) {
$commentLink.click(function() {
- if ($container.data("dirtyContainer").find("form.dirty").length != 0
+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
}
- $container.removeData("openComment");
- $container.data("mark", mark);
-
- $("#selection-popup").hide();
- window.getSelection().removeAllRanges();
-
- // continue to operate DOM in a timer to give browser a chance to
- // clear selections
- setTimeout(function() {
- gitplex.textdiff.mark($container, mark);
- gitplex.textdiff.highlightCommentTrigger($container);
- }, 100);
-
$container.data("callback")("addComment", mark.leftSide,
mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);
});
@@ -539,6 +511,7 @@ gitplex.textdiff = {
var $symbols = $expandedTrs.find(gitplex.textdiff.symbolClasses);
$symbols.mouseover($container.data("symbolHover"));
$expandedTrs.find("td.content").mouseover($container.data("onMouseOverContent"));
+ gitplex.revisionDiff.reposition();
},
getMarkInfo: function($container, mark) {
var oldOrNew = mark.leftSide?"old":"new";
@@ -575,20 +548,23 @@ gitplex.textdiff = {
};
},
scroll: function($container, mark) {
- var markInfo = gitplex.textdiff.getMarkInfo($container, mark);
- var $startTd = markInfo.startTd;
- var $endTd = markInfo.endTd;
- if ($startTd && $endTd) {
- var top = $startTd.offset().top;
- var bottom = $endTd.offset().top + $endTd.outerHeight();
- var markHeight = bottom - top;
- var windowHeight = $(window).height();
- if (windowHeight <= markHeight) {
- $(window).scrollTop(top-50);
- } else {
- $(window).scrollTop((top+bottom-windowHeight)/2);
+ // use a timer to scroll after possible view port resize
+ setTimeout(function() {
+ var markInfo = gitplex.textdiff.getMarkInfo($container, mark);
+ var $startTd = markInfo.startTd;
+ var $endTd = markInfo.endTd;
+ if ($startTd && $endTd) {
+ var top = $startTd.offset().top;
+ var bottom = $endTd.offset().top + $endTd.outerHeight();
+ var markHeight = bottom - top;
+ var windowHeight = $(window).height();
+ if (windowHeight <= markHeight) {
+ $(window).scrollTop(top-50);
+ } else {
+ $(window).scrollTop((top+bottom-windowHeight)/2);
+ }
}
- }
+ }, 0);
},
mark: function($container, mark) {
gitplex.textdiff.clearMark($container);
@@ -726,6 +702,7 @@ gitplex.textdiff = {
addCommentIndicator: function($container, leftSide, line, comments) {
var oldOrNew = leftSide?"old":"new";
$container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "']").remove();
+ var $lineNumTd = gitplex.textdiff.getLineNumTd($container, leftSide, line);
var callback = $container.data("callback");
@@ -743,9 +720,9 @@ gitplex.textdiff = {
}
$indicator.popover({
html: true,
- container: $container,
- placement: "right auto",
- template: "<div class='" + oldOrNew + "' data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",
+ container: $lineNumTd,
+ placement: "right",
+ template: "<div class='" + oldOrNew + " popover comment-popover' data-line='" + line + "'><div class='arrow'></div><div class='popover-content'></div></div>",
content: content
});
$indicator.on('shown.bs.popover', function () {
@@ -758,7 +735,7 @@ gitplex.textdiff = {
gitplex.textdiff.restoreMark($container);
});
$(this).click(function() {
- if ($container.data("dirtyContainer").find("form.dirty").length != 0
+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
}
@@ -779,36 +756,31 @@ gitplex.textdiff = {
gitplex.textdiff.restoreMark($container);
});
$indicator.click(function() {
- if ($container.data("dirtyContainer").find("form.dirty").length != 0
+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0
&& !confirm("There are unsaved changes, discard and continue?")) {
return;
}
callback("openComment", comment.id);
});
}
- var $lineNumTd = gitplex.textdiff.getLineNumTd($container, leftSide, line);
- if ($lineNumTd) {
- $lineNumTd.children(".comment-indicator").remove();
- $lineNumTd.prepend($indicator);
- }
+ $lineNumTd.children(".comment-indicator").remove();
+ $lineNumTd.prepend($indicator);
},
getLineNumTd: function($container, leftSide, line) {
if (leftSide) {
- var $lineNumTds = $container.find("td.content[data-old='" + line + "']").prevAll("td.number");
- if ($lineNumTds.length != 0) {
- return $lineNumTds.first();
- }
+ var $contentTd = $container.find("td.left.content[data-old='" + line + "']");
+ if ($contentTd.length == 0)
+ $contentTd = $container.find("td.content[data-old='" + line + "']");
+ return $contentTd.prevAll("td.number").last();
} else {
- var $lineNumTds = $container.find("td.content[data-new='" + line + "']").prevAll("td.number");
- if ($lineNumTds.length != 0) {
- return $lineNumTds.last();
- }
+ var $contentTd = $container.find("td.right.content[data-new='" + line + "']");
+ if ($contentTd.length == 0)
+ $contentTd = $container.find("td.content[data-new='" + line + "']");
+ return $contentTd.prevAll("td.number").first();
}
- return $();
},
highlightCommentTrigger: function($container) {
$container.find(".comment-trigger").removeClass("active");
-
var openComment = $container.data("openComment");
if (openComment) {
var line = parseInt(openComment.mark.beginLine);
@@ -818,7 +790,7 @@ gitplex.textdiff = {
if (comments.length == 1) {
$indicator.addClass("active");
} else {
- var oldOrNew = leftSide?"old":"new";
+ var oldOrNew = openComment.mark.leftSide?"old":"new";
$container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {
var comment = comments[$(this).index()];
if (comment.id == openComment.id) {
@@ -844,7 +816,7 @@ gitplex.textdiff = {
comments = [];
}
comments.push(comment);
- gitplex.textdiff.addCommentIndicator($container, line, leftSide, comments);
+ gitplex.textdiff.addCommentIndicator($container, leftSide, line, comments);
gitplex.textdiff.highlightCommentTrigger($container);
},
onCommentDeleted: function($container, comment) {
@@ -858,24 +830,40 @@ gitplex.textdiff = {
$indicator.remove();
} else {
for (var i in comments) {
- var comment = comments[i];
- if (comment.id == commentId) {
+ var each = comments[i];
+ if (each.id == comment.id) {
comments.splice(i, 1);
break;
}
}
- gitplex.textdiff.addCommentIndicator($container, line, leftSide, comments);
+ gitplex.textdiff.addCommentIndicator($container, leftSide, line, comments);
}
- gitplex.textdiff.highlightCommentTrigger();
+ gitplex.textdiff.highlightCommentTrigger($container);
},
onOpenComment: function($container, comment) {
$container.data("openComment", comment);
$container.data("mark", comment.mark);
gitplex.textdiff.highlightCommentTrigger($container);
gitplex.textdiff.mark($container, comment.mark);
+ gitplex.textdiff.scroll($container, comment.mark);
},
onCloseComment: function($container) {
$container.removeData("openComment");
gitplex.textdiff.highlightCommentTrigger($container);
- }
+ },
+ onAddComment: function($container, mark) {
+ $container.removeData("openComment");
+ $container.data("mark", mark);
+
+ $("#selection-popup").hide();
+ window.getSelection().removeAllRanges();
+
+ // continue to operate DOM in a timer to give browser a chance to
+ // clear selections
+ setTimeout(function() {
+ gitplex.textdiff.highlightCommentTrigger($container);
+ gitplex.textdiff.mark($container, mark);
+ gitplex.textdiff.scroll($container, mark);
+ }, 100);
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java
index 27b898b69b..20aeb3b9ef 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/DiffMark.java
@@ -1,5 +1,7 @@
package com.pmease.gitplex.web.component.diff.revision;
+import javax.annotation.Nullable;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@@ -98,5 +100,11 @@ public class DiffMark extends Mark {
throw new RuntimeException(e);
}
}
-
+
+ public static DiffMark of(@Nullable String markStr) {
+ if (markStr != null)
+ return new DiffMark(markStr);
+ else
+ return null;
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
index 7fd733fcd6..60526746e7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
@@ -39,7 +39,6 @@
</wicket:enclosure>
</li>
</ul>
- <div class="loading">Loading...</div>
<div class="detail">
<div wicket:id="comment" class="comment">
<div class="ui-resizable-handle ui-resizable-e"></div>
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.java
index 0d7dacdb64..650341badd 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
@@ -81,7 +81,7 @@ import com.pmease.gitplex.web.component.comment.CodeCommentPanel;
import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;
-import com.pmease.gitplex.web.component.diff.blob.CommentAware;
+import com.pmease.gitplex.web.component.diff.blob.MarkAware;
import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
import com.pmease.gitplex.web.util.SuggestionUtils;
@@ -502,7 +502,7 @@ public abstract class RevisionDiffPanel extends Panel {
});
add(form);
- commentContainer = new WebMarkupContainer("comment") {
+ commentContainer = new WebMarkupContainer("comment", Model.of((DiffMark)null)) {
@Override
public void renderHead(IHeaderResponse response) {
@@ -529,11 +529,11 @@ public abstract class RevisionDiffPanel extends Panel {
if (comment != null) {
mark = new DiffMark(comment, getOldCommit().name(), getNewCommit().name());
} else {
- mark = (DiffMark)commentContainer.getDefaultModel();
+ mark = (DiffMark)commentContainer.getDefaultModelObject();
}
- CommentAware commentAware = getCommentAware(mark.getPath());
- if (commentAware != null)
- commentAware.mark(target, mark);
+ MarkAware markAware = getMarkAware(mark.getPath());
+ if (markAware != null)
+ markAware.mark(target, mark);
markSupport.onMark(target, mark);
target.appendJavaScript(String.format("$('#%s').blur();", getMarkupId()));
}
@@ -578,12 +578,20 @@ public abstract class RevisionDiffPanel extends Panel {
clearComment(target);
CodeComment comment = markSupport.getOpenComment();
if (comment != null) {
- CommentAware commentAware = getCommentAware(comment.getPath());
- if (commentAware != null)
- commentAware.onCommentClosed(target, comment);
+ MarkAware markAware = getMarkAware(comment.getPath());
+ if (markAware != null)
+ markAware.onCommentClosed(target, comment);
markSupport.onCommentClosed(target);
}
- target.appendJavaScript("$(window).resize();");
+ target.appendJavaScript("gitplex.revisionDiff.reposition();");
+
+ DiffMark mark = markSupport.getMark();
+ if (mark != null) {
+ MarkAware markAware = getMarkAware(mark.getPath());
+ if (markAware != null) {
+ markAware.mark(target, mark);
+ }
+ }
}
});
@@ -641,7 +649,7 @@ public abstract class RevisionDiffPanel extends Panel {
totalChangedLink.add(AttributeAppender.append("class", "expanded"));
}
body.add(diffStats);
- diffStats.add(diffsView = new ListView<BlobChange>("diffStats", new AbstractReadOnlyModel<List<BlobChange>>() {
+ diffStats.add(new ListView<BlobChange>("diffStats", new AbstractReadOnlyModel<List<BlobChange>>() {
@Override
public List<BlobChange> getObject() {
@@ -692,7 +700,7 @@ public abstract class RevisionDiffPanel extends Panel {
});
- body.add(new ListView<BlobChange>("diffs", new AbstractReadOnlyModel<List<BlobChange>>() {
+ body.add(diffsView = new ListView<BlobChange>("diffs", new AbstractReadOnlyModel<List<BlobChange>>() {
@Override
public List<BlobChange> getObject() {
@@ -759,20 +767,20 @@ public abstract class RevisionDiffPanel extends Panel {
CodeComment prevComment = markSupport.getOpenComment();
if (prevComment != null) {
- CommentAware commentAware = getCommentAware(prevComment.getPath());
- if (commentAware != null)
- commentAware.onCommentClosed(target, prevComment);
+ MarkAware markAware = getMarkAware(prevComment.getPath());
+ if (markAware != null)
+ markAware.onCommentClosed(target, prevComment);
}
DiffMark prevMark = markSupport.getMark();
if (prevMark != null) {
- CommentAware commentAware = getCommentAware(prevMark.getPath());
- if (commentAware != null)
- commentAware.clearMark(target);
+ MarkAware markAware = getMarkAware(prevMark.getPath());
+ if (markAware != null)
+ markAware.clearMark(target);
}
markSupport.onCommentOpened(target, comment);
- target.appendJavaScript("$(window).resize();");
+ target.appendJavaScript("gitplex.revisionDiff.reposition();");
}
@Override
@@ -810,7 +818,7 @@ public abstract class RevisionDiffPanel extends Panel {
@Override
public void onClick(AjaxRequestTarget target) {
clearComment(target);
- target.appendJavaScript("$(window).resize();");
+ target.appendJavaScript("gitplex.revisionDiff.reposition();");
}
});
@@ -870,37 +878,39 @@ public abstract class RevisionDiffPanel extends Panel {
}
};
- commentContainer.replaceWith(commentPanel);
+ commentContainer.replace(commentPanel);
target.add(commentContainer);
- CommentAware commentAware = getCommentAware(comment.getPath());
- if (commentAware != null)
- commentAware.onCommentAdded(target, comment);
+ MarkAware markAware = getMarkAware(comment.getPath());
+ if (markAware != null)
+ markAware.onCommentAdded(target, comment);
markSupport.onCommentOpened(target, comment);
+ target.appendJavaScript("gitplex.revisionDiff.reposition();");
}
});
fragment.add(form);
+
commentContainer.replace(fragment);
commentContainer.setVisible(true);
target.add(commentContainer);
- CodeComment prevComment = markSupport.getOpenComment();
- if (prevComment != null) {
- CommentAware commentAware = getCommentAware(prevComment.getPath());
- if (commentAware != null)
- commentAware.onCommentClosed(target, prevComment);
- }
DiffMark prevMark = markSupport.getMark();
if (prevMark != null) {
- CommentAware commentAware = getCommentAware(prevMark.getPath());
- if (commentAware != null)
- commentAware.clearMark(target);
+ MarkAware markAware = getMarkAware(prevMark.getPath());
+ if (markAware != null)
+ markAware.clearMark(target);
}
+ CodeComment prevComment = markSupport.getOpenComment();
+ if (prevComment != null) {
+ MarkAware markAware = getMarkAware(prevComment.getPath());
+ if (markAware != null)
+ markAware.onCommentClosed(target, prevComment);
+ }
markSupport.onAddComment(target, mark);
- target.appendJavaScript("$(window).resize();");
+ target.appendJavaScript("gitplex.revisionDiff.reposition();");
}
@Override
@@ -917,7 +927,7 @@ public abstract class RevisionDiffPanel extends Panel {
@Override
public Component getDirtyContainer() {
- return RevisionDiffPanel.this;
+ return commentContainer;
}
}));
@@ -932,16 +942,20 @@ public abstract class RevisionDiffPanel extends Panel {
}
@Nullable
- private CommentAware getCommentAware(String path) {
- return diffsView.visitChildren(ListItem.class, new IVisitor<ListItem<BlobChange>, CommentAware>() {
+ private MarkAware getMarkAware(String path) {
+ return diffsView.visitChildren(new IVisitor<Component, MarkAware>() {
+ @SuppressWarnings("unchecked")
@Override
- public void component(ListItem<BlobChange> object, IVisit<CommentAware> visit) {
- if (object.getModelObject().getPaths().contains(path)) {
- visit.stop((CommentAware) object.get(DIFF_ID));
- } else {
- visit.dontGoDeeper();
- }
+ public void component(Component object, IVisit<MarkAware> visit) {
+ if (object instanceof ListItem) {
+ ListItem<BlobChange> item = (ListItem<BlobChange>) object;
+ if (item.getModelObject().getPaths().contains(path)) {
+ visit.stop((MarkAware) item.get(DIFF_ID));
+ } else {
+ visit.dontGoDeeper();
+ }
+ }
}
});
@@ -957,11 +971,18 @@ public abstract class RevisionDiffPanel extends Panel {
private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
clearComment(target);
- CommentAware commentAware = getCommentAware(comment.getPath());
- if (commentAware != null)
- commentAware.onCommentDeleted(target, comment);
+ MarkAware markAware = getMarkAware(comment.getPath());
+ if (markAware != null)
+ markAware.onCommentDeleted(target, comment);
markSupport.onCommentClosed(target);
- target.appendJavaScript("$(window).resize();");
+ target.appendJavaScript("gitplex.revisionDiff.reposition();");
+ DiffMark mark = markSupport.getMark();
+ if (mark != null) {
+ markAware = getMarkAware(mark.getPath());
+ if (markAware != null) {
+ markAware.mark(target, mark);
+ }
+ }
}
private void clearComment(AjaxRequestTarget target) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
index d505eb874d..e74665e247 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
@@ -64,9 +64,6 @@
margin-right: 4px;
margin-top: 2px;
}
-.revision-diff>.body>.loading {
- font-size: 20px;
-}
.revision-diff>.body>.detail>.diffs {
margin-bottom: 0;
}
@@ -75,7 +72,6 @@
}
.revision-diff>.body>.detail {
position: relative;
- display: none;
}
.revision-diff>.body>.detail>.comment {
border: 1px solid #DDD;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
index d89063e26f..e14ad15b50 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
@@ -15,17 +15,19 @@ gitplex.revisionDiff = {
Cookies.set(cookieName, "yes", {expires: Infinity});
}
});
- function onWindowResizeOrScroll(e) {
- if (e && e.target && $(e.target).hasClass("ui-resizable"))
+ gitplex.revisionDiff.reposition();
+ },
+ reposition: function(e) {
+ if (e) {
+ e.stopPropagation();
+ if (e.target && $(e.target).hasClass("ui-resizable"))
return;
-
- var $detail = $body.children(".detail");
- $detail.show();
- $body.children(".loading").hide();
-
+ }
+
+ var $detail = $(".revision-diff>.body>.detail");
+ if ($detail.length != 0) {
var $comment = $detail.children(".comment");
var $diffs = $detail.children(".diffs");
- var diffsHeight = $diffs.outerHeight();
if ($comment.is(":visible")) {
$diffs.css("left", $comment.outerWidth(true));
$diffs.outerWidth($detail.width() - $comment.outerWidth(true));
@@ -58,19 +60,14 @@ gitplex.revisionDiff = {
$diffs.css("left", "0");
$diffs.outerWidth($detail.width());
}
+ var diffsHeight = $diffs.outerHeight();
$detail.height(commentHeight>diffsHeight?commentHeight:diffsHeight);
}
-
- onWindowResizeOrScroll();
- $(window).on("scroll resize", onWindowResizeOrScroll);
},
initComment: function() {
var $comment = $(".revision-diff>.body>.detail>.comment");
- // we do not use $comment.is(":visible") here as comment can also be invisible
- // when its parent is not visible initially (in order not to display a weild
- // page before we adjust the width and height of comment and diffs)
- if ($comment.css("display") != "none") {
+ if ($comment.is(":visible")) {
var commentWidthCookieKey = "revisionDiff.comment.width";
var commentWidth = Cookies.get(commentWidthCookieKey);
if (!commentWidth)
@@ -96,3 +93,6 @@ gitplex.revisionDiff = {
}
}
}
+$(function() {
+ $(window).on("scroll resize", gitplex.revisionDiff.position);
+});
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.java
index 0e3ccf2987..183c52e518 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
@@ -414,9 +414,7 @@ public class CommitDetailPage extends DepotPage implements MarkSupport {
whitespaceOption = WhitespaceOption.of(params.get(PARAM_WHITESPACE_OPTION).toString());
pathFilter = params.get(PARAM_PATH_FILTER).toString();
commentId = params.get(PARAM_COMMENT).toOptionalLong();
- String markStr = params.get(PARAM_MARK).toString();
- if (markStr != null)
- mark = new DiffMark(markStr);
+ mark = DiffMark.of(params.get(PARAM_MARK).toString());
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html
index 552b60e398..d13cf64ea3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html
@@ -10,7 +10,7 @@
<div wicket:id="leftSide"></div>
</div>
<div class="action pull-left">
- <a wicket:id="swap" class="swap btn btn-default" title="Swap"><i class="fa fa-exchange"></i></a>
+ <a wicket:id="swap" class="swap btn btn-default" title="Swap"><i class="fa fa-info-circle"></i> <i class="fa fa-exchange"></i></a>
</div>
<div class="revision pull-left">
<div>
@@ -26,9 +26,6 @@
<div wicket:id="noChanges" class="alert alert-warning">
No changes between left side and right side
</div>
- <div wicket:id="leftAhead" class="alert alert-warning">
- Left side is ahead of right side, <a wicket:id="swap">swap</a> the comparison to see the changes
- </div>
<div>
<a wicket:id="createRequest" class="btn btn-primary">Create Pull Request</a>
</div>
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.java
index fe83e79115..fadfe4817c 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
@@ -27,6 +27,7 @@ import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
import com.pmease.commons.lang.diff.WhitespaceOption;
import com.pmease.commons.util.FileUtils;
+import com.pmease.commons.wicket.behavior.TooltipBehavior;
import com.pmease.commons.wicket.component.backtotop.BackToTop;
import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
import com.pmease.commons.wicket.component.tabbable.Tab;
@@ -120,6 +121,9 @@ public class RevisionComparePage extends DepotPage implements MarkSupport {
state.pathFilter = params.get(PARAM_PATH_FILTER).toString();
state.whitespaceOption = WhitespaceOption.of(params.get(PARAM_WHITESPACE_OPTION).toString());
+ state.commentId = params.get(PARAM_COMMENT).toOptionalLong();
+ state.mark = DiffMark.of(params.get(PARAM_MARK).toString());
+
requestModel = new LoadableDetachableModel<PullRequest>() {
@Override
@@ -180,27 +184,53 @@ public class RevisionComparePage extends DepotPage implements MarkSupport {
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot, String revision) {
- State state = new State(RevisionComparePage.this.state);
- state.leftSide = new DepotAndRevision(depot, revision);
+ State newState = new State();
+ newState.leftSide = new DepotAndRevision(depot, revision);
+ newState.rightSide = state.rightSide;
+ newState.pathFilter = state.pathFilter;
+ newState.whitespaceOption = state.whitespaceOption;
- PageParameters params = paramsOf(depot, state);
+ PageParameters params = paramsOf(depot, newState);
+ setResponsePage(RevisionComparePage.class, params);
+ }
+
+ });
+ add(new AffinalRevisionPicker("rightSide",
+ state.rightSide.getDepotId(), state.rightSide.getRevision()) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Depot depot, String revision) {
+ State newState = new State();
+ newState.leftSide = state.leftSide;
+ newState.rightSide = new DepotAndRevision(depot, revision);
+ newState.pathFilter = state.pathFilter;
+ newState.whitespaceOption = state.whitespaceOption;
+
+ PageParameters params = paramsOf(getDepot(), newState);
setResponsePage(RevisionComparePage.class, params);
}
});
- newRightSideRevisionPicker(null);
add(new Link<Void>("swap") {
@Override
public void onClick() {
- State state = new State(RevisionComparePage.this.state);
- state.leftSide = RevisionComparePage.this.state.rightSide;
- state.rightSide = RevisionComparePage.this.state.leftSide;
- setResponsePage(RevisionComparePage.class,paramsOf(getDepot(), state));
+ State newState = new State();
+ newState.leftSide = state.rightSide;
+ newState.rightSide = state.leftSide;
+ newState.pathFilter = state.pathFilter;
+ newState.whitespaceOption = state.whitespaceOption;
+ setResponsePage(RevisionComparePage.class,paramsOf(getDepot(), newState));
}
- });
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!mergeBaseModel.getObject().equals(state.leftSide.getCommit().name()));
+ }
+
+ }.add(new TooltipBehavior(Model.of("Left side is ahead of right side, swap to see changes"))));
add(new Link<Void>("createRequest") {
@@ -280,34 +310,6 @@ public class RevisionComparePage extends DepotPage implements MarkSupport {
setVisible(!hasChanges());
}
- });
- add(new WebMarkupContainer("leftAhead") {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new Link<Void>("swap") {
-
- @Override
- public void onClick() {
- State newState = new State(state);
- newState.leftSide = state.rightSide;
- newState.rightSide = state.leftSide;
- PageParameters params = paramsOf(getDepot(), newState);
- setResponsePage(RevisionComparePage.class, params);
- }
-
- });
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(!mergeBaseModel.getObject().equals(state.leftSide.getCommit().name()));
- }
-
});
List<Tab> tabs = new ArrayList<>();
@@ -349,28 +351,6 @@ public class RevisionComparePage extends DepotPage implements MarkSupport {
add(new BackToTop("backToTop"));
}
- private void newRightSideRevisionPicker(@Nullable AjaxRequestTarget target) {
- AffinalRevisionPicker revisionPicker = new AffinalRevisionPicker("rightSide",
- state.rightSide.getDepotId(), state.rightSide.getRevision()) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot, String revision) {
- State state = new State(RevisionComparePage.this.state);
- state.rightSide = new DepotAndRevision(depot, revision);
-
- PageParameters params = paramsOf(getDepot(), state);
- setResponsePage(RevisionComparePage.class, params);
- }
-
- };
- if (target != null) {
- replace(revisionPicker);
- target.add(revisionPicker);
- } else {
- add(revisionPicker);
- }
- }
-
private boolean hasChanges() {
return !mergeBaseModel.getObject().equals(state.rightSide.getCommit().name());
}
@@ -518,19 +498,19 @@ public class RevisionComparePage extends DepotPage implements MarkSupport {
markState.mark = mark;
markState.pathFilter = state.pathFilter;
markState.whitespaceOption = state.whitespaceOption;
- return urlFor(RevisionComparePage.class, paramsOf(state.rightSide.getDepot(), state)).toString();
+ return urlFor(RevisionComparePage.class, paramsOf(markState.rightSide.getDepot(), markState)).toString();
}
@Override
public String getCommentUrl(CodeComment comment) {
- State markState = new State();
- markState.leftSide = new DepotAndRevision(state.rightSide.getDepot(), mergeBaseModel.getObject());
- markState.rightSide = new DepotAndRevision(state.rightSide.getDepot(), resolvedRightSideRevision.name());
- markState.mark = new DiffMark(comment, mergeBaseModel.getObject(), resolvedRightSideRevision.name());
- markState.commentId = comment.getId();
- markState.pathFilter = state.pathFilter;
- markState.whitespaceOption = state.whitespaceOption;
- return urlFor(RevisionComparePage.class, paramsOf(state.rightSide.getDepot(), state)).toString();
+ State commentState = new State();
+ commentState.leftSide = new DepotAndRevision(state.rightSide.getDepot(), mergeBaseModel.getObject());
+ commentState.rightSide = new DepotAndRevision(state.rightSide.getDepot(), resolvedRightSideRevision.name());
+ commentState.mark = new DiffMark(comment, mergeBaseModel.getObject(), resolvedRightSideRevision.name());
+ commentState.commentId = comment.getId();
+ commentState.pathFilter = state.pathFilter;
+ commentState.whitespaceOption = state.whitespaceOption;
+ return urlFor(RevisionComparePage.class, paramsOf(commentState.rightSide.getDepot(), commentState)).toString();
}
@Override
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.java
index e2c6004f6b..eb2c3e3b51 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
@@ -206,9 +206,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
String modeStr = params.get(PARAM_MODE).toString();
if (modeStr != null)
mode = Mode.valueOf(modeStr.toUpperCase());
- String markStr = params.get(PARAM_MARK).toString();
- if (markStr != null)
- mark = new Mark(markStr);
+ mark = Mark.of(params.get(PARAM_MARK).toString());
String commentIdStr = params.get(PARAM_COMMENT).toString();
if (commentIdStr != null)
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.java
index 32a0572793..a9e6a6bd6e 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
@@ -160,9 +160,7 @@ public class RequestComparePage extends RequestDetailPage implements MarkSupport
state.pathFilter = params.get(PARAM_PATH_FILTER).toString();
state.whitespaceOption = WhitespaceOption.of(params.get(PARAM_WHITESPACE_OPTION).toString());
state.commentId = params.get(PARAM_COMMENT).toOptionalLong();
- String markStr = params.get(PARAM_MARK).toString();
- if (markStr != null)
- state.mark = new DiffMark(markStr);
+ state.mark = DiffMark.of(params.get(PARAM_MARK).toString());
initFromState(state);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
index 94dabb85a5..7ae9edf377 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
@@ -1,3 +1,9 @@
<wicket:extend>
- <a wicket:id="link">link</a>
+ <script type="text/javascript">
+ var $content = $("<div class='content'><a>gogo</a></div>");
+ $content.children("a").click(function() {
+ console.log("clicked");
+ });
+ $("body").append($content);
+ </script>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index 865f4ef345..30ef4b1601 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -1,16 +1,6 @@
package com.pmease.gitplex.web.page.test;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.JavaScriptHeaderItem;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
-
-import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.manager.DepotManager;
-import com.pmease.gitplex.web.component.diff.revision.DiffMark;
import com.pmease.gitplex.web.page.base.BasePage;
-import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;
@SuppressWarnings("serial")
public class TestPage extends BasePage {
@@ -18,20 +8,6 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
-
- Depot depot = GitPlex.getInstance(DepotManager.class).load(1L);
-
- CommitDetailPage.State state = new CommitDetailPage.State();
- state.mark = new DiffMark("dir a.java", false, 0, 0, 1, 1);
- state.revision = "master";
- add(new BookmarkablePageLink<Void>("link",
- CommitDetailPage.class, CommitDetailPage.paramsOf(depot, state)));
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(JavaScriptHeaderItem.forReference(JQueryUIResourceReference.INSTANCE));
}
}