Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine3324501e971d
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 35747a0874..c6aede4b2a 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
@@ -11,26 +11,12 @@
<wicket:container wicket:id="diffLines"></wicket:container>
</table>
</div>
- <div class="comments-placeholder hidden">
- <table wicket:id="lines" class="comments">
- <tr wicket:id="comments">
- <td class="avatar">
- <div wicket:id="avatar"></div>
- </td>
- <td class="comment">
- <div wicket:id="comment"></div>
- </td>
- </tr>
- </table>
- </div>
- <wicket:fragment wicket:id="addCommentFrag">
- <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">
- <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>
- </wicket:fragment>
+ <form wicket:id="newComments" class="hidden 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>
</wicket:panel>
\ No newline at end of file
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 76d74b89c3..6b6fbd201e 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
@@ -11,6 +11,8 @@ import org.apache.wicket.Component;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
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.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
@@ -18,14 +20,18 @@ import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.util.time.Duration;
import com.pmease.commons.git.BlobChange;
import com.pmease.commons.lang.diff.DiffBlock;
@@ -35,9 +41,12 @@ import com.pmease.commons.lang.diff.LineModification;
import com.pmease.commons.lang.diff.TokenDiffBlock;
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.InlineCommentSupport;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.Constants;
+import com.pmease.gitplex.web.component.comment.CommentInput;
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;
@@ -60,6 +69,8 @@ public class TextDiffPanel extends Panel {
private AbstractDefaultAjaxBehavior addCommentBehavior;
+ private RepeatingView newComments;
+
public TextDiffPanel(String id, IModel<Repository> repoModel, BlobChange change, DiffMode diffMode,
@Nullable InlineCommentSupport commentSupport) {
super(id);
@@ -128,18 +139,41 @@ public class TextDiffPanel extends Panel {
int oldLineNo = params.getParameterValue("oldLineNo").toInt();
int newLineNo = params.getParameterValue("newLineNo").toInt();
- String script;
- if (oldLineNo != -1 && newLineNo != -1) {
- script = String.format("gitplex.textdiff.beforeAddComments('%s', %d, %d);",
- getMarkupId(), oldLineNo, newLineNo);
- } else if (oldLineNo != -1) {
- script = String.format("gitplex.textdiff.beforeAddComments('%s', %d, undefined);",
- getMarkupId(), oldLineNo);
- } else {
- script = String.format("gitplex.textdiff.beforeAddComments('%s', undefined, %d);",
- getMarkupId(), newLineNo);
- }
+ Form<?> newComment = new Form<Void>(newComments.newChildId());
+ newComment.setOutputMarkupId(true);
+
+ final CommentInput input;
+ newComment.add(input = new CommentInput("input", Model.of("")));
+ input.setRequired(true);
+ newComment.add(new FeedbackPanel("feedback", input).hideAfter(Duration.seconds(5)));
+
+ newComment.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ }
+
+ }.add(new DirtyIgnoreBehavior()));
+ newComment.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);
+ }
+
+ }.add(new DirtyIgnoreBehavior()));
+
+ newComments.add(newComment);
+ target.add(newComment);
+ String script = String.format("gitplex.textdiff.placeNewComment('%s', '%s', %d, %d);",
+ getMarkupId(), newComment.getMarkupId(), oldLineNo, newLineNo);
target.appendJavaScript(script);
}
@@ -155,6 +189,8 @@ public class TextDiffPanel extends Panel {
});
+ add(newComments = new RepeatingView("newComments"));
+
setOutputMarkupId(true);
}
@@ -286,8 +322,8 @@ public class TextDiffPanel extends Panel {
}
private String getAddCommentLink(int oldLineNo, int newLineNo) {
- return String.format("<a class='add-comment' "
- + "href='javascript: document.getElementById('%s').addComment(%d, %d);'></a>",
+ return String.format("<span class='add-comment'><a class='add-comment' "
+ + "href=\"javascript: document.getElementById('%s').addComment(%d, %d);\"><i class='fa fa-plus'></i></a></span>",
getMarkupId(), oldLineNo, newLineNo);
}
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 bde6afcfde..400534ce37 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
@@ -19,7 +19,7 @@
table-layout: fixed;
}
.text-diff>.body>tbody>tr>td.number {
- padding: 0 8px;
+ padding: 0 10px 0 8px;
border-left: 1px solid #EEE;
border-right: 1px solid #EEE;
text-align: right;
@@ -87,8 +87,45 @@
}
.text-diff>.body>tbody>tr>td.content>.operation {
font-weight: bold;
- margin: 0 2px 0 4px;
+ margin: 0 2px 0 10px;
}
.text-diff>.body>tbody>tr.expanded>td {
background: #F9F9F9;
}
+.text-diff>.body>tbody>tr>td.content>span.add-comment {
+ position: relative;
+ display: inline-block;
+}
+.text-diff>.body>tbody>tr>td.content>span.add-comment>a {
+ display: none;
+ position: absolute;
+ left: -8px;
+ border-radius: 3px;
+ color: white;
+ background: #087AD8;
+ z-index: 100;
+ line-height: 14px;
+ padding: 1px 2px;
+ text-decoration: none;
+}
+.text-diff>.body>tbody>tr>td.content>span.add-comment>a {
+ display: none;
+ position: absolute;
+ left: -8px;
+ border-radius: 3px;
+ color: white;
+ background: #087AD8;
+ z-index: 100;
+ line-height: 14px;
+ padding: 1px 2px;
+ text-decoration: none;
+}
+.text-diff>.body>tbody>tr>td.content>span.add-comment>a:hover {
+ font-size: 16px;
+ left: -9px;
+ top: -1px;
+ padding-top: 2px;
+}
+.text-diff>.body>tbody>tr:hover>td.content>span.add-comment>a {
+ display: block;
+}
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 4e2e1f0e99..9aede67916 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
@@ -11,11 +11,11 @@ gitplex.textdiff = {
$line.find("a.add-comment").hide();
});
},
- beforeAddComments: function(containerId, oldLineNo, newLineNo) {
+ placeNewComment: function(containerId, newCommentId, oldLineNo, newLineNo) {
var $container = $("#" + containerId);
var $content;
- if (newLineNo)
+ if (newLineNo != -1)
$content = $container.find(".new" + newLineNo);
else
$content = $container.find(".old" + oldLineNo);
@@ -31,23 +31,14 @@ gitplex.textdiff = {
else
$commentLine.append("<td colspan='2'>&nbsp;</td><td colspan='2' class='content'></td>");
- var $addComment = $container.find("form.add-comment");
-
- var $prevCommentLine = $addComment.closest(".line");
- $addComment.find("textarea").val("");
- $commentLine.children(".content").append($addComment);
-
- $prevCommentLine.prev().find("a.add-comment").show();
- $prevCommentLine.remove();
- $addComment.find("textarea").focus();
- pmease.commons.form.trackDirty($addComment);
+ var $newComment = $("#" + newCommentId);
+ $commentLine.children(".content").replaceWith($newComment);
+ $newComment.removeClass("hidden");
$line.find("a.add-comment").hide();
},
- afterAddComments: function(index) {
- $("#comments-placeholder").append($("#add-comment"));
+ afterAddComment: function(index) {
var $line = $("#diffline-" + index);
$line.next().find("td").append($("#comment-diffline-" + index));
- $("#add-comment").areYouSure({"silent": "true"});
},
cancelAddComments: function(index) {
$("#comments-placeholder").append($("#add-comment"));
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 94f4711367..ed4332b2f3 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,5 @@
<wicket:extend>
- <input wicket:id="date"></input>
+ <form wicket:id="list">
+ <span wicket:id="name"></span>
+ </form>
</wicket:extend>
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 b83211a11f..1e674295ad 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,8 +1,10 @@
package com.pmease.gitplex.web.page.test;
-import com.pmease.gitplex.web.page.base.BasePage;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.RepeatingView;
-import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.DateTextField;
+import com.pmease.gitplex.web.page.base.BasePage;
@SuppressWarnings("serial")
public class TestPage extends BasePage {
@@ -10,8 +12,13 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
-
- add(new DateTextField("date"));
+
+ RepeatingView repeatingView = new RepeatingView("list");
+ WebMarkupContainer child = new WebMarkupContainer(repeatingView.newChildId());
+ child.add(new Label("name", "robin"));
+ child.setOutputMarkupId(true);
+ repeatingView.add(child);
+ add(repeatingView);
}
}