Skip to content

The Unified and Autonomous Development Platform

Migrating TextDiffPanel

robin shine9e273656cdbf
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.html
index 40fea4782a..09fc932221 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.html
@@ -13,7 +13,7 @@
<span wicket:id="hideComments" class="btn btn-default btn-xs hide-comments" title="Hide comments"><i class="fa fa-eye-slash"></i> <i class="fa fa-comments"></i></span>
</div>
</div>
- <table id="diffs-table" class="table-diff body">
+ <table class="body">
<wicket:container wicket:id="hunks">
<tr wicket:id="head" class="line hunk-head">
<td colspan="2" class="action">
@@ -29,7 +29,7 @@
</tr>
</table>
- <div id="comments-placeholder" class="hidden">
+ <div class="comments-placeholder hidden">
<table wicket:id="lines" class="comments">
<tr wicket:id="comments">
<td class="avatar">
@@ -40,7 +40,7 @@
</td>
</tr>
</table>
- <form wicket:id="addComment" id="add-comment" class="leave-confirm">
+ <form wicket:id="addComment" class="add-comment leave-confirm">
<textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>
<div wicket:id="feedback"></div>
<div class="actions">
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 ecf37779ac..2ebdda6cdb 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
@@ -69,6 +69,8 @@ import com.pmease.gitplex.web.component.avatar.AvatarMode;
import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.comment.CommentPanel;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
+import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
+import com.pmease.gitplex.web.component.diff.difftitle.BlobDiffTitle;
import com.pmease.gitplex.web.component.userlink.UserLink;
import com.pmease.gitplex.web.model.UserModel;
import com.pmease.gitplex.web.page.repository.file.RepoFilePage;
@@ -194,19 +196,10 @@ public class TextDiffPanel extends Panel {
head.add(new StickyBehavior());
- /*
- head.add(new DiffStatBar("diffStat", new AbstractReadOnlyModel<List<DiffLine>>() {
-
- @Override
- public List<DiffLine> getObject() {
- return diffs;
- }
-
- }));
- */
+ head.add(new DiffStatBar("diffStat", change.getAdditions(), change.getDeletions(), true));
add(head);
-// head.add(new BlobDiffTitle("title", change));
+ head.add(new BlobDiffTitle("title", change));
head.add(new AjaxLink<Void>("showComments") {
@@ -259,7 +252,8 @@ public class TextDiffPanel extends Panel {
@Override
public void onClick(AjaxRequestTarget target) {
input.setModelObject("");
- target.appendJavaScript(String.format("gitplex.textdiff.cancelAddComment(%d);", index));
+ target.appendJavaScript(String.format("gitplex.textdiff.cancelAddComment('%s', %d);",
+ TextDiffPanel.this.getMarkupId(), index));
}
}.add(new DirtyIgnoreBehavior()));
@@ -301,10 +295,11 @@ public class TextDiffPanel extends Panel {
target.add(commentsRow);
input.setModelObject("");
- String prependScript = String.format("$('#comments-placeholder').append('<table id=\"%s\"></table>')",
- commentsRow.getMarkupId());
+ String prependScript = String.format("$('#%s .comments-placeholder').append('<table data-line=\"%s\"></table>')",
+ TextDiffPanel.this.getMarkupId(), commentsRow.getMarkupAttributes().get("data-line"));
target.prependJavaScript(prependScript);
- target.appendJavaScript(String.format("gitplex.textdiff.afterAddComment(%d);", index));
+ target.appendJavaScript(String.format("gitplex.textdiff.afterAddComment('%s', %d);",
+ TextDiffPanel.this.getMarkupId(), index));
if (commentsView.size() == 1)
target.add(head);
@@ -333,7 +328,8 @@ public class TextDiffPanel extends Panel {
if (!showComments)
showComments(target);
- target.appendJavaScript(String.format("gitplex.textdiff.beforeAddComment(%d);", index));
+ target.appendJavaScript(String.format("gitplex.textdiff.beforeAddComment('%s', %d);",
+ TextDiffPanel.this.getMarkupId(), index));
}
});
@@ -395,9 +391,6 @@ public class TextDiffPanel extends Panel {
}
private String renderDiffs(List<DiffLine> diffLines) {
- if (diffLines.isEmpty())
- return "";
-
StringBuilder builder = new StringBuilder();
DiffLine firstLine = diffLines.get(0);
@@ -417,7 +410,7 @@ public class TextDiffPanel extends Panel {
} else {
addCommentLink = "";
}
- builder.append("<tr id='diffline-").append(index).append("' class='line diff ");
+ builder.append("<tr class='diffline-").append(index).append("' class='line diff ");
if (line.getAction() == ADD) {
if (index == 0 || diffs.get(index-1).getAction() == EQUAL)
builder.append("new diff-block'>");
@@ -550,8 +543,7 @@ public class TextDiffPanel extends Panel {
}
};
- row.setOutputMarkupId(true);
- row.setMarkupId("comment-diffline-" + index);
+ row.add(AttributeAppender.append("data-line", "diffline-" + index));
row.add(new ListView<InlineComment>("comments", new LoadableDetachableModel<List<InlineComment>>() {
@@ -616,7 +608,8 @@ public class TextDiffPanel extends Panel {
response.render(CssHeaderItem.forReference(
new CssResourceReference(TextDiffPanel.class, "text-diff.css")));
- response.render(OnDomReadyHeaderItem.forScript("gitplex.textdiff.placeComments();"));
+ response.render(OnDomReadyHeaderItem.forScript(
+ String.format("gitplex.textdiff.placeComments('%s');", getMarkupId())));
}
@Override
@@ -654,7 +647,7 @@ public class TextDiffPanel extends Panel {
String row = renderDiffs(Lists.newArrayList(line));
row = StringUtils.replace(row, "\"", "\\\"");
- String script = String.format("$(\"%s\").insertAfter('#diffline-%d')", row, i-1);
+ String script = String.format("$(\"%s\").insertAfter('#%s .diffline-%d')", row, getMarkupId(), i-1);
target.appendJavaScript(script);
} else {
break;
@@ -683,7 +676,7 @@ public class TextDiffPanel extends Panel {
hunk.getDiffLines().add(0, line);
String row = renderDiffs(Lists.newArrayList(line));
row = StringUtils.replace(row, "\"", "\\\"");
- String script = String.format("$(\"%s\").insertBefore('#diffline-%d')", row, i+1);
+ String script = String.format("$(\"%s\").insertBefore('#%s .diffline-%d')", row, getMarkupId(), i+1);
target.appendJavaScript(script);
} else {
break;
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 91717dbdc5..0205122938 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
@@ -4,37 +4,37 @@
.text-diff>.head .title {font-size: 16px;}
.text-diff>.head .pull-right {margin-left: 12px;}
-.table-diff .line.diff>td.line-no {color: #999; width: 1%; text-align: right; white-space: nowrap;}
-.table-diff .line.diff td.text, .table-diff .hunk-head td.content {
+.text-diff>.body .line.diff>td.line-no {color: #999; width: 1%; text-align: right; white-space: nowrap;}
+.text-diff>.body .line.diff td.text, .text-diff>.body .hunk-head td.content {
font-family: Consolas,"Liberation Mono",Menlo,Courier,monospace;}
-.table-diff .line.diff td.text {overflow: visible; white-space: pre;}
-.table-diff {font-size: 12px; position:relative;}
-.table-diff>tbody>tr>td {padding: 2px 8px;}
-.table-diff>tbody>tr>td.text, .table-diff>tbody>tr>td.detail, .table-diff>tbody>tr>td.new {
+.text-diff>.body .line.diff td.text {overflow: visible; white-space: pre;}
+.text-diff>.body {font-size: 12px; position:relative;}
+.text-diff>.body>tbody>tr>td {padding: 2px 8px;}
+.text-diff>.body>tbody>tr>td.text, .text-diff>.body>tbody>tr>td.detail, .text-diff>.body>tbody>tr>td.new {
border-left: 1px solid #E5E5E5;}
-.table-diff .old.line.diff>td.line-no {background: #faa; color: #8f0000;}
-.table-diff .old.line.diff {background: #fdd;}
-.table-diff .old.line.diff .emphasize {background: #FC9090;}
-.table-diff .new.line.diff {background: #cfc;}
-.table-diff .new.line.diff>td.line-no {background: #89FB89; color: #007f00;}
-.table-diff .new.line.diff .emphasize {background: #07C907;}
-.table-diff .line.diff:hover {background: #fea; }
-.table-diff .line.diff:hover>td.line-no, .table-diff .line.hunk-head:hover .action {background: #FBDE6D;}
-.table-diff .hunk-head, .equal.hunk-line>td.info {color: #999;}
-.table-diff .hunk-head a {display: block; color: #999;}
-.table-diff .hunk-head a:hover {color: #444;}
-.table-diff .hunk-head td.action {text-align: center;}
-.table-diff .hunk-head {background: none repeat scroll 0 0 #eef;}
+.text-diff>.body .old.line.diff>td.line-no {background: #faa; color: #8f0000;}
+.text-diff>.body .old.line.diff {background: #fdd;}
+.text-diff>.body .old.line.diff .emphasize {background: #FC9090;}
+.text-diff>.body .new.line.diff {background: #cfc;}
+.text-diff>.body .new.line.diff>td.line-no {background: #89FB89; color: #007f00;}
+.text-diff>.body .new.line.diff .emphasize {background: #07C907;}
+.text-diff>.body .line.diff:hover {background: #fea; }
+.text-diff>.body .line.diff:hover>td.line-no, .text-diff>.body .line.hunk-head:hover .action {background: #FBDE6D;}
+.text-diff>.body .hunk-head, .equal.hunk-line>td.info {color: #999;}
+.text-diff>.body .hunk-head a {display: block; color: #999;}
+.text-diff>.body .hunk-head a:hover {color: #444;}
+.text-diff>.body .hunk-head td.action {text-align: center;}
+.text-diff>.body .hunk-head {background: none repeat scroll 0 0 #eef;}
-.table-diff table.content {width: 100%;}
-.table-diff .line.comments>td {padding: 0 12px; border-top: 1px solid #DDD;
+.text-diff>.body table.content {width: 100%;}
+.text-diff>.body .line.comments>td {padding: 0 12px; border-top: 1px solid #DDD;
border-bottom: 1px solid #DDD;}
-.table-diff .line.comments td.avatar .fa-flag {display: none; margin-top: 12px; font-size: 36px; color: #E7C325;}
-.table-diff .line.comments .concerned td.avatar .fa-flag {display: block;}
+.text-diff>.body .line.comments td.avatar .fa-flag {display: none; margin-top: 12px; font-size: 36px; color: #E7C325;}
+.text-diff>.body .line.comments .concerned td.avatar .fa-flag {display: block;}
form#add-comment {margin: 16px 4px;}
-.table-diff a.add-comment {position: absolute; left:0; margin-left: -20px;
+.text-diff>.body a.add-comment {position: absolute; left:0; margin-left: -20px;
width: 20px; height: 20px; text-decoration: none;}
-.table-diff a.add-comment .fa {display:none; font-size: 18px;}
-.table-diff tr:hover a.add-comment .fa {display:inline;}
-.table-diff .md-editor {margin-bottom: 16px;}
+.text-diff>.body a.add-comment .fa {display:none; font-size: 18px;}
+.text-diff>.body tr:hover a.add-comment .fa {display:inline;}
+.text-diff>.body .md-editor {margin-bottom: 16px;}
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 2fa53b05ee..f222facf45 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
@@ -1,20 +1,20 @@
gitplex.textdiff = {
- placeComments: function() {
- $("#comments-placeholder").children("table").each(function() {
+ placeComments: function(containerId) {
+ var $container = $("#" + containerId);
+ $container.find(".comments-placeholder").children("table").each(function() {
var $lineComments = $(this);
- var id = $lineComments.attr("id");
- var lineId = id.substring("comment-".length);
- var $line = $("#" + lineId);
+ var $line = $container.find("." + $lineComments.attr("data-line"));
var $tr = $("<tr class='line comments'><td colspan='3'></td></tr>").insertAfter($line);
$tr.children().append($lineComments);
$line.find("a.add-comment").hide();
});
},
- beforeAddComment: function(index) {
- var $line = $("#diffline-" + index);
+ beforeAddComment: function(containerId, index) {
+ var $container = $("#" + containerId);
+ var $line = $container.find(".diffline-" + index);
var $tr = $("<tr class='line comments'><td colspan='3'></td></tr>").insertAfter($line);
- var $addComment = $("#add-comment");
+ var $addComment = $container.find("form.add-comment");
var $commentsRow = $addComment.closest("tr.line.comments");
$addComment.find("textarea").val("");
$tr.children().append($addComment);
@@ -24,22 +24,25 @@ gitplex.textdiff = {
pmease.commons.form.trackDirty($addComment);
$line.find("a.add-comment").hide();
},
- afterAddComment: function(index) {
- $("#comments-placeholder").append($("#add-comment"));
- var $line = $("#diffline-" + index);
- $line.next().find("td").append($("#comment-diffline-" + index));
- $("#add-comment").areYouSure({"silent": "true"});
+ afterAddComment: function(containerId, index) {
+ var $container = $("#" + containerId);
+ $container.find(".comments-placeholder").append($container.find("form.add-comment"));
+ var $line = $container.find(".diffline-" + index);
+ $line.next().find("td").append($container.find(".comment-diffline-" + index));
+ $container.find("form.add-comment").areYouSure({"silent": "true"});
},
- cancelAddComment: function(index) {
- $("#comments-placeholder").append($("#add-comment"));
- var $line = $("#diffline-" + index);
+ cancelAddComment: function(containerId, index) {
+ var $container = $("#" + containerId);
+ $container.find(".comments-placeholder").append($container.find("form.add-comment"));
+ var $line = $container.find(".diffline-" + index);
$line.next().remove();
$line.find("a.add-comment").show();
- $("#add-comment").areYouSure({"silent": "true"});
+ $container.find("form.add-comment").areYouSure({"silent": "true"});
},
- afterRemoveComment: function(index) {
- $("#comment-diffline-" + index).closest("tr").remove();
- $("#diffline-" + index).find("a.add-comment").show();
+ afterRemoveComment: function(containerId, index) {
+ var $container = $("#" + containerId);
+ $container.find(".comment-diffline-" + index).closest("tr").remove();
+ $container.find(".diffline-" + index).find("a.add-comment").show();
}
}
\ No newline at end of file