Skip to content

The Unified and Autonomous Development Platform

Make commit comment more re-usable

steve8b6ec769adb0
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
index 234ed8b7e1..cca96f8e18 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/assets/css/page.css
@@ -560,24 +560,27 @@ a.diffstat:hover { text-decoration: none; }
.diff-line .add-comment .icon { line-height: 20px; }
.diff-line .add-comment:hover { text-decoration: none; }
-.table-diff .inline-comment-holder { background: #f1eae0; }
+.table-diff .inline-comment-holder { background: #fffcf5; }
.table-diff .inline-comment-holder td { border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; }
.inline-comment-holder td.comment-count { border-right: 1px solid #ddd; text-align: center; vertical-align: top; padding-top: 10px; }
.inline-comment-holder td.line-comment { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; }
.form-comment { margin-top: 10px; }
-.form-comment .head { padding: 0; }
-.form-comment .head .nav-tabs { padding-left: 18px; }
-.form-comment .body { background: white; padding: 12px; }
-.form-comment textarea { display: block; width: 100%; resize: vertical; padding: 10px; min-height: 100px; border-color: #aaa; }
+.form-comment .comment-editor-head { padding: 0; }
+.form-comment .comment-editor-head .nav-tabs { padding-left: 18px; }
+.form-comment .comment-editor-body { background: white; padding: 12px; }
+.form-comment textarea { display: block; width: 100%; resize: vertical; padding: 10px; min-height: 100px; max-height: 500px; border-color: #aaa; }
+.form-comment .form-actions { padding: 0 12px; margin-bottom: 12px; }
+.form-comment .form-actions .primary { float: right; }
+.form-comment .form-actions .secondary { float: left; }
.inline-comment { padding: 0 12px; margin: 10px 0; }
.inline-comment .panel-comment { margin: 0; }
-.panel-comment .panel-heading { padding-top: 5px; padding-bottom: 5px; background: #fffcf5; color: #555; }
-.panel-comment .panel-heading .left a { color: #333; font-weight: bold;}
-.panel-comment .panel-heading .right a { margin-left: 5px; color: #555; }
-.panel-comment .panel-heading .right a:hover { color: #09f; text-decoration: none; }
+.panel-comment .panel-heading { padding-top: 5px; padding-bottom: 5px; background: #f1eae0; color: #555; }
+.panel-comment .panel-heading .author a { color: #333; font-weight: bold;}
+.panel-comment .panel-heading .actions a { margin-left: 5px; color: #555; }
+.panel-comment .panel-heading .actions a:hover { color: #09f; text-decoration: none; }
-.panel-comment .panel-body { padding: 8px 12px; }
+.panel-comment .panel-body .wiki { padding: 8px 12px; }
.panel-diff .image-diff { padding: 30px; text-align: center; position: relative; background: #999; }
.image-diff .btn-group.compares { margin-bottom: 18px; }
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommentEditor.html b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommentEditor.html
deleted file mode 100644
index 1d4be0a9b5..0000000000
--- a/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommentEditor.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html xmlns:wicket>
-<wicket:panel>
- <form class="comment-editor" wicket:id="form">
- <div class="heading">
- <ul class="nav nav-tabs">
- </ul>
- </div>
- </form>
-</wicket:panel>
-</html>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommentEditor.java b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommentEditor.java
deleted file mode 100644
index 8acc7fc6a9..0000000000
--- a/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommentEditor.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.pmease.gitop.web.component.comment;
-
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
-
-@SuppressWarnings("serial")
-public class CommentEditor extends Panel {
-
- public CommentEditor(String id, IModel<String> textModel) {
- super(id, textModel);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
-
- }
-}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentEditor.html b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentEditor.html
new file mode 100644
index 0000000000..06f7b8727e
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentEditor.html
@@ -0,0 +1,31 @@
+<html xmlns:wicket>
+<wicket:panel>
+ <form class="form-comment" wicket:id="form">
+ <div class="comment-editor-head">
+ <ul class="nav nav-tabs">
+ <li wicket:id="tabli"><a wicket:id="link"><span wicket:id="name"></span></a></li>
+ </ul>
+ </div>
+ <div class="comment-editor-body">
+ <div wicket:id="body"></div>
+ </div>
+ <div class="form-actions clearfix" wicket:id="actions"></div>
+ </form>
+
+ <wicket:fragment wicket:id="editfrag">
+ <div wicket:id="feedback"></div>
+ <textarea wicket:id="input" placeholder="Leave a comment" class="focusable"></textarea>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="previewfrag">
+ <div class="panel panel-default panel-comment">
+ <div class="panel-heading">
+ <span class="author" wicket:id="author"></span>
+ </div>
+ <div class="panel-body">
+ <div wicket:id="content"></div>
+ </div>
+ </div>
+ </wicket:fragment>
+</wicket:panel>
+</html>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentEditor.java b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentEditor.java
new file mode 100644
index 0000000000..d678de78e1
--- /dev/null
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentEditor.java
@@ -0,0 +1,128 @@
+package com.pmease.gitop.web.component.comment;
+
+import org.apache.commons.lang3.text.WordUtils;
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextArea;
+import org.apache.wicket.markup.html.link.AbstractLink;
+import org.apache.wicket.markup.html.list.Loop;
+import org.apache.wicket.markup.html.list.LoopItem;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.parboiled.common.Preconditions;
+
+import com.pmease.gitop.core.Gitop;
+import com.pmease.gitop.core.manager.UserManager;
+import com.pmease.gitop.model.User;
+import com.pmease.gitop.web.common.wicket.form.BaseForm;
+import com.pmease.gitop.web.component.link.UserAvatarLink;
+import com.pmease.gitop.web.component.wiki.WikiTextPanel;
+import com.pmease.gitop.web.model.UserModel;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+public abstract class CommitCommentEditor extends Panel {
+
+ abstract protected Component createSubmitButtons(String id, Form<?> form);
+
+ protected Form<?> form;
+
+ public CommitCommentEditor(String id) {
+ this(id, Model.of(""));
+ }
+
+ public CommitCommentEditor(String id, IModel<String> textModel) {
+ super(id, textModel);
+
+ form = new BaseForm<Void>("form");
+ add(form);
+ }
+
+ private static enum Mode {
+ WRITE, PREVIEW
+ }
+
+ private Mode mode = Mode.WRITE;
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ form.add(new Loop("tabli", Mode.values().length) {
+
+ @Override
+ protected void populateItem(LoopItem item) {
+ final Mode m = Mode.values()[item.getIndex()];
+ item.add(AttributeAppender.append("class", m == mode ? "active" : ""));
+ AbstractLink link = new AjaxLink<Void>("link") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ mode = m;
+ onModeChanged(target);
+ }
+ };
+
+ link.add(new Label("name", WordUtils.capitalizeFully(m.name())));
+ item.add(link);
+ }
+ });
+
+ form.add(newContent("body"));
+
+ form.add(createSubmitButtons("actions", form));
+ }
+
+ protected void onModeChanged(AjaxRequestTarget target) {
+ Component c = newContent("body");
+ form.addOrReplace(c);
+ target.add(form);
+ }
+
+ protected Component newContent(String id) {
+ Component c;
+ if (mode == Mode.WRITE) {
+ c = newEditPanel(id);
+ } else {
+ // PREVIEW
+ c = newPreviewPanel(id);
+ }
+
+ c.setOutputMarkupId(true);
+ return c;
+ }
+
+ public String getCommentText() {
+ return (String) getDefaultModelObject();
+ }
+
+ @SuppressWarnings("unchecked")
+ private Component newEditPanel(String id) {
+ Fragment frag = new Fragment(id, "editfrag", this);
+ frag.add(new NotificationPanel("feedback", form));
+ frag.add(new TextArea<String>("input", (IModel<String>) getDefaultModel()));
+
+ return frag;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Component newPreviewPanel(String id) {
+ Fragment frag = new Fragment(id, "previewfrag", this);
+ User user = Preconditions.checkNotNull(Gitop.getInstance(UserManager.class).getCurrent());
+ frag.add(new UserAvatarLink("author", new UserModel(user)));
+ frag.add(new WikiTextPanel("content", (IModel<String>) getDefaultModel()));
+
+ return frag;
+ }
+
+ public Form<?> getForm() {
+ return form;
+ }
+}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentPanel.html
similarity index 69%
rename from gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentPanel.html
rename to gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentPanel.html
index 648ecd90f8..a6910425d1 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentPanel.html
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentPanel.html
@@ -4,10 +4,10 @@
<div class="panel-heading">
<div class="clearfix">
<div class="left">
- <wicket:container wicket:id="author"></wicket:container>
+ <span class="author" wicket:id="author"></span>
<span class="label " wicket:id="authorType"></span>
</div>
- <div class="right">
+ <div class="right actions">
<span wicket:id="age"></span>
<a wicket:id="editlink"><i class="icon icon-pencil"></i></a>
<a wicket:id="removelink"><i class="icon icon-delete"></i></a>
@@ -20,8 +20,8 @@
</div>
<wicket:fragment wicket:id="submitfrag">
- <button class="btn btn-default" wicket:id="btnCancel">Cancel</button>
- <button class="btn btn-gray" wicket:id="btnUpdate">Update Comment</button>
+ <button class="btn btn-default secondary" wicket:id="btnCancel">Cancel</button>
+ <button class="btn btn-gray primary" wicket:id="btnUpdate">Update Comment</button>
</wicket:fragment>
</wicket:panel>
</html>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentPanel.java
similarity index 94%
rename from gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentPanel.java
rename to gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentPanel.java
index 60ac9304a1..f494599f26 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/component/comment/CommitCommentPanel.java
@@ -1,4 +1,4 @@
-package com.pmease.gitop.web.page.project.source.commit.diff.renderer.text;
+package com.pmease.gitop.web.component.comment;
import java.util.Date;
@@ -111,10 +111,10 @@ public class CommitCommentPanel extends Panel {
}
protected void onEdit(AjaxRequestTarget target) {
- Component c = new CommitCommentFormPanel("content", Model.of(getCommitComment().getContent())) {
+ Component c = new CommitCommentEditor("content", Model.of(getCommitComment().getContent())) {
@Override
- protected Component newSubmitButtons(String id, Form<?> form) {
+ protected Component createSubmitButtons(String id, Form<?> form) {
Fragment frag = new Fragment(id, "submitfrag", CommitCommentPanel.this);
frag.add(new AjaxLink<Void>("btnCancel") {
@@ -128,7 +128,7 @@ public class CommitCommentPanel extends Panel {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- String comment = getComment();
+ String comment = getCommentText();
if (Strings.isNullOrEmpty(comment)) {
form.error("Comment can not be empty");
target.add(form);
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentFormPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentFormPanel.html
deleted file mode 100644
index 269a4f1ef5..0000000000
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentFormPanel.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<html xmlns:wicket>
-<wicket:panel>
- <form class="form-comment" wicket:id="form">
- <div class="head">
- <ul class="nav nav-tabs">
- <li wicket:id="li"><a wicket:id="link" href="javascript:void(0);)"><span wicket:id="name"></span></a></li>
- </ul>
- </div>
- <div class="body">
- <div wicket:id="tabcontent"></div>
- <div class="form-actions">
- <wicket:container wicket:id="actions"></wicket:container>
- </div>
- </div>
- </form>
-
- <wicket:fragment wicket:id="writefrag">
- <div wicket:id="feedback"></div>
- <textarea class="focusable" placeholder="Leave a comment" wicket:id="input"></textarea>
- </wicket:fragment>
-
- <wicket:fragment wicket:id="previewfrag">
- here is a comment
- </wicket:fragment>
-</wicket:panel>
-</html>
\ No newline at end of file
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentFormPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentFormPanel.java
deleted file mode 100644
index d3d4afb8d2..0000000000
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/CommitCommentFormPanel.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.pmease.gitop.web.page.project.source.commit.diff.renderer.text;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.TextArea;
-import org.apache.wicket.markup.html.list.Loop;
-import org.apache.wicket.markup.html.list.LoopItem;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-import com.google.common.base.CaseFormat;
-import com.pmease.gitop.web.common.wicket.form.BaseForm;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-public abstract class CommitCommentFormPanel extends Panel {
-
- public CommitCommentFormPanel(String id) {
- this(id, Model.of(""));
- }
-
- public CommitCommentFormPanel(String id, IModel<String> textModel) {
- super(id, textModel);
- setOutputMarkupId(true);
- }
-
- private static enum ViewMode {
- WRITE, PREVIEW
- }
-
- private ViewMode viewMode = ViewMode.WRITE;
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- final Form<?> form = new BaseForm<Void>("form");
- add(form);
-
- Loop tabLinks = new Loop("li", ViewMode.values().length) {
-
- @Override
- protected void populateItem(LoopItem item) {
- final ViewMode m = ViewMode.values()[item.getIndex()];
- item.add(AttributeAppender.append("class", m == viewMode ? "active" : ""));
- AjaxButton tabLink = new AjaxButton("link", form) {
-
- @Override
- public void onSubmit(AjaxRequestTarget target, Form<?> form) {
- if (m == viewMode)
- return;
-
- viewMode = m;
- form.addOrReplace(createContent("tabcontent"));
- target.add(form);
- }
-
- };
-
- item.add(tabLink);
-
- tabLink.add(new Label("name", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, m.name())));
- }
-
- };
-
- form.add(tabLinks);
-
- form.add(createContent("tabcontent"));
- form.add(newSubmitButtons("actions", form));
- }
-
- abstract protected Component newSubmitButtons(String id, Form<?> form);
-
- private Component createContent(String id) {
- if (viewMode == ViewMode.WRITE) {
- return createWritePanel(id);
- } else {
- return createPreviewPanel(id);
- }
- }
-
- @SuppressWarnings("unchecked")
- private Component createWritePanel(String id) {
- Fragment frag = new Fragment(id, "writefrag", this);
- frag.setOutputMarkupId(true);
- frag.add(new NotificationPanel("feedback", frag));
- frag.add(new TextArea<String>("input", (IModel<String>) getDefaultModel()));
- return frag;
- }
-
- private Component createPreviewPanel(String id) {
- Fragment frag = new Fragment(id, "previewfrag", this);
- frag.setOutputMarkupId(true);
- return frag;
- }
-
- protected String getComment() {
- return (String) getDefaultModelObject();
- }
-
-}
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java
index fa75333801..95d6dc08cf 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/commit/diff/renderer/text/HunkPanel.java
@@ -37,6 +37,8 @@ import com.pmease.gitop.core.manager.UserManager;
import com.pmease.gitop.model.CommitComment;
import com.pmease.gitop.model.Project;
import com.pmease.gitop.web.Constants;
+import com.pmease.gitop.web.component.comment.CommitCommentEditor;
+import com.pmease.gitop.web.component.comment.CommitCommentPanel;
import com.pmease.gitop.web.model.CommitCommentModel;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.FileHeader;
import com.pmease.gitop.web.page.project.source.commit.diff.patch.HunkHeader;
@@ -378,10 +380,10 @@ public class HunkPanel extends Panel {
}
private WebMarkupContainer newCommentForm(final int position) {
- return new CommitCommentFormPanel("commentform") {
+ return new CommitCommentEditor("commentform") {
@Override
- protected Component newSubmitButtons(String id, final Form<?> form) {
+ protected Component createSubmitButtons(String id, final Form<?> form) {
Fragment frag = new Fragment(id, "commentformsubmitsfrag", HunkPanel.this);
frag.add(new AjaxLink<Void>("close") {
@@ -400,7 +402,7 @@ public class HunkPanel extends Panel {
comment.setCommit(commitModel.getObject());
comment.setLine(lineId);
comment.setProject(projectModel.getObject());
- comment.setContent(getComment());
+ comment.setContent(getCommentText());
Gitop.getInstance(CommitCommentManager.class).save(comment);
send(HunkPanel.this, Broadcast.DEPTH, new InlineCommentAddedEvent(target, position, comment.getId()));
@@ -575,7 +577,7 @@ public class HunkPanel extends Panel {
e.getTarget().add(commentForm);
}
} else if (e instanceof AddInlineCommentEvent) {
- if (commentForm instanceof CommitCommentFormPanel) {
+ if (commentForm instanceof CommitCommentEditor) {
// form maybe hidden
e.getTarget().appendJavaScript("$('#" + commentForm.getMarkupId(true) + "').show()");
} else {