The Unified and Autonomous Development Platform
midwork
robin shineb56055953f6e
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.javaindex 12f48ffe4b..293afda59f 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java@@ -5,6 +5,8 @@ import com.pmease.commons.lang.diff.AroundContext;public interface InlineComment extends Comment {+ public static final int CONTEXT_SIZE = 7;+BlobIdent getBlobIdent();int getLine();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.javaindex d53f1144c8..8ac6b18e48 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java@@ -12,7 +12,6 @@ public class Constants {/* diff constants */public static final int DIFF_DEFAULT_CONTEXT_SIZE = 3;- public static final int LINE_COMMENT_CONTEXT_SIZE = 7;public static final int DIFF_EXPAND_CONTEXT_SIZE = 15;public static final int MAX_DIFF_FILES = 500;public static final int MAX_SINGLE_FILE_DIFF_LINES = 5000;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.cssindex ed4662df54..f39689ddfe 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.css@@ -11,13 +11,9 @@background: #FCF6D6;}-div.replies {- padding-top: 8px;- padding-left: 16px;-}div.replies>table>tbody>tr>td {border-top: 1px dashed #CCC;- padding: 8px 0 8px 0;+ padding: 8px 0;background: #F5F5F5;}div.replies>table>tbody>tr:first-child>td {@@ -25,12 +21,15 @@ div.replies>table>tbody>tr:first-child>td {}div.replies>table>tbody>tr>td.avatar {width: 1px;- padding: 10px;+ padding-left: 10px;}div.replies>table>tbody>tr>td.avatar img {width: 26px;height: 26px;}+div.replies>table>tbody>tr>td.detail {+ padding-left: 10px;+}div.replies>.add-reply {padding-top: 10px;color: #999;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.htmlindex 127e44d4f0..80b9f4ee5a 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@@ -8,19 +8,18 @@</div></div><table class="body"><wicket:container wicket:id="diffLines"></wicket:container></table>- </div>- <form wicket:id="newComments" class="new-comment leave-confirm">- <textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>- <div wicket:id="feedback"></div>- <div class="actions">- <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware leave-confirm">Comment on this line</button>- <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button>- </div>- </form>- <div class="comments hidden">+ <form wicket:id="newComments" class="new-comment leave-confirm">+ <textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>+ <div wicket:id="feedback"></div>+ <div class="actions">+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware leave-confirm">Comment on this line</button>+ <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button>+ </div>+ </form><div wicket:id="comments" class="comment clearfix"><div wicket:id="avatar" class="avatar pull-left"></div>- <div wicket:id="detail" class="detail pull-left"></div>+ <div wicket:id="detail" class="detail"></div></div>+ <script wicket:id="script" type="text/javascript"></script></div></wicket:panel>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex 362f7302c8..78f90b1b89 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@@ -17,17 +17,11 @@ import org.apache.wicket.ajax.attributes.CallbackParameter;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.behavior.Behavior;-import org.apache.wicket.event.Broadcast;import org.apache.wicket.event.IEvent;-import org.apache.wicket.event.IEventSink;-import org.apache.wicket.markup.ComponentTag;-import org.apache.wicket.markup.MarkupStream;import org.apache.wicket.markup.head.CssHeaderItem;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptHeaderItem;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;-import org.apache.wicket.markup.html.WebComponent;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.Form;@@ -38,7 +32,6 @@ import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;import org.apache.wicket.request.IRequestParameters;-import org.apache.wicket.request.component.IRequestablePage;import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.mapper.parameter.PageParameters;import org.apache.wicket.request.resource.CssResourceReference;@@ -57,15 +50,20 @@ import com.pmease.commons.lang.tokenizers.CmToken;import com.pmease.commons.util.StringUtils;import com.pmease.commons.wicket.behavior.DirtyIgnoreBehavior;import com.pmease.commons.wicket.component.feedback.FeedbackPanel;+import com.pmease.gitplex.core.comment.Comment;import com.pmease.gitplex.core.comment.InlineComment;import com.pmease.gitplex.core.comment.InlineCommentSupport;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.Constants;+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.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.diff.revision.DiffMode;+import com.pmease.gitplex.web.component.userlink.UserLink;+import com.pmease.gitplex.web.model.UserModel;import com.pmease.gitplex.web.page.repository.file.RepoFilePage;import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;@@ -88,32 +86,36 @@ public class TextDiffPanel extends Panel {@Overrideprotected List<DiffComment> load() {List<DiffComment> comments = new ArrayList<>();- for (Map.Entry<Integer, List<InlineComment>> entry:+ if (commentSupport != null) {+ for (Map.Entry<Integer, List<InlineComment>> entry:commentSupport.getComments(change.getOldBlobIdent()).entrySet()) {- for (InlineComment inline: entry.getValue()) {- DiffComment comment = new DiffComment();- comment.inline = inline;- comment.oldLineNo = entry.getKey();- comment.newLineNo = -1;+ for (InlineComment inline: entry.getValue()) {+ DiffComment comment = new DiffComment();+ comment.inline = inline;+ comment.oldLineNo = entry.getKey();+ comment.newLineNo = -1;+ comments.add(comment);+ }}- }- for (Map.Entry<Integer, List<InlineComment>> entry:- commentSupport.getComments(change.getNewBlobIdent()).entrySet()) {- for (InlineComment inline: entry.getValue()) {- DiffComment comment = new DiffComment();- comment.inline = inline;- comment.oldLineNo = -1;- comment.newLineNo = entry.getKey();+ for (Map.Entry<Integer, List<InlineComment>> entry:+ commentSupport.getComments(change.getNewBlobIdent()).entrySet()) {+ for (InlineComment inline: entry.getValue()) {+ DiffComment comment = new DiffComment();+ comment.inline = inline;+ comment.oldLineNo = -1;+ comment.newLineNo = entry.getKey();+ comments.add(comment);+ }}+ Collections.sort(comments, new Comparator<DiffComment>() {++ @Override+ public int compare(DiffComment comment1, DiffComment comment2) {+ return comment1.inline.getDate().compareTo(comment2.inline.getDate());+ }++ });}- Collections.sort(comments, new Comparator<DiffComment>() {-- @Override- public int compare(DiffComment comment1, DiffComment comment2) {- return comment1.inline.getDate().compareTo(comment2.inline.getDate());- }-- });return comments;}@@ -234,27 +236,25 @@ public class TextDiffPanel extends Panel {lineNo = newLineNo;}commentContext = DiffUtils.around(change.getDiffBlocks(), oldLineNo, newLineNo,- Constants.LINE_COMMENT_CONTEXT_SIZE);+ InlineComment.CONTEXT_SIZE);commentSupport.addComment(commentAt, compareWith, commentContext,lineNo, input.getModelObject());- Component commentsRow = newCommentsRow(comments.newChildId(), index);- comments.add(commentsRow);- target.add(commentsRow);+ Component commentRow = newCommentRow(commentRows.newChildId(), commentsModel.getObject().size()-1);+ commentRows.add(commentRow);+ commentRow.setMarkupId(newCommentForm.getMarkupId());+ newCommentForm.remove();- String prependScript = String.format("$('#comments-placeholder').append('<table id=\"%s\"></table>')",- commentsRow.getMarkupId());- target.prependJavaScript(prependScript);- target.appendJavaScript(String.format("gitplex.textdiff.afterAddComment(%d);", index));+ target.add(commentRow);}}.add(new DirtyIgnoreBehavior()));newCommentForms.add(newCommentForm);- String script = String.format("gitplex.textdiff.beforeAddComment('%s', '%s', %d, %d);",- getMarkupId(), newCommentForm.getMarkupId(), oldLineNo, newLineNo);+ String script = String.format("gitplex.textdiff.placeComment($('#%s'), %d, %d, $('<div id=\"%s\"></div>'));",+ getMarkupId(), oldLineNo, newLineNo, newCommentForm.getMarkupId());target.prependJavaScript(script);target.add(newCommentForm);@@ -273,6 +273,20 @@ public class TextDiffPanel extends Panel {});add(newCommentForms = new RepeatingView("newComments"));++ commentRows = new RepeatingView("comments");++ for (int i=0; i<commentsModel.getObject().size(); i++)+ commentRows.add(newCommentRow(commentRows.newChildId(), i));++ add(commentRows);++ // do not call init script via onDomReady as otherwise there will be a noticeable delay+ // between displaying diffs and comments if there are many diff files+ CharSequence addCommentCallback = addCommentBehavior.getCallbackFunction(+ CallbackParameter.explicit("oldLineNo"), CallbackParameter.explicit("newLineNo"));+ String script = String.format("gitplex.textdiff.init('%s', %s);", getMarkupId(), addCommentCallback);+ add(new Label("script", script).setEscapeModelStrings(false));setOutputMarkupId(true);}@@ -320,12 +334,6 @@ public class TextDiffPanel extends Panel {new WebjarsCssResourceReference("codemirror/current/theme/eclipse.css")));response.render(CssHeaderItem.forReference(new CssResourceReference(TextDiffPanel.class, "text-diff.css")));-- CharSequence addCommentCallback = addCommentBehavior.getCallbackFunction(- CallbackParameter.explicit("oldLineNo"), CallbackParameter.explicit("newLineNo"));- String script = String.format("document.getElementById('%s').addComment=%s;",- getMarkupId(), addCommentCallback);- response.render(OnDomReadyHeaderItem.forScript(script));}private String renderDiffs() {@@ -405,10 +413,12 @@ public class TextDiffPanel extends Panel {}private void appendAddComment(StringBuilder builder, int oldLineNo, int newLineNo) {- builder.append("<span class='add-comment'>");- String script = String.format("document.getElementById('%s').addComment(%d, %d);",- getMarkupId(), oldLineNo, newLineNo);- builder.append("<a href=\"javascript:").append(script).append("\">").append("<i class='fa fa-plus'></i></a></span>");+ if (commentSupport != null) {+ builder.append("<span class='add-comment'>");+ String script = String.format("document.getElementById('%s').addComment(%d, %d);",+ getMarkupId(), oldLineNo, newLineNo);+ builder.append("<a href=\"javascript:").append(script).append("\">").append("<i class='fa fa-plus'></i></a></span>");+ }}private void appendEqual(StringBuilder builder, DiffBlock block, int lineIndex, int lastContextSize) {@@ -580,21 +590,8 @@ public class TextDiffPanel extends Panel {builder.append("</tr>");}- private Component newCommentRows() {- commentRows = new RepeatingView("commentLines");-- if (commentSupport != null) {- for (int index: commentSupport.getComments(blobIdent).keySet())- commentRows.add(newCommentsRow(commentsView.newChildId(), index));- for (int index: commentSupportsModel.getObject().keySet())- commentRows.add(newCommentsRow(commentsView.newChildId(), index));- }-- return commentRows;- }-- private Component newCommentRow(String id, final int oldLineNo, final int newLineNo) {- WebMarkupContainer row = new WebMarkupContainer(commentLines.newChildId()) {+ private Component newCommentRow(String id, final int index) {+ WebMarkupContainer row = new WebMarkupContainer(id) {@Overridepublic void onEvent(IEvent<?> event) {@@ -603,43 +600,32 @@ public class TextDiffPanel extends Panel {if (event.getPayload() instanceof CommentRemoved) {CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();commentRows.remove(this);- String script = String.format("$('#%s').closest('tr').remove();",- TextDiffPanel.this.getMarkupId(), oldLineNo, newLineNo);+ String script = String.format("$('#%s').closest('tr.line').remove();", getMarkupId());commentRemoved.getTarget().appendJavaScript(script);}}};- row.setOutputMarkupId(true);- row.setMarkupId("comment-diffline-" + index);+ DiffComment comment = commentsModel.getObject().get(index);- row.add(new ListView<InlineComment>("comments", new LoadableDetachableModel<List<InlineComment>>() {-- @Override- protected List<InlineComment> load() {- return commentsModel.getObject().get(index);- }-- }) {+ row.add(new UserLink("avatar", new UserModel(comment.inline.getUser()), AvatarMode.AVATAR));+ row.add(new CommentPanel("detail", new LoadableDetachableModel<Comment>() {@Override- protected void populateItem(ListItem<InlineComment> item) {- item.add(new UserLink("avatar", new UserModel(item.getModelObject().getUser()), AvatarMode.AVATAR));- item.add(new CommentPanel("comment", item.getModel()).setOutputMarkupId(true));- if (item.getModelObject().equals(commentSupport.getConcernedComment()))- item.add(AttributeAppender.append("class", " concerned"));+ protected Comment load() {+ return commentsModel.getObject().get(index).inline;}- });+ }));- return row;- }-- @Override- protected void onBeforeRender() {- replace(newCommentLines());+ if (comment.inline.equals(commentSupport.getConcernedComment()))+ row.add(AttributeAppender.append("class", " concerned"));+ row.add(AttributeAppender.append("data-oldLineNo", comment.oldLineNo));+ row.add(AttributeAppender.append("data-newLineNo", comment.newLineNo));- super.onBeforeRender();+ row.setOutputMarkupId(true);++ return row;}@Overridediff --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.cssindex 22eefe7a2f..fc6d6b8803 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@@ -46,6 +46,12 @@.text-diff>.body>tbody>tr>td:FIRST-CHILD {border-left: none !important;}+.text-diff>.body>tbody>tr:FIRST-CHILD>td {+ border-top: none !important;+}+.text-diff>.body>tbody>tr:LAST-CHILD>td {+ border-bottom: none !important;+}.text-diff>.body>tbody>tr.expander>td.skipped {padding: 6px 16px;border-left: 1px solid #D8E2F2;@@ -140,16 +146,22 @@.text-diff>.body>tbody>tr>td.number:hover+.number+.content>span.add-comment {display: inline-block;}-.text-diff>.body>tbody>tr.comments>td.content.comments {+.text-diff>.body>tbody>tr.comment>td.content.comment {white-space: normal;word-wrap: normal;padding: 12px;- border-top: 1px solid #EEE;- border-bottom: 1px solid #EEE;+ border-top: 1px solid #DDD;+ border-bottom: 1px solid #DDD;}-.text-diff>.body>tbody>tr:FIRST-CHILD>td {- border-top: none !important;+.text-diff>.body>tbody>tr.comment>td.content.comment>div>.detail {+ margin-left: 36px;+ font-size: 14px;+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;}-.text-diff>.body>tbody>tr:LAST-CHILD>td {- border-bottom: none !important;+.text-diff>.body>tbody>tr.comment>td.content.comment>div>.avatar img {+ width: 28px;+ height: 28px;}+.text-diff>.comment {+ display: none;+}\ No newline at end of filediff --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.jsindex 2a671de4e9..3bf4c90176 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,19 +1,14 @@gitplex.textdiff = {- placeComments: function(containerId) {+ init: function(containerId, addCommentCallback) {var $container = $("#" + containerId);- $("#comments-placeholder").children("table").each(function() {- var $lineComments = $(this);- var id = $lineComments.attr("id");- var lineId = id.substring("comment-".length);- var $line = $("#" + lineId);- var $tr = $("<tr class='line comments'><td colspan='3'></td></tr>").insertAfter($line);- $tr.children().append($lineComments);- $line.find("a.add-comment").hide();+ $container[0].addComment = addCommentCallback;+ $container.find(">.text-diff>.comment").each(function() {+ var oldLineNo = $(this).data("oldlineno");+ var newLineNo = $(this).data("newlineno");+ gitplex.textdiff.placeComment($container, oldLineNo, newLineNo, $(this));});},- beforeAddComment: function(containerId, commentId, oldLineNo, newLineNo) {- var $container = $("#" + containerId);-+ placeComment: function($container, oldLineNo, newLineNo, $comment) {var $content;if (newLineNo != -1)$content = $container.find(".content.new" + newLineNo);@@ -21,23 +16,20 @@ gitplex.textdiff = {$content = $container.find(".content.old" + oldLineNo);var $line = $content.closest(".line");- while ($line.next().hasClass("comment"))- $line = $line.next();+ var $lastLine = $line;+ while ($lastLine.next().hasClass("comment"))+ $lastLine = $lastLine.next();- var $commentLine = $("<tr class='line comment'></tr>").insertAfter($line);+ var $commentLine = $("<tr class='line comment'></tr>").insertAfter($lastLine);if ($line.children().length == 3)$commentLine.append("<td colspan='3' class='content comment'></td>");- else if (oldLineNo != -1 && newLineNo != -1)+ else if (!$content.hasClass("old") && !$content.hasClass("new"))$commentLine.append("<td colspan='4' class='content comment'></td>");- else if (oldLineNo != -1)- $commentLine.append("<td colspan='2' class='content comment'></td><td class='number'> </td><td class='content'> </td>");- else+ else if (newLineNo != -1)$commentLine.append("<td class='number'> </td><td class='content'> </td><td colspan='2' class='content comment'></td>");-- $commentLine.children(".content.comment").append("<div id=" + commentId + "></div>");- },- afterAddComment: function(index) {- var $line = $("#diffline-" + index);- $line.next().find("td").append($("#comment-diffline-" + index));+ else+ $commentLine.append("<td colspan='2' class='content comment'></td><td class='number'> </td><td class='content'> </td>");++ $commentLine.children(".content.comment").append($comment);}}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.htmlindex 25532b7a62..91c7821795 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/NewRequestPage.html@@ -19,7 +19,7 @@</table><div wicket:id="status" class="status"></div><ul wicket:id="tabs" class="nav nav-tabs"></ul>- <div wicket:id="tabPanel"></div>+ <div wicket:id="tabPanel" class="tab-panel"></div><div wicket:id="backToTop"></div></div></div>@@ -109,7 +109,7 @@</div></wicket:fragment><wicket:fragment wicket:id="compareFrag">- <div wicket:id="diffOption"></div>+ <div wicket:id="diffOption" class="diff-option"></div><div wicket:id="revisionDiff"></div></wicket:fragment></wicket:extend>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/new-request.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/new-request.cssindex 06b2b4a091..f6e6de4514 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/new-request.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/newrequest/new-request.css@@ -76,9 +76,8 @@#new-request>.body>.nav-tabs {margin-bottom: 16px;}-#new-request .diff-option {+#new-request>.body>.tab-panel>.diff-option {padding: 8px;- display: block;background: #F2F2F2;border: 1px solid #DDD;z-index: 200;