The Unified and Autonomous Development Platform
refactored since last change indicator in request overview page
robin shine643ef9bf3bca
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 177ffaf8a5..9be1ee8ca2 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@@ -1,801 +1,814 @@-package com.pmease.gitplex.web.component.comment;--import java.util.ArrayList;-import java.util.Date;-import java.util.List;--import javax.annotation.Nullable;--import org.apache.commons.lang3.StringUtils;-import org.apache.wicket.Component;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.markup.html.AjaxLink;-import org.apache.wicket.ajax.markup.html.form.AjaxButton;-import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;-import org.apache.wicket.event.IEvent;-import org.apache.wicket.markup.head.CssHeaderItem;-import org.apache.wicket.markup.head.IHeaderResponse;-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.form.TextField;-import org.apache.wicket.markup.html.link.Link;-import org.apache.wicket.markup.html.panel.Fragment;-import org.apache.wicket.markup.html.panel.Panel;-import org.apache.wicket.markup.repeater.RepeatingView;-import org.apache.wicket.model.AbstractReadOnlyModel;-import org.apache.wicket.model.LoadableDetachableModel;-import org.apache.wicket.model.Model;-import org.apache.wicket.request.mapper.parameter.PageParameters;-import org.apache.wicket.request.resource.CssResourceReference;-import org.hibernate.StaleObjectStateException;--import com.pmease.commons.hibernate.dao.Dao;-import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;-import com.pmease.commons.wicket.ajaxlistener.ConfirmListener;-import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;-import com.pmease.commons.wicket.component.markdown.MarkdownEditSupport;-import com.pmease.commons.wicket.component.markdown.MarkdownPanel;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.entity.Account;-import com.pmease.gitplex.core.entity.CodeComment;-import com.pmease.gitplex.core.entity.CodeCommentReply;-import com.pmease.gitplex.core.entity.CodeCommentStatusChange;-import com.pmease.gitplex.core.entity.Depot;-import com.pmease.gitplex.core.entity.PullRequest;-import com.pmease.gitplex.core.entity.support.CodeCommentActivity;-import com.pmease.gitplex.core.entity.support.CompareContext;-import com.pmease.gitplex.core.entity.support.DepotAndRevision;-import com.pmease.gitplex.core.manager.CodeCommentManager;-import com.pmease.gitplex.core.manager.CodeCommentReplyManager;-import com.pmease.gitplex.core.manager.CodeCommentStatusChangeManager;-import com.pmease.gitplex.core.manager.VisitInfoManager;-import com.pmease.gitplex.core.security.SecurityUtils;-import com.pmease.gitplex.web.component.AccountLink;-import com.pmease.gitplex.web.component.avatar.AvatarLink;-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;-import com.pmease.gitplex.web.util.DateUtils;-import com.pmease.gitplex.web.websocket.CodeCommentChangeRenderer;-import com.pmease.gitplex.web.websocket.CodeCommentChanged;--import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;--@SuppressWarnings("serial")-public abstract class CodeCommentPanel extends Panel {-- private final Long commentId;-- private RepeatingView activitiesView;-- /**- * We pass comment id instead of comment model as we want to make sure that- * comment is always loaded upon usage as this panel is involved in websocket- * update and websocket update does not detach models at end of request which- * may result in Hibernate lazy load exception when the comment is used again- * in next request- *- * @param id- * @param commentId- */- public CodeCommentPanel(String id, Long commentId) {- super(id);- this.commentId = commentId;- }-- protected CodeComment getComment() {- return GitPlex.getInstance(CodeCommentManager.class).load(commentId);- }-- @Override- protected void onAfterRender() {- super.onAfterRender();- Account user = SecurityUtils.getAccount();- if (user != null)- GitPlex.getInstance(VisitInfoManager.class).visit(user, getComment());- }-- @Override- public void onEvent(IEvent<?> event) {- super.onEvent(event);-- if (event.getPayload() instanceof CodeCommentChanged) {- CodeCommentChanged codeCommentChanged = (CodeCommentChanged) event.getPayload();- IPartialPageRequestHandler partialPageRequestHandler = codeCommentChanged.getPartialPageRequestHandler();-- Date lastActivityDate;- String prevActivityMarkupId;- if (activitiesView.size() != 0) {- @SuppressWarnings("deprecation")- Component lastReplyContainer = activitiesView.get(activitiesView.size()-1);- CodeCommentReply lastReply = GitPlex.getInstance(CodeCommentReplyManager.class)- .load((Long) lastReplyContainer.getDefaultModelObject());- lastActivityDate = lastReply.getDate();- prevActivityMarkupId = lastReplyContainer.getMarkupId();- } else {- lastActivityDate = getComment().getDate();- prevActivityMarkupId = get("comment").getMarkupId();- }-- PullRequest request = getPullRequest();- List<CodeCommentActivity> activities = new ArrayList<>();- for (CodeCommentReply reply: getComment().getReplies()) {- if (reply.getDate().getTime()>lastActivityDate.getTime()- && (request == null || request.getRequestComparingInfo(reply.getComparingInfo()) != null)) {- activities.add(reply);- }- }- for (CodeCommentStatusChange statusChange: getComment().getStatusChanges()) {- if (statusChange.getDate().getTime()>lastActivityDate.getTime()- && (request == null || request.getRequestComparingInfo(statusChange.getComparingInfo()) != null)) {- activities.add(statusChange);- }- }- activities.sort((o1, o2)->o1.getDate().compareTo(o2.getDate()));-- for (CodeCommentActivity activity: activities) {- Component newActivityContainer = newActivityContainer(activitiesView.newChildId(), activity);- activitiesView.add(newActivityContainer);-- String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",- newActivityContainer.getMarkupId(), prevActivityMarkupId);- partialPageRequestHandler.prependJavaScript(script);- partialPageRequestHandler.add(newActivityContainer);- prevActivityMarkupId = newActivityContainer.getMarkupId();- }- }- }-- private WebMarkupContainer newCommentContainer() {- WebMarkupContainer commentContainer = new Fragment("comment", "viewFrag", this);- commentContainer.setOutputMarkupId(true);-- commentContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {-- @Override- protected String load() {- return getComment().isVisitedAfter(getComment().getDate())?"": "new";- }-- }));-- commentContainer.add(new AvatarLink("userAvatar", getComment().getUser()));- commentContainer.add(new AccountLink("userName", getComment().getUser()));- commentContainer.add(new Label("activityDescription", "commented"));- commentContainer.add(new Label("activityDate", DateUtils.formatAge(getComment().getDate())));- commentContainer.add(new Link<Void>("compareContext") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(!getCompareContext(getComment()).equals(getComment().getCompareContext()));- }-- @Override- public void onClick() {- CodeComment comment = getComment();- CompareContext compareContext = comment.getCompareContext();- PullRequest request = getPullRequest();- if (request != null) {- RequestChangesPage.State state = new RequestChangesPage.State();- state.commentId = comment.getId();- if (compareContext.isLeftSide()) {- state.oldCommit = compareContext.getCompareCommit();- state.newCommit = comment.getCommentPos().getCommit();- } else {- state.oldCommit = comment.getCommentPos().getCommit();- state.newCommit = compareContext.getCompareCommit();- }- state.mark = comment.getCommentPos();- state.pathFilter = compareContext.getPathFilter();- state.whitespaceOption = compareContext.getWhitespaceOption();- PageParameters params = RequestChangesPage.paramsOf(request, state);- setResponsePage(RequestChangesPage.class, params);- } else {- RevisionComparePage.State state = new RevisionComparePage.State();- state.commentId = comment.getId();- state.compareWithMergeBase = false;- if (compareContext.isLeftSide()) {- state.leftSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());- state.rightSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());- } else {- state.leftSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());- state.rightSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());- }- state.mark = comment.getCommentPos();- state.pathFilter = compareContext.getPathFilter();- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;- state.whitespaceOption = compareContext.getWhitespaceOption();- PageParameters params = RevisionComparePage.paramsOf(comment.getDepot(), state);- setResponsePage(RevisionComparePage.class, params);- }- }-- }.add(AttributeAppender.append("title", "This comment is added in a different compare context, click to show")));-- MarkdownEditSupport editSupport;- if (SecurityUtils.canModify(getComment())) {- editSupport = new MarkdownEditSupport() {-- @Override- public void setContent(String content) {- CodeComment comment = getComment();- comment.setContent(content);- GitPlex.getInstance(CodeCommentManager.class).save(comment);- }-- @Override- public long getVersion() {- return getComment().getVersion();- }-- };- } else {- editSupport = null;- }- commentContainer.add(new MarkdownPanel("content", new AbstractReadOnlyModel<String>() {-- @Override- public String getObject() {- return getComment().getContent();- }-- }, editSupport));-- WebMarkupContainer foot = new WebMarkupContainer("foot");- foot.setVisible(SecurityUtils.canModify(getComment()));- foot.add(new AjaxLink<Void>("edit") {-- @Override- public void onClick(AjaxRequestTarget target) {- Fragment fragment = new Fragment(commentContainer.getId(), "commentEditFrag", CodeCommentPanel.this);- Form<?> form = new Form<Void>("form");- form.setOutputMarkupId(true);-- TextField<String> titleInput = new TextField<String>("title", Model.of(getComment().getTitle()));- titleInput.setRequired(true);- form.add(titleInput);- CommentInput contentInput = new CommentInput("content", Model.of(getComment().getContent())) {-- @Override- protected AttachmentSupport getAttachmentSupport() {- return new DepotAttachmentSupport(getComment().getDepot(), getComment().getUUID());- }-- @Override- protected Depot getDepot() {- return getComment().getDepot();- }-- };- form.add(contentInput);- contentInput.setRequired(true);-- NotificationPanel feedback = new NotificationPanel("feedback", form);- feedback.setOutputMarkupPlaceholderTag(true);- form.add(feedback);-- form.add(new AjaxLink<Void>("cancel") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));- }-- @Override- public void onClick(AjaxRequestTarget target) {- WebMarkupContainer commentContainer = newCommentContainer();- fragment.replaceWith(commentContainer);- target.add(commentContainer);- }-- });-- long lastVersion = getComment().getVersion();- form.add(new AjaxButton("save") {-- @Override- protected void onError(AjaxRequestTarget target, Form<?> form) {- super.onError(target, form);- target.add(feedback);- }-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);-- try {- CodeComment comment = getComment();- if (comment.getVersion() != lastVersion)- throw new StaleObjectStateException(CodeComment.class.getName(), comment.getId());- comment.setTitle(titleInput.getModelObject());- comment.setContent(contentInput.getModelObject());- GitPlex.getInstance(CodeCommentManager.class).save(comment);- WebMarkupContainer commentContainer = newCommentContainer();- fragment.replaceWith(commentContainer);- target.add(commentContainer);- onSaveComment(target, comment);- } catch (StaleObjectStateException e) {- error("Some one changed the content you are editing. Reload the page and try again.");- target.add(feedback);- }- }-- });-- fragment.add(form);- fragment.setOutputMarkupId(true);- commentContainer.replaceWith(fragment);- target.add(fragment);- }-- });-- foot.add(new AjaxLink<Void>("delete") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- String confirmMessage;- if (getComment().getReplies().isEmpty()) {- confirmMessage = "Do you really want to delete this comment?";- } else {- confirmMessage = "Deleting this comment will also delete all replies, do you really "- + "want to continue?";- }- attributes.getAjaxCallListeners().add(new ConfirmListener(confirmMessage));- }-- @Override- public void onClick(AjaxRequestTarget target) {- onDeleteComment(target, getComment());- GitPlex.getInstance(CodeCommentManager.class).delete(getComment());- }-- });-- commentContainer.add(foot);- return commentContainer;- }-- private WebMarkupContainer newActivityContainer(String componentId, CodeCommentActivity activity) {- Class<? extends CodeCommentActivity> activityClass = activity.getClass();- Long activityId = activity.getId();- Fragment activityContainer = new Fragment(componentId, "viewFrag", this, Model.of(activityId));- activityContainer.setOutputMarkupId(true);-- activityContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {-- @Override- protected String load() {- return getComment().isVisitedAfter(getActivity(activityClass, activityId).getDate())?"":"new";- }-- }));-- activityContainer.add(new AvatarLink("userAvatar", activity.getUser()));- activityContainer.add(new AccountLink("userName", activity.getUser()));- String activityDescription;- if (activity instanceof CodeCommentStatusChange) {- CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;- if (statusChange.isResolved())- activityDescription = "resolved";- else- activityDescription = "unresolved";- } else {- activityDescription = "replied";- }- activityContainer.add(new Label("activityDescription", activityDescription));- activityContainer.add(new Label("activityDate", DateUtils.formatAge(activity.getDate())));- activityContainer.add(new Link<Void>("compareContext") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(!getCompareContext(getComment()).equals(getActivity(activityClass, activityId).getCompareContext()));- }-- @Override- public void onClick() {- CodeCommentActivity activity = getActivity(activityClass, activityId);- CompareContext compareContext = activity.getCompareContext();- PullRequest request = getPullRequest();- if (request != null) {- RequestChangesPage.State state = new RequestChangesPage.State();- state.commentId = activity.getComment().getId();- if (compareContext.isLeftSide()) {- state.oldCommit = compareContext.getCompareCommit();- state.newCommit = activity.getComment().getCommentPos().getCommit();- } else {- state.oldCommit = activity.getComment().getCommentPos().getCommit();- state.newCommit = compareContext.getCompareCommit();- }- state.mark = activity.getComment().getCommentPos();- state.pathFilter = compareContext.getPathFilter();- state.whitespaceOption = compareContext.getWhitespaceOption();- PageParameters params = RequestChangesPage.paramsOf(request, state);- setResponsePage(RequestChangesPage.class, params);- } else {- RevisionComparePage.State state = new RevisionComparePage.State();- CodeComment comment = activity.getComment();- state.commentId = comment.getId();- state.compareWithMergeBase = false;- if (compareContext.isLeftSide()) {- state.leftSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());- state.rightSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());- } else {- state.leftSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());- state.rightSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());- }- state.mark = comment.getCommentPos();- state.pathFilter = compareContext.getPathFilter();- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;- state.whitespaceOption = compareContext.getWhitespaceOption();- PageParameters params = RevisionComparePage.paramsOf(comment.getDepot(), state);- setResponsePage(RevisionComparePage.class, params);- }- }-- }.add(AttributeAppender.append("title", "This reply is added in a different compare context, click to show")));-- if (StringUtils.isNotBlank(activity.getNote())) {- MarkdownEditSupport editSupport;- if (SecurityUtils.canModify(getComment())) {- editSupport = new MarkdownEditSupport() {-- @Override- public void setContent(String content) {- if (activityClass == CodeCommentReply.class) {- CodeCommentReply reply = (CodeCommentReply) activity;- reply.setContent(content);- GitPlex.getInstance(CodeCommentReplyManager.class).save(reply);- } else {- CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;- statusChange.setNote(content);- GitPlex.getInstance(CodeCommentStatusChangeManager.class).save(statusChange);- }- }-- @Override- public long getVersion() {- return getActivity(activityClass, activityId).getVersion();- }-- };- } else {- editSupport = null;- }- activityContainer.add(new MarkdownPanel("content", new LoadableDetachableModel<String>() {-- @Override- protected String load() {- return getActivity(activityClass, activityId).getNote();- }-- }, editSupport));-- } else {- activityContainer.add(new Label("content", "<div class='no-note'>No note</div>").setEscapeModelStrings(false));- }-- WebMarkupContainer foot = new WebMarkupContainer("foot");- foot.setVisible(SecurityUtils.canModify(activity));-- foot.add(new AjaxLink<Void>("edit") {-- @Override- public void onClick(AjaxRequestTarget target) {- Fragment fragment = new Fragment(activityContainer.getId(), "activityEditFrag",- CodeCommentPanel.this, Model.of(activityId));- Form<?> form = new Form<Void>("form");- CommentInput contentInput = new CommentInput("content", Model.of(getActivity(activityClass, activityId).getNote())) {-- @Override- protected AttachmentSupport getAttachmentSupport() {- return new DepotAttachmentSupport(getComment().getDepot(), getComment().getUUID());- }-- @Override- protected Depot getDepot() {- return getComment().getDepot();- }-- };- contentInput.setRequired(activityClass == CodeCommentReply.class);- form.add(contentInput);-- NotificationPanel feedback = new NotificationPanel("feedback", form);- feedback.setOutputMarkupPlaceholderTag(true);- form.add(feedback);-- form.add(new AjaxLink<Void>("cancel") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));- }-- @Override- public void onClick(AjaxRequestTarget target) {- WebMarkupContainer replyContainer = newActivityContainer(componentId, getActivity(activityClass, activityId));- fragment.replaceWith(replyContainer);- target.add(replyContainer);- }-- });-- long lastVersion = getActivity(activityClass, activityId).getVersion();- form.add(new AjaxButton("save") {-- @Override- protected void onError(AjaxRequestTarget target, Form<?> form) {- super.onError(target, form);- target.add(feedback);- }-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);-- try {- CodeCommentActivity activity = getActivity(activityClass, activityId);- if (activity.getVersion() != lastVersion)- throw new StaleObjectStateException(activityClass.getName(), activity.getId());-- if (activityClass == CodeCommentReply.class) {- CodeCommentReply reply = (CodeCommentReply) activity;- reply.setContent(contentInput.getModelObject());- GitPlex.getInstance(CodeCommentReplyManager.class).save(reply);- } else {- CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;- statusChange.setNote(contentInput.getModelObject());- GitPlex.getInstance(CodeCommentStatusChangeManager.class).save(statusChange);- }- WebMarkupContainer activityContainer = newActivityContainer(componentId, getActivity(activityClass, activityId));- fragment.replaceWith(activityContainer);- target.add(activityContainer);- } catch (StaleObjectStateException e) {- error("Some one changed the content you are editing. Reload the page and try again.");- target.add(feedback);- }- }-- }.add(new Label("label", "Save")));-- fragment.add(form);- fragment.setOutputMarkupId(true);- activityContainer.replaceWith(fragment);- target.add(fragment);- }-- });- foot.add(new AjaxLink<Void>("delete") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to delete this reply?"));- }-- @Override- public void onClick(AjaxRequestTarget target) {- activityContainer.remove();- GitPlex.getInstance(CodeCommentReplyManager.class).delete((CodeCommentReply) getActivity(activityClass, activityId));- String script = String.format("$('#%s').remove();", activityContainer.getMarkupId());- target.appendJavaScript(script);- }-- }.setVisible(activity instanceof CodeCommentReply));-- activityContainer.add(foot);- return activityContainer;- }-- private WebMarkupContainer newAddReplyContainer() {- WebMarkupContainer addReplyContainer = new Fragment("addReply", "addReplyFrag", this) {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(SecurityUtils.getAccount() != null);- }-- };- addReplyContainer.setOutputMarkupId(true);- addReplyContainer.add(new AjaxLink<Void>("reply") {-- @Override- public void onClick(AjaxRequestTarget target) {- onAddReply(target, false);- }-- });- return addReplyContainer;- }-- @Override- protected void onInitialize() {- super.onInitialize();-- add(newCommentContainer());-- activitiesView = new RepeatingView("activities");- PullRequest request = getPullRequest();-- List<CodeCommentActivity> activities = new ArrayList<>();- for (CodeCommentReply reply: getComment().getReplies()) {- if (request == null || request.getRequestComparingInfo(reply.getComparingInfo()) != null) {- activities.add(reply);- }- }- for (CodeCommentStatusChange statusChange: getComment().getStatusChanges()) {- if (request == null || request.getRequestComparingInfo(statusChange.getComparingInfo()) != null) {- activities.add(statusChange);- }- }-- activities.sort((o1, o2)->o1.getDate().compareTo(o2.getDate()));-- for (CodeCommentActivity activity: activities) {- activitiesView.add(newActivityContainer(activitiesView.newChildId(), activity));- }- add(activitiesView);- add(newAddReplyContainer());-- setOutputMarkupId(true);-- add(new CodeCommentChangeRenderer(getComment().getId()));- }-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);- response.render(CssHeaderItem.forReference(new CssResourceReference(- CodeCommentPanel.class, "code-comment.css")));- }-- private CodeCommentActivity getActivity(Class<? extends CodeCommentActivity> entityClass, Long activityId) {- return GitPlex.getInstance(Dao.class).load(entityClass, activityId);- }-- private void onAddReply(AjaxRequestTarget target, boolean changeStatus) {- Fragment fragment = new Fragment("addReply", "activityEditFrag", CodeCommentPanel.this);- Form<?> form = new Form<Void>("form");- CommentInput contentInput = new CommentInput("content", Model.of("")) {-- @Override- protected AttachmentSupport getAttachmentSupport() {- return new DepotAttachmentSupport(getComment().getDepot(), getComment().getUUID());- }-- @Override- protected Depot getDepot() {- return getComment().getDepot();- }-- };- contentInput.setRequired(!changeStatus);- form.add(contentInput);-- NotificationPanel feedback = new NotificationPanel("feedback", form);- feedback.setOutputMarkupPlaceholderTag(true);- form.add(feedback);-- form.add(new AjaxLink<Void>("cancel") {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));- }-- @Override- public void onClick(AjaxRequestTarget target) {- WebMarkupContainer addReplyContainer = newAddReplyContainer();- fragment.replaceWith(addReplyContainer);- target.add(addReplyContainer);- }-- });-- AjaxButton saveButton = new AjaxButton("save") {-- @Override- protected void onError(AjaxRequestTarget target, Form<?> form) {- super.onError(target, form);- target.add(feedback);- }-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);-- Account user = SecurityUtils.getAccount();- CodeComment comment = getComment();- Date date = new Date();- CompareContext compareContext = getCompareContext(comment);- if (changeStatus) {- CodeCommentStatusChange statusChange = new CodeCommentStatusChange();- statusChange.setComment(getComment());- statusChange.setUser(user);- statusChange.setCompareContext(compareContext);- statusChange.setResolved(!comment.isResolved());- statusChange.setDate(date);-- GitPlex.getInstance(CodeCommentManager.class).changeStatus(statusChange);- onStatusChanged(target, fragment, statusChange);- onSaveComment(target, getComment());- } else {- CodeCommentReply reply = new CodeCommentReply();- reply.setComment(comment);- reply.setDate(date);- reply.setUser(user);- reply.setContent(contentInput.getModelObject());- reply.setCompareContext(compareContext);- GitPlex.getInstance(CodeCommentReplyManager.class).save(reply);- onReplyAdded(target, fragment, reply);- }- }-- };- if (changeStatus) {- saveButton.add(new Label("label", getComment().isResolved()?"Confirm unresolve":"Confirm resolve"));- } else {- saveButton.add(new Label("label", "Save"));- saveButton.add(AttributeAppender.append("class", "dirty-aware"));- }- form.add(saveButton);-- fragment.add(form);- fragment.setOutputMarkupId(true);- get("addReply").replaceWith(fragment);- target.add(fragment);- }-- public void onChangeStatus(AjaxRequestTarget target) {- onAddReply(target, true);- }-- private void onStatusChanged(AjaxRequestTarget target, Fragment fragment, CodeCommentStatusChange statusChange) {- WebMarkupContainer activityContainer = newActivityContainer(activitiesView.newChildId(), statusChange);- activitiesView.add(activityContainer);-- String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');",- CodeCommentPanel.this.getMarkupId(), activityContainer.getMarkupId());- target.prependJavaScript(script);- target.add(activityContainer);-- WebMarkupContainer addReplyContainer = newAddReplyContainer();- fragment.replaceWith(addReplyContainer);- target.add(addReplyContainer);- }-- private void onReplyAdded(AjaxRequestTarget target, Fragment fragment, @Nullable CodeCommentReply reply) {- if (reply != null) {- WebMarkupContainer activityContainer = newActivityContainer(activitiesView.newChildId(), reply);- activitiesView.add(activityContainer);-- String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');",- CodeCommentPanel.this.getMarkupId(), activityContainer.getMarkupId());- target.prependJavaScript(script);- target.add(activityContainer);- }-- WebMarkupContainer addReplyContainer = newAddReplyContainer();- fragment.replaceWith(addReplyContainer);- target.add(addReplyContainer);- }-- protected abstract void onDeleteComment(AjaxRequestTarget target, CodeComment comment);-- protected abstract void onSaveComment(AjaxRequestTarget target, CodeComment comment);-- protected abstract CompareContext getCompareContext(CodeComment comment);-- @Nullable- protected abstract PullRequest getPullRequest();-}+package com.pmease.gitplex.web.component.comment;++import java.io.Serializable;+import java.util.ArrayList;+import java.util.Date;+import java.util.List;++import javax.annotation.Nullable;++import org.apache.commons.lang3.StringUtils;+import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.ajax.markup.html.form.AjaxButton;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;+import org.apache.wicket.event.IEvent;+import org.apache.wicket.markup.head.CssHeaderItem;+import org.apache.wicket.markup.head.IHeaderResponse;+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.form.TextField;+import org.apache.wicket.markup.html.link.Link;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.markup.repeater.RepeatingView;+import org.apache.wicket.model.AbstractReadOnlyModel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;+import org.apache.wicket.request.mapper.parameter.PageParameters;+import org.apache.wicket.request.resource.CssResourceReference;+import org.hibernate.StaleObjectStateException;++import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;+import com.pmease.commons.wicket.ajaxlistener.ConfirmListener;+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;+import com.pmease.commons.wicket.component.markdown.MarkdownEditSupport;+import com.pmease.commons.wicket.component.markdown.MarkdownPanel;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.Account;+import com.pmease.gitplex.core.entity.CodeComment;+import com.pmease.gitplex.core.entity.CodeCommentReply;+import com.pmease.gitplex.core.entity.CodeCommentStatusChange;+import com.pmease.gitplex.core.entity.Depot;+import com.pmease.gitplex.core.entity.PullRequest;+import com.pmease.gitplex.core.entity.support.CodeCommentActivity;+import com.pmease.gitplex.core.entity.support.CompareContext;+import com.pmease.gitplex.core.entity.support.DepotAndRevision;+import com.pmease.gitplex.core.manager.AccountManager;+import com.pmease.gitplex.core.manager.CodeCommentManager;+import com.pmease.gitplex.core.manager.CodeCommentReplyManager;+import com.pmease.gitplex.core.manager.CodeCommentStatusChangeManager;+import com.pmease.gitplex.core.manager.VisitInfoManager;+import com.pmease.gitplex.core.security.SecurityUtils;+import com.pmease.gitplex.web.component.AccountLink;+import com.pmease.gitplex.web.component.avatar.AvatarLink;+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;+import com.pmease.gitplex.web.util.DateUtils;+import com.pmease.gitplex.web.websocket.CodeCommentChangeRenderer;+import com.pmease.gitplex.web.websocket.CodeCommentChanged;++import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;++@SuppressWarnings("serial")+public abstract class CodeCommentPanel extends Panel {++ private final Long commentId;++ private RepeatingView activitiesView;++ /**+ * We pass comment id instead of comment model as we want to make sure that+ * comment is always loaded upon usage as this panel is involved in websocket+ * update and websocket update does not detach models at end of request which+ * may result in Hibernate lazy load exception when the comment is used again+ * in next request+ *+ * @param id+ * @param commentId+ */+ public CodeCommentPanel(String id, Long commentId) {+ super(id);+ this.commentId = commentId;+ }++ protected CodeComment getComment() {+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);+ }++ @Override+ protected void onAfterRender() {+ super.onAfterRender();+ Account user = SecurityUtils.getAccount();+ if (user != null)+ GitPlex.getInstance(VisitInfoManager.class).visit(user, getComment());+ }++ @Override+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);++ if (event.getPayload() instanceof CodeCommentChanged) {+ CodeCommentChanged codeCommentChanged = (CodeCommentChanged) event.getPayload();+ IPartialPageRequestHandler partialPageRequestHandler = codeCommentChanged.getPartialPageRequestHandler();++ Date lastActivityDate;+ String prevActivityMarkupId;+ if (activitiesView.size() != 0) {+ @SuppressWarnings("deprecation")+ Component lastActivityContainer = activitiesView.get(activitiesView.size()-1);++ CodeCommentActivity lastActivity = ((ActivityIdentity) lastActivityContainer.getDefaultModelObject()).getActivity();+ lastActivityDate = lastActivity.getDate();+ prevActivityMarkupId = lastActivityContainer.getMarkupId();+ } else {+ lastActivityDate = getComment().getDate();+ prevActivityMarkupId = get("comment").getMarkupId();+ }++ PullRequest request = getPullRequest();+ List<CodeCommentActivity> activities = new ArrayList<>();+ for (CodeCommentReply reply: getComment().getReplies()) {+ if (reply.getDate().getTime()>lastActivityDate.getTime()+ && (request == null || request.getRequestComparingInfo(reply.getComparingInfo()) != null)) {+ activities.add(reply);+ }+ }+ for (CodeCommentStatusChange statusChange: getComment().getStatusChanges()) {+ if (statusChange.getDate().getTime()>lastActivityDate.getTime()+ && (request == null || request.getRequestComparingInfo(statusChange.getComparingInfo()) != null)) {+ activities.add(statusChange);+ }+ }+ activities.sort((o1, o2)->o1.getDate().compareTo(o2.getDate()));++ for (CodeCommentActivity activity: activities) {+ Component newActivityContainer = newActivityContainer(activitiesView.newChildId(), activity);+ newActivityContainer.add(AttributeAppender.append("class", "new"));+ activitiesView.add(newActivityContainer);++ String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",+ newActivityContainer.getMarkupId(), prevActivityMarkupId);+ partialPageRequestHandler.prependJavaScript(script);+ partialPageRequestHandler.add(newActivityContainer);+ prevActivityMarkupId = newActivityContainer.getMarkupId();+ }++ Account user = GitPlex.getInstance(AccountManager.class).getCurrent();+ if (user != null)+ GitPlex.getInstance(VisitInfoManager.class).visit(user, getComment());+ }+ }++ private WebMarkupContainer newCommentContainer() {+ WebMarkupContainer commentContainer = new Fragment("comment", "viewFrag", this);+ commentContainer.setOutputMarkupId(true);++ commentContainer.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ return getComment().isVisitedAfter(getComment().getDate())?"": "new";+ }++ }));++ commentContainer.add(new AvatarLink("userAvatar", getComment().getUser()));+ commentContainer.add(new AccountLink("userName", getComment().getUser()));+ commentContainer.add(new Label("activityDescription", "commented"));+ commentContainer.add(new Label("activityDate", DateUtils.formatAge(getComment().getDate())));+ commentContainer.add(new Link<Void>("compareContext") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(!getCompareContext(getComment()).equals(getComment().getCompareContext()));+ }++ @Override+ public void onClick() {+ CodeComment comment = getComment();+ CompareContext compareContext = comment.getCompareContext();+ PullRequest request = getPullRequest();+ if (request != null) {+ RequestChangesPage.State state = new RequestChangesPage.State();+ state.commentId = comment.getId();+ if (compareContext.isLeftSide()) {+ state.oldCommit = compareContext.getCompareCommit();+ state.newCommit = comment.getCommentPos().getCommit();+ } else {+ state.oldCommit = comment.getCommentPos().getCommit();+ state.newCommit = compareContext.getCompareCommit();+ }+ state.mark = comment.getCommentPos();+ state.pathFilter = compareContext.getPathFilter();+ state.whitespaceOption = compareContext.getWhitespaceOption();+ PageParameters params = RequestChangesPage.paramsOf(request, state);+ setResponsePage(RequestChangesPage.class, params);+ } else {+ RevisionComparePage.State state = new RevisionComparePage.State();+ state.commentId = comment.getId();+ state.compareWithMergeBase = false;+ if (compareContext.isLeftSide()) {+ state.leftSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());+ state.rightSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());+ } else {+ state.leftSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());+ state.rightSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());+ }+ state.mark = comment.getCommentPos();+ state.pathFilter = compareContext.getPathFilter();+ state.tabPanel = RevisionComparePage.TabPanel.CHANGES;+ state.whitespaceOption = compareContext.getWhitespaceOption();+ PageParameters params = RevisionComparePage.paramsOf(comment.getDepot(), state);+ setResponsePage(RevisionComparePage.class, params);+ }+ }++ }.add(AttributeAppender.append("title", "This comment is added in a different compare context, click to show")));++ MarkdownEditSupport editSupport;+ if (SecurityUtils.canModify(getComment())) {+ editSupport = new MarkdownEditSupport() {++ @Override+ public void setContent(String content) {+ CodeComment comment = getComment();+ comment.setContent(content);+ GitPlex.getInstance(CodeCommentManager.class).save(comment);+ }++ @Override+ public long getVersion() {+ return getComment().getVersion();+ }++ };+ } else {+ editSupport = null;+ }+ commentContainer.add(new MarkdownPanel("content", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ return getComment().getContent();+ }++ }, editSupport));++ WebMarkupContainer foot = new WebMarkupContainer("foot");+ foot.setVisible(SecurityUtils.canModify(getComment()));+ foot.add(new AjaxLink<Void>("edit") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = new Fragment(commentContainer.getId(), "commentEditFrag", CodeCommentPanel.this);+ Form<?> form = new Form<Void>("form");+ form.setOutputMarkupId(true);++ TextField<String> titleInput = new TextField<String>("title", Model.of(getComment().getTitle()));+ titleInput.setRequired(true);+ form.add(titleInput);+ CommentInput contentInput = new CommentInput("content", Model.of(getComment().getContent())) {++ @Override+ protected AttachmentSupport getAttachmentSupport() {+ return new DepotAttachmentSupport(getComment().getDepot(), getComment().getUUID());+ }++ @Override+ protected Depot getDepot() {+ return getComment().getDepot();+ }++ };+ form.add(contentInput);+ contentInput.setRequired(true);++ NotificationPanel feedback = new NotificationPanel("feedback", form);+ feedback.setOutputMarkupPlaceholderTag(true);+ form.add(feedback);++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ WebMarkupContainer commentContainer = newCommentContainer();+ fragment.replaceWith(commentContainer);+ target.add(commentContainer);+ }++ });++ long lastVersion = getComment().getVersion();+ form.add(new AjaxButton("save") {++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(feedback);+ }++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);++ try {+ CodeComment comment = getComment();+ if (comment.getVersion() != lastVersion)+ throw new StaleObjectStateException(CodeComment.class.getName(), comment.getId());+ comment.setTitle(titleInput.getModelObject());+ comment.setContent(contentInput.getModelObject());+ GitPlex.getInstance(CodeCommentManager.class).save(comment);+ WebMarkupContainer commentContainer = newCommentContainer();+ fragment.replaceWith(commentContainer);+ target.add(commentContainer);+ onSaveComment(target, comment);+ } catch (StaleObjectStateException e) {+ error("Some one changed the content you are editing. Reload the page and try again.");+ target.add(feedback);+ }+ }++ });++ fragment.add(form);+ fragment.setOutputMarkupId(true);+ commentContainer.replaceWith(fragment);+ target.add(fragment);+ }++ });++ foot.add(new AjaxLink<Void>("delete") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ String confirmMessage;+ if (getComment().getReplies().isEmpty()) {+ confirmMessage = "Do you really want to delete this comment?";+ } else {+ confirmMessage = "Deleting this comment will also delete all replies, do you really "+ + "want to continue?";+ }+ attributes.getAjaxCallListeners().add(new ConfirmListener(confirmMessage));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ onDeleteComment(target, getComment());+ GitPlex.getInstance(CodeCommentManager.class).delete(getComment());+ }++ });++ commentContainer.add(foot);+ return commentContainer;+ }++ private WebMarkupContainer newActivityContainer(String componentId, CodeCommentActivity activity) {+ ActivityIdentity identity = new ActivityIdentity(activity);+ Fragment activityContainer = new Fragment(componentId, "viewFrag", this, Model.of(identity));+ activityContainer.setOutputMarkupId(true);++ activityContainer.add(new AvatarLink("userAvatar", activity.getUser()));+ activityContainer.add(new AccountLink("userName", activity.getUser()));+ String activityDescription;+ if (activity instanceof CodeCommentStatusChange) {+ CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;+ if (statusChange.isResolved())+ activityDescription = "resolved";+ else+ activityDescription = "unresolved";+ } else {+ activityDescription = "replied";+ }+ activityContainer.add(new Label("activityDescription", activityDescription));+ activityContainer.add(new Label("activityDate", DateUtils.formatAge(activity.getDate())));+ activityContainer.add(new Link<Void>("compareContext") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(!getCompareContext(getComment()).equals(identity.getActivity().getCompareContext()));+ }++ @Override+ public void onClick() {+ CodeCommentActivity activity = identity.getActivity();+ CompareContext compareContext = activity.getCompareContext();+ PullRequest request = getPullRequest();+ if (request != null) {+ RequestChangesPage.State state = new RequestChangesPage.State();+ state.commentId = activity.getComment().getId();+ if (compareContext.isLeftSide()) {+ state.oldCommit = compareContext.getCompareCommit();+ state.newCommit = activity.getComment().getCommentPos().getCommit();+ } else {+ state.oldCommit = activity.getComment().getCommentPos().getCommit();+ state.newCommit = compareContext.getCompareCommit();+ }+ state.mark = activity.getComment().getCommentPos();+ state.pathFilter = compareContext.getPathFilter();+ state.whitespaceOption = compareContext.getWhitespaceOption();+ PageParameters params = RequestChangesPage.paramsOf(request, state);+ setResponsePage(RequestChangesPage.class, params);+ } else {+ RevisionComparePage.State state = new RevisionComparePage.State();+ CodeComment comment = activity.getComment();+ state.commentId = comment.getId();+ state.compareWithMergeBase = false;+ if (compareContext.isLeftSide()) {+ state.leftSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());+ state.rightSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());+ } else {+ state.leftSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());+ state.rightSide = new DepotAndRevision(comment.getDepot(), compareContext.getCompareCommit());+ }+ state.mark = comment.getCommentPos();+ state.pathFilter = compareContext.getPathFilter();+ state.tabPanel = RevisionComparePage.TabPanel.CHANGES;+ state.whitespaceOption = compareContext.getWhitespaceOption();+ PageParameters params = RevisionComparePage.paramsOf(comment.getDepot(), state);+ setResponsePage(RevisionComparePage.class, params);+ }+ }++ }.add(AttributeAppender.append("title", "This reply is added in a different compare context, click to show")));++ if (StringUtils.isNotBlank(activity.getNote())) {+ MarkdownEditSupport editSupport;+ if (SecurityUtils.canModify(getComment())) {+ editSupport = new MarkdownEditSupport() {++ @Override+ public void setContent(String content) {+ if (identity.clazz == CodeCommentReply.class) {+ CodeCommentReply reply = (CodeCommentReply) activity;+ reply.setContent(content);+ GitPlex.getInstance(CodeCommentReplyManager.class).save(reply);+ } else {+ CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;+ statusChange.setNote(content);+ GitPlex.getInstance(CodeCommentStatusChangeManager.class).save(statusChange);+ }+ }++ @Override+ public long getVersion() {+ return identity.getActivity().getVersion();+ }++ };+ } else {+ editSupport = null;+ }+ activityContainer.add(new MarkdownPanel("content", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ return identity.getActivity().getNote();+ }++ }, editSupport));++ } else {+ activityContainer.add(new Label("content", "<div class='no-note'>No note</div>").setEscapeModelStrings(false));+ }++ WebMarkupContainer foot = new WebMarkupContainer("foot");+ foot.setVisible(SecurityUtils.canModify(activity));++ foot.add(new AjaxLink<Void>("edit") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = new Fragment(activityContainer.getId(), "activityEditFrag",+ CodeCommentPanel.this, Model.of(identity.id));+ Form<?> form = new Form<Void>("form");+ CommentInput contentInput = new CommentInput("content", Model.of(identity.getActivity().getNote())) {++ @Override+ protected AttachmentSupport getAttachmentSupport() {+ return new DepotAttachmentSupport(getComment().getDepot(), getComment().getUUID());+ }++ @Override+ protected Depot getDepot() {+ return getComment().getDepot();+ }++ };+ contentInput.setRequired(identity.clazz == CodeCommentReply.class);+ form.add(contentInput);++ NotificationPanel feedback = new NotificationPanel("feedback", form);+ feedback.setOutputMarkupPlaceholderTag(true);+ form.add(feedback);++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ WebMarkupContainer replyContainer = newActivityContainer(componentId, identity.getActivity());+ fragment.replaceWith(replyContainer);+ target.add(replyContainer);+ }++ });++ long lastVersion = identity.getActivity().getVersion();+ form.add(new AjaxButton("save") {++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(feedback);+ }++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);++ try {+ CodeCommentActivity activity = identity.getActivity();+ if (activity.getVersion() != lastVersion)+ throw new StaleObjectStateException("", "");++ if (identity.clazz == CodeCommentReply.class) {+ CodeCommentReply reply = (CodeCommentReply) activity;+ reply.setContent(contentInput.getModelObject());+ GitPlex.getInstance(CodeCommentReplyManager.class).save(reply);+ } else {+ CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;+ statusChange.setNote(contentInput.getModelObject());+ GitPlex.getInstance(CodeCommentStatusChangeManager.class).save(statusChange);+ }+ WebMarkupContainer activityContainer = newActivityContainer(componentId, identity.getActivity());+ fragment.replaceWith(activityContainer);+ target.add(activityContainer);+ } catch (StaleObjectStateException e) {+ error("Some one changed the content you are editing. Reload the page and try again.");+ target.add(feedback);+ }+ }++ }.add(new Label("label", "Save")));++ fragment.add(form);+ fragment.setOutputMarkupId(true);+ activityContainer.replaceWith(fragment);+ target.add(fragment);+ }++ });+ foot.add(new AjaxLink<Void>("delete") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to delete this reply?"));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ activityContainer.remove();+ GitPlex.getInstance(CodeCommentReplyManager.class).delete((CodeCommentReply) identity.getActivity());+ String script = String.format("$('#%s').remove();", activityContainer.getMarkupId());+ target.appendJavaScript(script);+ }++ }.setVisible(activity instanceof CodeCommentReply));++ activityContainer.add(foot);+ return activityContainer;+ }++ private WebMarkupContainer newAddReplyContainer() {+ WebMarkupContainer addReplyContainer = new Fragment("addReply", "addReplyFrag", this) {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(SecurityUtils.getAccount() != null);+ }++ };+ addReplyContainer.setOutputMarkupId(true);+ addReplyContainer.add(new AjaxLink<Void>("reply") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ onAddReply(target, false);+ }++ });+ return addReplyContainer;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(newCommentContainer());++ activitiesView = new RepeatingView("activities");+ PullRequest request = getPullRequest();++ List<CodeCommentActivity> activities = new ArrayList<>();+ for (CodeCommentReply reply: getComment().getReplies()) {+ if (request == null || request.getRequestComparingInfo(reply.getComparingInfo()) != null) {+ activities.add(reply);+ }+ }+ for (CodeCommentStatusChange statusChange: getComment().getStatusChanges()) {+ if (request == null || request.getRequestComparingInfo(statusChange.getComparingInfo()) != null) {+ activities.add(statusChange);+ }+ }++ activities.sort((o1, o2)->o1.getDate().compareTo(o2.getDate()));++ for (CodeCommentActivity activity: activities) {+ Component activityContainer = newActivityContainer(activitiesView.newChildId(), activity);+ if (!getComment().isVisitedAfter(activity.getDate()))+ activityContainer.add(AttributeAppender.append("class", "new"));+ activitiesView.add(activityContainer);+ }+ add(activitiesView);+ add(newAddReplyContainer());++ setOutputMarkupId(true);++ add(new CodeCommentChangeRenderer(getComment().getId()));+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(CssHeaderItem.forReference(new CssResourceReference(+ CodeCommentPanel.class, "code-comment.css")));+ }++ private void onAddReply(AjaxRequestTarget target, boolean changeStatus) {+ Fragment fragment = new Fragment("addReply", "activityEditFrag", CodeCommentPanel.this);+ Form<?> form = new Form<Void>("form");+ CommentInput contentInput = new CommentInput("content", Model.of("")) {++ @Override+ protected AttachmentSupport getAttachmentSupport() {+ return new DepotAttachmentSupport(getComment().getDepot(), getComment().getUUID());+ }++ @Override+ protected Depot getDepot() {+ return getComment().getDepot();+ }++ };+ contentInput.setRequired(!changeStatus);+ form.add(contentInput);++ NotificationPanel feedback = new NotificationPanel("feedback", form);+ feedback.setOutputMarkupPlaceholderTag(true);+ form.add(feedback);++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(form));+ }++ @Override+ public void onClick(AjaxRequestTarget target) {+ WebMarkupContainer addReplyContainer = newAddReplyContainer();+ fragment.replaceWith(addReplyContainer);+ target.add(addReplyContainer);+ }++ });++ AjaxButton saveButton = new AjaxButton("save") {++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(feedback);+ }++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);++ Account user = SecurityUtils.getAccount();+ CodeComment comment = getComment();+ Date date = new Date();+ CompareContext compareContext = getCompareContext(comment);+ if (changeStatus) {+ CodeCommentStatusChange statusChange = new CodeCommentStatusChange();+ statusChange.setComment(getComment());+ statusChange.setUser(user);+ statusChange.setCompareContext(compareContext);+ statusChange.setResolved(!comment.isResolved());+ statusChange.setDate(date);++ GitPlex.getInstance(CodeCommentManager.class).changeStatus(statusChange);+ onStatusChanged(target, fragment, statusChange);+ onSaveComment(target, getComment());+ } else {+ CodeCommentReply reply = new CodeCommentReply();+ reply.setComment(comment);+ reply.setDate(date);+ reply.setUser(user);+ reply.setContent(contentInput.getModelObject());+ reply.setCompareContext(compareContext);+ GitPlex.getInstance(CodeCommentReplyManager.class).save(reply);+ onReplyAdded(target, fragment, reply);+ }+ }++ };+ if (changeStatus) {+ saveButton.add(new Label("label", getComment().isResolved()?"Confirm unresolve":"Confirm resolve"));+ } else {+ saveButton.add(new Label("label", "Save"));+ saveButton.add(AttributeAppender.append("class", "dirty-aware"));+ }+ form.add(saveButton);++ fragment.add(form);+ fragment.setOutputMarkupId(true);+ get("addReply").replaceWith(fragment);+ target.add(fragment);+ }++ public void onChangeStatus(AjaxRequestTarget target) {+ onAddReply(target, true);+ }++ private void onStatusChanged(AjaxRequestTarget target, Fragment fragment, CodeCommentStatusChange statusChange) {+ WebMarkupContainer activityContainer = newActivityContainer(activitiesView.newChildId(), statusChange);+ activitiesView.add(activityContainer);++ String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');",+ CodeCommentPanel.this.getMarkupId(), activityContainer.getMarkupId());+ target.prependJavaScript(script);+ target.add(activityContainer);++ WebMarkupContainer addReplyContainer = newAddReplyContainer();+ fragment.replaceWith(addReplyContainer);+ target.add(addReplyContainer);+ }++ private void onReplyAdded(AjaxRequestTarget target, Fragment fragment, @Nullable CodeCommentReply reply) {+ if (reply != null) {+ WebMarkupContainer activityContainer = newActivityContainer(activitiesView.newChildId(), reply);+ activitiesView.add(activityContainer);++ String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');",+ CodeCommentPanel.this.getMarkupId(), activityContainer.getMarkupId());+ target.prependJavaScript(script);+ target.add(activityContainer);+ }++ WebMarkupContainer addReplyContainer = newAddReplyContainer();+ fragment.replaceWith(addReplyContainer);+ target.add(addReplyContainer);+ }++ protected abstract void onDeleteComment(AjaxRequestTarget target, CodeComment comment);++ protected abstract void onSaveComment(AjaxRequestTarget target, CodeComment comment);++ protected abstract CompareContext getCompareContext(CodeComment comment);++ @Nullable+ protected abstract PullRequest getPullRequest();++ private static class ActivityIdentity implements Serializable {++ final Class<? extends CodeCommentActivity> clazz;++ final Long id;++ ActivityIdentity(CodeCommentActivity activity) {+ this.clazz = activity.getClass();+ this.id = activity.getId();+ }++ CodeCommentActivity getActivity() {+ return GitPlex.getInstance(Dao.class).load(clazz, id);+ }++ }+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.javaindex 9382662d7c..ed9fe01e9d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java@@ -1,708 +1,726 @@-package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview;--import java.util.ArrayList;-import java.util.Arrays;-import java.util.Date;-import java.util.List;--import org.apache.wicket.Component;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;-import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;-import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;-import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;-import org.apache.wicket.event.Broadcast;-import org.apache.wicket.event.IEvent;-import org.apache.wicket.markup.head.CssHeaderItem;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.html.WebMarkupContainer;-import org.apache.wicket.markup.html.basic.Label;-import org.apache.wicket.markup.html.form.DropDownChoice;-import org.apache.wicket.markup.html.form.Form;-import org.apache.wicket.markup.html.form.IChoiceRenderer;-import org.apache.wicket.markup.html.list.ListItem;-import org.apache.wicket.markup.html.list.ListView;-import org.apache.wicket.markup.html.panel.Fragment;-import org.apache.wicket.markup.repeater.RepeatingView;-import org.apache.wicket.model.IModel;-import org.apache.wicket.model.LoadableDetachableModel;-import org.apache.wicket.model.Model;-import org.apache.wicket.request.mapper.parameter.PageParameters;-import org.apache.wicket.request.resource.CssResourceReference;-import org.joda.time.DateTime;--import com.google.common.base.Preconditions;-import com.pmease.commons.hibernate.dao.Dao;-import com.pmease.commons.wicket.behavior.TooltipBehavior;-import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.entity.Account;-import com.pmease.gitplex.core.entity.Depot;-import com.pmease.gitplex.core.entity.PullRequest;-import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;-import com.pmease.gitplex.core.entity.PullRequestComment;-import com.pmease.gitplex.core.entity.PullRequestReference;-import com.pmease.gitplex.core.entity.PullRequestStatusChange;-import com.pmease.gitplex.core.entity.PullRequestUpdate;-import com.pmease.gitplex.core.entity.PullRequestWatch;-import com.pmease.gitplex.core.entity.PullRequestReview;-import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;-import com.pmease.gitplex.core.manager.AccountManager;-import com.pmease.gitplex.core.manager.PullRequestCommentManager;-import com.pmease.gitplex.core.manager.PullRequestManager;-import com.pmease.gitplex.core.security.ObjectPermission;-import com.pmease.gitplex.core.security.SecurityUtils;-import com.pmease.gitplex.web.component.avatar.Avatar;-import com.pmease.gitplex.web.component.avatar.AvatarLink;-import com.pmease.gitplex.web.component.comment.CommentInput;-import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;-import com.pmease.gitplex.web.component.pullrequest.ReviewResultIcon;-import com.pmease.gitplex.web.component.pullrequest.requestassignee.AssigneeChoice;-import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerAvatar;-import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerChoice;-import com.pmease.gitplex.web.model.EntityModel;-import com.pmease.gitplex.web.model.ReviewersModel;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.CommentRemoved;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.CommentedActivity;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.OpenedActivity;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.ReferencedActivity;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.StatusChangeActivity;-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.UpdatedActivity;-import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.RequestListPage;-import com.pmease.gitplex.web.websocket.PullRequestChanged;--import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig.Placement;--@SuppressWarnings("serial")-public class RequestOverviewPage extends RequestDetailPage {-- private static final String ASSIGNEE_HELP = "Assignee has write permission to the "- + "repository and is resonsible for integrating the pull request into "- + "target branch after it passes gate keeper check.";-- private enum WatchStatus {- WATCHING("Watching"),- NOT_WATCHING("Not Watching"),- IGNORE("Ignore");-- private final String displayName;-- WatchStatus(String displayName) {- this.displayName = displayName;- }-- @Override- public String toString() {- return displayName;- }-- };-- private RepeatingView activitiesView;-- public RequestOverviewPage(PageParameters params) {- super(params);- }-- private Component newActivityRow(String id, PullRequestActivity activity) {- WebMarkupContainer row = new WebMarkupContainer(id, Model.of(activity)) {-- @Override- public void onEvent(IEvent<?> event) {- super.onEvent(event);-- if (event.getPayload() instanceof CommentRemoved) {- CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();- remove();- commentRemoved.getPartialPageRequestHandler().appendJavaScript(String.format("$('#%s').remove();", getMarkupId()));- }- }-- };-- row.setOutputMarkupId(true);-- if (row.get("content") == null)- row.add(activity.render("content"));-- WebMarkupContainer avatarColumn = new WebMarkupContainer("avatar");- row.add(avatarColumn);-- if (activity instanceof OpenedActivity) {- row.add(AttributeAppender.append("class", " discussion"));- avatarColumn.add(new AvatarLink("avatar", ((OpenedActivity)activity).getRequest().getSubmitter(), null));- } else if (activity instanceof CommentedActivity) {- row.add(AttributeAppender.append("class", " discussion"));- avatarColumn.add(new AvatarLink("avatar", ((CommentedActivity)activity).getComment().getUser(), null));- } else {- row.add(AttributeAppender.append("class", " non-discussion"));- avatarColumn.add(new WebMarkupContainer("avatar"));- }-- if (activity instanceof UpdatedActivity)- row.add(AttributeAppender.append("class", " update"));- else- row.add(AttributeAppender.append("class", " non-update"));-- return row;- }-- private List<PullRequestActivity> getActivities() {- PullRequest request = getPullRequest();- List<PullRequestActivity> activities = new ArrayList<>();-- activities.add(new OpenedActivity(request));-- for (PullRequestUpdate update: request.getUpdates())- activities.add(new UpdatedActivity(update));-- for (PullRequestComment comment: request.getComments()) {- activities.add(new CommentedActivity(comment));- }-- for (PullRequestReference reference: request.getReferencedBy()) {- activities.add(new ReferencedActivity(reference));- }-- for (PullRequestStatusChange statusChange: request.getStatusChanges()) {- activities.add(new StatusChangeActivity(statusChange));- }-- activities.sort((o1, o2) -> {- if (o1.getDate().getTime()<o2.getDate().getTime())- return -1;- else if (o1.getDate().getTime()>o2.getDate().getTime())- return 1;- else if (o1 instanceof OpenedActivity)- return -1;- else- return 1;- });-- return activities;- }-- @Override- public void onEvent(IEvent<?> event) {- super.onEvent(event);-- if (event.getPayload() instanceof PullRequestChanged) {- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();- IPartialPageRequestHandler partialPageRequestHandler = pullRequestChanged.getPartialPageRequestHandler();- List<PullRequestActivity> activities = getActivities();-- PullRequest request = getPullRequest();- @SuppressWarnings("deprecation")- Component prevActivityRow = activitiesView.get(activitiesView.size()-1);- PullRequestActivity lastActivity = (PullRequestActivity) prevActivityRow.getDefaultModelObject();- for (PullRequestActivity activity: activities) {- if (activity.getDate().getTime()>lastActivity.getDate().getTime()) {- Component newActivityRow = newActivityRow(activitiesView.newChildId(), activity);- Component sinceChangesRow = null;- if (!request.isVisitedAfter(activity.getDate())) {- PullRequestActivity prevActivity = (PullRequestActivity) prevActivityRow.getDefaultModelObject();- if (request.isVisitedAfter(prevActivity.getDate())) {- Date sinceDate = new DateTime(activity.getDate()).minusMillis(1).toDate();- sinceChangesRow = newSinceChangesRow(activitiesView.newChildId(), sinceDate);- activitiesView.add(sinceChangesRow);- String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",- sinceChangesRow.getMarkupId(), prevActivityRow.getMarkupId());- partialPageRequestHandler.prependJavaScript(script);- partialPageRequestHandler.add(sinceChangesRow);- }- newActivityRow.add(AttributeAppender.append("class", "new"));- if (activity instanceof UpdatedActivity) {- partialPageRequestHandler.appendJavaScript("$('tr.since-changes').addClass('visible');");- }- }- activitiesView.add(newActivityRow);-- String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",- newActivityRow.getMarkupId(),- sinceChangesRow!=null?sinceChangesRow.getMarkupId():prevActivityRow.getMarkupId());- partialPageRequestHandler.prependJavaScript(script);- partialPageRequestHandler.add(newActivityRow);-- prevActivityRow = newActivityRow;- }- }- }- }-- private Component newSinceChangesRow(String id, Date sinceDate) {- WebMarkupContainer row = new WebMarkupContainer(id);- row.setOutputMarkupId(true);- row.add(AttributeAppender.append("class", " non-discussion"));-- WebMarkupContainer avatarColumn = new WebMarkupContainer("avatar");- avatarColumn.add(new WebMarkupContainer("avatar"));- row.add(avatarColumn);-- WebMarkupContainer contentColumn = new Fragment("content", "sinceChangesRowContentFrag", this);- contentColumn.add(new SinceChangesLink("sinceChanges", requestModel, sinceDate));- row.add(contentColumn);-- row.add(AttributeAppender.append("class", "since-changes"));-- return row;- }-- @Override- protected void onInitialize() {- super.onInitialize();-- add(activitiesView = new RepeatingView("requestActivities"));- activitiesView.setOutputMarkupId(true);-- List<PullRequestActivity> activities = getActivities();-- PullRequest request = getPullRequest();- Component sinceChangesRow = null;- boolean visible = false;- for (int i=0; i<activities.size(); i++) {- PullRequestActivity activity = activities.get(i);- Component row = newActivityRow(activitiesView.newChildId(), activity);- if (!request.isVisitedAfter(activity.getDate())) {- row.add(AttributeAppender.append("class", "new"));- if (sinceChangesRow == null) {- if (i != 0) {- Date prevActivityDate = activities.get(i-1).getDate();- if (request.isVisitedAfter(prevActivityDate)) {- Date sinceDate = new DateTime(activity.getDate()).minusMillis(1).toDate();- System.out.println(sinceDate.getTime());- sinceChangesRow = newSinceChangesRow(activitiesView.newChildId(), sinceDate);- activitiesView.add(sinceChangesRow);- }- }- }- if (activity instanceof UpdatedActivity) {- visible = true;- }- }- if (sinceChangesRow != null && visible)- sinceChangesRow.add(AttributeAppender.append("class", "visible"));- activitiesView.add(row);- }-- WebMarkupContainer addComment = new WebMarkupContainer("addComment") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(getLoginUser() != null);- }-- };- addComment.setOutputMarkupId(true);- add(addComment);-- Form<?> form = new Form<Void>("form");- addComment.add(form);-- CommentInput input = new CommentInput("input", Model.of("")) {-- @Override- protected AttachmentSupport getAttachmentSupport() {- return new DepotAttachmentSupport(getDepot(), getPullRequest().getUUID());- }-- @Override- protected Depot getDepot() {- return RequestOverviewPage.this.getDepot();- }-- };- input.setRequired(true);- form.add(input);-- form.add(new NotificationPanel("feedback", input));-- form.add(new AjaxSubmitLink("comment") {-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);-- PullRequestComment comment = new PullRequestComment();- comment.setRequest(getPullRequest());- comment.setUser(getLoginUser());- comment.setContent(input.getModelObject());- GitPlex.getInstance(PullRequestCommentManager.class).save(comment);- input.setModelObject("");-- target.add(addComment);-- @SuppressWarnings("deprecation")- Component lastActivityRow = activitiesView.get(activitiesView.size()-1);- Component newActivityRow = newActivityRow(activitiesView.newChildId(), new CommentedActivity(comment));- activitiesView.add(newActivityRow);-- String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",- newActivityRow.getMarkupId(), lastActivityRow.getMarkupId());- target.prependJavaScript(script);- target.add(newActivityRow);- }-- @Override- protected void onError(AjaxRequestTarget target, Form<?> form) {- super.onError(target, form);- target.add(form);- }-- });-- add(newIntegrationStrategyContainer());- add(newAssigneeContainer());- add(newReviewersContainer());- add(newWatchContainer());- }-- private WebMarkupContainer newIntegrationStrategyContainer() {- WebMarkupContainer integrationStrategyContainer = new WebMarkupContainer("integrationStrategy") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(getPullRequest().isOpen());- }-- };-- PullRequest request = getPullRequest();-- final List<IntegrationStrategy> strategies =- GitPlex.getInstance(PullRequestManager.class).getApplicableIntegrationStrategies(request);- if (!strategies.contains(request.getIntegrationStrategy())) {- request.setIntegrationStrategy(strategies.get(0));- GitPlex.getInstance(Dao.class).persist(request);- }- IModel<IntegrationStrategy> strategyModel = new IModel<IntegrationStrategy>() {-- @Override- public void detach() {- }-- @Override- public IntegrationStrategy getObject() {- return getPullRequest().getIntegrationStrategy();- }-- @Override- public void setObject(IntegrationStrategy object) {- getPullRequest().setIntegrationStrategy(object);- }-- };-- DropDownChoice<IntegrationStrategy> editor =- new DropDownChoice<IntegrationStrategy>("editor", strategyModel, strategies) {-- @Override- protected void onConfigure() {- super.onConfigure();-- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());- setVisible(SecurityUtils.getSubject().isPermitted(writePermission) && strategies.size() > 1);- }-- };- editor.add(new OnChangeAjaxBehavior() {-- @Override- protected void onUpdate(AjaxRequestTarget target) {- GitPlex.getInstance(Dao.class).persist(getPullRequest());- send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target, getPullRequest()));- }-- });- integrationStrategyContainer.add(editor);-- integrationStrategyContainer.add(new Label("viewer", request.getIntegrationStrategy()) {-- @Override- protected void onConfigure() {- super.onConfigure();-- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());- setVisible(!SecurityUtils.getSubject().isPermitted(writePermission) || strategies.size() == 1);- }-- });-- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());-- if (!SecurityUtils.getSubject().isPermitted(writePermission) || strategies.size() == 1) {- integrationStrategyContainer.add(new WebMarkupContainer("help").add(- new TooltipBehavior(Model.of(getPullRequest().getIntegrationStrategy().getDescription()))));- } else {- StringBuilder strategyHelp = new StringBuilder("<dl class='integration-strategy-help'>");-- for (IntegrationStrategy strategy: strategies) {- strategyHelp.append("<dt>").append(strategy.toString()).append("</dt>");- strategyHelp.append("<dd>").append(strategy.getDescription()).append("</dd>");- }-- strategyHelp.append("</dl>");-- integrationStrategyContainer.add(new WebMarkupContainer("help")- .add(AttributeAppender.append("data-html", "true"))- .add(new TooltipBehavior(Model.of(strategyHelp.toString()), new TooltipConfig().withPlacement(Placement.left))));- }-- return integrationStrategyContainer;- }-- private WebMarkupContainer newWatchContainer() {- final WebMarkupContainer watchContainer = new WebMarkupContainer("watch") {-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(getLoginUser() != null);- }-- };-- watchContainer.setOutputMarkupId(true);-- final IModel<WatchStatus> optionModel = new LoadableDetachableModel<WatchStatus>() {-- @Override- protected WatchStatus load() {- PullRequestWatch watch = getPullRequest().getWatch(getLoginUser());- if (watch != null) {- if (watch.isIgnore())- return WatchStatus.IGNORE;- else- return WatchStatus.WATCHING;- } else {- return WatchStatus.NOT_WATCHING;- }- }-- };-- List<WatchStatus> options = Arrays.asList(WatchStatus.values());-- IChoiceRenderer<WatchStatus> choiceRenderer = new IChoiceRenderer<WatchStatus>() {-- @Override- public Object getDisplayValue(WatchStatus object) {- return object.toString();- }-- @Override- public String getIdValue(WatchStatus object, int index) {- return object.name();- }-- @Override- public WatchStatus getObject(String id, IModel<? extends List<? extends WatchStatus>> choices) {- return WatchStatus.valueOf(id);- }-- };- DropDownChoice<WatchStatus> choice = new DropDownChoice<>("option", optionModel,- options, choiceRenderer);-- choice.add(new OnChangeAjaxBehavior() {-- @Override- protected void onUpdate(AjaxRequestTarget target) {- PullRequestWatch watch = getPullRequest().getWatch(getLoginUser());- Dao dao = GitPlex.getInstance(Dao.class);- if (optionModel.getObject() == WatchStatus.WATCHING) {- if (watch != null) {- watch.setIgnore(false);- watch.setReason(null);- } else {- watch = new PullRequestWatch();- watch.setRequest(getPullRequest());- watch.setUser(getLoginUser());- getPullRequest().getWatches().add(watch);- }- dao.persist(watch);- } else if (optionModel.getObject() == WatchStatus.NOT_WATCHING) {- if (watch != null) {- dao.remove(watch);- getPullRequest().getWatches().remove(watch);- }- } else {- if (watch != null) {- watch.setIgnore(true);- } else {- watch = new PullRequestWatch();- watch.setRequest(getPullRequest());- watch.setUser(getLoginUser());- watch.setIgnore(true);- getPullRequest().getWatches().add(watch);- }- dao.persist(watch);- }- target.add(watchContainer);- }-- });- watchContainer.add(choice);- watchContainer.add(new Label("help", new LoadableDetachableModel<String>() {-- @Override- protected String load() {- PullRequestWatch watch = getPullRequest().getWatch(getLoginUser());- if (watch != null) {- if (watch.isIgnore()) {- return "Ignore notifications irrelevant to me.";- } else if (watch.getReason() != null) {- return watch.getReason();- } else {- return "You will be notified of any activities.";- }- } else {- return "Ignore notifications irrelevant to me, but start to watch once I am involved.";- }- }-- }));-- return watchContainer;- }-- private Component newAssigneeContainer() {- PullRequest request = getPullRequest();-- Fragment assigneeContainer;- Account assignee = request.getAssignee();- Account currentUser = getLoginUser();- boolean canChangeAssignee = request.isOpen()- && (currentUser != null && currentUser.equals(request.getSubmitter())- || SecurityUtils.canManage(getDepot()));- if (assignee != null) {-- if (canChangeAssignee) {- assigneeContainer = new Fragment("assignee", "assigneeEditFrag", this);- assigneeContainer.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(ASSIGNEE_HELP))));-- AssigneeChoice choice = new AssigneeChoice("assignee", depotModel, new IModel<Account>() {-- @Override- public void detach() {- }-- @Override- public Account getObject() {- return getPullRequest().getAssignee();- }-- @Override- public void setObject(Account object) {- getPullRequest().setAssignee(object);- }-- });- choice.setRequired(true);- assigneeContainer.add(choice);- choice.add(new AjaxFormComponentUpdatingBehavior("change") {-- @Override- protected void onUpdate(AjaxRequestTarget target) {- Preconditions.checkNotNull(getPullRequest().getAssignee());- GitPlex.getInstance(PullRequestManager.class).changeAssignee(getPullRequest());- }-- });- } else {- assigneeContainer = new Fragment("assignee", "assigneeViewFrag", this);- assigneeContainer.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(ASSIGNEE_HELP))));- assigneeContainer.add(new Avatar("assignee", assignee, new TooltipConfig()));- }- } else {- assigneeContainer = new Fragment("assignee", "noAssigneeFrag", this);- }-- return assigneeContainer;- }-- private WebMarkupContainer newReviewersContainer() {- final WebMarkupContainer reviewersContainer = new WebMarkupContainer("reviewers") {-- @Override- protected void onConfigure() {- super.onConfigure();-- PullRequest request = getPullRequest();- if (request.getReviewInvitations().isEmpty()) {- Account currentUser = GitPlex.getInstance(AccountManager.class).getCurrent();- setVisible(request.isOpen()- && !request.getPotentialReviewers().isEmpty()- && (currentUser != null && currentUser.equals(request.getSubmitter()) || SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotAdmin(request.getTarget().getDepot()))));- } else {- setVisible(true);- }- }-- };- reviewersContainer.setOutputMarkupId(true);- reviewersContainer.add(new ListView<PullRequestReviewInvitation>("reviewers", new ReviewersModel(requestModel)) {-- @Override- protected void populateItem(ListItem<PullRequestReviewInvitation> item) {- PullRequestReviewInvitation invitation = item.getModelObject();- item.add(new ReviewerAvatar("avatar", invitation) {-- @Override- protected void onAvatarRemove(AjaxRequestTarget target) {- super.onAvatarRemove(target);-- target.add(reviewersContainer);- send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target, getPullRequest()));- }-- });-- List<PullRequestReview> userReviews = new ArrayList<>();- for (PullRequestReview review: getPullRequest().getReviews()) {- if (review.getUser().equals(invitation.getUser()))- userReviews.add(review);- }- if (!userReviews.isEmpty()) {- PullRequestReview review = userReviews.get(userReviews.size()-1);- item.add(new ReviewResultIcon("result", new EntityModel<PullRequestReview>(review)));- } else {- item.add(new WebMarkupContainer("result").setVisible(false));- }- }-- });-- reviewersContainer.add(new ReviewerChoice("addReviewer", requestModel) {-- @Override- protected void onSelect(AjaxRequestTarget target, Account user) {- super.onSelect(target, user);-- target.add(reviewersContainer);- send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target, getPullRequest()));- }-- });-- return reviewersContainer;- }-- @Override- protected void onSelect(AjaxRequestTarget target, Depot depot) {- setResponsePage(RequestListPage.class, paramsOf(depot));- }-- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);- response.render(CssHeaderItem.forReference(- new CssResourceReference(RequestOverviewPage.class, "request-overview.css")));- }--}+package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview;++import java.util.ArrayList;+import java.util.Arrays;+import java.util.Date;+import java.util.List;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;+import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;+import org.apache.wicket.event.Broadcast;+import org.apache.wicket.event.IEvent;+import org.apache.wicket.markup.head.CssHeaderItem;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.markup.html.form.DropDownChoice;+import org.apache.wicket.markup.html.form.Form;+import org.apache.wicket.markup.html.form.IChoiceRenderer;+import org.apache.wicket.markup.html.list.ListItem;+import org.apache.wicket.markup.html.list.ListView;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.markup.repeater.RepeatingView;+import org.apache.wicket.model.IModel;+import org.apache.wicket.model.LoadableDetachableModel;+import org.apache.wicket.model.Model;+import org.apache.wicket.request.mapper.parameter.PageParameters;+import org.apache.wicket.request.resource.CssResourceReference;+import org.joda.time.DateTime;++import com.google.common.base.Preconditions;+import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.wicket.behavior.TooltipBehavior;+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.Account;+import com.pmease.gitplex.core.entity.Depot;+import com.pmease.gitplex.core.entity.PullRequest;+import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;+import com.pmease.gitplex.core.entity.PullRequestComment;+import com.pmease.gitplex.core.entity.PullRequestReference;+import com.pmease.gitplex.core.entity.PullRequestReview;+import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;+import com.pmease.gitplex.core.entity.PullRequestStatusChange;+import com.pmease.gitplex.core.entity.PullRequestUpdate;+import com.pmease.gitplex.core.entity.PullRequestWatch;+import com.pmease.gitplex.core.manager.AccountManager;+import com.pmease.gitplex.core.manager.PullRequestCommentManager;+import com.pmease.gitplex.core.manager.PullRequestManager;+import com.pmease.gitplex.core.manager.VisitInfoManager;+import com.pmease.gitplex.core.security.ObjectPermission;+import com.pmease.gitplex.core.security.SecurityUtils;+import com.pmease.gitplex.web.component.avatar.Avatar;+import com.pmease.gitplex.web.component.avatar.AvatarLink;+import com.pmease.gitplex.web.component.comment.CommentInput;+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;+import com.pmease.gitplex.web.component.pullrequest.ReviewResultIcon;+import com.pmease.gitplex.web.component.pullrequest.requestassignee.AssigneeChoice;+import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerAvatar;+import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerChoice;+import com.pmease.gitplex.web.model.EntityModel;+import com.pmease.gitplex.web.model.ReviewersModel;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.CommentRemoved;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.CommentedActivity;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.OpenedActivity;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.ReferencedActivity;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.StatusChangeActivity;+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.activity.UpdatedActivity;+import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.RequestListPage;+import com.pmease.gitplex.web.websocket.PullRequestChanged;++import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;+import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;+import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig.Placement;++@SuppressWarnings("serial")+public class RequestOverviewPage extends RequestDetailPage {++ private static final String ASSIGNEE_HELP = "Assignee has write permission to the "+ + "repository and is resonsible for integrating the pull request into "+ + "target branch after it passes gate keeper check.";++ private enum WatchStatus {+ WATCHING("Watching"),+ NOT_WATCHING("Not Watching"),+ IGNORE("Ignore");++ private final String displayName;++ WatchStatus(String displayName) {+ this.displayName = displayName;+ }++ @Override+ public String toString() {+ return displayName;+ }++ };++ private RepeatingView activitiesView;++ public RequestOverviewPage(PageParameters params) {+ super(params);+ }++ private Component newActivityRow(String id, PullRequestActivity activity) {+ WebMarkupContainer row = new WebMarkupContainer(id, Model.of(activity)) {++ @Override+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);++ if (event.getPayload() instanceof CommentRemoved) {+ CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();+ remove();+ commentRemoved.getPartialPageRequestHandler().appendJavaScript(String.format("$('#%s').remove();", getMarkupId()));+ }+ }++ };++ row.setOutputMarkupId(true);++ if (row.get("content") == null)+ row.add(activity.render("content"));++ WebMarkupContainer avatarColumn = new WebMarkupContainer("avatar");+ row.add(avatarColumn);++ if (activity instanceof OpenedActivity) {+ row.add(AttributeAppender.append("class", " discussion"));+ avatarColumn.add(new AvatarLink("avatar", ((OpenedActivity)activity).getRequest().getSubmitter(), null));+ } else if (activity instanceof CommentedActivity) {+ row.add(AttributeAppender.append("class", " discussion"));+ avatarColumn.add(new AvatarLink("avatar", ((CommentedActivity)activity).getComment().getUser(), null));+ } else {+ row.add(AttributeAppender.append("class", " non-discussion"));+ avatarColumn.add(new WebMarkupContainer("avatar"));+ }++ if (activity instanceof UpdatedActivity)+ row.add(AttributeAppender.append("class", " update"));+ else+ row.add(AttributeAppender.append("class", " non-update"));++ return row;+ }++ private List<PullRequestActivity> getActivities() {+ PullRequest request = getPullRequest();+ List<PullRequestActivity> activities = new ArrayList<>();++ activities.add(new OpenedActivity(request));++ for (PullRequestUpdate update: request.getUpdates())+ activities.add(new UpdatedActivity(update));++ for (PullRequestComment comment: request.getComments()) {+ activities.add(new CommentedActivity(comment));+ }++ for (PullRequestReference reference: request.getReferencedBy()) {+ activities.add(new ReferencedActivity(reference));+ }++ for (PullRequestStatusChange statusChange: request.getStatusChanges()) {+ activities.add(new StatusChangeActivity(statusChange));+ }++ activities.sort((o1, o2) -> {+ if (o1.getDate().getTime()<o2.getDate().getTime())+ return -1;+ else if (o1.getDate().getTime()>o2.getDate().getTime())+ return 1;+ else if (o1 instanceof OpenedActivity)+ return -1;+ else+ return 1;+ });++ return activities;+ }++ @Override+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);++ if (event.getPayload() instanceof PullRequestChanged) {+ PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();+ IPartialPageRequestHandler partialPageRequestHandler = pullRequestChanged.getPartialPageRequestHandler();++ PullRequest request = getPullRequest();+ @SuppressWarnings("deprecation")+ Component prevActivityRow = activitiesView.get(activitiesView.size()-1);+ PullRequestActivity lastActivity = (PullRequestActivity) prevActivityRow.getDefaultModelObject();+ List<PullRequestActivity> newActivities = new ArrayList<>();+ for (PullRequestActivity activity: getActivities()) {+ if (activity.getDate().getTime() > lastActivity.getDate().getTime())+ newActivities.add(activity);+ }++ Component sinceChangesRow = null;+ for (Component row: activitiesView) {+ if (row.getDefaultModelObject() == null) {+ sinceChangesRow = row;+ break;+ }+ }++ if (sinceChangesRow == null && !newActivities.isEmpty()) {+ Date sinceDate = new DateTime(newActivities.iterator().next().getDate()).minusMillis(1).toDate();+ sinceChangesRow = newSinceChangesRow(activitiesView.newChildId(), sinceDate);+ activitiesView.add(sinceChangesRow);+ String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",+ sinceChangesRow.getMarkupId(), prevActivityRow.getMarkupId());+ partialPageRequestHandler.prependJavaScript(script);+ partialPageRequestHandler.add(sinceChangesRow);+ prevActivityRow = sinceChangesRow;+ }++ for (PullRequestActivity activity: newActivities) {+ Component newActivityRow = newActivityRow(activitiesView.newChildId(), activity);+ newActivityRow.add(AttributeAppender.append("class", "new"));+ activitiesView.add(newActivityRow);++ String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",+ newActivityRow.getMarkupId(), prevActivityRow.getMarkupId());+ partialPageRequestHandler.prependJavaScript(script);+ partialPageRequestHandler.add(newActivityRow);++ if (activity instanceof UpdatedActivity) {+ partialPageRequestHandler.appendJavaScript("$('tr.since-changes').addClass('visible');");+ }+ prevActivityRow = newActivityRow;+ }++ Account user = GitPlex.getInstance(AccountManager.class).getCurrent();+ if (user != null)+ GitPlex.getInstance(VisitInfoManager.class).visit(user, request);+ }+ }++ private Component newSinceChangesRow(String id, Date sinceDate) {+ WebMarkupContainer row = new WebMarkupContainer(id);+ row.setOutputMarkupId(true);+ row.add(AttributeAppender.append("class", " non-discussion"));++ WebMarkupContainer avatarColumn = new WebMarkupContainer("avatar");+ avatarColumn.add(new WebMarkupContainer("avatar"));+ row.add(avatarColumn);++ WebMarkupContainer contentColumn = new Fragment("content", "sinceChangesRowContentFrag", this);+ contentColumn.add(new SinceChangesLink("sinceChanges", requestModel, sinceDate));+ row.add(contentColumn);++ row.add(AttributeAppender.append("class", "since-changes"));++ return row;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(activitiesView = new RepeatingView("requestActivities"));+ activitiesView.setOutputMarkupId(true);++ List<PullRequestActivity> activities = getActivities();++ PullRequest request = getPullRequest();+ List<PullRequestActivity> oldActivities = new ArrayList<>();+ List<PullRequestActivity> newActivities = new ArrayList<>();+ for (PullRequestActivity activity: activities) {+ if (request.isVisitedAfter(activity.getDate())) {+ oldActivities.add(activity);+ } else {+ newActivities.add(activity);+ }+ }++ for (PullRequestActivity activity: oldActivities) {+ activitiesView.add(newActivityRow(activitiesView.newChildId(), activity));+ }++ if (!oldActivities.isEmpty() && !newActivities.isEmpty()) {+ Date sinceDate = new DateTime(newActivities.iterator().next().getDate()).minusMillis(1).toDate();+ Component row = newSinceChangesRow(activitiesView.newChildId(), sinceDate);+ for (PullRequestActivity activity: newActivities) {+ if (activity instanceof UpdatedActivity) {+ row.add(AttributeAppender.append("class", "visible"));+ break;+ }+ }+ activitiesView.add(row);+ }++ for (PullRequestActivity activity: newActivities) {+ Component row = newActivityRow(activitiesView.newChildId(), activity);+ row.add(AttributeAppender.append("class", "new"));+ activitiesView.add(row);+ }++ WebMarkupContainer addComment = new WebMarkupContainer("addComment") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(getLoginUser() != null);+ }++ };+ addComment.setOutputMarkupId(true);+ add(addComment);++ Form<?> form = new Form<Void>("form");+ addComment.add(form);++ CommentInput input = new CommentInput("input", Model.of("")) {++ @Override+ protected AttachmentSupport getAttachmentSupport() {+ return new DepotAttachmentSupport(getDepot(), getPullRequest().getUUID());+ }++ @Override+ protected Depot getDepot() {+ return RequestOverviewPage.this.getDepot();+ }++ };+ input.setRequired(true);+ form.add(input);++ form.add(new NotificationPanel("feedback", input));++ form.add(new AjaxSubmitLink("comment") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);++ PullRequestComment comment = new PullRequestComment();+ comment.setRequest(getPullRequest());+ comment.setUser(getLoginUser());+ comment.setContent(input.getModelObject());+ GitPlex.getInstance(PullRequestCommentManager.class).save(comment);+ input.setModelObject("");++ target.add(addComment);++ @SuppressWarnings("deprecation")+ Component lastActivityRow = activitiesView.get(activitiesView.size()-1);+ Component newActivityRow = newActivityRow(activitiesView.newChildId(), new CommentedActivity(comment));+ activitiesView.add(newActivityRow);++ String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",+ newActivityRow.getMarkupId(), lastActivityRow.getMarkupId());+ target.prependJavaScript(script);+ target.add(newActivityRow);+ }++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(form);+ }++ });++ add(newIntegrationStrategyContainer());+ add(newAssigneeContainer());+ add(newReviewersContainer());+ add(newWatchContainer());+ }++ private WebMarkupContainer newIntegrationStrategyContainer() {+ WebMarkupContainer integrationStrategyContainer = new WebMarkupContainer("integrationStrategy") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(getPullRequest().isOpen());+ }++ };++ PullRequest request = getPullRequest();++ final List<IntegrationStrategy> strategies =+ GitPlex.getInstance(PullRequestManager.class).getApplicableIntegrationStrategies(request);+ if (!strategies.contains(request.getIntegrationStrategy())) {+ request.setIntegrationStrategy(strategies.get(0));+ GitPlex.getInstance(Dao.class).persist(request);+ }+ IModel<IntegrationStrategy> strategyModel = new IModel<IntegrationStrategy>() {++ @Override+ public void detach() {+ }++ @Override+ public IntegrationStrategy getObject() {+ return getPullRequest().getIntegrationStrategy();+ }++ @Override+ public void setObject(IntegrationStrategy object) {+ getPullRequest().setIntegrationStrategy(object);+ }++ };++ DropDownChoice<IntegrationStrategy> editor =+ new DropDownChoice<IntegrationStrategy>("editor", strategyModel, strategies) {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());+ setVisible(SecurityUtils.getSubject().isPermitted(writePermission) && strategies.size() > 1);+ }++ };+ editor.add(new OnChangeAjaxBehavior() {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ GitPlex.getInstance(Dao.class).persist(getPullRequest());+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target, getPullRequest()));+ }++ });+ integrationStrategyContainer.add(editor);++ integrationStrategyContainer.add(new Label("viewer", request.getIntegrationStrategy()) {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());+ setVisible(!SecurityUtils.getSubject().isPermitted(writePermission) || strategies.size() == 1);+ }++ });++ ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());++ if (!SecurityUtils.getSubject().isPermitted(writePermission) || strategies.size() == 1) {+ integrationStrategyContainer.add(new WebMarkupContainer("help").add(+ new TooltipBehavior(Model.of(getPullRequest().getIntegrationStrategy().getDescription()))));+ } else {+ StringBuilder strategyHelp = new StringBuilder("<dl class='integration-strategy-help'>");++ for (IntegrationStrategy strategy: strategies) {+ strategyHelp.append("<dt>").append(strategy.toString()).append("</dt>");+ strategyHelp.append("<dd>").append(strategy.getDescription()).append("</dd>");+ }++ strategyHelp.append("</dl>");++ integrationStrategyContainer.add(new WebMarkupContainer("help")+ .add(AttributeAppender.append("data-html", "true"))+ .add(new TooltipBehavior(Model.of(strategyHelp.toString()), new TooltipConfig().withPlacement(Placement.left))));+ }++ return integrationStrategyContainer;+ }++ private WebMarkupContainer newWatchContainer() {+ final WebMarkupContainer watchContainer = new WebMarkupContainer("watch") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(getLoginUser() != null);+ }++ };++ watchContainer.setOutputMarkupId(true);++ final IModel<WatchStatus> optionModel = new LoadableDetachableModel<WatchStatus>() {++ @Override+ protected WatchStatus load() {+ PullRequestWatch watch = getPullRequest().getWatch(getLoginUser());+ if (watch != null) {+ if (watch.isIgnore())+ return WatchStatus.IGNORE;+ else+ return WatchStatus.WATCHING;+ } else {+ return WatchStatus.NOT_WATCHING;+ }+ }++ };++ List<WatchStatus> options = Arrays.asList(WatchStatus.values());++ IChoiceRenderer<WatchStatus> choiceRenderer = new IChoiceRenderer<WatchStatus>() {++ @Override+ public Object getDisplayValue(WatchStatus object) {+ return object.toString();+ }++ @Override+ public String getIdValue(WatchStatus object, int index) {+ return object.name();+ }++ @Override+ public WatchStatus getObject(String id, IModel<? extends List<? extends WatchStatus>> choices) {+ return WatchStatus.valueOf(id);+ }++ };+ DropDownChoice<WatchStatus> choice = new DropDownChoice<>("option", optionModel,+ options, choiceRenderer);++ choice.add(new OnChangeAjaxBehavior() {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ PullRequestWatch watch = getPullRequest().getWatch(getLoginUser());+ Dao dao = GitPlex.getInstance(Dao.class);+ if (optionModel.getObject() == WatchStatus.WATCHING) {+ if (watch != null) {+ watch.setIgnore(false);+ watch.setReason(null);+ } else {+ watch = new PullRequestWatch();+ watch.setRequest(getPullRequest());+ watch.setUser(getLoginUser());+ getPullRequest().getWatches().add(watch);+ }+ dao.persist(watch);+ } else if (optionModel.getObject() == WatchStatus.NOT_WATCHING) {+ if (watch != null) {+ dao.remove(watch);+ getPullRequest().getWatches().remove(watch);+ }+ } else {+ if (watch != null) {+ watch.setIgnore(true);+ } else {+ watch = new PullRequestWatch();+ watch.setRequest(getPullRequest());+ watch.setUser(getLoginUser());+ watch.setIgnore(true);+ getPullRequest().getWatches().add(watch);+ }+ dao.persist(watch);+ }+ target.add(watchContainer);+ }++ });+ watchContainer.add(choice);+ watchContainer.add(new Label("help", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ PullRequestWatch watch = getPullRequest().getWatch(getLoginUser());+ if (watch != null) {+ if (watch.isIgnore()) {+ return "Ignore notifications irrelevant to me.";+ } else if (watch.getReason() != null) {+ return watch.getReason();+ } else {+ return "You will be notified of any activities.";+ }+ } else {+ return "Ignore notifications irrelevant to me, but start to watch once I am involved.";+ }+ }++ }));++ return watchContainer;+ }++ private Component newAssigneeContainer() {+ PullRequest request = getPullRequest();++ Fragment assigneeContainer;+ Account assignee = request.getAssignee();+ Account currentUser = getLoginUser();+ boolean canChangeAssignee = request.isOpen()+ && (currentUser != null && currentUser.equals(request.getSubmitter())+ || SecurityUtils.canManage(getDepot()));+ if (assignee != null) {++ if (canChangeAssignee) {+ assigneeContainer = new Fragment("assignee", "assigneeEditFrag", this);+ assigneeContainer.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(ASSIGNEE_HELP))));++ AssigneeChoice choice = new AssigneeChoice("assignee", depotModel, new IModel<Account>() {++ @Override+ public void detach() {+ }++ @Override+ public Account getObject() {+ return getPullRequest().getAssignee();+ }++ @Override+ public void setObject(Account object) {+ getPullRequest().setAssignee(object);+ }++ });+ choice.setRequired(true);+ assigneeContainer.add(choice);+ choice.add(new AjaxFormComponentUpdatingBehavior("change") {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ Preconditions.checkNotNull(getPullRequest().getAssignee());+ GitPlex.getInstance(PullRequestManager.class).changeAssignee(getPullRequest());+ }++ });+ } else {+ assigneeContainer = new Fragment("assignee", "assigneeViewFrag", this);+ assigneeContainer.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(ASSIGNEE_HELP))));+ assigneeContainer.add(new Avatar("assignee", assignee, new TooltipConfig()));+ }+ } else {+ assigneeContainer = new Fragment("assignee", "noAssigneeFrag", this);+ }++ return assigneeContainer;+ }++ private WebMarkupContainer newReviewersContainer() {+ final WebMarkupContainer reviewersContainer = new WebMarkupContainer("reviewers") {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ PullRequest request = getPullRequest();+ if (request.getReviewInvitations().isEmpty()) {+ Account currentUser = GitPlex.getInstance(AccountManager.class).getCurrent();+ setVisible(request.isOpen()+ && !request.getPotentialReviewers().isEmpty()+ && (currentUser != null && currentUser.equals(request.getSubmitter()) || SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotAdmin(request.getTarget().getDepot()))));+ } else {+ setVisible(true);+ }+ }++ };+ reviewersContainer.setOutputMarkupId(true);+ reviewersContainer.add(new ListView<PullRequestReviewInvitation>("reviewers", new ReviewersModel(requestModel)) {++ @Override+ protected void populateItem(ListItem<PullRequestReviewInvitation> item) {+ PullRequestReviewInvitation invitation = item.getModelObject();+ item.add(new ReviewerAvatar("avatar", invitation) {++ @Override+ protected void onAvatarRemove(AjaxRequestTarget target) {+ super.onAvatarRemove(target);++ target.add(reviewersContainer);+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target, getPullRequest()));+ }++ });++ List<PullRequestReview> userReviews = new ArrayList<>();+ for (PullRequestReview review: getPullRequest().getReviews()) {+ if (review.getUser().equals(invitation.getUser()))+ userReviews.add(review);+ }+ if (!userReviews.isEmpty()) {+ PullRequestReview review = userReviews.get(userReviews.size()-1);+ item.add(new ReviewResultIcon("result", new EntityModel<PullRequestReview>(review)));+ } else {+ item.add(new WebMarkupContainer("result").setVisible(false));+ }+ }++ });++ reviewersContainer.add(new ReviewerChoice("addReviewer", requestModel) {++ @Override+ protected void onSelect(AjaxRequestTarget target, Account user) {+ super.onSelect(target, user);++ target.add(reviewersContainer);+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target, getPullRequest()));+ }++ });++ return reviewersContainer;+ }++ @Override+ protected void onSelect(AjaxRequestTarget target, Depot depot) {+ setResponsePage(RequestListPage.class, paramsOf(depot));+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(CssHeaderItem.forReference(+ new CssResourceReference(RequestOverviewPage.class, "request-overview.css")));+ }++}