The Unified and Autonomous Development Platform
Add back the ability to check concurrent editing in code comment panel
robin shinedada73fd0330
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.htmlindex 3f87618d36..6aebb8fa95 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.html@@ -12,7 +12,10 @@<a wicket:id="authorName" class="author-name pull-left"></a><span wicket:id="authorDate" class="author-date pull-right"></span></div>- <div wicket:id="body" class="body"></div>+ <div class="body">+ <div wicket:id="feedback" class="feedback"></div>+ <div wicket:id="content"></div>+ </div><div wicket:id="foot" class="foot"><a wicket:id="edit">Edit</a><span class="middot"></span>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.javaindex c9a238b587..a6d9ced3a2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java@@ -2,6 +2,7 @@ package com.pmease.gitplex.web.component.comment;import java.util.ArrayList;import java.util.List;+import java.util.concurrent.atomic.AtomicLong;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;@@ -18,8 +19,11 @@ import org.apache.wicket.markup.html.panel.GenericPanel;import org.apache.wicket.markup.repeater.RepeatingView;import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;+import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.resource.CssResourceReference;+import org.hibernate.StaleObjectStateException;+import com.google.common.base.Preconditions;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;import com.pmease.commons.wicket.ajaxlistener.ConfirmListener;import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;@@ -53,7 +57,41 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {commentContainer.add(new AccountLink("authorName", getComment().getUser()));commentContainer.add(new Label("authorDate", DateUtils.formatAge(getComment().getDate())));- commentContainer.add(new MarkdownViewer("body", Model.of(getComment().getContent()), true));+ NotificationPanel feedback = new NotificationPanel("feedback", commentContainer);+ feedback.setOutputMarkupPlaceholderTag(true);+ commentContainer.add(feedback);+ AtomicLong lastVersionRef = new AtomicLong(getComment().getVersion());+ commentContainer.add(new MarkdownViewer("content", new IModel<String>() {++ @Override+ public void detach() {+ }++ @Override+ public String getObject() {+ return getComment().getContent();+ }++ @Override+ public void setObject(String object) {+ AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);+ Preconditions.checkNotNull(target);+ CodeComment comment = getComment();+ try {+ if (comment.getVersion() != lastVersionRef.get())+ throw new StaleObjectStateException(CodeComment.class.getName(), comment.getId());+ comment.setContent(object);+ GitPlex.getInstance(CodeCommentManager.class).persist(comment);+ target.add(feedback); // clear the feedback+ } catch (StaleObjectStateException e) {+ commentContainer.warn("Some one changed the content you are editing. "+ + "The content has now been reloaded, please try again.");+ target.add(commentContainer);+ }+ lastVersionRef.set(comment.getVersion());+ }++ }, SecurityUtils.canModify(getComment())));WebMarkupContainer foot = new WebMarkupContainer("foot");foot.setVisible(SecurityUtils.canModify(getComment()));@@ -81,7 +119,7 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {form.add(input);input.setRequired(true);- NotificationPanel feedback = new NotificationPanel("feedback", input);+ NotificationPanel feedback = new NotificationPanel("feedback", form);feedback.setOutputMarkupPlaceholderTag(true);form.add(feedback);@@ -102,6 +140,7 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {});+ long lastVersion = getComment().getVersion();form.add(new AjaxButton("save") {@Override@@ -114,12 +153,19 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {protected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);- CodeComment comment = getComment();- comment.setContent(input.getModelObject());- GitPlex.getInstance(CodeCommentManager.class).persist(comment);- WebMarkupContainer commentContainer = newCommentContainer();- fragment.replaceWith(commentContainer);- target.add(commentContainer);+ try {+ CodeComment comment = getComment();+ if (comment.getVersion() != lastVersion)+ throw new StaleObjectStateException(CodeComment.class.getName(), comment.getId());+ comment.setContent(input.getModelObject());+ GitPlex.getInstance(CodeCommentManager.class).persist(comment);+ WebMarkupContainer commentContainer = newCommentContainer();+ fragment.replaceWith(commentContainer);+ target.add(commentContainer);+ } catch (StaleObjectStateException e) {+ error("Some one changed the content you are editing. Reload the page and try again.");+ target.add(feedback);+ }}});@@ -172,8 +218,42 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {replyContainer.add(new AccountLink("authorName", getReply(replyId).getUser()));replyContainer.add(new Label("authorDate", DateUtils.formatAge(getReply(replyId).getDate())));- replyContainer.add(new MarkdownViewer("body", Model.of(getReply(replyId).getContent()), true));+ NotificationPanel feedback = new NotificationPanel("feedback", replyContainer);+ feedback.setOutputMarkupPlaceholderTag(true);+ replyContainer.add(feedback);+ AtomicLong lastVersionRef = new AtomicLong(getReply(replyId).getVersion());+ replyContainer.add(new MarkdownViewer("content", new IModel<String>() {+ @Override+ public void detach() {+ }++ @Override+ public String getObject() {+ return getReply(replyId).getContent();+ }++ @Override+ public void setObject(String object) {+ AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);+ Preconditions.checkNotNull(target);+ CodeCommentReply reply = getReply(replyId);+ try {+ if (reply.getVersion() != lastVersionRef.get())+ throw new StaleObjectStateException(CodeCommentReply.class.getName(), reply.getId());+ reply.setContent(object);+ GitPlex.getInstance(CodeCommentReplyManager.class).persist(reply);+ target.add(feedback); // clear the feedback+ } catch (StaleObjectStateException e) {+ replyContainer.warn("Some one changed the content you are editing. The content has now been reloaded, "+ + "please try again.");+ target.add(replyContainer);+ }+ lastVersionRef.set(reply.getVersion());+ }++ }, SecurityUtils.canModify(getComment())));+WebMarkupContainer foot = new WebMarkupContainer("foot");foot.setVisible(SecurityUtils.canModify(getReply(replyId)));@@ -200,7 +280,7 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {form.add(input);input.setRequired(true);- NotificationPanel feedback = new NotificationPanel("feedback", input);+ NotificationPanel feedback = new NotificationPanel("feedback", form);feedback.setOutputMarkupPlaceholderTag(true);form.add(feedback);@@ -221,6 +301,7 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {});+ long lastVersion = getReply(replyId).getVersion();form.add(new AjaxButton("save") {@Override@@ -233,13 +314,19 @@ public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {protected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);- CodeCommentReply reply = getReply(replyId);- reply.setContent(input.getModelObject());- GitPlex.getInstance(CodeCommentReplyManager.class).persist(reply);-- WebMarkupContainer replyContainer = newReplyContainer(componentId, replyId);- fragment.replaceWith(replyContainer);- target.add(replyContainer);+ try {+ CodeCommentReply reply = getReply(replyId);+ if (reply.getVersion() != lastVersion)+ throw new StaleObjectStateException(CodeComment.class.getName(), reply.getId());+ reply.setContent(input.getModelObject());+ GitPlex.getInstance(CodeCommentReplyManager.class).persist(reply);+ WebMarkupContainer replyContainer = newReplyContainer(componentId, replyId);+ fragment.replaceWith(replyContainer);+ target.add(replyContainer);+ } catch (StaleObjectStateException e) {+ error("Some one changed the content you are editing. Reload the page and try again.");+ target.add(feedback);+ }}});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.cssindex a9c01f1399..ef94dc198a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.css@@ -27,6 +27,12 @@font-size: 12px;color: #999;}+.code-comment>.post>.detail>.body {+ padding-top: 8px;+}+.code-comment>.post>.detail>.body>.feedback .alert {+ margin-bottom: 0;+}.code-comment>.post>.detail>.foot a {font-size: 12px;color: #999;@@ -39,6 +45,9 @@vertical-align: 25%;color: #999;}+.code-comment>.add-reply {+ margin-top: 16px;+}.code-comment>.add-reply a {color: #999;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.cssindex 4ce5dbb5d1..417107f969 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css@@ -24,7 +24,7 @@.source-view>.comment>.content>.head {font-size: 16px;padding: 4px 8px;- border-bottom: 1px dotted #BBB;+ background: #F2F2F2;}.source-view>.comment>.content>.body {font-size: 13px;@@ -54,7 +54,7 @@.source-view>.outline>.content>.head {font-size: 16px;padding: 4px 8px;- border-bottom: 1px dotted #BBB;+ background: #F2F2F2;}.source-view>.outline>.content>.body {font-size: 13px;