The Unified and Autonomous Development Platform
Diff page with comment ability.
robin shineaa04e56a16f6
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/util/Triple.java b/commons.util/src/main/java/com/pmease/commons/util/Triple.javasimilarity index 97%rename from gitplex.web/src/main/java/com/pmease/gitplex/web/util/Triple.javarename to commons.util/src/main/java/com/pmease/commons/util/Triple.javaindex a64df6d974..4cc091d1ae 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/util/Triple.java+++ b/commons.util/src/main/java/com/pmease/commons/util/Triple.java@@ -1,4 +1,4 @@-package com.pmease.gitplex.web.util;+package com.pmease.commons.util;public class Triple<First, Second, Third> {private final First first;diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.javaindex 6fbd8c1d55..02d2e573ce 100644--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java@@ -35,16 +35,24 @@ public class DiffLine implements Serializable {private final Action action;+ private final int oldLineNo;++ private final int newLineNo;+private final List<Partial> partials;- public DiffLine(Action action, String line) {+ public DiffLine(Action action, String line, int oldLineNo, int newLineNo) {this.action = action;+ this.oldLineNo = oldLineNo;+ this.newLineNo = newLineNo;this.partials = Lists.newArrayList(new Partial(line, false));}- public DiffLine(Action action, List<Partial> partials) {+ public DiffLine(Action action, List<Partial> partials, int oldLineNo, int newLineNo) {this.action = action;this.partials = partials;+ this.oldLineNo = oldLineNo;+ this.newLineNo = newLineNo;}public Action getAction() {@@ -64,6 +72,14 @@ public class DiffLine implements Serializable {return partials;}+ public int getOldLineNo() {+ return oldLineNo;+ }++ public int getNewLineNo() {+ return newLineNo;+ }+@Overridepublic String toString() {StringBuffer buffer = new StringBuffer();diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.javaindex c6e4848975..794e065ba7 100644--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java@@ -10,6 +10,7 @@ import javax.annotation.Nullable;import org.apache.commons.lang3.StringUtils;import com.google.common.base.Preconditions;+import com.pmease.commons.util.Triple;import com.pmease.commons.util.diff.DiffLine.Action;import com.pmease.commons.util.diff.DiffMatchPatch.Diff;@@ -42,19 +43,22 @@ public class DiffUtils {if (partialSplitter != null) {List<DiffLine> processedDiffLines = new ArrayList<>();- List<String> deletions = new ArrayList<>();- List<String> additions = new ArrayList<>();+ List<Triple<String, Integer, Integer>> deletions = new ArrayList<>();+ List<Triple<String, Integer, Integer>> additions = new ArrayList<>();List<DiffLine> processedDeletions = new ArrayList<>();List<DiffLine> processedAdditions = new ArrayList<>();for (DiffLine diffLine: diffLines) {Preconditions.checkState(diffLine.getPartials().size() == 1);if (diffLine.getAction() == DiffLine.Action.DELETE) {- deletions.add(diffLine.getPartials().get(0).getContent());+ deletions.add(new Triple<String, Integer, Integer>(+ diffLine.getPartials().get(0).getContent(), diffLine.getOldLineNo(), diffLine.getNewLineNo()));} else if (diffLine.getAction() == DiffLine.Action.ADD) {- additions.add(diffLine.getPartials().get(0).getContent());+ additions.add(new Triple<String, Integer, Integer>(+ diffLine.getPartials().get(0).getContent(), diffLine.getOldLineNo(), diffLine.getNewLineNo()));} else {process(processedDiffLines, deletions, additions, processedDeletions, processedAdditions, partialSplitter);- processedDiffLines.add(new DiffLine(DiffLine.Action.EQUAL, diffLine.getPartials().get(0).getContent()));+ processedDiffLines.add(new DiffLine(DiffLine.Action.EQUAL, diffLine.getPartials().get(0).getContent(),+ diffLine.getOldLineNo(), diffLine.getNewLineNo()));}}process(processedDiffLines, deletions, additions, processedDeletions, processedAdditions, partialSplitter);@@ -74,25 +78,29 @@ public class DiffUtils {return partials;}- private static void process(List<DiffLine> processedDiffLines, List<String> deletions, List<String> additions,- List<DiffLine> processedDeletions, List<DiffLine> processedAdditions, PartialSplitter partialSplitter) {+ private static void process(List<DiffLine> processedDiffLines, List<Triple<String, Integer, Integer>> deletions,+ List<Triple<String, Integer, Integer>> additions, List<DiffLine> processedDeletions,+ List<DiffLine> processedAdditions, PartialSplitter partialSplitter) {Map<String, List<String>> partialsCache = new HashMap<String, List<String>>();- for (String deletion: deletions) {+ for (Triple<String, Integer, Integer> deletion: deletions) {boolean matching = false;for (int i=0; i<additions.size(); i++) {- String addition = additions.get(i);+ Triple<String, Integer, Integer> addition = additions.get(i);- List<DiffLine> diffPartials = diff(getPartials(deletion, partialSplitter, partialsCache),- getPartials(addition, partialSplitter, partialsCache), null);+ List<DiffLine> diffPartials = diff(getPartials(deletion.getFirst(), partialSplitter, partialsCache),+ getPartials(addition.getFirst(), partialSplitter, partialsCache), null);int equals = 0;for (DiffLine diffPartial: diffPartials) {if (diffPartial.getAction() == DiffLine.Action.EQUAL)equals++;}if (equals*3 >= diffPartials.size()) {- for (int j=0; j<i; j++)- processedAdditions.add(new DiffLine(DiffLine.Action.ADD, additions.get(j)));+ for (int j=0; j<i; j++) {+ Triple<String, Integer, Integer> prevAddition = additions.get(j);+ processedAdditions.add(new DiffLine(DiffLine.Action.ADD, prevAddition.getFirst(),+ prevAddition.getSecond(), prevAddition.getThird()));+ }for (int j=0; j<=i; j++)additions.remove(0);List<Partial> addPartials = new ArrayList<>();@@ -108,18 +116,24 @@ public class DiffUtils {deletePartials.add(new Partial(diffPartial.getPartials().get(0).getContent(), false));}}- processedAdditions.add(new DiffLine(DiffLine.Action.ADD, addPartials));- processedDeletions.add(new DiffLine(DiffLine.Action.DELETE, deletePartials));+ processedAdditions.add(new DiffLine(DiffLine.Action.ADD, addPartials,+ addition.getSecond(), addition.getThird()));+ processedDeletions.add(new DiffLine(DiffLine.Action.DELETE, deletePartials,+ deletion.getSecond(), deletion.getThird()));matching = true;break;}}- if (!matching)- processedDeletions.add(new DiffLine(DiffLine.Action.DELETE, deletion));+ if (!matching) {+ processedDeletions.add(new DiffLine(DiffLine.Action.DELETE,+ deletion.getFirst(), deletion.getSecond(), deletion.getThird()));+ }}- for (String addition: additions)- processedAdditions.add(new DiffLine(DiffLine.Action.ADD, addition));+ for (Triple<String, Integer, Integer> addition: additions) {+ processedAdditions.add(new DiffLine(DiffLine.Action.ADD,+ addition.getFirst(), addition.getSecond(), addition.getThird()));+ }additions.clear();deletions.clear();@@ -215,7 +229,8 @@ public class DiffUtils {DiffChunkBuilder chunkBuilder = null;for (String line : unifiedDiff) {if (line.startsWith("@@")) {- if (chunkBuilder != null) chunks.add(chunkBuilder.build());+ if (chunkBuilder != null)+ chunks.add(chunkBuilder.build());chunkBuilder = new DiffChunkBuilder();line = StringUtils.substringBefore(line.substring(4), " @@");String first = StringUtils.substringBefore(line, " +");@@ -230,13 +245,22 @@ public class DiffUtils {} else {chunkBuilder.start2 = Integer.parseInt(second) - 1;}+ chunkBuilder.current1 = chunkBuilder.start1;+ chunkBuilder.current2 = chunkBuilder.start2;} else if (chunkBuilder != null) {if (line.startsWith("+")) {- chunkBuilder.diffUnits.add(new DiffLine(Action.ADD, line.substring(1)));+ chunkBuilder.diffUnits.add(new DiffLine(Action.ADD, line.substring(1),+ chunkBuilder.current1, chunkBuilder.current2));+ chunkBuilder.current2++;} else if (line.startsWith("-")) {- chunkBuilder.diffUnits.add(new DiffLine(Action.DELETE, line.substring(1)));+ chunkBuilder.diffUnits.add(new DiffLine(Action.DELETE, line.substring(1),+ chunkBuilder.current1, chunkBuilder.current2));+ chunkBuilder.current1++;} else if (line.startsWith(" ")) {- chunkBuilder.diffUnits.add(new DiffLine(Action.EQUAL, line.substring(1)));+ chunkBuilder.diffUnits.add(new DiffLine(Action.EQUAL, line.substring(1),+ chunkBuilder.current1, chunkBuilder.current2));+ chunkBuilder.current1++;+ chunkBuilder.current2++;}}}@@ -277,10 +301,21 @@ public class DiffUtils {private static List<DiffLine> charsToTokens(List<Diff> diffs, List<String> tokenArray) {List<DiffLine> diffTokens = new ArrayList<>();+ int oldLineNo = 0;+ int newLineNo = 0;for (Diff diff : diffs) {for (int i = 0; i < diff.text.length(); i++) {+ Action action = Action.fromOperation(diff.operation);diffTokens.add(new DiffLine(Action.fromOperation(diff.operation),- tokenArray.get(diff.text.charAt(i))));+ tokenArray.get(diff.text.charAt(i)), oldLineNo, newLineNo));+ if (action == Action.ADD) {+ newLineNo ++;+ } else if (action == Action.DELETE) {+ oldLineNo ++;+ } else {+ oldLineNo ++;+ newLineNo ++;+ }}}return diffTokens;@@ -301,10 +336,13 @@ public class DiffUtils {private static class DiffChunkBuilder {private int start1, start2;+ private int current1, current2;+private List<DiffLine> diffUnits = new ArrayList<>();private DiffChunk build() {return new DiffChunk(start1, start2, diffUnits);}}+}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.jsindex 89041fc5cc..f70f61e064 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js@@ -526,6 +526,16 @@ pmease.commons = {},scroll: {+ setupScrollStop: function() {+ var $window = $(window);+ $window.scroll(function() {+ if ($window.data('scrollTimeout')) {+ clearTimeout($window.data('scrollTimeout'));+ }+ $window.data('scrollTimeout', setTimeout("$(window).trigger('scrollStopped');",250));+ });+ },+next: function(fixContainerId, selector, margin) {var next = pmease.commons.scroll.getNext(fixContainerId, selector, margin);if (next != null) {@@ -656,4 +666,5 @@ $(function() {pmease.commons.setupAjaxLoadingIndicator();pmease.commons.form.setupDirtyCheck();pmease.commons.focus.setupAutoFocus();+ pmease.commons.scroll.setupScrollStop();});diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.javaindex a74680c970..6b084058a5 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java@@ -51,13 +51,13 @@ public class ScrollBehavior extends Behavior {elsefunction = "getPrev";- String script = String.format("$(window).scroll(function() {"+ String script = String.format("$(window).on('scrollStopped', function() {"+ "var $component = $('#%s');"+ "if (pmease.commons.scroll.%s('%s', '%s', %d) == null)"+ " $component.attr('disabled', 'disabled');"+ "else "+ " $component.removeAttr('disabled');"- + "}); $(window).trigger('scroll');",+ + "}); $(window).trigger('scrollStopped');",component.getMarkupId(), function, fixContainer.getMarkupId(), selector, margin);response.render(OnDomReadyHeaderItem.forScript(script));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.cssindex 4e3bd6358b..4727a4bc85 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css@@ -773,8 +773,20 @@ h2.section-title { margin: 18px 0; font-size: 16px; }.table-diff .line.content td.text {font-family: Consolas,"Liberation Mono",Menlo,Courier,monospace;color: #333; overflow: visible; white-space: pre;}.table-diff {font-size: 12px; position:relative;}-.table-diff>tbody>tr>td {padding: 0 8px;}-.table-diff>tbody>tr>td.text, .table-diff>tbody>tr>td.new {border-left: 1px solid #E5E5E5;}+.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 {+ border-left: 1px solid #E5E5E5;}+.table-diff .line.comments>td {border-top: 1px solid #E5E5E5; border-bottom: 1px solid #E5E5E5;+ padding: 12px 0;}+.table-diff .line.comments .panel {margin: 0 12px 12px 12px;}+.table-diff .line.comments .panel-heading {color: #999; font-size: 16px;}+.table-diff .line.comments .panel-heading .actions a {margin-left: 8px;}+.table-diff .line.comments .panel-heading a {color: #888;}+.table-diff .line.comments .panel-heading a:hover {color: black;}+.table-diff .line.comments form .actions {padding: 8px 12px;}+.table-diff .line.comments form .actions button {margin-right: 16px;}+.table-diff .line.comments .summary {padding: 12px; vertical-align: top;}+.table-diff .line.comments .detail>a {padding: 0 12px;}.table-diff .old.line.content>td.line-no {background: #faa; color: #8f0000;}.table-diff .old.line.content {background: #fdd;}.table-diff .old.line.content .emphasize {background: #FC9090;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.htmlindex 3433eb477c..0f2347d25a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.html@@ -3,7 +3,7 @@<div wicket:id="tabs" class="tab-head"></div><div class="tab-pane"><div wicket:id="feedback"></div>- <textarea wicket:id="input" class="form-control" placeholder="Leave a comment"></textarea>+ <textarea wicket:id="input" class="form-control focusable" placeholder="Leave a comment"></textarea><div wicket:id="preview" class="preview"></div></div></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.htmlindex 39817a1329..28f63fd6b1 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html@@ -6,16 +6,18 @@<span wicket:id="title" class="panel-title"></span></div><div class="pull-right">- <span wicket:id="diffOptionsTrigger" class="btn btn-sm btn-default">Diff Options <i class="caret"></i></span>+ <span wicket:id="diffOptionsTrigger" class="btn btn-sm btn-default" title="Diff options"><i class="fa fa-gear"></i> <i class="caret"></i></span><div wicket:id="diffOptions"></div></div>- <div class="btn-group pull-right">- <span wicket:id="prevComment" class="btn btn-default btn-sm"><i class="fa fa-arrow-up"></i> Prev Comment</span>- <span wicket:id="nextComment" class="btn btn-default btn-sm"><i class="fa fa-arrow-down"></i> Next Comment</span>+ <div wicket:id="commentActions" class="btn-group pull-right">+ <span wicket:id="prevComment" class="btn btn-default btn-sm comments-nav" title="Previous commented line"><i class="fa fa-arrow-up"></i> <i class="fa fa-comments"></i></span>+ <span wicket:id="nextComment" class="btn btn-default btn-sm comments-nav" title="Next commented line"><i class="fa fa-arrow-down"></i> <i class="fa fa-comments"></i></span>+ <span wicket:id="showComments" class="btn btn-default btn-sm show-comments" title="Show comments"><i class="fa fa-eye-open"></i> <i class="fa fa-comments"></i></span>+ <span wicket:id="hideComments" class="btn btn-default btn-sm hide-comments" title="Hide comments"><i class="fa fa-eye-slash"></i> <i class="fa fa-comments"></i></span></div><div class="btn-group pull-right">- <span wicket:id="prevDiff" class="btn btn-default btn-sm"><i class="fa fa-arrow-up"></i> Prev Diff</span>- <span wicket:id="nextDiff" class="btn btn-default btn-sm"><i class="fa fa-arrow-down"></i> Next Diff</span>+ <span wicket:id="prevDiff" class="btn btn-default btn-sm" title="Previous changed block"><i class="fa fa-arrow-up"></i> <i class="fa fa-diff"></i></span>+ <span wicket:id="nextDiff" class="btn btn-default btn-sm" title="Next changed block"><i class="fa fa-arrow-down"></i> <i class="fa fa-diff"></i></span></div><div class="pull-right"><span wicket:id="identical" class="label label-warning">Identical Content</span>@@ -34,49 +36,48 @@<td class="text"><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td></tr><tr wicket:id="commentsRow" class="line comments">- <div wicket:id="comments">- <div wicket:id="comment"></div>- </div>- <div wicket:id="newComment"></div>+ <td colspan="2" class="summary">+ <i class="fa fa-comment"></i> <span wicket:id="commentCount"></span>+ </td>+ <td class="detail">+ <div wicket:id="comments">+ <div wicket:id="comment"></div>+ </div>+ <a wicket:id="addComment">Add a comment</a>+ <div wicket:id="newComment"></div>+ </td></tr></wicket:container></table></div><wicket:fragment wicket:id="viewCommentFrag"><div class="panel panel-default">- <div class="panel-heading">+ <div class="panel-heading clearfix"><div wicket:id="name" class="pull-left"></div>- <div wicket:id="age" class="pull-right"></div><div class="actions pull-right">- <a wicket:id="edit"><i class="fa fa-pencil"></i></a>- <a wicket:id="delete"><i class="fa fa-times"></i></a>+ <a wicket:id="edit" title="Edit this comment"><i class="fa fa-pencil"></i></a>+ <a wicket:id="delete" title="Delete this comment"><i class="fa fa-times"></i></a></div>+ <div wicket:id="age" class="pull-right small"></div></div>+ <div wicket:id="content" class="panel-body"></div></div></wicket:fragment><wicket:fragment wicket:id="editCommentFrag"><form wicket:id="form"><div wicket:id="input"></div>- <div class="submits">- <div class="pull-left">- <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button>- </div>- <div class="pull-right">- <button wicket:id="save" class="btn btn-sm btn-primary">Update comment</button>- </div>+ <div class="actions">+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Update comment</button>+ <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button></div></form></wicket:fragment><wicket:fragment wicket:id="newCommentFrag"><form wicket:id="form"><div wicket:id="input"></div>- <div class="submits">- <div class="pull-left">- <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button>- </div>- <div class="pull-right">- <button wicket:id="save" class="btn btn-sm btn-primary">Comment on this line</button>- </div>+ <div class="actions">+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Comment on this line</button>+ <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button></div></form></wicket:fragment>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.javaindex c82d4bad7b..8bc82aecfd 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java@@ -23,7 +23,6 @@ import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;-import org.apache.wicket.model.PropertyModel;import com.pmease.commons.git.GitText;import com.pmease.commons.git.GitUtils;@@ -49,6 +48,7 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.permission.ObjectPermission;import com.pmease.gitplex.web.component.comment.CommentInput;import com.pmease.gitplex.web.component.label.AgeLabel;+import com.pmease.gitplex.web.component.markdown.MarkdownPanel;import com.pmease.gitplex.web.component.user.AvatarMode;import com.pmease.gitplex.web.component.user.UserLink;import com.pmease.gitplex.web.model.UserModel;@@ -60,6 +60,16 @@ public class TextDiffPanel extends Panel {private static final int SCROLL_MARGIN = 50;+ private static final String COMMENTS_ROW_ID = "commentsRow";++ private static final String CONTENT_ROW_ID = "contentRow";++ private static final String COMMENT_ACTIONS_ID = "commentActions";++ private static final String NEW_COMMENT_ID = "newComment";++ private static final String HEAD_ID = "head";+private final IModel<Repository> repoModel;private final BlobDiffInfo diffInfo;@@ -72,15 +82,19 @@ public class TextDiffPanel extends Panel {private final IModel<Map<Integer, List<CommitComment>>> newCommentsModel;+ private final IModel<Boolean> allowToAddCommentModel;+private GitText effectiveOldText;private GitText effectiveNewText;private DiffOption diffOption = DiffOption.IGNORE_NOTHING;+ private boolean showComments = true;+private List<DiffLine> diffs;- public TextDiffPanel(String id, IModel<Repository> repoModel,+ public TextDiffPanel(String id, final IModel<Repository> repoModel,BlobDiffInfo diffInfo, GitText oldText, GitText newText) {super(id);@@ -125,6 +139,18 @@ public class TextDiffPanel extends Panel {};+ // cache add comment permission check in model to avoid recalculation for every line+ allowToAddCommentModel = new LoadableDetachableModel<Boolean>() {++ @Override+ protected Boolean load() {+ User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();+ ObjectPermission readPermission = ObjectPermission.ofRepositoryRead(repoModel.getObject());+ return currentUser != null && SecurityUtils.getSubject().isPermitted(readPermission);+ }++ };+onDiffOptionChanged();}@@ -173,7 +199,8 @@ public class TextDiffPanel extends Panel {setOutputMarkupId(true);- WebMarkupContainer head = new WebMarkupContainer("head");+ final WebMarkupContainer head = new WebMarkupContainer(HEAD_ID);+head.add(new StickyBehavior());head.add(new DiffStatBar("diffStat", new AbstractReadOnlyModel<List<DiffLine>>() {@@ -234,8 +261,61 @@ public class TextDiffPanel extends Panel {}.add(new ScrollBehavior(head, ".diff-block", SCROLL_MARGIN, true)));- head.add(new WebMarkupContainer("prevComment").add(new ScrollBehavior(head, ".comments.line", 50, false)));- head.add(new WebMarkupContainer("nextComment").add(new ScrollBehavior(head, ".comments.line", 50, true)));+ // add a separate comment actions container in order not to refresh the whole+ // sticky head when show/hide comment actions (refreshing sticky head via Wicket+ // ajax has some displaying issues)+ WebMarkupContainer commentActions = new WebMarkupContainer(COMMENT_ACTIONS_ID);+ commentActions.setOutputMarkupId(true);++ head.add(commentActions);+ commentActions.add(new WebMarkupContainer("prevComment") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(showComments);+ }++ }.add(new ScrollBehavior(head, ".comments.line", 50, false)));++ commentActions.add(new WebMarkupContainer("nextComment") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(showComments);+ }++ }.add(new ScrollBehavior(head, ".comments.line", 50, true)));++ commentActions.add(new AjaxLink<Void>("showComments") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ showComments(target);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(!showComments);+ }++ });+ commentActions.add(new AjaxLink<Void>("hideComments") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ hideComments(target);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(showComments);+ }++ });MenuPanel diffOptionMenuPanel = new MenuPanel("diffOptions") {@@ -375,43 +455,19 @@ public class TextDiffPanel extends Panel {}) {- private int oldLineNo;-- private int newLineNo;-@Override- protected void onBeforeRender() {- oldLineNo = newLineNo = 0;- super.onBeforeRender();- }-- @Override- protected void populateItem(ListItem<DiffLine> item) {- final DiffLine diffLine = item.getModelObject();- final WebMarkupContainer contentRow = new WebMarkupContainer("contentRow");+ protected void populateItem(ListItem<DiffLine> lineItem) {+ final DiffLine diffLine = lineItem.getModelObject();+ final WebMarkupContainer contentRow = new WebMarkupContainer(CONTENT_ROW_ID);- final WebMarkupContainer commentsRow = new WebMarkupContainer("commentsRow") {-- @Override- protected void onConfigure() {- super.onConfigure();- if (!(get("newComment").getClass() == WebMarkupContainer.class))- setVisible(true);- else- setVisible(((ListView<?>) get("comments")).size() != 0);- }-- };- commentsRow.setOutputMarkupId(true);- commentsRow.add(new ListView<CommitComment>("comments",- new LoadableDetachableModel<List<CommitComment>>() {+ final IModel<List<CommitComment>> lineCommentsModel = new LoadableDetachableModel<List<CommitComment>>() {@Overrideprotected List<CommitComment> load() {- List<CommitComment> oldLineComments = oldCommentsModel.getObject().get(oldLineNo);+ List<CommitComment> oldLineComments = oldCommentsModel.getObject().get(diffLine.getOldLineNo());if (oldLineComments == null)oldLineComments = new ArrayList<>();- List<CommitComment> newLineComments = newCommentsModel.getObject().get(newLineNo);+ List<CommitComment> newLineComments = newCommentsModel.getObject().get(diffLine.getNewLineNo());if (newLineComments == null)newLineComments = new ArrayList<>();@@ -428,21 +484,50 @@ public class TextDiffPanel extends Panel {}}- }) {+ };++ final WebMarkupContainer commentsRow = new WebMarkupContainer(COMMENTS_ROW_ID) {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ if (showComments) {+ if (isAddingComment(this))+ setVisible(true);+ else+ setVisible(!lineCommentsModel.getObject().isEmpty());+ } else {+ setVisible(false);+ }+ }++ };++ commentsRow.setOutputMarkupId(true);+ commentsRow.add(new Label("commentCount", new AbstractReadOnlyModel<Integer> () {++ @Override+ public Integer getObject() {+ return lineCommentsModel.getObject().size();+ }++ }));+ commentsRow.add(new ListView<CommitComment>("comments", lineCommentsModel) {@Override- protected void populateItem(final ListItem<CommitComment> item) {- CommitComment comment = item.getModelObject();+ protected void populateItem(final ListItem<CommitComment> commentItem) {+ CommitComment comment = commentItem.getModelObject();Fragment fragment = new Fragment("comment", "viewCommentFrag", TextDiffPanel.this);- item.add(fragment);- fragment.add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME));+ fragment.setOutputMarkupId(true);+ fragment.add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME_AND_AVATAR));fragment.add(new AgeLabel("age", new AbstractReadOnlyModel<Date>() {@Overridepublic Date getObject() {- return item.getModelObject().getDate();+ return commentItem.getModelObject().getDate();}}));@@ -452,26 +537,33 @@ public class TextDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {Fragment fragment = new Fragment("comment", "editCommentFrag", TextDiffPanel.this);- item.replace(fragment);+ fragment.setOutputMarkupId(true);Form<?> form = new Form<Void>("form");+ form.setOutputMarkupId(true);final CommentInput input;- form.add(input = new CommentInput("input", Model.of(item.getModelObject().getContent())));+ form.add(input = new CommentInput("input", Model.of(commentItem.getModelObject().getContent())));form.add(new AjaxLink<Void>("cancel") {@Overridepublic void onClick(AjaxRequestTarget target) {- commentsRow.replace(new WebMarkupContainer("newComment"));+ commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));target.add(commentsRow);}});form.add(new AjaxSubmitLink("save") {+ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(form);+ }+@Overrideprotected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);- CommitComment comment = item.getModelObject();+ CommitComment comment = commentItem.getModelObject();comment.setDate(new Date());comment.setContent(input.getModelObject());@@ -481,22 +573,26 @@ public class TextDiffPanel extends Panel {});fragment.add(form);- target.add(commentsRow);+ commentItem.replace(fragment);++ target.add(fragment);}@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(item.getModelObject()));+ setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(commentItem.getModelObject()));}});+ final Long commentId = commentItem.getModelObject().getId();fragment.add(new AjaxLink<Void>("delete") {@Overridepublic void onClick(AjaxRequestTarget target) {- GitPlex.getInstance(Dao.class).remove(item.getModelObject());+ Dao dao = GitPlex.getInstance(Dao.class);+ dao.remove(dao.load(CommitComment.class, commentId));target.add(commentsRow);}@@ -504,104 +600,54 @@ public class TextDiffPanel extends Panel {protected void onConfigure() {super.onConfigure();- setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(item.getModelObject()));+ setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(commentItem.getModelObject()));}}.add(new ConfirmBehavior("Do you really want to delete this comment?")));+ fragment.add(new MarkdownPanel("content", Model.of(comment.getContent())));++ commentItem.add(fragment);}});- commentsRow.add(new WebMarkupContainer("newComment"));-- item.add(commentsRow);-- contentRow.add(new AjaxLink<Void>("addComment") {-- private String newComment;-- @Override- public void onClick(AjaxRequestTarget target) {- Fragment frag = new Fragment("newComment", "newCommentFrag", TextDiffPanel.this);- Form<?> form = new Form<Void>("form");- form.add(new CommentInput("input", new PropertyModel<String>(this, "newComment")));-- form.add(new AjaxLink<Void>("cancel") {-- @Override- public void onClick(AjaxRequestTarget target) {- commentsRow.replace(new WebMarkupContainer("newComment"));- target.add(commentsRow);- }-- });- form.add(new AjaxSubmitLink("save") {-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);- CommitComment comment = new CommitComment();- comment.setRepository(repoModel.getObject());- comment.setUser(GitPlex.getInstance(UserManager.class).getCurrent());- String commit;- if (diffLine.getAction() == DiffLine.Action.ADD- || diffLine.getAction() == DiffLine.Action.EQUAL) {- commit = diffInfo.getNewRevision();- comment.setFile(diffInfo.getNewPath());- } else {- commit = diffInfo.getOldRevision();- comment.setFile(diffInfo.getOldPath());- }- comment.setCommit(commit);- comment.setContent(newComment);- comment.setDate(new Date());-- GitPlex.getInstance(Dao.class).persist(comment);-- commentsRow.replace(new WebMarkupContainer("newComment"));- target.add(commentsRow);- }-- });- frag.add(form);- commentsRow.replace(frag);- if (!commentsRow.isVisible()) {- String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",- commentsRow.getMarkupId(), contentRow.getMarkupId());- target.prependJavaScript(script);- }- target.add(commentsRow);- }+ commentsRow.add(new AddCommentLink("addComment", lineItem) {@Overrideprotected void onConfigure() {super.onConfigure();- User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();- ObjectPermission readPermission = ObjectPermission.ofRepositoryRead(repoModel.getObject());- setVisible(currentUser != null && SecurityUtils.getSubject().isPermitted(readPermission));+ if (isVisible() && isAddingComment(commentsRow))+ setVisible(false);}});++ commentsRow.add(new WebMarkupContainer(NEW_COMMENT_ID));++ lineItem.add(commentsRow);++ contentRow.add(new AddCommentLink("addComment", lineItem));+if (diffLine.getAction() == DiffLine.Action.ADD) {- if (item.getIndex() == 0 || diffs.get(item.getIndex()-1).getAction() == DiffLine.Action.EQUAL)+ if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == DiffLine.Action.EQUAL)contentRow.add(AttributeAppender.append("class", " new diff-block"));elsecontentRow.add(AttributeAppender.append("class", " new"));contentRow.add(new Label("oldLineNo"));- contentRow.add(new Label("newLineNo", "+ " + (++newLineNo)));+ contentRow.add(new Label("newLineNo", "+ " + (diffLine.getNewLineNo()+1)));} else if (diffLine.getAction() == DiffLine.Action.DELETE) {- if (item.getIndex() == 0 || diffs.get(item.getIndex()-1).getAction() == DiffLine.Action.EQUAL)+ if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == DiffLine.Action.EQUAL)contentRow.add(AttributeAppender.append("class", " old diff-block"));elsecontentRow.add(AttributeAppender.append("class", " old"));- contentRow.add(new Label("oldLineNo", "- " + (++oldLineNo)));+ contentRow.add(new Label("oldLineNo", "- " + (diffLine.getOldLineNo()+1)));contentRow.add(new Label("newLineNo"));} else {contentRow.add(AttributeAppender.append("class", " equal"));- contentRow.add(new Label("oldLineNo", " " + (++oldLineNo)));- contentRow.add(new Label("newLineNo", " " + (++newLineNo)));+ contentRow.add(new Label("oldLineNo", " " + (diffLine.getOldLineNo()+1)));+ contentRow.add(new Label("newLineNo", " " + (diffLine.getNewLineNo()+1)));}contentRow.add(new ListView<Partial>("partials", diffLine.getPartials()) {@@ -621,17 +667,125 @@ public class TextDiffPanel extends Panel {});contentRow.setOutputMarkupId(true);- item.add(contentRow);+ lineItem.add(contentRow);}});}+ private void showComments(AjaxRequestTarget target) {+ showComments = true;+ target.add(get(HEAD_ID).get(COMMENT_ACTIONS_ID));++ target.appendJavaScript("$('.comments.line').show();");+ }++ private void hideComments(AjaxRequestTarget target) {+ showComments = false;+ target.add(get(HEAD_ID).get(COMMENT_ACTIONS_ID));++ target.appendJavaScript("$('.comments.line').hide();");+ }++ private boolean isAddingComment(WebMarkupContainer commentsRow) {+ return commentsRow.get(NEW_COMMENT_ID) instanceof Fragment;+ }++ private class AddCommentLink extends AjaxLink<Void> {++ private ListItem<DiffLine> item;++ public AddCommentLink(String id, ListItem<DiffLine> item) {+ super(id);+ this.item = item;+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ if (!showComments)+ showComments(target);++ Fragment frag = new Fragment(NEW_COMMENT_ID, "newCommentFrag", TextDiffPanel.this);+ Form<?> form = new Form<Void>("form");+ form.setOutputMarkupId(true);++ final CommentInput input;+ form.add(input = new CommentInput("input", Model.of("")));++ final WebMarkupContainer contentRow = (WebMarkupContainer) item.get(CONTENT_ROW_ID);+ final WebMarkupContainer commentsRow = (WebMarkupContainer) item.get(COMMENTS_ROW_ID);+ final DiffLine diffLine = item.getModelObject();++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));+ target.add(commentsRow);+ }++ });+ form.add(new AjaxSubmitLink("save") {++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(form);+ }++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);+ CommitComment comment = new CommitComment();+ comment.setRepository(repoModel.getObject());+ comment.setUser(GitPlex.getInstance(UserManager.class).getCurrent());+ String commit;+ if (diffLine.getAction() == DiffLine.Action.ADD+ || diffLine.getAction() == DiffLine.Action.EQUAL) {+ commit = diffInfo.getNewRevision();+ comment.setFile(diffInfo.getNewPath());+ comment.setLine(diffLine.getNewLineNo());+ } else {+ commit = diffInfo.getOldRevision();+ comment.setFile(diffInfo.getOldPath());+ comment.setLine(diffLine.getOldLineNo());+ }+ comment.setCommit(commit);+ comment.setContent(input.getModelObject());+ comment.setDate(new Date());++ GitPlex.getInstance(Dao.class).persist(comment);++ commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));+ target.add(commentsRow);+ }++ });+ frag.add(form);+ commentsRow.replace(frag);+ if (!commentsRow.isVisible()) {+ String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",+ commentsRow.getMarkupId(), contentRow.getMarkupId());+ target.prependJavaScript(script);+ commentsRow.setVisible(true);+ }+ target.add(commentsRow);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(allowToAddCommentModel.getObject());+ }++ }+@Overrideprotected void onDetach() {oldCommentsModel.detach();newCommentsModel.detach();super.onDetach();}-+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/util/UniTriple.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/util/UniTriple.javadeleted file mode 100644index 5445e9272a..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/util/UniTriple.java+++ /dev/null@@ -1,13 +0,0 @@-package com.pmease.gitplex.web.util;--/**- * Three elements of the same type- * if only java had tuples...- *- * @param <T>- */-public class UniTriple<T> extends Triple<T,T,T> {- public UniTriple(T t, T t1, T t2) {- super(t, t1, t2);- }-}