Skip to content

The Unified and Autonomous Development Platform

Add/show comment in source view panel.

robin shine8eba921cbf74
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
index bf1810315b..1ad097d46c 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
@@ -1,4 +1,13 @@
pmease.commons.codemirror = {
+ clearMark: function(cm) {
+ var marks = cm.getAllMarks();
+ for (var i=0; i<marks.length; i++) {
+ marks[i].clear();
+ }
+ },
+ clearSelection: function(cm) {
+ cm.setCursor(cm.getCursor("from"));
+ },
mark: function(cm, mark, scroll) {
if (scroll) {
var top = cm.charCoords({line: mark.beginLine, ch: 0}, "local").top;
@@ -12,18 +21,12 @@ pmease.commons.codemirror = {
cm.scrollTo(null, (top+bottom-clientHeight)/2);
}
}
-
- var allMarks = cm.getAllMarks();
- for (var i=0; i<allMarks.length; i++)
- allMarks[i].clear();
+
+ pmease.commons.codemirror.clearMark(cm);
cm.markText(
{line: mark.beginLine, ch: mark.beginChar},
{line: mark.endLine, ch: mark.endChar},
{className: "CodeMirror-mark"});
- cm.setCursor({line:mark.beginLine, ch:mark.beginChar});
- setTimeout(function() {
- cm.focus();
- }, 10);
},
setMode: function(cm, filePath) {
var modeInfo = CodeMirror.findModeByFileName(filePath);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
index 322c44df6f..5ec69ee4db 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
@@ -1,216 +1,219 @@
-package com.pmease.gitplex.core;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
-
-import com.google.common.collect.Sets;
-import com.pmease.commons.git.GitConfig;
-import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.commons.hibernate.ModelProvider;
-import com.pmease.commons.hibernate.PersistListener;
-import com.pmease.commons.hibernate.PrefixedNamingStrategy;
-import com.pmease.commons.jetty.ServletConfigurator;
-import com.pmease.commons.loader.AbstractPlugin;
-import com.pmease.commons.loader.AbstractPluginModule;
-import com.pmease.commons.loader.ImplementationProvider;
-import com.pmease.commons.shiro.AbstractRealm;
-import com.pmease.commons.util.ClassUtils;
-import com.pmease.gitplex.core.entity.Config;
-import com.pmease.gitplex.core.entity.EntityLocator;
-import com.pmease.gitplex.core.entity.persistlistener.ListenerLocator;
-import com.pmease.gitplex.core.listener.ConfigListener;
-import com.pmease.gitplex.core.listener.DepotListener;
-import com.pmease.gitplex.core.listener.LifecycleListener;
-import com.pmease.gitplex.core.listener.PullRequestListener;
-import com.pmease.gitplex.core.listener.RefListener;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.core.manager.TeamAuthorizationManager;
-import com.pmease.gitplex.core.manager.AuxiliaryManager;
-import com.pmease.gitplex.core.manager.BranchWatchManager;
-import com.pmease.gitplex.core.manager.CodeCommentManager;
-import com.pmease.gitplex.core.manager.PullRequestCommentManager;
-import com.pmease.gitplex.core.manager.ConfigManager;
-import com.pmease.gitplex.core.manager.DataManager;
-import com.pmease.gitplex.core.manager.DepotManager;
-import com.pmease.gitplex.core.manager.MailManager;
-import com.pmease.gitplex.core.manager.OrganizationMembershipManager;
-import com.pmease.gitplex.core.manager.PullRequestActivityManager;
-import com.pmease.gitplex.core.manager.NotificationManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
-import com.pmease.gitplex.core.manager.PullRequestVisitManager;
-import com.pmease.gitplex.core.manager.PullRequestWatchManager;
-import com.pmease.gitplex.core.manager.ReviewInvitationManager;
-import com.pmease.gitplex.core.manager.ReviewManager;
-import com.pmease.gitplex.core.manager.SequentialWorkManager;
-import com.pmease.gitplex.core.manager.StorageManager;
-import com.pmease.gitplex.core.manager.TeamManager;
-import com.pmease.gitplex.core.manager.TeamMembershipManager;
-import com.pmease.gitplex.core.manager.UserAuthorizationManager;
-import com.pmease.gitplex.core.manager.VerificationManager;
-import com.pmease.gitplex.core.manager.WorkManager;
-import com.pmease.gitplex.core.manager.impl.DefaultAccountManager;
-import com.pmease.gitplex.core.manager.impl.DefaultTeamAuthorizationManager;
-import com.pmease.gitplex.core.manager.impl.DefaultAuxiliaryManager;
-import com.pmease.gitplex.core.manager.impl.DefaultBranchWatchManager;
-import com.pmease.gitplex.core.manager.impl.DefaultCodeCommentManager;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestCommentManager;
-import com.pmease.gitplex.core.manager.impl.DefaultConfigManager;
-import com.pmease.gitplex.core.manager.impl.DefaultDataManager;
-import com.pmease.gitplex.core.manager.impl.DefaultDepotManager;
-import com.pmease.gitplex.core.manager.impl.DefaultMailManager;
-import com.pmease.gitplex.core.manager.impl.DefaultOrganizationMembershipManager;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestActivityManager;
-import com.pmease.gitplex.core.manager.impl.DefaultNotificationManager;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestManager;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestUpdateManager;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestVisitManager;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestWatchManager;
-import com.pmease.gitplex.core.manager.impl.DefaultReviewInvitationManager;
-import com.pmease.gitplex.core.manager.impl.DefaultReviewManager;
-import com.pmease.gitplex.core.manager.impl.DefaultSequentialWorkManager;
-import com.pmease.gitplex.core.manager.impl.DefaultStorageManager;
-import com.pmease.gitplex.core.manager.impl.DefaultTeamManager;
-import com.pmease.gitplex.core.manager.impl.DefaultTeamMembershipManager;
-import com.pmease.gitplex.core.manager.impl.DefaultUserAuthorizationManager;
-import com.pmease.gitplex.core.manager.impl.DefaultVerificationManager;
-import com.pmease.gitplex.core.manager.impl.DefaultWorkManager;
-import com.pmease.gitplex.core.security.SecurityRealm;
-import com.pmease.gitplex.core.setting.SpecifiedGit;
-import com.pmease.gitplex.core.setting.SystemGit;
-import com.pmease.gitplex.core.util.validation.AccountNameReservation;
-import com.pmease.gitplex.core.util.validation.DepotNameReservation;
-
-/**
- * NOTE: Do not forget to rename moduleClass property defined in the pom if you've renamed this class.
- *
- */
-public class CoreModule extends AbstractPluginModule {
-
- @Override
- protected void configure() {
- super.configure();
-
- bind(PhysicalNamingStrategy.class).toInstance(new PrefixedNamingStrategy("g_"));
-
- contribute(ModelProvider.class, new ModelProvider() {
-
- @Override
- public Collection<Class<? extends AbstractEntity>> getModelClasses() {
- Collection<Class<? extends AbstractEntity>> modelClasses =
- new HashSet<Class<? extends AbstractEntity>>();
- modelClasses.addAll(ClassUtils.findImplementations(AbstractEntity.class, EntityLocator.class));
- return modelClasses;
- }
-
- });
-
- /*
- * Contribute empty reservations to avoid Guice complain
- */
- contribute(AccountNameReservation.class, new AccountNameReservation() {
-
- @Override
- public Set<String> getReserved() {
- return Sets.newHashSet();
- }
- });
-
- /*
- * Contribute empty reservations to avoid Guice complain
- */
- contribute(DepotNameReservation.class, new DepotNameReservation() {
-
- @Override
- public Set<String> getReserved() {
- return Sets.newHashSet();
- }
- });
-
- contribute(ServletConfigurator.class, CoreServletConfigurator.class);
-
- contribute(ImplementationProvider.class, new ImplementationProvider() {
-
- @Override
- public Collection<Class<?>> getImplementations() {
- Collection<Class<?>> implementations = new HashSet<Class<?>>();
- implementations.add(SystemGit.class);
- implementations.add(SpecifiedGit.class);
- return implementations;
- }
-
- @Override
- public Class<?> getAbstractClass() {
- return GitConfig.class;
- }
- });
-
- bind(GitConfig.class).toProvider(GitConfigProvider.class);
-
- /*
- * Declare bindings explicitly instead of using ImplementedBy annotation as
- * HK2 to guice bridge can only search in explicit bindings in Guice
- */
- bind(StorageManager.class).to(DefaultStorageManager.class);
- bind(ConfigManager.class).to(DefaultConfigManager.class);
- bind(DataManager.class).to(DefaultDataManager.class);
- bind(PullRequestCommentManager.class).to(DefaultPullRequestCommentManager.class);
- bind(CodeCommentManager.class).to(DefaultCodeCommentManager.class);
- bind(PullRequestManager.class).to(DefaultPullRequestManager.class);
- bind(PullRequestUpdateManager.class).to(DefaultPullRequestUpdateManager.class);
- bind(DepotManager.class).to(DefaultDepotManager.class);
- bind(AccountManager.class).to(DefaultAccountManager.class);
- bind(VerificationManager.class).to(DefaultVerificationManager.class);
- bind(ReviewInvitationManager.class).to(DefaultReviewInvitationManager.class);
- bind(ReviewManager.class).to(DefaultReviewManager.class);
- bind(MailManager.class).to(DefaultMailManager.class);
- bind(BranchWatchManager.class).to(DefaultBranchWatchManager.class);
- bind(PullRequestWatchManager.class).to(DefaultPullRequestWatchManager.class);
- bind(NotificationManager.class).to(DefaultNotificationManager.class);
- bind(AuxiliaryManager.class).to(DefaultAuxiliaryManager.class);
- bind(WorkManager.class).to(DefaultWorkManager.class);
- bind(SequentialWorkManager.class).to(DefaultSequentialWorkManager.class);
- bind(TeamManager.class).to(DefaultTeamManager.class);
- bind(OrganizationMembershipManager.class).to(DefaultOrganizationMembershipManager.class);
- bind(TeamMembershipManager.class).to(DefaultTeamMembershipManager.class);
- bind(TeamAuthorizationManager.class).to(DefaultTeamAuthorizationManager.class);
- bind(UserAuthorizationManager.class).to(DefaultUserAuthorizationManager.class);
- bind(PullRequestActivityManager.class).to(DefaultPullRequestActivityManager.class);
- bind(PullRequestVisitManager.class).to(DefaultPullRequestVisitManager.class);
-
- bind(AbstractRealm.class).to(SecurityRealm.class);
-
- contribute(DepotListener.class, DefaultPullRequestManager.class);
- contribute(DepotListener.class, DefaultAuxiliaryManager.class);
- contribute(DepotListener.class, DefaultTeamAuthorizationManager.class);
- contribute(RefListener.class, DefaultPullRequestManager.class);
- contribute(RefListener.class, DefaultAuxiliaryManager.class);
- contribute(RefListener.class, DefaultDepotManager.class);
- contribute(PullRequestListener.class, DefaultNotificationManager.class);
- contribute(PullRequestListener.class, DefaultPullRequestWatchManager.class);
- contribute(LifecycleListener.class, DefaultPullRequestManager.class);
- contribute(LifecycleListener.class, DefaultAccountManager.class);
- contribute(LifecycleListener.class, DefaultDepotManager.class);
- contribute(LifecycleListener.class, DefaultAuxiliaryManager.class);
- contribute(LifecycleListener.class, DefaultWorkManager.class);
- contribute(LifecycleListener.class, DefaultSequentialWorkManager.class);
-
- contribute(ConfigListener.class, new ConfigListener() {
-
- @Override
- public void onSave(Config config) {
- }
-
- });
- contributeFromPackage(PersistListener.class, ListenerLocator.class);
- }
-
- @Override
- protected Class<? extends AbstractPlugin> getPluginClass() {
- return GitPlex.class;
- }
-
-}
+package com.pmease.gitplex.core;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
+
+import com.google.common.collect.Sets;
+import com.pmease.commons.git.GitConfig;
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.ModelProvider;
+import com.pmease.commons.hibernate.PersistListener;
+import com.pmease.commons.hibernate.PrefixedNamingStrategy;
+import com.pmease.commons.jetty.ServletConfigurator;
+import com.pmease.commons.loader.AbstractPlugin;
+import com.pmease.commons.loader.AbstractPluginModule;
+import com.pmease.commons.loader.ImplementationProvider;
+import com.pmease.commons.shiro.AbstractRealm;
+import com.pmease.commons.util.ClassUtils;
+import com.pmease.gitplex.core.entity.Config;
+import com.pmease.gitplex.core.entity.EntityLocator;
+import com.pmease.gitplex.core.entity.persistlistener.ListenerLocator;
+import com.pmease.gitplex.core.listener.ConfigListener;
+import com.pmease.gitplex.core.listener.DepotListener;
+import com.pmease.gitplex.core.listener.LifecycleListener;
+import com.pmease.gitplex.core.listener.PullRequestListener;
+import com.pmease.gitplex.core.listener.RefListener;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.core.manager.TeamAuthorizationManager;
+import com.pmease.gitplex.core.manager.AuxiliaryManager;
+import com.pmease.gitplex.core.manager.BranchWatchManager;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.manager.CodeCommentReplyManager;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
+import com.pmease.gitplex.core.manager.ConfigManager;
+import com.pmease.gitplex.core.manager.DataManager;
+import com.pmease.gitplex.core.manager.DepotManager;
+import com.pmease.gitplex.core.manager.MailManager;
+import com.pmease.gitplex.core.manager.OrganizationMembershipManager;
+import com.pmease.gitplex.core.manager.PullRequestActivityManager;
+import com.pmease.gitplex.core.manager.NotificationManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
+import com.pmease.gitplex.core.manager.PullRequestVisitManager;
+import com.pmease.gitplex.core.manager.PullRequestWatchManager;
+import com.pmease.gitplex.core.manager.ReviewInvitationManager;
+import com.pmease.gitplex.core.manager.ReviewManager;
+import com.pmease.gitplex.core.manager.SequentialWorkManager;
+import com.pmease.gitplex.core.manager.StorageManager;
+import com.pmease.gitplex.core.manager.TeamManager;
+import com.pmease.gitplex.core.manager.TeamMembershipManager;
+import com.pmease.gitplex.core.manager.UserAuthorizationManager;
+import com.pmease.gitplex.core.manager.VerificationManager;
+import com.pmease.gitplex.core.manager.WorkManager;
+import com.pmease.gitplex.core.manager.impl.DefaultAccountManager;
+import com.pmease.gitplex.core.manager.impl.DefaultTeamAuthorizationManager;
+import com.pmease.gitplex.core.manager.impl.DefaultAuxiliaryManager;
+import com.pmease.gitplex.core.manager.impl.DefaultBranchWatchManager;
+import com.pmease.gitplex.core.manager.impl.DefaultCodeCommentManager;
+import com.pmease.gitplex.core.manager.impl.DefaultCodeCommentReplyManager;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestCommentManager;
+import com.pmease.gitplex.core.manager.impl.DefaultConfigManager;
+import com.pmease.gitplex.core.manager.impl.DefaultDataManager;
+import com.pmease.gitplex.core.manager.impl.DefaultDepotManager;
+import com.pmease.gitplex.core.manager.impl.DefaultMailManager;
+import com.pmease.gitplex.core.manager.impl.DefaultOrganizationMembershipManager;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestActivityManager;
+import com.pmease.gitplex.core.manager.impl.DefaultNotificationManager;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestManager;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestUpdateManager;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestVisitManager;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestWatchManager;
+import com.pmease.gitplex.core.manager.impl.DefaultReviewInvitationManager;
+import com.pmease.gitplex.core.manager.impl.DefaultReviewManager;
+import com.pmease.gitplex.core.manager.impl.DefaultSequentialWorkManager;
+import com.pmease.gitplex.core.manager.impl.DefaultStorageManager;
+import com.pmease.gitplex.core.manager.impl.DefaultTeamManager;
+import com.pmease.gitplex.core.manager.impl.DefaultTeamMembershipManager;
+import com.pmease.gitplex.core.manager.impl.DefaultUserAuthorizationManager;
+import com.pmease.gitplex.core.manager.impl.DefaultVerificationManager;
+import com.pmease.gitplex.core.manager.impl.DefaultWorkManager;
+import com.pmease.gitplex.core.security.SecurityRealm;
+import com.pmease.gitplex.core.setting.SpecifiedGit;
+import com.pmease.gitplex.core.setting.SystemGit;
+import com.pmease.gitplex.core.util.validation.AccountNameReservation;
+import com.pmease.gitplex.core.util.validation.DepotNameReservation;
+
+/**
+ * NOTE: Do not forget to rename moduleClass property defined in the pom if you've renamed this class.
+ *
+ */
+public class CoreModule extends AbstractPluginModule {
+
+ @Override
+ protected void configure() {
+ super.configure();
+
+ bind(PhysicalNamingStrategy.class).toInstance(new PrefixedNamingStrategy("g_"));
+
+ contribute(ModelProvider.class, new ModelProvider() {
+
+ @Override
+ public Collection<Class<? extends AbstractEntity>> getModelClasses() {
+ Collection<Class<? extends AbstractEntity>> modelClasses =
+ new HashSet<Class<? extends AbstractEntity>>();
+ modelClasses.addAll(ClassUtils.findImplementations(AbstractEntity.class, EntityLocator.class));
+ return modelClasses;
+ }
+
+ });
+
+ /*
+ * Contribute empty reservations to avoid Guice complain
+ */
+ contribute(AccountNameReservation.class, new AccountNameReservation() {
+
+ @Override
+ public Set<String> getReserved() {
+ return Sets.newHashSet();
+ }
+ });
+
+ /*
+ * Contribute empty reservations to avoid Guice complain
+ */
+ contribute(DepotNameReservation.class, new DepotNameReservation() {
+
+ @Override
+ public Set<String> getReserved() {
+ return Sets.newHashSet();
+ }
+ });
+
+ contribute(ServletConfigurator.class, CoreServletConfigurator.class);
+
+ contribute(ImplementationProvider.class, new ImplementationProvider() {
+
+ @Override
+ public Collection<Class<?>> getImplementations() {
+ Collection<Class<?>> implementations = new HashSet<Class<?>>();
+ implementations.add(SystemGit.class);
+ implementations.add(SpecifiedGit.class);
+ return implementations;
+ }
+
+ @Override
+ public Class<?> getAbstractClass() {
+ return GitConfig.class;
+ }
+ });
+
+ bind(GitConfig.class).toProvider(GitConfigProvider.class);
+
+ /*
+ * Declare bindings explicitly instead of using ImplementedBy annotation as
+ * HK2 to guice bridge can only search in explicit bindings in Guice
+ */
+ bind(StorageManager.class).to(DefaultStorageManager.class);
+ bind(ConfigManager.class).to(DefaultConfigManager.class);
+ bind(DataManager.class).to(DefaultDataManager.class);
+ bind(PullRequestCommentManager.class).to(DefaultPullRequestCommentManager.class);
+ bind(CodeCommentManager.class).to(DefaultCodeCommentManager.class);
+ bind(PullRequestManager.class).to(DefaultPullRequestManager.class);
+ bind(PullRequestUpdateManager.class).to(DefaultPullRequestUpdateManager.class);
+ bind(DepotManager.class).to(DefaultDepotManager.class);
+ bind(AccountManager.class).to(DefaultAccountManager.class);
+ bind(VerificationManager.class).to(DefaultVerificationManager.class);
+ bind(ReviewInvitationManager.class).to(DefaultReviewInvitationManager.class);
+ bind(ReviewManager.class).to(DefaultReviewManager.class);
+ bind(MailManager.class).to(DefaultMailManager.class);
+ bind(BranchWatchManager.class).to(DefaultBranchWatchManager.class);
+ bind(PullRequestWatchManager.class).to(DefaultPullRequestWatchManager.class);
+ bind(NotificationManager.class).to(DefaultNotificationManager.class);
+ bind(AuxiliaryManager.class).to(DefaultAuxiliaryManager.class);
+ bind(WorkManager.class).to(DefaultWorkManager.class);
+ bind(SequentialWorkManager.class).to(DefaultSequentialWorkManager.class);
+ bind(TeamManager.class).to(DefaultTeamManager.class);
+ bind(OrganizationMembershipManager.class).to(DefaultOrganizationMembershipManager.class);
+ bind(TeamMembershipManager.class).to(DefaultTeamMembershipManager.class);
+ bind(TeamAuthorizationManager.class).to(DefaultTeamAuthorizationManager.class);
+ bind(UserAuthorizationManager.class).to(DefaultUserAuthorizationManager.class);
+ bind(PullRequestActivityManager.class).to(DefaultPullRequestActivityManager.class);
+ bind(PullRequestVisitManager.class).to(DefaultPullRequestVisitManager.class);
+ bind(CodeCommentReplyManager.class).to(DefaultCodeCommentReplyManager.class);
+
+ bind(AbstractRealm.class).to(SecurityRealm.class);
+
+ contribute(DepotListener.class, DefaultPullRequestManager.class);
+ contribute(DepotListener.class, DefaultAuxiliaryManager.class);
+ contribute(DepotListener.class, DefaultTeamAuthorizationManager.class);
+ contribute(RefListener.class, DefaultPullRequestManager.class);
+ contribute(RefListener.class, DefaultAuxiliaryManager.class);
+ contribute(RefListener.class, DefaultDepotManager.class);
+ contribute(PullRequestListener.class, DefaultNotificationManager.class);
+ contribute(PullRequestListener.class, DefaultPullRequestWatchManager.class);
+ contribute(LifecycleListener.class, DefaultPullRequestManager.class);
+ contribute(LifecycleListener.class, DefaultAccountManager.class);
+ contribute(LifecycleListener.class, DefaultDepotManager.class);
+ contribute(LifecycleListener.class, DefaultAuxiliaryManager.class);
+ contribute(LifecycleListener.class, DefaultWorkManager.class);
+ contribute(LifecycleListener.class, DefaultSequentialWorkManager.class);
+
+ contribute(ConfigListener.class, new ConfigListener() {
+
+ @Override
+ public void onSave(Config config) {
+ }
+
+ });
+ contributeFromPackage(PersistListener.class, ListenerLocator.class);
+ }
+
+ @Override
+ protected Class<? extends AbstractPlugin> getPluginClass() {
+ return GitPlex.class;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java
index 7a336d0547..47b68fd41e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java
@@ -1,158 +1,156 @@
-package com.pmease.gitplex.core.entity;
-
-import java.util.Date;
-
-import javax.annotation.Nullable;
-import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
-import javax.persistence.Column;
-import javax.persistence.Embedded;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
-import javax.persistence.ManyToOne;
-import javax.persistence.Version;
-
-import org.hibernate.annotations.DynamicUpdate;
-import org.hibernate.annotations.OptimisticLock;
-
-import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.component.TextRange;
-
-/*
- * @DynamicUpdate annotation here along with various @OptimisticLock annotations
- * on certain fields tell Hibernate not to perform version check on those fields
- * which can be updated from background thread.
- */
-@Entity
-@DynamicUpdate
-public class CodeComment extends AbstractEntity {
-
- private static final long serialVersionUID = 1L;
-
- public static final int DIFF_CONTEXT_SIZE = 3;
-
- @Version
- private long version;
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private Depot depot;
-
- @ManyToOne(fetch=FetchType.LAZY)
- private Account user;
-
- @Lob
- @Column(nullable=false, length=65535)
- private String content;
-
- @Column(nullable=false)
- private Date date = new Date();
-
- @OptimisticLock(excluded=true)
- @Embedded
- @AttributeOverrides({
- @AttributeOverride(name="revision", column=@Column(name="G_BLOB_REV")),
- @AttributeOverride(name="path", column=@Column(name="G_BLOB_PATH")),
- @AttributeOverride(name="mode", column=@Column(name="G_BLOB_MODE")),
- @AttributeOverride(name="id", column=@Column(name="G_BLOB_ID"))
- })
- private BlobIdent blobIdent;
-
- @OptimisticLock(excluded=true)
- @Embedded
- private TextRange textRange;
-
- @OptimisticLock(excluded=true)
- private String compareCommit;
-
- /**
- * @return the depot
- */
- public Depot getDepot() {
- return depot;
- }
-
- /**
- * @param depot the depot to set
- */
- public void setDepot(Depot depot) {
- this.depot = depot;
- }
-
- @Nullable
- public Account getUser() {
- return user;
- }
-
- public void setUser(@Nullable Account user) {
- this.user = user;
- }
-
- public long getVersion() {
- return version;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void delete() {
- GitPlex.getInstance(Dao.class).remove(this);
- }
-
- /**
- * @return the blobIdent
- */
- public BlobIdent getBlobIdent() {
- return blobIdent;
- }
-
- /**
- * @param blobIdent the blobIdent to set
- */
- public void setBlobIdent(BlobIdent blobIdent) {
- this.blobIdent = blobIdent;
- }
-
- /**
- * @return the textRange
- */
- public TextRange getTextRange() {
- return textRange;
- }
-
- /**
- * @param textRange the textRange to set
- */
- public void setTextRange(TextRange textRange) {
- this.textRange = textRange;
- }
-
- /**
- * @return the compareCommit
- */
- public String getCompareCommit() {
- return compareCommit;
- }
-
- /**
- * @param compareCommit the compareCommit to set
- */
- public void setCompareCommit(String compareCommit) {
- this.compareCommit = compareCommit;
- }
-
-}
+package com.pmease.gitplex.core.entity;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.annotation.Nullable;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Version;
+
+import org.hibernate.annotations.DynamicUpdate;
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
+import org.hibernate.annotations.OptimisticLock;
+
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.component.Mark;
+
+/*
+ * @DynamicUpdate annotation here along with various @OptimisticLock annotations
+ * on certain fields tell Hibernate not to perform version check on those fields
+ * which can be updated from background thread.
+ */
+@Entity
+@DynamicUpdate
+public class CodeComment extends AbstractEntity {
+
+ private static final long serialVersionUID = 1L;
+
+ @Version
+ private long version;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(nullable=false)
+ private Depot depot;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ private Account user;
+
+ @Lob
+ @Column(nullable=false, length=65535)
+ private String content;
+
+ @Column(nullable=false)
+ private Date date = new Date();
+
+ @OptimisticLock(excluded=true)
+ @Column(nullable=false)
+ private String commit;
+
+ @OptimisticLock(excluded=true)
+ private String path;
+
+ @OptimisticLock(excluded=true)
+ @Embedded
+ private Mark mark;
+
+ @OptimisticLock(excluded=true)
+ @Column(nullable=false)
+ private String compareCommit;
+
+ @OneToMany(mappedBy="comment")
+ @OnDelete(action=OnDeleteAction.CASCADE)
+ private Collection<CodeCommentReply> replies = new ArrayList<>();
+
+ public Depot getDepot() {
+ return depot;
+ }
+
+ public void setDepot(Depot depot) {
+ this.depot = depot;
+ }
+
+ @Nullable
+ public Account getUser() {
+ return user;
+ }
+
+ public void setUser(@Nullable Account user) {
+ this.user = user;
+ }
+
+ public long getVersion() {
+ return version;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void delete() {
+ GitPlex.getInstance(Dao.class).remove(this);
+ }
+
+ public String getCommit() {
+ return commit;
+ }
+
+ public void setCommit(String commit) {
+ this.commit = commit;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public Mark getMark() {
+ return mark;
+ }
+
+ public void setMark(Mark mark) {
+ this.mark = mark;
+ }
+
+ public String getCompareCommit() {
+ return compareCommit;
+ }
+
+ public void setCompareCommit(String compareCommit) {
+ this.compareCommit = compareCommit;
+ }
+
+ public Collection<CodeCommentReply> getReplies() {
+ return replies;
+ }
+
+ public void setReplies(Collection<CodeCommentReply> replies) {
+ this.replies = replies;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java
new file mode 100644
index 0000000000..bdf58943de
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java
@@ -0,0 +1,101 @@
+package com.pmease.gitplex.core.entity;
+
+import java.util.Date;
+
+import javax.annotation.Nullable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.Version;
+
+import org.hibernate.annotations.DynamicUpdate;
+import org.hibernate.annotations.OptimisticLock;
+
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+
+/*
+ * @DynamicUpdate annotation here along with various @OptimisticLock annotations
+ * on certain fields tell Hibernate not to perform version check on those fields
+ * which can be updated from background thread.
+ */
+@Entity
+@DynamicUpdate
+public class CodeCommentReply extends AbstractEntity {
+
+ private static final long serialVersionUID = 1L;
+
+ @Version
+ private long version;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(nullable=false)
+ private CodeComment comment;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ private Account user;
+
+ @Lob
+ @Column(nullable=false, length=65535)
+ private String content;
+
+ @Column(nullable=false)
+ private Date date = new Date();
+
+ @OptimisticLock(excluded=true)
+ private String compareCommit;
+
+ @Nullable
+ public Account getUser() {
+ return user;
+ }
+
+ public void setUser(@Nullable Account user) {
+ this.user = user;
+ }
+
+ public long getVersion() {
+ return version;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public CodeComment getComment() {
+ return comment;
+ }
+
+ public void setComment(CodeComment comment) {
+ this.comment = comment;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public void delete() {
+ GitPlex.getInstance(Dao.class).remove(this);
+ }
+
+ public String getCompareCommit() {
+ return compareCommit;
+ }
+
+ public void setCompareCommit(String compareCommit) {
+ this.compareCommit = compareCommit;
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/Mark.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java
similarity index 92%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/Mark.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java
index 849f69736c..b3b54d3b6e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/Mark.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/Mark.java
@@ -1,111 +1,114 @@
-package com.pmease.gitplex.web.page.depot.file;
-
-import java.io.Serializable;
-
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.pmease.commons.lang.extractors.TokenPosition;
-import com.pmease.gitplex.core.GitPlex;
-
-public class Mark implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final int beginLine, beginChar, endLine, endChar;
-
- public Mark(int beginLine, int beginChar, int endLine, int endChar) {
- this.beginLine = beginLine;
- this.beginChar = beginChar;
- this.endLine = endLine;
- this.endChar = endChar;
- }
-
- public Mark(Mark mark) {
- this.beginLine = mark.beginLine;
- this.beginChar = mark.beginChar;
- this.endLine = mark.endLine;
- this.endChar = mark.endChar;
- }
-
- public Mark(TokenPosition tokenPos) {
- this(tokenPos.getLine(), tokenPos.getRange().getFrom(),
- tokenPos.getLine(), tokenPos.getRange().getTo());
- }
-
- public Mark(String str) {
- String begin = StringUtils.substringBefore(str, "-");
- String end = StringUtils.substringAfter(str, "-");
- beginLine = Integer.parseInt(StringUtils.substringBefore(begin, "."))-1;
- beginChar = Integer.parseInt(StringUtils.substringAfter(begin, "."));
- endLine = Integer.parseInt(StringUtils.substringBefore(end, "."))-1;
- endChar = Integer.parseInt(StringUtils.substringAfter(end, "."));
- }
-
- public int getBeginLine() {
- return beginLine;
- }
-
- public int getBeginChar() {
- return beginChar;
- }
-
- public int getEndLine() {
- return endLine;
- }
-
- public int getEndChar() {
- return endChar;
- }
-
- @Override
- public String toString() {
- return (beginLine+1) + "." + beginChar + "-" + (endLine+1) + "." + endChar;
- }
-
- @Override
- public boolean equals(Object other) {
- if (!(other instanceof Mark))
- return false;
- if (this == other)
- return true;
- Mark otherMark = (Mark) other;
- return new EqualsBuilder()
- .append(beginLine, otherMark.beginLine)
- .append(beginChar, otherMark.beginChar)
- .append(endLine, otherMark.endLine)
- .append(endChar, otherMark.endChar)
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37)
- .append(beginLine)
- .append(beginChar)
- .append(endLine)
- .append(endChar)
- .toHashCode();
- }
-
- public static @Nullable Mark of(@Nullable TokenPosition tokenPos) {
- if (tokenPos != null)
- return new Mark(tokenPos);
- else
- return null;
- }
-
- public String toJSON() {
- try {
- return GitPlex.getInstance(ObjectMapper.class).writeValueAsString(this);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- }
-
-}
+package com.pmease.gitplex.core.entity.component;
+
+import java.io.Serializable;
+
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.pmease.commons.lang.extractors.TokenPosition;
+import com.pmease.gitplex.core.GitPlex;
+
+public class Mark implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public int beginLine, beginChar, endLine, endChar;
+
+ public Mark() {
+ }
+
+ public Mark(int beginLine, int beginChar, int endLine, int endChar) {
+ this.beginLine = beginLine;
+ this.beginChar = beginChar;
+ this.endLine = endLine;
+ this.endChar = endChar;
+ }
+
+ public Mark(Mark mark) {
+ this.beginLine = mark.beginLine;
+ this.beginChar = mark.beginChar;
+ this.endLine = mark.endLine;
+ this.endChar = mark.endChar;
+ }
+
+ public Mark(TokenPosition tokenPos) {
+ this(tokenPos.getLine(), tokenPos.getRange().getFrom(),
+ tokenPos.getLine(), tokenPos.getRange().getTo());
+ }
+
+ public Mark(String str) {
+ String begin = StringUtils.substringBefore(str, "-");
+ String end = StringUtils.substringAfter(str, "-");
+ beginLine = Integer.parseInt(StringUtils.substringBefore(begin, "."))-1;
+ beginChar = Integer.parseInt(StringUtils.substringAfter(begin, "."));
+ endLine = Integer.parseInt(StringUtils.substringBefore(end, "."))-1;
+ endChar = Integer.parseInt(StringUtils.substringAfter(end, "."));
+ }
+
+ public int getBeginLine() {
+ return beginLine;
+ }
+
+ public int getBeginChar() {
+ return beginChar;
+ }
+
+ public int getEndLine() {
+ return endLine;
+ }
+
+ public int getEndChar() {
+ return endChar;
+ }
+
+ @Override
+ public String toString() {
+ return (beginLine+1) + "." + beginChar + "-" + (endLine+1) + "." + endChar;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof Mark))
+ return false;
+ if (this == other)
+ return true;
+ Mark otherMark = (Mark) other;
+ return new EqualsBuilder()
+ .append(beginLine, otherMark.beginLine)
+ .append(beginChar, otherMark.beginChar)
+ .append(endLine, otherMark.endLine)
+ .append(endChar, otherMark.endChar)
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder(17, 37)
+ .append(beginLine)
+ .append(beginChar)
+ .append(endLine)
+ .append(endChar)
+ .toHashCode();
+ }
+
+ public static @Nullable Mark of(@Nullable TokenPosition tokenPos) {
+ if (tokenPos != null)
+ return new Mark(tokenPos);
+ else
+ return null;
+ }
+
+ public String toJSON() {
+ try {
+ return GitPlex.getInstance(ObjectMapper.class).writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/TextRange.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/TextRange.java
deleted file mode 100644
index a6b1a7115e..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/TextRange.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.pmease.gitplex.core.entity.component;
-
-public class TextRange {
-
- private Integer beginLine;
-
- private Integer beginChar;
-
- private Integer endLine;
-
- private Integer endChar;
-
- /**
- * @return the beginLine
- */
- public Integer getBeginLine() {
- return beginLine;
- }
-
- /**
- * @param beginLine the beginLine to set
- */
- public void setBeginLine(Integer beginLine) {
- this.beginLine = beginLine;
- }
-
- /**
- * @return the beginChar
- */
- public Integer getBeginChar() {
- return beginChar;
- }
-
- /**
- * @param beginChar the beginChar to set
- */
- public void setBeginChar(Integer beginChar) {
- this.beginChar = beginChar;
- }
-
- /**
- * @return the endLine
- */
- public Integer getEndLine() {
- return endLine;
- }
-
- /**
- * @param endLine the endLine to set
- */
- public void setEndLine(Integer endLine) {
- this.endLine = endLine;
- }
-
- /**
- * @return the endChar
- */
- public Integer getEndChar() {
- return endChar;
- }
-
- /**
- * @param endChar the endChar to set
- */
- public void setEndChar(Integer endChar) {
- this.endChar = endChar;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java
index 716d1eaf36..cac62855ed 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentManager.java
@@ -1,8 +1,15 @@
-package com.pmease.gitplex.core.manager;
-
-import com.pmease.commons.hibernate.dao.EntityDao;
-import com.pmease.gitplex.core.entity.CodeComment;
-
-public interface CodeCommentManager extends EntityDao<CodeComment> {
-
-}
+package com.pmease.gitplex.core.manager;
+
+import java.util.Collection;
+
+import javax.annotation.Nullable;
+
+import com.pmease.commons.hibernate.dao.EntityDao;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.Depot;
+
+public interface CodeCommentManager extends EntityDao<CodeComment> {
+
+ Collection<CodeComment> query(Depot depot, String commit, @Nullable String path);
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentReplyManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentReplyManager.java
new file mode 100644
index 0000000000..05c47b2698
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentReplyManager.java
@@ -0,0 +1,8 @@
+package com.pmease.gitplex.core.manager;
+
+import com.pmease.commons.hibernate.dao.EntityDao;
+import com.pmease.gitplex.core.entity.CodeCommentReply;
+
+public interface CodeCommentReplyManager extends EntityDao<CodeCommentReply> {
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/StorageManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/StorageManager.java
index 766eebd05e..e49065b406 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/StorageManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/StorageManager.java
@@ -1,23 +1,23 @@
-package com.pmease.gitplex.core.manager;
-
-import java.io.File;
-
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-
-public interface StorageManager {
-
- File getDepotDir(Depot depot);
-
- File getIndexDir(Depot depot);
-
- File getCacheDir(Depot depot);
-
- File getCacheDir(PullRequest request);
-
- File getAttachmentsDir(PullRequest request);
-
- File getCacheDir(PullRequestUpdate update);
-
-}
+package com.pmease.gitplex.core.manager;
+
+import java.io.File;
+
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+
+public interface StorageManager {
+
+ File getDepotDir(Depot depot);
+
+ File getIndexDir(Depot depot);
+
+ File getCacheDir(Depot depot);
+
+ File getAttachmentsDir(Depot depot);
+
+ File getCacheDir(PullRequest request);
+
+ File getCacheDir(PullRequestUpdate update);
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
index 82eb04d21c..6d84f8c007 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
@@ -1,20 +1,36 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import com.pmease.commons.hibernate.dao.AbstractEntityDao;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.entity.CodeComment;
-import com.pmease.gitplex.core.manager.CodeCommentManager;
-
-@Singleton
-public class DefaultCodeCommentManager extends AbstractEntityDao<CodeComment>
- implements CodeCommentManager {
-
- @Inject
- public DefaultCodeCommentManager(Dao dao) {
- super(dao);
- }
-
-}
+package com.pmease.gitplex.core.manager.impl;
+
+import java.util.Collection;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.hibernate.criterion.Restrictions;
+
+import com.pmease.commons.hibernate.dao.AbstractEntityDao;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+
+@Singleton
+public class DefaultCodeCommentManager extends AbstractEntityDao<CodeComment>
+ implements CodeCommentManager {
+
+ @Inject
+ public DefaultCodeCommentManager(Dao dao) {
+ super(dao);
+ }
+
+ @Override
+ public Collection<CodeComment> query(Depot depot, String commit, String path) {
+ EntityCriteria<CodeComment> criteria = newCriteria();
+ criteria.add(Restrictions.eq("depot", depot));
+ criteria.add(Restrictions.eq("commit", commit));
+ if (path != null)
+ criteria.add(Restrictions.eq("path", path));
+ return query(criteria);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentReplyManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentReplyManager.java
new file mode 100644
index 0000000000..d6d9d530c2
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentReplyManager.java
@@ -0,0 +1,20 @@
+package com.pmease.gitplex.core.manager.impl;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import com.pmease.commons.hibernate.dao.AbstractEntityDao;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.entity.CodeCommentReply;
+import com.pmease.gitplex.core.manager.CodeCommentReplyManager;
+
+@Singleton
+public class DefaultCodeCommentReplyManager extends AbstractEntityDao<CodeCommentReply>
+ implements CodeCommentReplyManager {
+
+ @Inject
+ public DefaultCodeCommentReplyManager(Dao dao) {
+ super(dao);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
index 77cb404bc3..66d7113a65 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
@@ -1,69 +1,68 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import java.io.File;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import com.pmease.commons.util.FileUtils;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.manager.ConfigManager;
-import com.pmease.gitplex.core.manager.StorageManager;
-
-@Singleton
-public class DefaultStorageManager implements StorageManager {
-
- private final ConfigManager configManager;
-
- @Inject
- public DefaultStorageManager(ConfigManager configManager) {
- this.configManager = configManager;
- }
-
- @Override
- public File getDepotDir(Depot depot) {
- File storageDir = new File(configManager.getSystemSetting().getStoragePath());
- return createIfNotExist(new File(storageDir, "repositories/" + depot.getId()));
- }
-
- @Override
- public File getCacheDir(Depot depot) {
- File storageDir = new File(configManager.getSystemSetting().getStoragePath());
- return createIfNotExist(new File(storageDir, "caches/repositories/" + depot.getId()));
- }
-
- @Override
- public File getCacheDir(PullRequest request) {
- File repoCacheDir = getCacheDir(request.getTargetDepot());
- return createIfNotExist(new File(repoCacheDir, "requests/" + request.getId()));
- }
-
- @Override
- public File getCacheDir(PullRequestUpdate update) {
- File requestCacheDir = getCacheDir(update.getRequest());
- return createIfNotExist(new File(requestCacheDir, "updates/" + update.getId()));
- }
-
- private File createIfNotExist(File dir) {
- if (!dir.exists())
- FileUtils.createDir(dir);
- return dir;
- }
-
- @Override
- public File getIndexDir(Depot depot) {
- File storageDir = new File(configManager.getSystemSetting().getStoragePath());
- return createIfNotExist(new File(storageDir, "indexes/repositories/" + depot.getId()));
- }
-
- @Override
- public File getAttachmentsDir(PullRequest request) {
- File storageDir = new File(configManager.getSystemSetting().getStoragePath());
- File repoDir = new File(storageDir, "attachments/repositories/" + request.getTargetDepot().getId());
- File requestDir = new File(repoDir, "requests/" + request.getId());
- return createIfNotExist(requestDir);
- }
-
-}
+package com.pmease.gitplex.core.manager.impl;
+
+import java.io.File;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import com.pmease.commons.util.FileUtils;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.manager.ConfigManager;
+import com.pmease.gitplex.core.manager.StorageManager;
+
+@Singleton
+public class DefaultStorageManager implements StorageManager {
+
+ private final ConfigManager configManager;
+
+ @Inject
+ public DefaultStorageManager(ConfigManager configManager) {
+ this.configManager = configManager;
+ }
+
+ @Override
+ public File getDepotDir(Depot depot) {
+ File storageDir = new File(configManager.getSystemSetting().getStoragePath());
+ return createIfNotExist(new File(storageDir, "repositories/" + depot.getId()));
+ }
+
+ @Override
+ public File getCacheDir(Depot depot) {
+ File storageDir = new File(configManager.getSystemSetting().getStoragePath());
+ return createIfNotExist(new File(storageDir, "caches/repositories/" + depot.getId()));
+ }
+
+ @Override
+ public File getCacheDir(PullRequest request) {
+ File repoCacheDir = getCacheDir(request.getTargetDepot());
+ return createIfNotExist(new File(repoCacheDir, "requests/" + request.getId()));
+ }
+
+ @Override
+ public File getCacheDir(PullRequestUpdate update) {
+ File requestCacheDir = getCacheDir(update.getRequest());
+ return createIfNotExist(new File(requestCacheDir, "updates/" + update.getId()));
+ }
+
+ private File createIfNotExist(File dir) {
+ if (!dir.exists())
+ FileUtils.createDir(dir);
+ return dir;
+ }
+
+ @Override
+ public File getIndexDir(Depot depot) {
+ File storageDir = new File(configManager.getSystemSetting().getStoragePath());
+ return createIfNotExist(new File(storageDir, "indexes/repositories/" + depot.getId()));
+ }
+
+ @Override
+ public File getAttachmentsDir(Depot depot) {
+ File storageDir = new File(configManager.getSystemSetting().getStoragePath());
+ File attachmentsDir = new File(storageDir, "attachments/repositories/" + depot.getId());
+ return createIfNotExist(attachmentsDir);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
index 3f080e11bd..3ae0eda92c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
@@ -1,110 +1,115 @@
-package com.pmease.gitplex.core.security;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.annotation.Nullable;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-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.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.Review;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.core.security.privilege.DepotPrivilege;
-import com.pmease.gitplex.core.security.privilege.Privilege;
-
-public class SecurityUtils extends org.apache.shiro.SecurityUtils {
-
- public static Collection<Account> findUsersCan(Depot depot, DepotPrivilege operation) {
- Set<Account> authorizedUsers = new HashSet<Account>();
- for (Account user: GitPlex.getInstance(AccountManager.class).all()) {
- if (user.asSubject().isPermitted(new ObjectPermission(depot, operation)))
- authorizedUsers.add(user);
- }
- return authorizedUsers;
- }
-
- public static boolean canModify(PullRequest request) {
- Depot depot = request.getTargetDepot();
- if (SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot))) {
- return true;
- } else {
- Account currentUser = getAccount();
- Account submitter = request.getSubmitter();
- return currentUser != null && currentUser.equals(submitter);
- }
- }
-
- public static Account getAccount() {
- return GitPlex.getInstance(AccountManager.class).getCurrent();
- }
-
- public static boolean canModify(Review review) {
- Depot depot = review.getUpdate().getRequest().getTargetDepot();
- if (SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot))) {
- return true;
- } else {
- return review.getReviewer().equals(getAccount());
- }
- }
-
- public static boolean canModify(CodeComment comment) {
- Account currentUser = getAccount();
- if (currentUser == null) {
- return false;
- } else {
- if (currentUser.equals(comment.getUser())) {
- return true;
- } else {
- ObjectPermission adminPermission = ObjectPermission.ofDepotAdmin(comment.getDepot());
- return SecurityUtils.getSubject().isPermitted(adminPermission);
- }
- }
- }
-
- public static boolean canPushRef(Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
- Account currentUser = getAccount();
- return currentUser != null
- && currentUser.asSubject().isPermitted(ObjectPermission.ofDepotWrite(depot))
- && depot.getGateKeeper().checkPush(currentUser, depot, refName, oldCommit, newCommit).isPassed();
- }
-
- public static boolean canModify(Depot depot, String branch, @Nullable String file) {
- return canWrite(depot) && depot.getGateKeeper().checkFile(getAccount(), depot, branch, file).isPassed();
- }
-
- public static boolean canManage(Account account) {
- return getSubject().isPermitted(ObjectPermission.ofAccountAdmin(account));
- }
-
- public static boolean canAccess(Account organization) {
- return getSubject().isPermitted(ObjectPermission.ofAccountAccess(organization));
- }
-
- public static boolean canRead(Depot depot) {
- return getSubject().isPermitted(ObjectPermission.ofDepotRead(depot));
- }
-
- public static boolean canWrite(Depot depot) {
- return getSubject().isPermitted(ObjectPermission.ofDepotWrite(depot));
- }
-
- public static boolean canManage(Depot depot) {
- return getSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot));
- }
-
- public static boolean canManageSystem() {
- Account currentUser = getAccount();
- return currentUser != null && currentUser.isAdministrator();
- }
-
- public static boolean isGreater(Privilege greater, Privilege lesser) {
- return greater.can(lesser) && !lesser.can(greater);
- }
-
-}
+package com.pmease.gitplex.core.security;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
+import org.eclipse.jgit.lib.ObjectId;
+
+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.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.Review;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.core.security.privilege.DepotPrivilege;
+import com.pmease.gitplex.core.security.privilege.Privilege;
+
+public class SecurityUtils extends org.apache.shiro.SecurityUtils {
+
+ public static Collection<Account> findUsersCan(Depot depot, DepotPrivilege operation) {
+ Set<Account> authorizedUsers = new HashSet<Account>();
+ for (Account user: GitPlex.getInstance(AccountManager.class).all()) {
+ if (user.asSubject().isPermitted(new ObjectPermission(depot, operation)))
+ authorizedUsers.add(user);
+ }
+ return authorizedUsers;
+ }
+
+ public static boolean canModify(PullRequest request) {
+ Depot depot = request.getTargetDepot();
+ if (SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot))) {
+ return true;
+ } else {
+ Account currentUser = getAccount();
+ Account submitter = request.getSubmitter();
+ return currentUser != null && currentUser.equals(submitter);
+ }
+ }
+
+ public static Account getAccount() {
+ return GitPlex.getInstance(AccountManager.class).getCurrent();
+ }
+
+ public static boolean canModify(Review review) {
+ Depot depot = review.getUpdate().getRequest().getTargetDepot();
+ if (SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot))) {
+ return true;
+ } else {
+ return review.getReviewer().equals(getAccount());
+ }
+ }
+
+ public static boolean canModify(CodeComment comment) {
+ Account currentUser = getAccount();
+ if (currentUser == null) {
+ return false;
+ } else {
+ return currentUser.equals(comment.getUser()) || canManage(comment.getDepot());
+ }
+ }
+
+ public static boolean canModify(CodeCommentReply reply) {
+ Account currentUser = getAccount();
+ if (currentUser == null) {
+ return false;
+ } else {
+ return currentUser.equals(reply.getUser()) || canManage(reply.getComment().getDepot());
+ }
+ }
+
+ public static boolean canPushRef(Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
+ Account currentUser = getAccount();
+ return currentUser != null
+ && currentUser.asSubject().isPermitted(ObjectPermission.ofDepotWrite(depot))
+ && depot.getGateKeeper().checkPush(currentUser, depot, refName, oldCommit, newCommit).isPassed();
+ }
+
+ public static boolean canModify(Depot depot, String branch, @Nullable String file) {
+ return canWrite(depot) && depot.getGateKeeper().checkFile(getAccount(), depot, branch, file).isPassed();
+ }
+
+ public static boolean canManage(Account account) {
+ return getSubject().isPermitted(ObjectPermission.ofAccountAdmin(account));
+ }
+
+ public static boolean canAccess(Account organization) {
+ return getSubject().isPermitted(ObjectPermission.ofAccountAccess(organization));
+ }
+
+ public static boolean canRead(Depot depot) {
+ return getSubject().isPermitted(ObjectPermission.ofDepotRead(depot));
+ }
+
+ public static boolean canWrite(Depot depot) {
+ return getSubject().isPermitted(ObjectPermission.ofDepotWrite(depot));
+ }
+
+ public static boolean canManage(Depot depot) {
+ return getSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot));
+ }
+
+ public static boolean canManageSystem() {
+ Account currentUser = getAccount();
+ return currentUser != null && currentUser.isAdministrator();
+ }
+
+ public static boolean isGreater(Privilege greater, Privilege lesser) {
+ return greater.can(lesser) && !lesser.can(greater);
+ }
+
+}
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java
index f5042dcacb..c6078dde40 100644
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java
+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java
@@ -1,286 +1,286 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.RepositoryCache;
-import org.eclipse.jgit.lib.RepositoryCache.FileKey;
-import org.eclipse.jgit.util.FS;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-
-import com.google.common.collect.Sets;
-import com.pmease.commons.git.AbstractGitTest;
-import com.pmease.commons.git.Git;
-import com.pmease.commons.loader.AppLoader;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.manager.DepotManager;
-import com.pmease.gitplex.core.manager.StorageManager;
-
-public class PullRequestUpdateTest extends AbstractGitTest {
-
- private Git bareGit;
-
- private Depot depot;
-
- @Override
- public void setup() {
- super.setup();
-
- bareGit = new Git(new File(tempDir, "bare"));
- bareGit.clone(git, true, false, false, null);
-
- depot = new Depot() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Git git() {
- return bareGit;
- }
-
- };
-
- Repository repository;
- try {
- repository = RepositoryCache.open(FileKey.lenient(depot.git().depotDir(), FS.DETECTED));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- DepotManager depotManager = Mockito.mock(DepotManager.class);
- Mockito.when(depotManager.getRepository(Matchers.any())).thenReturn(repository);
- Mockito.when(AppLoader.getInstance(DepotManager.class)).thenReturn(depotManager);
- Mockito.when(AppLoader.getInstance(StorageManager.class)).thenReturn(new StorageManager() {
-
- @Override
- public File getDepotDir(Depot depot) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public File getCacheDir(PullRequestUpdate update) {
- File cacheDir = new File(tempDir, "updates/" + update.getId());
- cacheDir.mkdirs();
- return cacheDir;
- }
-
- @Override
- public File getCacheDir(PullRequest request) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public File getCacheDir(Depot depot) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public File getIndexDir(Depot depot) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public File getAttachmentsDir(PullRequest request) {
- throw new UnsupportedOperationException();
- }
- });
- }
-
- @Test
- public void testResolveChangedFilesWhenThereIsNoMerge() {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("a", "", "master:1");
-
- git.checkout("HEAD", "dev");
-
- addFileAndCommit("b", "", "dev:2");
-
- addFileAndCommit("c", "", "dev:3");
-
- git.checkout("master", null);
-
- addFileAndCommit("d", "", "master:4");
-
- git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
- git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
-
- request.setBaseCommitHash(bareGit.showRevision("master~1").getHash());
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(bareGit.showRevision("dev~1").getHash());
- bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
- request.addUpdate(update1);
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
- bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
- request.addUpdate(update2);
-
- depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
-
- Assert.assertEquals(Sets.newHashSet("c"), update2.getChangedFiles());
- Assert.assertEquals(Sets.newHashSet("b"), update1.getChangedFiles());
- }
-
- @Test
- public void testResolveChangedFilesWhenThereIsMerge() {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("1", "", "master:1");
-
- addFileAndCommit("2", "", "master:2");
-
- git.checkout("master~1", "dev");
-
- addFileAndCommit("3", "", "dev:3");
-
- git.merge("master", null, null, null, null);
-
- addFileAndCommit("4", "", "dev:4");
-
- git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
- git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
-
- request.setBaseCommitHash(bareGit.calcMergeBase("dev~2", "master"));
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(bareGit.showRevision("dev~2").getHash());
- bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
- request.addUpdate(update1);
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
- bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
- request.addUpdate(update2);
-
- depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
-
- Assert.assertEquals(Sets.newHashSet("4"), update2.getChangedFiles());
- }
-
- @Test
- public void testGetCommitsWhenTargetBranchIsMergedToSourceBranch() {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("0", "", "0");
-
- git.checkout("HEAD", "dev");
- git.checkout("master", null);
-
- addFileAndCommit("m1", "", "m1");
-
- git.checkout("dev", null);
-
- addFileAndCommit("d1", "", "d1");
-
- addFileAndCommit("d2", "", "d2");
-
- git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
- git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
-
- request.setBaseCommitHash(bareGit.calcMergeBase("master", "dev"));
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(bareGit.showRevision("dev").getHash());
- bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
- request.addUpdate(update1);
-
- git.merge("master", null, null, null, "merge master to dev");
- git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
- bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
- request.addUpdate(update2);
-
- depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
-
- Assert.assertEquals(2, update1.getCommits().size());
- Assert.assertEquals("d1", update1.getCommits().get(0).getMessage());
- Assert.assertEquals("d2", update1.getCommits().get(1).getMessage());
-
- Assert.assertEquals(1, update2.getCommits().size());
- Assert.assertTrue(update2.getCommits().get(0).getMessage().startsWith("merge master to dev"));
- }
-
- @Test
- public void testGetCommitsWhenSourceBranchIsMergedToTargetBranch() {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("0", "", "0");
-
- git.checkout("HEAD", "dev");
- git.checkout("master", null);
-
- addFileAndCommit("m1", "", "m1");
-
- git.checkout("dev", null);
-
- addFileAndCommit("d1", "", "d1");
-
- request.setBaseCommitHash(git.parseRevision("master", true));
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(git.showRevision("dev").getHash());
- request.addUpdate(update1);
-
- addFileAndCommit("d2", "", "d2");
-
- git.checkout("master", null);
- git.merge("dev", null, null, null, null);
-
- git.checkout("dev", null);
-
- addFileAndCommit("d3", "", "d3");
-
- git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
- git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
-
- bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
- bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
-
- request.addUpdate(update2);
-
- depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
-
- Assert.assertEquals(2, update2.getCommits().size());
- Assert.assertEquals("d2", update2.getCommits().get(0).getMessage());
- Assert.assertEquals("d3", update2.getCommits().get(1).getMessage());
- }
-
+package com.pmease.gitplex.core.model;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryCache;
+import org.eclipse.jgit.lib.RepositoryCache.FileKey;
+import org.eclipse.jgit.util.FS;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
+import com.google.common.collect.Sets;
+import com.pmease.commons.git.AbstractGitTest;
+import com.pmease.commons.git.Git;
+import com.pmease.commons.loader.AppLoader;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.manager.DepotManager;
+import com.pmease.gitplex.core.manager.StorageManager;
+
+public class PullRequestUpdateTest extends AbstractGitTest {
+
+ private Git bareGit;
+
+ private Depot depot;
+
+ @Override
+ public void setup() {
+ super.setup();
+
+ bareGit = new Git(new File(tempDir, "bare"));
+ bareGit.clone(git, true, false, false, null);
+
+ depot = new Depot() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Git git() {
+ return bareGit;
+ }
+
+ };
+
+ Repository repository;
+ try {
+ repository = RepositoryCache.open(FileKey.lenient(depot.git().depotDir(), FS.DETECTED));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ DepotManager depotManager = Mockito.mock(DepotManager.class);
+ Mockito.when(depotManager.getRepository(Matchers.any())).thenReturn(repository);
+ Mockito.when(AppLoader.getInstance(DepotManager.class)).thenReturn(depotManager);
+ Mockito.when(AppLoader.getInstance(StorageManager.class)).thenReturn(new StorageManager() {
+
+ @Override
+ public File getDepotDir(Depot depot) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public File getCacheDir(PullRequestUpdate update) {
+ File cacheDir = new File(tempDir, "updates/" + update.getId());
+ cacheDir.mkdirs();
+ return cacheDir;
+ }
+
+ @Override
+ public File getCacheDir(PullRequest request) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public File getCacheDir(Depot depot) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public File getIndexDir(Depot depot) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public File getAttachmentsDir(Depot depot) {
+ throw new UnsupportedOperationException();
+ }
+ });
+ }
+
+ @Test
+ public void testResolveChangedFilesWhenThereIsNoMerge() {
+ PullRequest request = new PullRequest();
+ request.setTargetDepot(depot);
+ request.setTargetBranch("master");
+
+ addFileAndCommit("a", "", "master:1");
+
+ git.checkout("HEAD", "dev");
+
+ addFileAndCommit("b", "", "dev:2");
+
+ addFileAndCommit("c", "", "dev:3");
+
+ git.checkout("master", null);
+
+ addFileAndCommit("d", "", "master:4");
+
+ git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
+ git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
+
+ request.setBaseCommitHash(bareGit.showRevision("master~1").getHash());
+
+ PullRequestUpdate update1 = new PullRequestUpdate();
+ update1.setId(1L);
+ update1.setRequest(request);
+ update1.setHeadCommitHash(bareGit.showRevision("dev~1").getHash());
+ bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
+ request.addUpdate(update1);
+
+ PullRequestUpdate update2 = new PullRequestUpdate();
+ update2.setId(2L);
+ update2.setRequest(request);
+ update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
+ bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
+ request.addUpdate(update2);
+
+ depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
+
+ Assert.assertEquals(Sets.newHashSet("c"), update2.getChangedFiles());
+ Assert.assertEquals(Sets.newHashSet("b"), update1.getChangedFiles());
+ }
+
+ @Test
+ public void testResolveChangedFilesWhenThereIsMerge() {
+ PullRequest request = new PullRequest();
+ request.setTargetDepot(depot);
+ request.setTargetBranch("master");
+
+ addFileAndCommit("1", "", "master:1");
+
+ addFileAndCommit("2", "", "master:2");
+
+ git.checkout("master~1", "dev");
+
+ addFileAndCommit("3", "", "dev:3");
+
+ git.merge("master", null, null, null, null);
+
+ addFileAndCommit("4", "", "dev:4");
+
+ git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
+ git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
+
+ request.setBaseCommitHash(bareGit.calcMergeBase("dev~2", "master"));
+
+ PullRequestUpdate update1 = new PullRequestUpdate();
+ update1.setId(1L);
+ update1.setRequest(request);
+ update1.setHeadCommitHash(bareGit.showRevision("dev~2").getHash());
+ bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
+ request.addUpdate(update1);
+
+ PullRequestUpdate update2 = new PullRequestUpdate();
+ update2.setId(2L);
+ update2.setRequest(request);
+ update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
+ bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
+ request.addUpdate(update2);
+
+ depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
+
+ Assert.assertEquals(Sets.newHashSet("4"), update2.getChangedFiles());
+ }
+
+ @Test
+ public void testGetCommitsWhenTargetBranchIsMergedToSourceBranch() {
+ PullRequest request = new PullRequest();
+ request.setTargetDepot(depot);
+ request.setTargetBranch("master");
+
+ addFileAndCommit("0", "", "0");
+
+ git.checkout("HEAD", "dev");
+ git.checkout("master", null);
+
+ addFileAndCommit("m1", "", "m1");
+
+ git.checkout("dev", null);
+
+ addFileAndCommit("d1", "", "d1");
+
+ addFileAndCommit("d2", "", "d2");
+
+ git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
+ git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
+
+ request.setBaseCommitHash(bareGit.calcMergeBase("master", "dev"));
+
+ PullRequestUpdate update1 = new PullRequestUpdate();
+ update1.setId(1L);
+ update1.setRequest(request);
+ update1.setHeadCommitHash(bareGit.showRevision("dev").getHash());
+ bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
+ request.addUpdate(update1);
+
+ git.merge("master", null, null, null, "merge master to dev");
+ git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
+
+ PullRequestUpdate update2 = new PullRequestUpdate();
+ update2.setId(2L);
+ update2.setRequest(request);
+ update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
+ bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
+ request.addUpdate(update2);
+
+ depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
+
+ Assert.assertEquals(2, update1.getCommits().size());
+ Assert.assertEquals("d1", update1.getCommits().get(0).getMessage());
+ Assert.assertEquals("d2", update1.getCommits().get(1).getMessage());
+
+ Assert.assertEquals(1, update2.getCommits().size());
+ Assert.assertTrue(update2.getCommits().get(0).getMessage().startsWith("merge master to dev"));
+ }
+
+ @Test
+ public void testGetCommitsWhenSourceBranchIsMergedToTargetBranch() {
+ PullRequest request = new PullRequest();
+ request.setTargetDepot(depot);
+ request.setTargetBranch("master");
+
+ addFileAndCommit("0", "", "0");
+
+ git.checkout("HEAD", "dev");
+ git.checkout("master", null);
+
+ addFileAndCommit("m1", "", "m1");
+
+ git.checkout("dev", null);
+
+ addFileAndCommit("d1", "", "d1");
+
+ request.setBaseCommitHash(git.parseRevision("master", true));
+
+ PullRequestUpdate update1 = new PullRequestUpdate();
+ update1.setId(1L);
+ update1.setRequest(request);
+ update1.setHeadCommitHash(git.showRevision("dev").getHash());
+ request.addUpdate(update1);
+
+ addFileAndCommit("d2", "", "d2");
+
+ git.checkout("master", null);
+ git.merge("dev", null, null, null, null);
+
+ git.checkout("dev", null);
+
+ addFileAndCommit("d3", "", "d3");
+
+ git.push(bareGit.depotDir().getAbsolutePath(), "master:master");
+ git.push(bareGit.depotDir().getAbsolutePath(), "dev:dev");
+
+ bareGit.updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null, null);
+
+ PullRequestUpdate update2 = new PullRequestUpdate();
+ update2.setId(2L);
+ update2.setRequest(request);
+ update2.setHeadCommitHash(bareGit.showRevision("dev").getHash());
+ bareGit.updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null, null);
+
+ request.addUpdate(update2);
+
+ depot.cacheObjectId("master", ObjectId.fromString(bareGit.parseRevision("master", true)));
+
+ Assert.assertEquals(2, update2.getCommits().size());
+ Assert.assertEquals("d2", update2.getCommits().get(0).getMessage());
+ Assert.assertEquals("d3", update2.getCommits().get(1).getMessage());
+ }
+
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java
index 6a3c2b4b2b..3a9875a2d8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java
@@ -1,25 +1,26 @@
-package com.pmease.gitplex.web;
-
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
-
-public class Constants {
-
- public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm";
- public static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormat.forPattern(DATETIME_FORMAT);
-
- public static final String DATE_FORMAT = "yyyy-MM-dd";
- public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern(DATE_FORMAT);
-
- public static final int DEFAULT_PAGE_SIZE = 25;
-
- /* diff constants */
- public static final int DIFF_EXPAND_SIZE = 15;
- public static final int MAX_DIFF_FILES = 200;
- public static final int MAX_SINGLE_FILE_DIFF_LINES = 5000;
- public static final int MAX_DIFF_LINES = 10000;
-
- /* commit constants */
- public static final int MAX_DISPLAY_COMMITS = 500;
-
-}
+package com.pmease.gitplex.web;
+
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+public class Constants {
+
+ public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm";
+ public static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormat.forPattern(DATETIME_FORMAT);
+
+ public static final String DATE_FORMAT = "yyyy-MM-dd";
+ public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern(DATE_FORMAT);
+
+ public static final int DEFAULT_PAGE_SIZE = 25;
+
+ /* diff constants */
+ public static final int DIFF_EXPAND_SIZE = 15;
+ public static final int MAX_DIFF_FILES = 200;
+ public static final int MAX_SINGLE_FILE_DIFF_LINES = 5000;
+ public static final int MAX_DIFF_LINES = 10000;
+ public static final int DIFF_CONTEXT_SIZE = 3;
+
+ /* commit constants */
+ public static final int MAX_DISPLAY_COMMITS = 500;
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/AccountLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/AccountLink.java
index 51f2d19228..7564d63952 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/AccountLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/AccountLink.java
@@ -1,59 +1,77 @@
-package com.pmease.gitplex.web.component;
-
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.eclipse.jgit.lib.PersonIdent;
-
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.web.page.account.AccountPage;
-import com.pmease.gitplex.web.page.account.overview.AccountOverviewPage;
-
-@SuppressWarnings("serial")
-public class AccountLink extends BookmarkablePageLink<Void> {
-
- private final PageParameters params;
-
- private final String name;
-
- public AccountLink(String id, Account account) {
- super(id, AccountOverviewPage.class);
-
- params = AccountPage.paramsOf(account);
- name = account.getDisplayName();
- }
-
- public AccountLink(String id, PersonIdent person) {
- super(id, AccountOverviewPage.class);
- name = person.getName();
- Account account = GitPlex.getInstance(AccountManager.class).findByPerson(person);
- if (account != null) {
- params = AccountPage.paramsOf(account);
- } else {
- params = new PageParameters();
- }
- }
-
- @Override
- public PageParameters getPageParameters() {
- return params;
- }
-
- @Override
- public IModel<?> getBody() {
- return Model.of(name);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- if (params.isEmpty()) {
- setEnabled(false);
- }
- }
-
-}
+package com.pmease.gitplex.web.component;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.eclipse.jgit.lib.PersonIdent;
+
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.web.page.account.AccountPage;
+import com.pmease.gitplex.web.page.account.overview.AccountOverviewPage;
+
+@SuppressWarnings("serial")
+public class AccountLink extends BookmarkablePageLink<Void> {
+
+ private final PageParameters params;
+
+ private final String name;
+
+ public AccountLink(String id, @Nullable Account account) {
+ super(id, AccountOverviewPage.class);
+
+ if (account != null) {
+ params = AccountPage.paramsOf(account);
+ name = account.getDisplayName();
+ } else {
+ params = new PageParameters();
+ name = null;
+ }
+ }
+
+ public AccountLink(String id, PersonIdent person) {
+ super(id, AccountOverviewPage.class);
+ name = person.getName();
+ Account account = GitPlex.getInstance(AccountManager.class).findByPerson(person);
+ if (account != null) {
+ params = AccountPage.paramsOf(account);
+ } else {
+ params = new PageParameters();
+ }
+ }
+
+ @Override
+ public PageParameters getPageParameters() {
+ return params;
+ }
+
+ @Override
+ public IModel<?> getBody() {
+ if (name != null)
+ return Model.of(name);
+ else
+ return Model.of("Unknown");
+ }
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+ if (params.isEmpty())
+ tag.setName("i");
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ if (params.isEmpty()) {
+ setEnabled(false);
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.html
new file mode 100644
index 0000000000..3f87618d36
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.html
@@ -0,0 +1,36 @@
+<wicket:panel>
+ <div class="code-comment">
+ <div wicket:id="comment" class="comment post"></div>
+ <div wicket:id="replies" class="reply post"></div>
+ <div wicket:id="addReply" class="add-reply">
+ </div>
+ </div>
+ <wicket:fragment wicket:id="viewFrag">
+ <div class="author-avatar"><a wicket:id="authorAvatar"></a></div>
+ <div class="detail">
+ <div class="head clearfix">
+ <a wicket:id="authorName" class="author-name pull-left"></a>
+ <span wicket:id="authorDate" class="author-date pull-right"></span>
+ </div>
+ <div wicket:id="body" class="body"></div>
+ <div wicket:id="foot" class="foot">
+ <a wicket:id="edit">Edit</a>
+ <span class="middot"></span>
+ <a wicket:id="delete">Delete</a>
+ </div>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="editFrag">
+ <form wicket:id="form" class="leave-confirm">
+ <div wicket:id="feedback" class="feedback"></div>
+ <textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>
+ <div class="actions">
+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Save</button>
+ <button wicket:id="cancel" class="btn btn-sm btn-default">Cancel</button>
+ </div>
+ </form>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="addReplyFrag">
+ <a wicket:id="reply" class="btn btn-sm btn-default"><i class="fa fa-reply"></i> Reply</a>
+ </wicket:fragment>
+</wicket:panel>
\ No newline at end of file
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.java
new file mode 100644
index 0000000000..c9a238b587
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
@@ -0,0 +1,410 @@
+package com.pmease.gitplex.web.component.comment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.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.panel.Fragment;
+import org.apache.wicket.markup.html.panel.GenericPanel;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.resource.CssResourceReference;
+
+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.markdownviewer.MarkdownViewer;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.CodeCommentReply;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.manager.CodeCommentReplyManager;
+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.util.DateUtils;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+public abstract class CodeCommentPanel extends GenericPanel<CodeComment> {
+
+ private RepeatingView repliesView;
+
+ public CodeCommentPanel(String id, IModel<CodeComment> commentModel) {
+ super(id, commentModel);
+ }
+
+ private WebMarkupContainer newCommentContainer() {
+ WebMarkupContainer commentContainer = new Fragment("comment", "viewFrag", this);
+ commentContainer.setOutputMarkupId(true);
+
+ commentContainer.add(new AvatarLink("authorAvatar", getComment().getUser()));
+ commentContainer.add(new AccountLink("authorName", getComment().getUser()));
+ commentContainer.add(new Label("authorDate", DateUtils.formatAge(getComment().getDate())));
+
+ commentContainer.add(new MarkdownViewer("body", Model.of(getComment().getContent()), true));
+
+ WebMarkupContainer foot = new WebMarkupContainer("foot");
+ foot.setVisible(SecurityUtils.canModify(getComment()));
+ foot.add(new AjaxLink<Void>("edit") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.canModify(getComment()));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ Fragment fragment = new Fragment(commentContainer.getId(), "editFrag", CodeCommentPanel.this);
+ Form<?> form = new Form<Void>("form");
+ form.setOutputMarkupId(true);
+ CommentInput input = new CommentInput("input", Model.of(getComment().getContent())) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(getComment().getDepot());
+ }
+
+ };
+ form.add(input);
+ input.setRequired(true);
+
+ NotificationPanel feedback = new NotificationPanel("feedback", input);
+ 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);
+ }
+
+ });
+
+ 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);
+
+ CodeComment comment = getComment();
+ comment.setContent(input.getModelObject());
+ GitPlex.getInstance(CodeCommentManager.class).persist(comment);
+ WebMarkupContainer commentContainer = newCommentContainer();
+ fragment.replaceWith(commentContainer);
+ target.add(commentContainer);
+ }
+
+ });
+
+ 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
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.canModify(getComment()));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ GitPlex.getInstance(CodeCommentManager.class).remove(getComment());
+ onCommentDeleted(target);
+ }
+
+ });
+
+ commentContainer.add(foot);
+ return commentContainer;
+ }
+
+ private WebMarkupContainer newReplyContainer(String componentId, Long replyId) {
+ Fragment replyContainer = new Fragment(componentId, "viewFrag", this);
+ replyContainer.setOutputMarkupId(true);
+
+ replyContainer.add(new AvatarLink("authorAvatar", getReply(replyId).getUser()));
+ replyContainer.add(new AccountLink("authorName", getReply(replyId).getUser()));
+ replyContainer.add(new Label("authorDate", DateUtils.formatAge(getReply(replyId).getDate())));
+
+ replyContainer.add(new MarkdownViewer("body", Model.of(getReply(replyId).getContent()), true));
+
+ WebMarkupContainer foot = new WebMarkupContainer("foot");
+ foot.setVisible(SecurityUtils.canModify(getReply(replyId)));
+
+ foot.add(new AjaxLink<Void>("edit") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.canModify(getReply(replyId)));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ Fragment fragment = new Fragment(replyContainer.getId(), "editFrag", CodeCommentPanel.this);
+ Form<?> form = new Form<Void>("form");
+ CommentInput input = new CommentInput("input", Model.of(getReply(replyId).getContent())) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(getComment().getDepot());
+ }
+
+ };
+ form.add(input);
+ input.setRequired(true);
+
+ NotificationPanel feedback = new NotificationPanel("feedback", input);
+ 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 = newReplyContainer(componentId, replyId);
+ fragment.replaceWith(replyContainer);
+ target.add(replyContainer);
+ }
+
+ });
+
+ 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);
+
+ CodeCommentReply reply = getReply(replyId);
+ reply.setContent(input.getModelObject());
+ GitPlex.getInstance(CodeCommentReplyManager.class).persist(reply);
+
+ WebMarkupContainer replyContainer = newReplyContainer(componentId, replyId);
+ fragment.replaceWith(replyContainer);
+ target.add(replyContainer);
+ }
+
+ });
+
+ fragment.add(form);
+ fragment.setOutputMarkupId(true);
+ replyContainer.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
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.canModify(getComment()));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ GitPlex.getInstance(CodeCommentReplyManager.class).remove(getReply(replyId));
+ String script = String.format("$('#%s').remove();", replyContainer.getMarkupId());
+ target.appendJavaScript(script);
+ }
+
+ });
+
+ replyContainer.add(foot);
+ return replyContainer;
+ }
+
+ 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) {
+ Fragment fragment = new Fragment(addReplyContainer.getId(), "editFrag", CodeCommentPanel.this);
+ Form<?> form = new Form<Void>("form");
+ CommentInput input = new CommentInput("input", Model.of("")) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(getComment().getDepot());
+ }
+
+ };
+ form.add(input);
+ input.setRequired(true);
+
+ NotificationPanel feedback = new NotificationPanel("feedback", input);
+ 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);
+ }
+
+ });
+
+ 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);
+
+ CodeCommentReply reply = new CodeCommentReply();
+ reply.setComment(getComment());
+ reply.setUser(SecurityUtils.getAccount());
+ reply.setContent(input.getModelObject());
+ GitPlex.getInstance(CodeCommentReplyManager.class).persist(reply);
+
+ WebMarkupContainer replyContainer = newReplyContainer(repliesView.newChildId(), reply.getId());
+ repliesView.add(replyContainer);
+
+ String script = String.format("$('#%s .add-reply').before('<div id=\"%s\"></div>');",
+ CodeCommentPanel.this.getMarkupId(), replyContainer.getMarkupId());
+ target.prependJavaScript(script);
+ target.add(replyContainer);
+
+ WebMarkupContainer addReplyContainer = newAddReplyContainer();
+ fragment.replaceWith(addReplyContainer);
+ target.add(addReplyContainer);
+ }
+
+ });
+
+ fragment.add(form);
+ fragment.setOutputMarkupId(true);
+ addReplyContainer.replaceWith(fragment);
+ target.add(fragment);
+ }
+
+ });
+ return addReplyContainer;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(newCommentContainer());
+
+ repliesView = new RepeatingView("replies");
+ List<CodeCommentReply> replies = new ArrayList<>(getComment().getReplies());
+ replies.sort((reply1, reply2)->(int)(reply1.getId()-reply2.getId()));
+ for (CodeCommentReply reply: replies) {
+ repliesView.add(newReplyContainer(repliesView.newChildId(), reply.getId()));
+ }
+ add(repliesView);
+ add(newAddReplyContainer());
+
+ add(AttributeAppender.append("data-line", getComment().getMark().getBeginLine()));
+ add(AttributeAppender.append("data-comment", getComment().getId()));
+
+ setOutputMarkupId(true);
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new CssResourceReference(
+ CodeCommentPanel.class, "code-comment.css")));
+ }
+
+ private CodeComment getComment() {
+ return getModelObject();
+ }
+
+ private CodeCommentReply getReply(Long replyId) {
+ return GitPlex.getInstance(CodeCommentReplyManager.class).load(replyId);
+ }
+
+ protected abstract void onCommentDeleted(AjaxRequestTarget target);
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.java
index ff79848839..446bfd0bcb 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentInput.java
@@ -1,160 +1,151 @@
-package com.pmease.gitplex.web.component.comment;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.CallbackParameter;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.JavaScriptHeaderItem;
-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
-import org.apache.wicket.markup.html.form.TextArea;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.request.IRequestParameters;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.request.resource.JavaScriptResourceReference;
-import org.hibernate.criterion.MatchMode;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.util.StringUtils;
-import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
-import com.pmease.commons.wicket.behavior.markdown.MarkdownBehavior;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.web.avatar.AvatarManager;
-
-@SuppressWarnings("serial")
-public class CommentInput extends TextArea<String> {
-
- private final IModel<PullRequest> requestModel;
-
- public CommentInput(String id, IModel<PullRequest> requestModel, IModel<String> contentModel) {
- super(id, contentModel);
-
- this.requestModel = requestModel;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new MarkdownBehavior() {
-
- @Override
- protected void respond(AjaxRequestTarget target) {
- IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
- String type = params.getParameterValue("type").toString();
-
- if (type.equals("userQuery")) {
- String userQuery = params.getParameterValue("param").toOptionalString();
-
- AvatarManager avatarManager = GitPlex.getInstance(AvatarManager.class);
- List<Map<String, String>> userList = new ArrayList<>();
- for (Account user: queryUsers(userQuery, ATWHO_LIMIT)) {
- Map<String, String> userMap = new HashMap<>();
- userMap.put("name", user.getName());
- userMap.put("fullName", user.getFullName());
- if (user.getNoSpaceFullName() != null)
- userMap.put("searchKey", user.getNoSpaceName() + " " + user.getNoSpaceFullName());
- else
- userMap.put("searchKey", user.getNoSpaceName());
- String avatarUrl = avatarManager.getAvatarUrl(user);
- userMap.put("avatarUrl", avatarUrl);
- userList.add(userMap);
- }
-
- String json;
- try {
- json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(userList);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- String script = String.format("$('#%s').data('atWhoUserRenderCallback')(%s);",
- getComponent().getMarkupId(), json);
- target.appendJavaScript(script);
- } else if (type.equals("requestQuery")) {
- String requestQuery = params.getParameterValue("param").toOptionalString();
-
- List<Map<String, String>> requestList = new ArrayList<>();
- for (PullRequest request: queryRequests(requestQuery, ATWHO_LIMIT)) {
- Map<String, String> requestMap = new HashMap<>();
- requestMap.put("requestId", request.getIdStr());
- requestMap.put("requestTitle", request.getTitle());
- requestMap.put("searchKey", request.getIdStr() + " " + request.getNoSpaceTitle());
- requestList.add(requestMap);
- }
-
- String json;
- try {
- json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(requestList);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- String script = String.format("$('#%s').data('atWhoRequestRenderCallback')(%s);",
- getComponent().getMarkupId(), json);
- target.appendJavaScript(script);
- } else {
- super.respond(target);
- }
- }
-
- @Override
- public AttachmentSupport getAttachmentSupport() {
- return new CommentAttachmentSupport(requestModel.getObject().getId());
- }
-
- @Override
- public void renderHead(Component component, IHeaderResponse response) {
- super.renderHead(component, response);
-
- response.render(JavaScriptHeaderItem.forReference(
- new JavaScriptResourceReference(CommentInput.class, "comment-input.js")));
- String script = String.format("gitplex.comment('%s', %s, %s);",
- component.getMarkupId(true), ATWHO_LIMIT,
- getCallbackFunction(CallbackParameter.explicit("type"), CallbackParameter.explicit("param")));
- response.render(OnDomReadyHeaderItem.forScript(script));
- }
-
- });
- }
-
- protected List<Account> queryUsers(String query, int count) {
- EntityCriteria<Account> criteria = EntityCriteria.of(Account.class);
- if (StringUtils.isNotBlank(query)) {
- criteria.add(Restrictions.or(
- Restrictions.ilike("noSpaceName", query, MatchMode.ANYWHERE),
- Restrictions.ilike("noSpaceFullName", query, MatchMode.ANYWHERE)));
- }
- criteria.addOrder(Order.asc("name"));
- return GitPlex.getInstance(Dao.class).query(criteria, 0, count);
- }
-
- protected List<PullRequest> queryRequests(String query, int count) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- if (StringUtils.isNotBlank(query)) {
- query = StringUtils.deleteWhitespace(query);
- criteria.add(Restrictions.or(
- Restrictions.ilike("noSpaceTitle", query, MatchMode.ANYWHERE),
- Restrictions.ilike("idStr", query, MatchMode.START)));
- }
- criteria.addOrder(Order.desc("id"));
- return GitPlex.getInstance(Dao.class).query(criteria, 0, count);
- }
-
- @Override
- protected void onDetach() {
- requestModel.detach();
-
- super.onDetach();
- }
-
-}
+package com.pmease.gitplex.web.component.comment;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.CallbackParameter;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.form.TextArea;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.hibernate.criterion.MatchMode;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
+import com.pmease.commons.wicket.behavior.markdown.MarkdownBehavior;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.web.avatar.AvatarManager;
+
+@SuppressWarnings("serial")
+public abstract class CommentInput extends TextArea<String> {
+
+ public CommentInput(String id, IModel<String> contentModel) {
+ super(id, contentModel);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new MarkdownBehavior() {
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
+ String type = params.getParameterValue("type").toString();
+
+ if (type.equals("userQuery")) {
+ String userQuery = params.getParameterValue("param").toOptionalString();
+
+ AvatarManager avatarManager = GitPlex.getInstance(AvatarManager.class);
+ List<Map<String, String>> userList = new ArrayList<>();
+ for (Account user: queryUsers(userQuery, ATWHO_LIMIT)) {
+ Map<String, String> userMap = new HashMap<>();
+ userMap.put("name", user.getName());
+ userMap.put("fullName", user.getFullName());
+ if (user.getNoSpaceFullName() != null)
+ userMap.put("searchKey", user.getNoSpaceName() + " " + user.getNoSpaceFullName());
+ else
+ userMap.put("searchKey", user.getNoSpaceName());
+ String avatarUrl = avatarManager.getAvatarUrl(user);
+ userMap.put("avatarUrl", avatarUrl);
+ userList.add(userMap);
+ }
+
+ String json;
+ try {
+ json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(userList);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ String script = String.format("$('#%s').data('atWhoUserRenderCallback')(%s);",
+ getComponent().getMarkupId(), json);
+ target.appendJavaScript(script);
+ } else if (type.equals("requestQuery")) {
+ String requestQuery = params.getParameterValue("param").toOptionalString();
+
+ List<Map<String, String>> requestList = new ArrayList<>();
+ for (PullRequest request: queryRequests(requestQuery, ATWHO_LIMIT)) {
+ Map<String, String> requestMap = new HashMap<>();
+ requestMap.put("requestId", request.getIdStr());
+ requestMap.put("requestTitle", request.getTitle());
+ requestMap.put("searchKey", request.getIdStr() + " " + request.getNoSpaceTitle());
+ requestList.add(requestMap);
+ }
+
+ String json;
+ try {
+ json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(requestList);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ String script = String.format("$('#%s').data('atWhoRequestRenderCallback')(%s);",
+ getComponent().getMarkupId(), json);
+ target.appendJavaScript(script);
+ } else {
+ super.respond(target);
+ }
+ }
+
+ @Override
+ public AttachmentSupport getAttachmentSupport() {
+ return CommentInput.this.getAttachmentSupport();
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+
+ response.render(JavaScriptHeaderItem.forReference(
+ new JavaScriptResourceReference(CommentInput.class, "comment-input.js")));
+ String script = String.format("gitplex.comment('%s', %s, %s);",
+ component.getMarkupId(true), ATWHO_LIMIT,
+ getCallbackFunction(CallbackParameter.explicit("type"), CallbackParameter.explicit("param")));
+ response.render(OnDomReadyHeaderItem.forScript(script));
+ }
+
+ });
+ }
+
+ protected List<Account> queryUsers(String query, int count) {
+ EntityCriteria<Account> criteria = EntityCriteria.of(Account.class);
+ if (StringUtils.isNotBlank(query)) {
+ criteria.add(Restrictions.or(
+ Restrictions.ilike("noSpaceName", query, MatchMode.ANYWHERE),
+ Restrictions.ilike("noSpaceFullName", query, MatchMode.ANYWHERE)));
+ }
+ criteria.addOrder(Order.asc("name"));
+ return GitPlex.getInstance(Dao.class).query(criteria, 0, count);
+ }
+
+ protected List<PullRequest> queryRequests(String query, int count) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ if (StringUtils.isNotBlank(query)) {
+ query = StringUtils.deleteWhitespace(query);
+ criteria.add(Restrictions.or(
+ Restrictions.ilike("noSpaceTitle", query, MatchMode.ANYWHERE),
+ Restrictions.ilike("idStr", query, MatchMode.START)));
+ }
+ criteria.addOrder(Order.desc("id"));
+ return GitPlex.getInstance(Dao.class).query(criteria, 0, count);
+ }
+
+ protected abstract AttachmentSupport getAttachmentSupport();
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentAttachmentSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/DepotAttachmentSupport.java
similarity index 82%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentAttachmentSupport.java
rename to gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/DepotAttachmentSupport.java
index 32918e7069..2fbabf4355 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentAttachmentSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/DepotAttachmentSupport.java
@@ -1,129 +1,128 @@
-package com.pmease.gitplex.web.component.comment;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.request.Url;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.util.FileUtils;
-import com.pmease.commons.util.StringUtils;
-import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.manager.StorageManager;
-import com.pmease.gitplex.core.security.SecurityUtils;
-import com.pmease.gitplex.web.resource.AttachmentResource;
-import com.pmease.gitplex.web.resource.AttachmentResourceReference;
-
-import jersey.repackaged.com.google.common.base.Throwables;
-
-public class CommentAttachmentSupport implements AttachmentSupport {
-
- private static final long serialVersionUID = 1L;
-
- private static final int MAX_FILE_SIZE = 50*1024*1024; // mega bytes
-
- private static final int BUFFER_SIZE = 1024*64;
-
- private final Long requestId;
-
- public CommentAttachmentSupport(Long requestId) {
- this.requestId = requestId;
- }
-
- @Override
- public String getAttachmentUrl(String attachment) {
- PageParameters params = AttachmentResource.paramsOf(getRequest(), attachment);
- String url = RequestCycle.get().urlFor(new AttachmentResourceReference(), params).toString();
- return RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(url));
- }
-
- @Override
- public List<String> getAttachments() {
- List<String> attachments = new ArrayList<>();
- File attachmentsDir = GitPlex.getInstance(StorageManager.class)
- .getAttachmentsDir(getRequest());
- if (attachmentsDir.exists()) {
- for (File file: attachmentsDir.listFiles())
- attachments.add(file.getName());
- }
- return attachments;
- }
-
- private File getAttachmentsDir() {
- return GitPlex.getInstance(StorageManager.class).getAttachmentsDir(getRequest());
- }
-
- @Override
- public void deleteAttachemnt(String attachment) {
- File attachmentsDir = GitPlex.getInstance(StorageManager.class)
- .getAttachmentsDir(getRequest());
- FileUtils.deleteFile(new File(attachmentsDir, attachment));
- }
-
- @Override
- public long getAttachmentMaxSize() {
- return MAX_FILE_SIZE;
- }
-
- @Override
- public long getAttachmentSize(String attachment) {
- return new File(getAttachmentsDir(), attachment).length();
- }
-
- private PullRequest getRequest() {
- return GitPlex.getInstance(Dao.class).load(PullRequest.class, requestId);
- }
-
- @Override
- public String saveAttachment(String suggestedAttachmentName, InputStream attachmentStream) {
- Preconditions.checkState(SecurityUtils.canRead(getRequest().getTargetDepot()));
-
- String attachmentName = suggestedAttachmentName;
- File attachmentsDir = getAttachmentsDir();
- int index = 2;
- while (new File(attachmentsDir, attachmentName).exists()) {
- if (suggestedAttachmentName.contains(".")) {
- String nameBeforeExt = StringUtils.substringBeforeLast(suggestedAttachmentName, ".");
- String ext = StringUtils.substringAfterLast(suggestedAttachmentName, ".");
- attachmentName = nameBeforeExt + "_" + index + "." + ext;
- } else {
- attachmentName = suggestedAttachmentName + "_" + index;
- }
- index++;
- }
-
- Exception ex = null;
- File file = new File(attachmentsDir, attachmentName);
- try (OutputStream os = new FileOutputStream(file)) {
- byte[] buffer = new byte[BUFFER_SIZE];
- long count = 0;
- int n = 0;
- while (-1 != (n = attachmentStream.read(buffer))) {
- count += n;
- if (count > getAttachmentMaxSize()) {
- throw new RuntimeException("Upload must be less than "
- + FileUtils.byteCountToDisplaySize(getAttachmentMaxSize()));
- }
- os.write(buffer, 0, n);
- }
- } catch (Exception e) {
- ex = e;
- }
- if (ex != null) {
- if (file.exists())
- FileUtils.deleteFile(file);
- throw Throwables.propagate(ex);
- } else {
- return file.getName();
- }
- }
-}
+package com.pmease.gitplex.web.component.comment;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import com.google.common.base.Preconditions;
+import com.pmease.commons.util.FileUtils;
+import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.manager.DepotManager;
+import com.pmease.gitplex.core.manager.StorageManager;
+import com.pmease.gitplex.core.security.SecurityUtils;
+import com.pmease.gitplex.web.resource.AttachmentResource;
+import com.pmease.gitplex.web.resource.AttachmentResourceReference;
+
+import jersey.repackaged.com.google.common.base.Throwables;
+
+public class DepotAttachmentSupport implements AttachmentSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final int MAX_FILE_SIZE = 50*1024*1024; // mega bytes
+
+ private static final int BUFFER_SIZE = 1024*64;
+
+ private final Long depotId;
+
+ public DepotAttachmentSupport(Depot depot) {
+ depotId = depot.getId();
+ }
+
+ @Override
+ public String getAttachmentUrl(String attachment) {
+ PageParameters params = AttachmentResource.paramsOf(getDepot(), attachment);
+ String url = RequestCycle.get().urlFor(new AttachmentResourceReference(), params).toString();
+ return RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(url));
+ }
+
+ @Override
+ public List<String> getAttachments() {
+ List<String> attachments = new ArrayList<>();
+ File attachmentsDir = GitPlex.getInstance(StorageManager.class).getAttachmentsDir(getDepot());
+ if (attachmentsDir.exists()) {
+ for (File file: attachmentsDir.listFiles())
+ attachments.add(file.getName());
+ }
+ return attachments;
+ }
+
+ private File getAttachmentsDir() {
+ return GitPlex.getInstance(StorageManager.class).getAttachmentsDir(getDepot());
+ }
+
+ @Override
+ public void deleteAttachemnt(String attachment) {
+ File attachmentsDir = GitPlex.getInstance(StorageManager.class)
+ .getAttachmentsDir(getDepot());
+ FileUtils.deleteFile(new File(attachmentsDir, attachment));
+ }
+
+ @Override
+ public long getAttachmentMaxSize() {
+ return MAX_FILE_SIZE;
+ }
+
+ @Override
+ public long getAttachmentSize(String attachment) {
+ return new File(getAttachmentsDir(), attachment).length();
+ }
+
+ private Depot getDepot() {
+ return GitPlex.getInstance(DepotManager.class).load(depotId);
+ }
+
+ @Override
+ public String saveAttachment(String suggestedAttachmentName, InputStream attachmentStream) {
+ Preconditions.checkState(SecurityUtils.canRead(getDepot()));
+
+ String attachmentName = suggestedAttachmentName;
+ File attachmentsDir = getAttachmentsDir();
+ int index = 2;
+ while (new File(attachmentsDir, attachmentName).exists()) {
+ if (suggestedAttachmentName.contains(".")) {
+ String nameBeforeExt = StringUtils.substringBeforeLast(suggestedAttachmentName, ".");
+ String ext = StringUtils.substringAfterLast(suggestedAttachmentName, ".");
+ attachmentName = nameBeforeExt + "_" + index + "." + ext;
+ } else {
+ attachmentName = suggestedAttachmentName + "_" + index;
+ }
+ index++;
+ }
+
+ Exception ex = null;
+ File file = new File(attachmentsDir, attachmentName);
+ try (OutputStream os = new FileOutputStream(file)) {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ long count = 0;
+ int n = 0;
+ while (-1 != (n = attachmentStream.read(buffer))) {
+ count += n;
+ if (count > getAttachmentMaxSize()) {
+ throw new RuntimeException("Upload must be less than "
+ + FileUtils.byteCountToDisplaySize(getAttachmentMaxSize()));
+ }
+ os.write(buffer, 0, n);
+ }
+ } catch (Exception e) {
+ ex = e;
+ }
+ if (ex != null) {
+ if (file.exists())
+ FileUtils.deleteFile(file);
+ throw Throwables.propagate(ex);
+ } else {
+ return file.getName();
+ }
+ }
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.css
new file mode 100644
index 0000000000..a9c01f1399
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/code-comment.css
@@ -0,0 +1,47 @@
+.code-comment>.post {
+ border-bottom: 1px solid #EEE;
+ position: relative;
+ padding-bottom: 8px;
+ margin-bottom: 8px;
+}
+.code-comment>.post>.author-avatar {
+ position: absolute;
+ left: 0;
+ top: 0;
+}
+.code-comment>.post>.author-avatar img {
+ width: 32px;
+ height: 32px;
+}
+.code-comment>.post>.detail {
+ padding-left: 40px;
+}
+.code-comment>.post>.detail>.head .author-name {
+ font-size: 14px;
+ color: #999;
+}
+.code-comment>.post>.detail>.head .author-name:hover {
+ color: #333;
+}
+.code-comment>.post>.detail>.head .author-date {
+ font-size: 12px;
+ color: #999;
+}
+.code-comment>.post>.detail>.foot a {
+ font-size: 12px;
+ color: #999;
+}
+.code-comment>.post>.detail>.foot a:hover {
+ font-size: 12px;
+ color: #333;
+}
+.code-comment>.post>.detail>.foot .middot:before {
+ vertical-align: 25%;
+ color: #999;
+}
+.code-comment>.add-reply a {
+ color: #999;
+}
+.code-comment>.add-reply a:hover {
+ color: inherit;
+}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.css
deleted file mode 100644
index 33ab514b11..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comment.css
+++ /dev/null
@@ -1,40 +0,0 @@
-.comment>.body {
- padding: 0 0 10px 0;
-}
-.comment .feedback .alert {
- margin-bottom: 8px;
-}
-.reply.new>.avatar {
- background: #FCF6D6;
-}
-div.replies>table {
- table-layout: fixed;
-}
-div.replies>table>tbody>tr>td {
- border-top: 1px solid #EEE;
- padding-top: 10px;
-}
-div.replies>table>tbody>tr>td.avatar {
- width: 26px;
-}
-div.replies>table>tbody>tr>td.avatar img {
- width: 26px;
- height: 26px;
-}
-div.replies>table>tbody>tr>td.detail {
- padding: 10px 0 10px 10px;
-}
-div.replies>table>tbody>tr>td.detail>.head {
- margin-bottom: 10px;
-}
-div.replies>.add-reply>div>a {
- border-top: 1px solid #EEE;
- display: block;
- color: #BBB;
- padding: 5px 10px;
- text-decoration: none;
-}
-div.replies>.add-reply:hover>div>a {
- color: #666;
- background: #F5F5F5;
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java
index cb9c2a35fd..7d58b5ca40 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/instant/InstantSearchPanel.java
@@ -48,6 +48,7 @@ import com.pmease.commons.wicket.component.floating.FloatingPanel;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
import com.pmease.gitplex.search.SearchManager;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.query.BlobQuery;
@@ -58,7 +59,6 @@ import com.pmease.gitplex.search.query.TooGeneralQueryException;
import com.pmease.gitplex.web.component.depotfile.blobsearch.result.SearchResultPanel;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
-import com.pmease.gitplex.web.page.depot.file.Mark;
@SuppressWarnings("serial")
public abstract class InstantSearchPanel extends Panel {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.html
index f27318ceff..a123df7e52 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.html
@@ -14,7 +14,7 @@
</div>
</wicket:enclosure>
<div class="pull-right">
- <a wicket:id="close" title="Close"><i class="fa fa-close"></i></a>
+ <a wicket:id="close" class="close" title="Close"><i class="fa fa-close"></i></a>
</div>
</div>
<ul class="body list-unstyled" tabindex="0">
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java
index e4abb94a8b..b88e3b0094 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobsearch/result/SearchResultPanel.java
@@ -34,13 +34,13 @@ import com.pmease.commons.wicket.assets.uri.URIResourceReference;
import com.pmease.commons.wicket.component.EmphasizeAwareLabel;
import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
import com.pmease.gitplex.search.hit.FileHit;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.hit.TextHit;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
-import com.pmease.gitplex.web.page.depot.file.Mark;
@SuppressWarnings("serial")
public abstract class SearchResultPanel extends Panel {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
index 9e41384416..2ffec7e536 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
@@ -6,15 +6,17 @@ import java.util.List;
import javax.annotation.Nullable;
import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.eclipse.jgit.revwalk.RevCommit;
import com.pmease.commons.git.BlobIdent;
import com.pmease.commons.lang.extractors.TokenPosition;
import com.pmease.commons.wicket.component.menu.MenuItem;
import com.pmease.commons.wicket.component.menu.MenuLink;
+import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
import com.pmease.gitplex.search.hit.QueryHit;
-import com.pmease.gitplex.web.page.depot.file.Mark;
public interface BlobViewContext extends Serializable {
@@ -30,6 +32,8 @@ public interface BlobViewContext extends Serializable {
@Nullable
Mark getMark();
+ void onMark(AjaxRequestTarget target, @Nullable Mark mark);
+
Mode getMode();
boolean isOnBranch();
@@ -45,7 +49,14 @@ public interface BlobViewContext extends Serializable {
void onDelete(AjaxRequestTarget target);
void onEdit(AjaxRequestTarget target, @Nullable String viewState);
+
+ void onShowComment(AjaxRequestTarget target, @Nullable CodeComment comment);
+ @Nullable
+ CodeComment getComment();
+
+ RevCommit getCommit();
+
List<MenuItem> getMenuItems(MenuLink menuLink);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/OutlinePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/OutlinePanel.java
deleted file mode 100644
index 7ccbd221b3..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/OutlinePanel.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package com.pmease.gitplex.web.component.depotfile.blobview.source;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.annotation.Nullable;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;
-import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;
-import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;
-import org.apache.wicket.markup.html.image.Image;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-import com.pmease.commons.lang.extractors.Symbol;
-import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;
-
-@SuppressWarnings("serial")
-abstract class OutlinePanel extends Panel {
-
- private final List<Symbol> symbols;
-
- public OutlinePanel(String id, List<Symbol> symbols) {
- super(id);
- this.symbols = symbols;
- }
-
- private List<Symbol> getChildSymbols(@Nullable Symbol parentSymbol) {
- List<Symbol> children = new ArrayList<>();
- for (Symbol symbol: symbols) {
- if (symbol.getParent() == parentSymbol)
- children.add(symbol);
- }
- return children;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- NestedTree<Symbol> tree;
- add(tree = new NestedTree<Symbol>("tree", new ITreeProvider<Symbol>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public Iterator<? extends Symbol> getRoots() {
- return getChildSymbols(null).iterator();
- }
-
- @Override
- public boolean hasChildren(Symbol symbol) {
- return !getChildSymbols(symbol).isEmpty();
- }
-
- @Override
- public Iterator<? extends Symbol> getChildren(Symbol symbol) {
- return getChildSymbols(symbol).iterator();
- }
-
- @Override
- public IModel<Symbol> model(Symbol symbol) {
- return Model.of(symbol);
- }
-
- }) {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
- add(new HumanTheme());
- }
-
- @Override
- protected Component newContentComponent(String id, IModel<Symbol> nodeModel) {
- Fragment fragment = new Fragment(id, "nodeFrag", OutlinePanel.this);
- final Symbol symbol = nodeModel.getObject();
-
- fragment.add(new Image("icon", symbol.getIcon()));
-
- AjaxLink<Void> link = new PreventDefaultAjaxLink<Void>("link") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- onSelect(target, symbol);
- }
-
- };
- link.add(symbol.render("label", null));
- fragment.add(link);
-
- return fragment;
- }
-
- });
-
- for (Symbol root: getChildSymbols(null))
- tree.expand(root);
-
- setOutputMarkupPlaceholderTag(true);
- }
-
- protected abstract void onSelect(AjaxRequestTarget target, Symbol symbol);
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html
index a801946fe6..682ca2f54c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.html
@@ -5,9 +5,10 @@
<div class="content">
<div class="head clearfix">
<span class="pull-left">Comment</span>
- <a wicket:id="close" class="pull-right" title="Hide comment"><i class="fa fa-times"></i></a>
+ <a wicket:id="close" class="pull-right close" title="Hide comment"><i class="fa fa-times"></i></a>
+ <a wicket:id="locate" class="pull-right locate close" title="Locate marked text of this comment"><i class="fa fa-hand-o-right"></i></a>
</div>
- <div class="body"></div>
+ <div wicket:id="body" class="body"></div>
</div>
</div>
<div class="code"></div>
@@ -16,7 +17,7 @@
<div class="content">
<div class="head clearfix">
<span class="pull-left">Outline</span>
- <a wicket:id="close" class="pull-right" title="Hide outline"><i class="fa fa-times"></i></a>
+ <a wicket:id="close" class="pull-right close" title="Hide outline"><i class="fa fa-times"></i></a>
</div>
<div wicket:id="body" class="body"></div>
</div>
@@ -26,4 +27,14 @@
<wicket:fragment wicket:id="outlineNodeFrag">
<img wicket:id="icon"></img> <a wicket:id="link"><span wicket:id="label"></span></a>
</wicket:fragment>
+ <wicket:fragment wicket:id="newCommentFrag">
+ <form wicket:id="form" class="new-comment leave-confirm">
+ <div wicket:id="feedback" class="feedback"></div>
+ <textarea wicket:id="input" rows="10" class="form-control focusable"></textarea>
+ <div class="actions">
+ <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Save</button>
+ <button wicket:id="cancel" class="btn btn-sm btn-default">Cancel</button>
+ </div>
+ </form>
+ </wicket:fragment>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
index 6b5a1f28a8..d2b0df4da4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
@@ -1,15 +1,23 @@
package com.pmease.gitplex.web.component.depotfile.blobview.source;
+import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;
+
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.annotation.Nullable;
import javax.servlet.http.Cookie;
import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
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.extensions.markup.html.repeater.tree.ITreeProvider;
import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;
import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;
@@ -18,12 +26,15 @@ import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
+import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebRequest;
import org.apache.wicket.request.http.WebResponse;
@@ -48,6 +59,7 @@ import com.pmease.commons.lang.extractors.Extractor;
import com.pmease.commons.lang.extractors.Extractors;
import com.pmease.commons.lang.extractors.Symbol;
import com.pmease.commons.util.Range;
+import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;
import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;
import com.pmease.commons.wicket.assets.uri.URIResourceReference;
@@ -55,19 +67,32 @@ import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;
import com.pmease.commons.wicket.component.menu.MenuItem;
import com.pmease.commons.wicket.component.menu.MenuLink;
import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.search.hit.QueryHit;
+import com.pmease.gitplex.web.component.comment.CodeCommentPanel;
+import com.pmease.gitplex.web.component.comment.CommentInput;
+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;
-import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;
+import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;
import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;
import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;
-import com.pmease.gitplex.web.page.depot.file.Mark;
import com.pmease.gitplex.web.util.DateUtils;
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
import de.agilecoders.wicket.extensions.markup.html.bootstrap.jqueryui.JQueryUIJavaScriptReference;
+/**
+ * Make sure to add only one source view panel per page
+ *
+ * @author robin
+ *
+ */
@SuppressWarnings("serial")
public class SourceViewPanel extends BlobViewPanel {
@@ -75,9 +100,22 @@ public class SourceViewPanel extends BlobViewPanel {
private static final String COOKIE_OUTLINE = "sourceView.outline";
+ private static final String BODY_ID = "body";
+
private final List<Symbol> symbols = new ArrayList<>();
private final String viewState;
+
+ private final IModel<Collection<CodeComment>> commentsModel =
+ new LoadableDetachableModel<Collection<CodeComment>>() {
+
+ @Override
+ protected Collection<CodeComment> load() {
+ return GitPlex.getInstance(CodeCommentManager.class).query(
+ context.getDepot(), context.getCommit().name(), context.getBlobIdent().path);
+ }
+
+ };
private WebMarkupContainer commentContainer;
@@ -85,6 +123,8 @@ public class SourceViewPanel extends BlobViewPanel {
private SymbolTooltipPanel symbolTooltip;
+ private AbstractDefaultAjaxBehavior commentBehavior;
+
public SourceViewPanel(String id, BlobViewContext context, @Nullable String viewState) {
super(id, context);
@@ -137,17 +177,6 @@ public class SourceViewPanel extends BlobViewPanel {
return menuItems;
}
- private void hideComment(AjaxRequestTarget target) {
- commentContainer.setVisible(false);
- target.add(commentContainer);
-
- String script = String.format(""
- + "var $sourceView = $('#%s .source-view');"
- + "$sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);",
- getMarkupId());
- target.appendJavaScript(script);
- }
-
private void toggleOutline(AjaxRequestTarget target) {
WebResponse response = (WebResponse) RequestCycle.get().getResponse();
Cookie cookie;
@@ -161,17 +190,12 @@ public class SourceViewPanel extends BlobViewPanel {
cookie.setMaxAge(Integer.MAX_VALUE);
response.addCookie(cookie);
target.add(outlineContainer);
-
- String script = String.format(""
- + "var $sourceView = $('#%s .source-view');"
- + "$sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);",
- getMarkupId());
- target.appendJavaScript(script);
+ target.appendJavaScript("gitplex.sourceview.onToggleOutline();");
}
- public void mark(AjaxRequestTarget target, Mark mark) {
- String script = String.format("gitplex.sourceview.mark('%s', %s, true);",
- getMarkupId(), mark.toJSON());
+ public void mark(AjaxRequestTarget target, Mark mark, boolean scroll) {
+ String script = String.format("gitplex.sourceview.mark(%s, %s);",
+ mark.toJSON(), scroll);
target.appendJavaScript(script);
}
@@ -184,31 +208,215 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- String script = String.format("gitplex.sourceview.initComment('%s');",
- SourceViewPanel.this.getMarkupId());
- response.render(OnDomReadyHeaderItem.forScript(script));
+ response.render(OnDomReadyHeaderItem.forScript("gitplex.sourceview.initComment();"));
}
};
+ commentContainer.add(new AjaxLink<Void>("locate") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ mark(target, context.getComment().getMark(), true);
+ context.onMark(target, context.getComment().getMark());
+ }
+
+ });
commentContainer.add(new AjaxLink<Void>("close") {
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener(commentContainer));
+ }
+
@Override
public void onClick(AjaxRequestTarget target) {
hideComment(target);
+ context.onShowComment(target, null);
}
});
commentContainer.setOutputMarkupPlaceholderTag(true);
+ if (context.getComment() != null) {
+ IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return context.getComment();
+ }
+
+ };
+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentModel) {
+
+ @Override
+ protected void onCommentDeleted(AjaxRequestTarget target) {
+ CodeComment comment = commentModel.getObject();
+ SourceViewPanel.this.onCommentDeleted(target, comment);
+ }
+
+ };
+ commentContainer.add(commentPanel);
+ } else {
+ commentContainer.add(new WebMarkupContainer(BODY_ID));
+ commentContainer.setVisible(false);
+ }
add(commentContainer);
+ add(commentBehavior = new AbstractDefaultAjaxBehavior() {
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();
+
+ switch(params.getParameterValue("action").toString()) {
+ case "add":
+ Preconditions.checkNotNull(SecurityUtils.getAccount());
+
+ // must use commit from source view page in case we are commenting on
+ // a branch and that branch has new commits since the file is being
+ // displayed
+ String commitHash = params.getParameterValue("param1").toString();
+
+ int fromLine = params.getParameterValue("param2").toInt();
+ int fromCh = params.getParameterValue("param3").toInt();
+ int toLine = params.getParameterValue("param4").toInt();
+ int toCh = params.getParameterValue("param5").toInt();
+
+ Fragment fragment = new Fragment(BODY_ID, "newCommentFrag", SourceViewPanel.this);
+ fragment.setOutputMarkupId(true);
+
+ Form<?> form = new Form<Void>("form");
+
+ CommentInput input;
+ form.add(input = new CommentInput("input", Model.of("")) {
+
+ @Override
+ protected DepotAttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(context.getDepot());
+ }
+
+ });
+ input.setRequired(true);
+
+ NotificationPanel feedback = new NotificationPanel("feedback", input);
+ 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) {
+ hideComment(target);
+ }
+
+ });
+
+ 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);
+
+ CodeComment comment = new CodeComment();
+ comment.setCommit(commitHash);
+ comment.setPath(context.getBlobIdent().path);
+ comment.setCompareCommit(commitHash);
+ comment.setContent(input.getModelObject());
+ comment.setDepot(context.getDepot());
+ comment.setUser(SecurityUtils.getAccount());
+ Mark mark = new Mark();
+ mark.beginLine = fromLine;
+ mark.beginChar = fromCh;
+ mark.endLine = toLine;
+ mark.endChar = toCh;
+ comment.setMark(mark);
+ GitPlex.getInstance(CodeCommentManager.class).persist(comment);
+
+ Long commentId = comment.getId();
+ IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ }
+
+ };
+ CodeCommentPanel commentPanel = new CodeCommentPanel(fragment.getId(), commentModel) {
+
+ @Override
+ protected void onCommentDeleted(AjaxRequestTarget target) {
+ CodeComment comment = commentModel.getObject();
+ SourceViewPanel.this.onCommentDeleted(target, comment);
+ }
+
+ };
+ fragment.replaceWith(commentPanel);
+ target.add(commentPanel);
+
+ String script = String.format("gitplex.sourceview.onCommentAdded(%d, %s);",
+ comment.getMark().getBeginLine(),
+ getJsonOfComment(comment));
+ target.appendJavaScript(script);
+ context.onShowComment(target, comment);
+ }
+
+ });
+ fragment.add(form);
+ commentContainer.replace(fragment);
+ commentContainer.setVisible(true);
+ target.add(commentContainer);
+ target.appendJavaScript("gitplex.sourceview.onAddingComment();");
+ break;
+ case "show":
+ Long commentId = params.getParameterValue("param1").toLong();
+ IModel<CodeComment> commentModel = new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ }
+
+ };
+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentModel) {
+
+ @Override
+ protected void onCommentDeleted(AjaxRequestTarget target) {
+ CodeComment comment = commentModel.getObject();
+ SourceViewPanel.this.onCommentDeleted(target, comment);
+ }
+
+ };
+ commentContainer.replace(commentPanel);
+ commentContainer.setVisible(true);
+ target.add(commentContainer);
+ String script = String.format("gitplex.sourceview.onShowComment(%s);",
+ getJsonOfComment(commentModel.getObject()));
+ target.appendJavaScript(script);
+ context.onShowComment(target, commentModel.getObject());
+ break;
+ }
+ }
+
+ });
+
outlineContainer = new WebMarkupContainer("outline") {
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- String script = String.format("gitplex.sourceview.initOutline('%s');",
- SourceViewPanel.this.getMarkupId());
- response.render(OnDomReadyHeaderItem.forScript(script));
+ response.render(OnDomReadyHeaderItem.forScript("gitplex.sourceview.initOutline();"));
}
};
@@ -221,7 +429,7 @@ public class SourceViewPanel extends BlobViewPanel {
});
NestedTree<Symbol> tree;
- outlineContainer.add(tree = new NestedTree<Symbol>("body", new ITreeProvider<Symbol>() {
+ outlineContainer.add(tree = new NestedTree<Symbol>(BODY_ID, new ITreeProvider<Symbol>() {
@Override
public void detach() {
@@ -327,8 +535,37 @@ public class SourceViewPanel extends BlobViewPanel {
}
});
-
- setOutputMarkupId(true);
+ }
+
+ private String getJsonOfComment(CodeComment comment) {
+ CommentInfo commentInfo = new CommentInfo();
+ commentInfo.id = comment.getId();
+ commentInfo.mark = comment.getMark();
+
+ String jsonOfCommentInfo;
+ try {
+ jsonOfCommentInfo = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfo);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ return jsonOfCommentInfo;
+ }
+
+ private void onCommentDeleted(AjaxRequestTarget target, CodeComment comment) {
+ commentContainer.replace(new WebMarkupContainer(BODY_ID));
+ commentContainer.setVisible(false);
+ target.add(commentContainer);
+ String script = String.format("gitplex.sourceview.onCommentDeleted(%d, %d);",
+ comment.getMark().getBeginLine(), comment.getId());
+ target.appendJavaScript(script);
+ context.onShowComment(target, null);
+ }
+
+ private void hideComment(AjaxRequestTarget target) {
+ commentContainer.replace(new WebMarkupContainer(BODY_ID));
+ commentContainer.setVisible(false);
+ target.add(commentContainer);
+ target.appendJavaScript("gitplex.sourceview.onShowComment();");
}
private List<Symbol> getChildSymbols(@Nullable Symbol parentSymbol) {
@@ -357,49 +594,86 @@ public class SourceViewPanel extends BlobViewPanel {
Blob blob = context.getDepot().getBlob(context.getBlobIdent());
- String blameCommitsJson;
+ String jsonOfBlameInfos;
if (context.getMode() == Mode.BLAME) {
- List<BlameCommit> commits = new ArrayList<>();
+ List<BlameInfo> blameInfos = new ArrayList<>();
- String commitHash = context.getDepot().getObjectId(context.getBlobIdent().revision).name();
+ String commitHash = context.getCommit().name();
for (Blame blame: context.getDepot().git().blame(commitHash, context.getBlobIdent().path).values()) {
- BlameCommit commit = new BlameCommit();
- commit.commitDate = DateUtils.formatDate(blame.getCommit().getCommitter().getWhen());
- commit.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());
- commit.hash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);
- commit.message = blame.getCommit().getSubject();
+ BlameInfo blameInfo = new BlameInfo();
+ blameInfo.commitDate = DateUtils.formatDate(blame.getCommit().getCommitter().getWhen());
+ blameInfo.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());
+ blameInfo.hash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);
+ blameInfo.message = blame.getCommit().getSubject();
CommitDetailPage.HistoryState state = new CommitDetailPage.HistoryState();
state.pathFilter = context.getBlobIdent().path;
PageParameters params = CommitDetailPage.paramsOf(context.getDepot(),
blame.getCommit().getHash(), state);
- commit.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();
- commit.ranges = blame.getRanges();
- commits.add(commit);
+ blameInfo.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();
+ blameInfo.ranges = blame.getRanges();
+ blameInfos.add(blameInfo);
}
try {
- blameCommitsJson = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commits);
+ jsonOfBlameInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(blameInfos);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
} else {
- blameCommitsJson = "undefined";
+ jsonOfBlameInfos = "undefined";
}
- String script = String.format("gitplex.sourceview.init('%s', '%s', '%s', %s, '%s', '%s', %s, %s);",
- getMarkupId(),
+ Map<Integer, List<CommentInfo>> commentInfos = new HashMap<>();
+ for (CodeComment comment: commentsModel.getObject()) {
+ if (comment.getMark() != null) {
+ int line = comment.getMark().getBeginLine();
+ List<CommentInfo> commentInfosAtLine = commentInfos.get(line);
+ if (commentInfosAtLine == null) {
+ commentInfosAtLine = new ArrayList<>();
+ commentInfos.put(line, commentInfosAtLine);
+ }
+ CommentInfo commentInfo = new CommentInfo();
+ commentInfo.id = comment.getId();
+ commentInfo.mark = comment.getMark();
+ commentInfosAtLine.add(commentInfo);
+ }
+ }
+ for (List<CommentInfo> value: commentInfos.values()) {
+ value.sort((o1, o2)->(int)(o1.id-o2.id));
+ }
+
+ String jsonOfCommentInfos;
+ try {
+ jsonOfCommentInfos = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commentInfos);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ CharSequence commentCallback = commentBehavior.getCallbackFunction(
+ explicit("action"), explicit("param1"), explicit("param2"),
+ explicit("param3"), explicit("param4"), explicit("param5"));
+ String script = String.format("gitplex.sourceview.init('%s', '%s', %s, '%s', '%s', "
+ + "%s, %s, %s, %s, %s);",
JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),
JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),
context.getMark()!=null?context.getMark().toJSON():"undefined",
symbolTooltip.getMarkupId(),
- context.getBlobIdent().revision,
- blameCommitsJson,
- viewState!=null?"JSON.parse('"+viewState+"')":"undefined");
+ context.getCommit().name(),
+ jsonOfBlameInfos,
+ jsonOfCommentInfos,
+ commentCallback,
+ viewState!=null?"JSON.parse('"+viewState+"')":"undefined",
+ SecurityUtils.getAccount()!=null);
response.render(OnDomReadyHeaderItem.forScript(script));
}
+ @Override
+ protected void onDetach() {
+ commentsModel.detach();
+ super.onDetach();
+ }
+
@SuppressWarnings("unused")
- private static class BlameCommit {
+ private static class BlameInfo {
String hash;
@@ -414,4 +688,11 @@ public class SourceViewPanel extends BlobViewPanel {
List<Range> ranges;
}
+ @SuppressWarnings("unused")
+ private static class CommentInfo {
+ long id;
+
+ Mark mark;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css
index 64b68be111..4ce5dbb5d1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css
@@ -8,6 +8,10 @@
top: 0;
left: 0;
}
+.source-view>.comment>.content>.head .locate {
+ margin-right: 8px;
+ font-size: 20px;
+}
.source-view>.comment>.ui-resizable-handle {
position: absolute;
border-right: 1px solid #CCC;
@@ -17,6 +21,17 @@
right: 0;
top: 0;
}
+.source-view>.comment>.content>.head {
+ font-size: 16px;
+ padding: 4px 8px;
+ border-bottom: 1px dotted #BBB;
+}
+.source-view>.comment>.content>.body {
+ font-size: 13px;
+ padding: 12px;
+ overflow: auto;
+}
+
.source-view>.outline {
background: white;
position: absolute;
@@ -36,24 +51,44 @@
.source-view>.outline .tree-node {
line-height: 1.8;
}
-.source-view>.comment>.content>.head, .source-view>.outline>.content>.head {
+.source-view>.outline>.content>.head {
font-size: 16px;
padding: 4px 8px;
border-bottom: 1px dotted #BBB;
}
-.source-view>.comment>.content>.body, .source-view>.outline>.content>.body {
+.source-view>.outline>.content>.body {
font-size: 13px;
padding: 4px;
overflow: auto;
}
-.source-view>.comment>.content>.head a, .source-view>.outline>.content>.head a {
- color: #666;
-}
+.CodeMirror-comments {
+ width: 20px;
+}
+.CodeMirror-comment {
+ padding-left: 4px;
+}
+.CodeMirror-comment a {
+ color: #999;
+}
+.CodeMirror-comment a:hover {
+ color: #333;
+}
+.comment-popover a {
+ display: block;
+ color: #999;
+ text-decoration: none;
+}
+.comment-popover a:hover {
+ color: #333;
+}
+.comment-trigger.active {
+ font-size: 16px;
+ color: #333;
+}
.CodeMirror-annotations {
width: 240px;
}
-
.CodeMirror-annotation {
font-family: monospace;
text-overflow: ellipsis;
@@ -67,7 +102,6 @@
.CodeMirror-annotation .same-as-above {
margin-left: 100px;
color: #666;
- font-size: 16px;
}
.CodeMirror-activeline .CodeMirror-annotation {
background: #E8F2FE;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
index 2386d9dd8e..16c0868f2c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
@@ -1,11 +1,31 @@
gitplex.sourceview = {
- init: function(containerId, fileContent, filePath, mark, symbolTooltipId, revision, blameCommits, viewState) {
+ init: function(fileContent, filePath, mark, symbolTooltipId,
+ commitHash, blameInfos, commentInfos, commentCallback, viewState, loggedIn) {
var cm;
- var $sourceView = $("#" + containerId + " .source-view");
+ var $sourceView = $(".source-view");
+ $sourceView.data("commentCallback", commentCallback);
+
var $code = $sourceView.children(".code");
$sourceView.closest(".content").css("overflow", "hidden");
+ function alignCommentPopovers() {
+ $(".comment-popover:visible").each(function() {
+ var $popover = $(this);
+ var lineInfo = cm.lineInfo($popover.data("line"));
+ if (lineInfo.gutterMarkers) {
+ var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
+ if (gutter) {
+ var $commentLink = $(gutter).children("a");
+ $popover.css({
+ "left": $commentLink.offset().left + $commentLink.outerWidth() - $sourceView.offset().left,
+ "top": $commentLink.offset().top + ($commentLink.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top
+ });
+ }
+ }
+ });
+ }
+
$sourceView.on("autofit", function(event, width, height) {
event.stopPropagation();
$sourceView.outerWidth(width);
@@ -71,19 +91,24 @@ gitplex.sourceview = {
};
cm = CodeMirror($code[0], options);
-
pmease.commons.codemirror.setMode(cm, filePath);
- if (mark)
- pmease.commons.codemirror.mark(cm, mark, true);
-
- if (blameCommits) {
- // render blame blocks with a timer to avoid the issue that occasionally
- // blame gutter becomes much wider than expected
- setTimeout(function() {
- gitplex.sourceview.blame(cm, blameCommits);
- }, 10);
- }
+ // add gutters with a timer to avoid the issue that occasionally
+ // gutter becomes much wider than expected
+ setTimeout(function() {
+ if (blameInfos) {
+ gitplex.sourceview.blame(blameInfos);
+ }
+ var gutters = cm.getOption("gutters").slice();
+ gutters.splice(0, 0, "CodeMirror-comments");
+ cm.setOption("gutters", gutters);
+ for (var line in commentInfos) {
+ if (commentInfos.hasOwnProperty(line)) {
+ gitplex.sourceview.addCommentGutter(line, commentInfos[line][1]);
+ }
+ }
+ gitplex.sourceview.highlightCommentTrigger();
+ }, 10);
function onSelectText() {
var from = cm.getCursor("from");
@@ -91,7 +116,7 @@ gitplex.sourceview = {
if (from.line != to.line || from.ch != to.ch) {
var ch = (from.ch + to.ch)/2;
var position = cm.charCoords({line:from.line, ch:ch});
- var permanentCallback = function($permanentLink) {
+ var permanentLinkCallback = function($permanentLink) {
$permanentLink.off("click");
var uri = new URI(window.location.href);
uri.removeSearch("mark").addSearch("mark",
@@ -101,6 +126,7 @@ gitplex.sourceview = {
e.preventDefault();
$("#selection-popup").hide();
pmease.commons.history.pushState(uri.toString());
+ pmease.commons.codemirror.clearSelection(cm);
pmease.commons.codemirror.mark(cm, {
beginLine: from.line,
beginChar: from.ch,
@@ -109,15 +135,34 @@ gitplex.sourceview = {
}, false);
});
};
- var commentCallback = function($commentLink) {
-
+ var commentLinkCallback = function($commentLink) {
+ $commentLink.off("click");
+ if (loggedIn) {
+ $commentLink.click(function() {
+ if ($sourceView.find("form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ $("#selection-popup").hide();
+ pmease.commons.codemirror.clearSelection(cm);
+ pmease.commons.codemirror.mark(cm, {
+ beginLine: from.line,
+ beginChar: from.ch,
+ endLine: to.line,
+ endChar: to.ch
+ }, false);
+ commentCallback("add", commitHash, from.line, from.ch, to.line, to.ch);
+ });
+ } else {
+ $commentLink.html("Log in to comment on selection");
+ }
};
- $("#selection-popup").data("show")(position, permanentCallback, commentCallback, $code[0]);
+ $("#selection-popup").data("show")(
+ position, permanentLinkCallback, commentLinkCallback, $code[0]);
} else {
$("#selection-popup").hide();
}
}
-
$code.on("mouseup", function() {
onSelectText();
});
@@ -131,19 +176,27 @@ gitplex.sourceview = {
var node = e.target || e.srcElement, $node = $(node);
if ($node.hasClass("cm-property") || $node.hasClass("cm-variable") || $node.hasClass("cm-variable-2")
|| $node.hasClass("cm-variable-3") || $node.hasClass("cm-def") || $node.hasClass("cm-meta")) {
- document.getElementById(symbolTooltipId).onMouseOverSymbol(revision, node);
+ document.getElementById(symbolTooltipId).onMouseOverSymbol(commitHash, node);
}
});
- }
- if (cm.getOption("fullScreen"))
- cm.setOption("fullScreen", false);
- cm.setSize($code.width(), $code.height());
- if (initState)
- pmease.commons.codemirror.initState(cm, viewState);
+ cm.setSize($code.width(), $code.height());
+ if (mark)
+ pmease.commons.codemirror.mark(cm, mark, true);
+ if (initState)
+ pmease.commons.codemirror.initState(cm, viewState);
+ cm.on("scroll", function() {
+ alignCommentPopovers(cm);
+ });
+ } else {
+ cm.setSize($code.width(), $code.height());
+ if (cm.getOption("fullScreen"))
+ cm.setOption("fullScreen", false);
+ alignCommentPopovers(cm);
+ }
});
},
- initComment: function(containerId) {
- var $sourceView = $("#" + containerId + " .source-view");
+ initComment: function() {
+ var $sourceView = $(".source-view");
var $code = $sourceView.children(".code");
var commentWidthCookieKey = "sourceView.comment.width";
var $comment = $sourceView.children(".comment");
@@ -167,8 +220,8 @@ gitplex.sourceview = {
}
});
},
- initOutline: function(containerId) {
- var $sourceView = $("#" + containerId + " .source-view");
+ initOutline: function() {
+ var $sourceView = $(".source-view");
var $code = $sourceView.children(".code");
var outlineWidthCookieKey = "sourceView.outline.width";
var $outline = $sourceView.children(".outline");
@@ -192,35 +245,204 @@ gitplex.sourceview = {
}
});
},
- mark: function(containerId, mark, scroll) {
- var cm = $("#"+ containerId + " .CodeMirror")[0].CodeMirror;
+ addCommentGutter: function(line, commentInfos) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var commentCallback = $(".source-view").data("commentCallback");
+ function restoreMark() {
+ var uri = new URI(window.location.href);
+ var markStr = uri.search(true).mark;
+ if (markStr) {
+ var splitted = markStr.split("-");
+ var fromInfo = splitted[0].split(".");
+ var toInfo = splitted[1].split(".");
+ var mark = {
+ beginLine: parseInt(fromInfo[0])-1,
+ beginChar: parseInt(fromInfo[1]),
+ endLine: parseInt(toInfo[0])-1,
+ endChar: parseInt(toInfo[1])
+ }
+ pmease.commons.codemirror.mark(cm, mark, false);
+ } else {
+ pmease.commons.codemirror.clearMark(cm);
+ }
+ }
+
+ var $gutter = $(document.createElement("div"));
+ $gutter.addClass("CodeMirror-comment");
+ $gutter.data("commentInfos", commentInfos);
+ if (commentInfos.length != 1) {
+ $gutter.append("<a><i class='fa fa-comments'></i></a>");
+ var $commentLink = $gutter.children("a");
+ var content = "";
+ for (var i in commentInfos) {
+ var commentInfo = commentInfos[i];
+ var index = parseInt(i) + 1;
+ content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + index + "</a>";
+ }
+ $commentLink.popover({
+ html: true,
+ container: ".source-view",
+ placement: "right auto",
+ template: "<div data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",
+ content: content
+ });
+ $commentLink.on('shown.bs.popover', function () {
+ $(".comment-popover[data-line='" + line + "'] a").each(function() {
+ $(this).mouseover(function() {
+ var commentInfo = commentInfos[$(this).index()];
+ pmease.commons.codemirror.mark(cm, commentInfo.mark, false);
+ });
+ $(this).mouseout(function() {
+ restoreMark();
+ });
+ $(this).click(function() {
+ if ($(".source-view form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ var commentInfo = commentInfos[$(this).index()];
+ commentCallback("show", commentInfo.id);
+ });
+ });
+ gitplex.sourceview.highlightCommentTrigger();
+ });
+ } else {
+ var commentInfo = commentInfos[0];
+ $gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");
+ var $commentLink = $gutter.children("a");
+ $commentLink.mouseover(function() {
+ pmease.commons.codemirror.mark(cm, commentInfo.mark, false);
+ });
+ $commentLink.mouseout(function() {
+ restoreMark();
+ });
+ $commentLink.click(function() {
+ if ($(".source-view form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ commentCallback("show", commentInfo.id);
+ });
+ }
+ cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);
+ },
+ onCommentAdded: function(line, commentInfo) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var commentCallback = $(".source-view").data("commentCallback");
+ var lineInfo = cm.lineInfo(line);
+ var gutter;
+ if (lineInfo.gutterMarkers)
+ gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
+ var commentInfos;
+ if (gutter) {
+ commentInfos = $(gutter).data("commentInfos");
+ } else {
+ commentInfos = [];
+ }
+ commentInfos.push(commentInfo);
+ gitplex.sourceview.addCommentGutter(line, commentInfos);
+ gitplex.sourceview.highlightCommentTrigger();
+ },
+ onCommentDeleted: function(line, commentId) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var commentCallback = $(".source-view").data("commentCallback");
+ var lineInfo = cm.lineInfo(line);
+ var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);
+ var commentInfos = $gutter.data("commentInfos");
+ if (commentInfos.length == 1) {
+ cm.setGutterMarker(line, "CodeMirror-comments", null);
+ } else {
+ for (var i in commentInfos) {
+ var commentInfo = commentInfos[i];
+ if (commentInfo.id == commentId) {
+ commentInfos.splice(i, 1);
+ break;
+ }
+ }
+ gitplex.sourceview.addCommentGutter(line, commentInfos);
+ $(".comment-popover[data-line='" + line + "']").remove();
+ }
+ gitplex.sourceview.highlightCommentTrigger();
+ },
+ onLayoutChange: function() {
+ $sourceView = $('.source-view');
+ $sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);
+ },
+ onAddingComment: function() {
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+ },
+ onShowComment: function(commentInfo) {
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+ if (commentInfo)
+ gitplex.sourceview.mark(commentInfo.mark, false);
+ },
+ onToggleOutline: function() {
+ gitplex.sourceview.onLayoutChange();
+ },
+ highlightCommentTrigger: function() {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ $(".comment-popover a").removeClass("active");
+ for (var i=0; i<cm.lineCount(); i++) {
+ var gutterMarkers = cm.lineInfo(i).gutterMarkers;
+ if (gutterMarkers) {
+ var gutter = gutterMarkers["CodeMirror-comments"];
+ if (gutter) {
+ $(gutter).children("a").removeClass("active");
+ }
+ }
+ }
+ var $comment = $(".source-view>.comment>.content>.body");
+ if ($comment.length != 0) {
+ var line = parseInt($comment.data("line"));
+ var lineInfo = cm.lineInfo(line);
+ if (lineInfo && lineInfo.gutterMarkers) {
+ var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
+ if (gutter) {
+ var commentInfos = $(gutter).data("commentInfos");
+ if (commentInfos.length == 1) {
+ $(gutter).children("a").addClass("active");
+ } else {
+ var commentId = $comment.data("comment");
+ $(".comment-popover[data-line='" + line + "'] a").each(function() {
+ var commentInfo = commentInfos[$(this).index()];
+ if (commentInfo.id == commentId) {
+ $(this).addClass("active");
+ }
+ });
+ }
+ }
+ }
+ }
+ },
+ mark: function(mark, scroll) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
pmease.commons.codemirror.mark(cm, mark, scroll);
},
-
- blame: function(cm, blameCommits) {
- if (typeof cm === "string")
- cm = $("#"+ cm + ">.CodeMirror")[0].CodeMirror;
+ blame: function(blameInfos) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- if (blameCommits) {
+ if (blameInfos) {
var gutters = cm.getOption("gutters").slice();
gutters.splice(0, 0, "CodeMirror-annotations");
cm.setOption("gutters", gutters);
- for (var i in blameCommits) {
- var commit = blameCommits[i];
- for (var j in commit.ranges) {
- var range = commit.ranges[j];
- var $ele = $(document.createElement("div"));
- $ele.addClass("CodeMirror-annotation");
- $("<a class='hash'>" + commit.hash + "</a>").appendTo($ele).attr("href", commit.url).attr("title", commit.message);
- $ele.append("<span class='date'>" + commit.commitDate + "</span>");
- $ele.append("<span class='author'>" + commit.authorName + "</span>");
- cm.setGutterMarker(range.from, "CodeMirror-annotations", $ele[0]);
+ for (var i in blameInfos) {
+ var blameInfo = blameInfos[i];
+ for (var j in blameInfo.ranges) {
+ var range = blameInfo.ranges[j];
+ var $gutter = $(document.createElement("div"));
+ $gutter.addClass("CodeMirror-annotation");
+ $("<a class='hash'>" + blameInfo.hash + "</a>").appendTo($gutter).attr("href", blameInfo.url).attr("title", blameInfo.message);
+ $gutter.append("<span class='date'>" + blameInfo.commitDate + "</span>");
+ $gutter.append("<span class='author'>" + blameInfo.authorName + "</span>");
+ cm.setGutterMarker(range.from, "CodeMirror-annotations", $gutter[0]);
for (var line = range.from+1; line<range.to; line++) {
- var $ele = $(document.createElement("div"));
- $ele.addClass("CodeMirror-annotation");
- $ele.append("<span class='same-as-above'>...</span>");
- cm.setGutterMarker(line, "CodeMirror-annotations", $ele[0]);
+ var $gutter = $(document.createElement("div"));
+ $gutter.addClass("CodeMirror-annotation");
+ $gutter.append("<span class='same-as-above'>...</span>");
+ cm.setGutterMarker(line, "CodeMirror-annotations", $gutter[0]);
}
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java
index 16ea775111..30dfe16517 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java
@@ -38,10 +38,10 @@ import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;
import com.pmease.commons.wicket.assets.diffmatchpatch.DiffMatchPatchResourceReference;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
import com.pmease.gitplex.web.component.depotfile.editsave.EditSavePanel;
import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;
import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;
-import com.pmease.gitplex.web.page.depot.file.Mark;
@SuppressWarnings("serial")
public abstract class FileEditPanel extends Panel {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
index c1cb3cf334..58e6ada77f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java
@@ -41,7 +41,6 @@ import com.pmease.commons.lang.tokenizers.CmToken;
import com.pmease.commons.util.StringUtils;
import com.pmease.commons.wicket.CommonPage;
import com.pmease.commons.wicket.assets.uri.URIResourceReference;
-import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.search.hit.QueryHit;
@@ -171,7 +170,7 @@ public class TextDiffPanel extends Panel {
int index = params.getParameterValue("param1").toInt();
Integer lastContextSize = contextSizes.get(index);
if (lastContextSize == null)
- lastContextSize = CodeComment.DIFF_CONTEXT_SIZE;
+ lastContextSize = Constants.DIFF_CONTEXT_SIZE;
int contextSize = lastContextSize + Constants.DIFF_EXPAND_SIZE;
contextSizes.put(index, contextSize);
@@ -283,7 +282,7 @@ public class TextDiffPanel extends Panel {
}
private String renderDiffs() {
- int contextSize = CodeComment.DIFF_CONTEXT_SIZE;
+ int contextSize = Constants.DIFF_CONTEXT_SIZE;
StringBuilder builder = new StringBuilder();
if (diffMode == DiffViewMode.UNIFIED) {
builder.append(""
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
index bdcc064e87..ad15e7afcb 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
@@ -106,15 +106,15 @@
background-color: #94F094;
}
.text-diff>.body>tbody>tr>td.old.new.number {
- background: #FFFFDD;
- border-left: 1px solid #F3E391;
+ background: #FAF3D0;
+ border-left: 1px solid #EBD049;
}
.text-diff>.body>tbody>tr>td.old.new.content {
- background: #FFFFEE;
+ background: #FCF8E4;
}
.text-diff>.body>tbody>tr>td.old.new.operation {
- border-left: 1px solid #F3E391;
- background: #FFFFEE;
+ border-left: 1px solid #EBD049;
+ background: #FCF8E4;
}
.text-diff>.body>tbody>tr>td.content {
white-space: pre-wrap;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
index 65997050b2..1d72b84bde 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
@@ -70,6 +70,12 @@ import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;
import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
import com.pmease.gitplex.web.util.SuggestionUtils;
+/**
+ * Make sure to add only one revision diff panel on a page
+ *
+ * @author robin
+ *
+ */
@SuppressWarnings("serial")
public abstract class RevisionDiffPanel extends Panel {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java
index 4ad3e74ea5..f42e2e2a59 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/symboltooltip/SymbolTooltipPanel.java
@@ -38,6 +38,7 @@ import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
import com.pmease.gitplex.search.SearchManager;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.query.BlobQuery;
@@ -46,7 +47,6 @@ import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.web.component.depotfile.blobsearch.result.SearchResultPanel;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
-import com.pmease.gitplex.web.page.depot.file.Mark;
@SuppressWarnings("serial")
public abstract class SymbolTooltipPanel extends Panel {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/mapper/UrlMapper.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/mapper/UrlMapper.java
index f957c7ec48..8c5f9c22c4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/mapper/UrlMapper.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/mapper/UrlMapper.java
@@ -39,7 +39,6 @@ import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import com.pmease.gitplex.web.page.depot.overview.DepotOverviewPage;
import com.pmease.gitplex.web.page.depot.pullrequest.newrequest.NewRequestPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.attachments.RequestAttachmentsPage;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.compare.RequestComparePage;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.updates.RequestUpdatesPage;
@@ -175,8 +174,6 @@ public class UrlMapper extends CompoundRequestMapper {
"${account}/${depot}/pulls/${request}/updates", RequestUpdatesPage.class));
add(new DepotMapper(
"${account}/${depot}/pulls/${request}/compare", RequestComparePage.class));
- add(new DepotMapper(
- "${account}/${depot}/pulls/${request}/attachments", RequestAttachmentsPage.class));
add(new DepotMapper("${account}/${depot}/settings/general", GeneralSettingPage.class));
add(new DepotMapper("${account}/${depot}/settings/teams", DepotTeamListPage.class));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.html
index 6398f48761..02e2078553 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.html
@@ -7,6 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" wicket:id="favicon" type="image/x-icon"/>
<link rel="apple-touch-icon" wicket:id="appleTouchIcon"/>
+ <link rel="apple-touch-icon-precomposed" wicket:id="appleTouchIconPrecomposed"/>
</wicket:head>
<wicket:extend>
<wicket:child></wicket:child>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.java
index 5a194ad71b..25b9e76097 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/BasePage.java
@@ -105,6 +105,18 @@ public abstract class BasePage extends CommonPage {
}
});
+ add(new WebMarkupContainer("appleTouchIconPrecomposed") {
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+ CharSequence url = urlFor(
+ new PackageResourceReference(BasePage.class, "apple-touch-icon.png"),
+ new PageParameters());
+ tag.put("href", url);
+ }
+
+ });
}
protected final String getPageTitle() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.html
index c4d2b3913e..8c92b6e621 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/ContributionPanel.html
@@ -1,19 +1,19 @@
-<wicket:panel>
- <div class="contribution clearfix">
- <div class="pull-left avatar">
- <a wicket:id="avatar"></a>
- </div>
- <div wicket:id="contributor" class="pull-left contributor"></div>
- <div class="pull-left message"><a wicket:id="messageLink"><span wicket:id="message"></span></a></div>
- <div class="contributors pull-left">
- <a wicket:id="contributors" title="Contributors" class="btn btn-default btn-xs"><i class="fa fa-group"></i> <i class="fa fa-caret-down"></i></a>
- </div>
- </div>
- <wicket:fragment wicket:id="contributorsFrag">
- <ul class="contributors list-unstyled">
- <li wicket:id="contributors">
- <a wicket:id="link"><img wicket:id="avatar"></img> <span wicket:id="name"></span></a>
- </li>
- </ul>
- </wicket:fragment>
+<wicket:panel>
+ <div class="contribution clearfix">
+ <div class="pull-left avatar">
+ <a wicket:id="avatar"></a>
+ </div>
+ <div wicket:id="contributor" class="pull-left contributor"></div>
+ <div class="pull-left message"><a wicket:id="messageLink"><span wicket:id="message"></span></a></div>
+ <div class="contributors pull-left">
+ <a wicket:id="contributors" title="Contributors"><i class="fa fa-group"></i> <i class="fa fa-caret-down"></i></a>
+ </div>
+ </div>
+ <wicket:fragment wicket:id="contributorsFrag">
+ <ul class="contributors list-unstyled">
+ <li wicket:id="contributors">
+ <a wicket:id="link"><img wicket:id="avatar"></img> <span wicket:id="name"></span></a>
+ </li>
+ </ul>
+ </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
index 68f08d6d5f..b9ae4d9d7d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
@@ -57,9 +57,12 @@ import com.pmease.commons.wicket.component.modal.ModalLink;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior;
import com.pmease.commons.wicket.websocket.WebSocketTrait;
import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.component.Mark;
import com.pmease.gitplex.core.listener.RefListener;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.search.IndexListener;
import com.pmease.gitplex.search.IndexManager;
@@ -142,6 +145,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
private Mode mode;
+ private Long commentId;
+
private Component revisionIndexing;
private WebMarkupContainer searchResultContainer;
@@ -201,6 +206,10 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
if (markStr != null)
mark = new Mark(markStr);
+ String commentIdStr = params.get(PARAM_COMMENT).toString();
+ if (commentIdStr != null)
+ commentId = Long.valueOf(commentIdStr);
+
queryHits = WebSession.get().getMetaData(SEARCH_RESULT_KEY);
if (queryHits != null) {
WebSession.get().setMetaData(SEARCH_RESULT_KEY, null);
@@ -370,6 +379,14 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
return requestModel.getObject();
}
+ @Override
+ public CodeComment getComment() {
+ if (commentId != null)
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ else
+ return null;
+ }
+
private void newFileNavigator(@Nullable AjaxRequestTarget target) {
final BlobNameChangeCallback callback;
@@ -591,6 +608,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
state.mark = mark;
state.mode = mode;
state.requestId = requestId;
+ state.commentId = commentId;
return state;
}
@@ -598,6 +616,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
blobIdent = new BlobIdent(state.blobIdent);
mark = state.mark;
mode = state.mode;
+ commentId = state.commentId;
requestId = state.requestId;
}
@@ -804,6 +823,12 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
return mark;
}
+ @Override
+ public void onMark(AjaxRequestTarget target, Mark mark) {
+ this.mark = mark;
+ pushState(target);
+ }
+
@Override
public Mode getMode() {
return mode;
@@ -819,7 +844,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
Component fileViewer = get(FILE_VIEWER_ID);
if (fileViewer instanceof SourceViewPanel) {
SourceViewPanel sourceViewer = (SourceViewPanel) fileViewer;
- sourceViewer.mark(target, mark);
+ sourceViewer.mark(target, mark, true);
} else if (fileViewer instanceof FileEditPanel) {
FileEditPanel fileEditor = (FileEditPanel) fileViewer;
fileEditor.mark(target, mark);
@@ -831,6 +856,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
} else {
this.blobIdent = blobIdent;
mode = null;
+ commentId = null;
newFileNavigator(target);
newContributionPanel(target);
@@ -849,10 +875,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
@Override
public void onBlameChange(AjaxRequestTarget target, @Nullable String viewState) {
- if (mode == null)
- mode = Mode.BLAME;
- else
- mode = null;
+ mode = (mode==null?Mode.BLAME:null);
newFileViewer(target, viewState);
pushState(target);
resizeWindow(target);
@@ -878,11 +901,27 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
resizeWindow(target);
}
+ @Override
+ public void onShowComment(AjaxRequestTarget target, CodeComment comment) {
+ if (comment != null) {
+ commentId = comment.getId();
+ mark = comment.getMark();
+ } else {
+ commentId = null;
+ }
+ pushState(target);
+ }
+
@Override
public boolean isOnBranch() {
return getDepot().getRefs(Constants.R_HEADS).containsKey(blobIdent.revision);
}
+ @Override
+ public RevCommit getCommit() {
+ return getDepot().getRevCommit(getBlobIdent().revision);
+ }
+
@Override
public boolean isAtSourceBranchHead() {
PullRequest request = getPullRequest();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.css
index 602d9212b7..2e3ffc9c12 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.css
@@ -95,6 +95,11 @@
font-weight: bold;
color: #555;
}
+#repo-file>.contribution .contributors a {
+ color: #666;
+ text-decoration: none;
+}
+
#repo-file>.revision-indexing {
padding: 8px 8px 9px 8px;
background: #fcf8e3;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
index 666d0aad75..307c3fd706 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
@@ -38,6 +38,7 @@ import com.pmease.commons.git.Git;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.lang.diff.WhitespaceOption;
import com.pmease.commons.util.FileUtils;
+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
import com.pmease.commons.wicket.component.backtotop.BackToTop;
import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
import com.pmease.commons.wicket.component.tabbable.Tab;
@@ -57,6 +58,7 @@ import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.security.ObjectPermission;
import com.pmease.gitplex.web.component.BranchLink;
import com.pmease.gitplex.web.component.branchpicker.AffinalBranchPicker;
+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.commitlist.CommitListPanel;
import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
@@ -478,7 +480,7 @@ public class NewRequestPage extends PullRequestPage {
}));
- form.add(new CommentInput("comment", requestModel, new IModel<String>() {
+ form.add(new CommentInput("comment", new IModel<String>() {
@Override
public void detach() {
@@ -494,7 +496,14 @@ public class NewRequestPage extends PullRequestPage {
getPullRequest().setDescription(object);
}
- }));
+ }) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(getDepot());
+ }
+
+ });
WebMarkupContainer assigneeContainer = new WebMarkupContainer("assignee");
form.add(assigneeContainer);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java
index 78b76beb0d..d0dfa7dff6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java
@@ -1,956 +1,970 @@
-package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail;
-
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.APPROVE;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DELETE_SOURCE_BRANCH;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DISAPPROVE;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DISCARD;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.INTEGRATE;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.REOPEN;
-import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.RESTORE_SOURCE_BRANCH;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.text.WordUtils;
-import org.apache.wicket.AttributeModifier;
-import org.apache.wicket.Component;
-import org.apache.wicket.Page;
-import org.apache.wicket.RestartResponseException;
-import org.apache.wicket.Session;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-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.event.IEvent;
-import org.apache.wicket.markup.ComponentTag;
-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.FormComponent;
-import org.apache.wicket.markup.html.form.TextArea;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
-import org.apache.wicket.markup.html.link.Link;
-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.model.AbstractReadOnlyModel;
-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 com.google.common.base.Preconditions;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.loader.InheritableThreadLocalData;
-import com.pmease.commons.wicket.component.DropdownLink;
-import com.pmease.commons.wicket.component.backtotop.BackToTop;
-import com.pmease.commons.wicket.component.tabbable.PageTab;
-import com.pmease.commons.wicket.component.tabbable.PageTabLink;
-import com.pmease.commons.wicket.component.tabbable.Tab;
-import com.pmease.commons.wicket.component.tabbable.Tabbable;
-import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
-import com.pmease.gitplex.core.entity.PullRequest.Status;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.entity.Verification;
-import com.pmease.gitplex.core.entity.component.DepotAndBranch;
-import com.pmease.gitplex.core.entity.component.IntegrationPreview;
-import com.pmease.gitplex.core.security.SecurityUtils;
-import com.pmease.gitplex.web.component.AccountLink;
-import com.pmease.gitplex.web.component.BranchLink;
-import com.pmease.gitplex.web.component.comment.CommentInput;
-import com.pmease.gitplex.web.component.pullrequest.verificationstatus.VerificationStatusPanel;
-import com.pmease.gitplex.web.model.EntityModel;
-import com.pmease.gitplex.web.page.depot.DepotPage;
-import com.pmease.gitplex.web.page.depot.NoCommitsPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.attachments.RequestAttachmentsPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.compare.RequestComparePage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.updates.RequestUpdatesPage;
-import com.pmease.gitplex.web.util.DateUtils;
-import com.pmease.gitplex.web.websocket.PullRequestChangeRenderer;
-import com.pmease.gitplex.web.websocket.PullRequestChanged;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-public abstract class RequestDetailPage extends PullRequestPage {
-
- protected IModel<PullRequest> requestModel;
-
- private boolean editingTitle;
-
- public RequestDetailPage(final PageParameters params) {
- super(params);
-
- if (!getDepot().git().hasRefs())
- throw new RestartResponseException(NoCommitsPage.class, paramsOf(getDepot()));
-
- requestModel = new LoadableDetachableModel<PullRequest>() {
-
- @Override
- protected PullRequest load() {
- return GitPlex.getInstance(Dao.class).load(PullRequest.class, params.get("request").toLong());
- }
-
- };
-
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- PullRequest request = getPullRequest();
-
- final WebMarkupContainer requestTitle = new WebMarkupContainer("requestHead");
- requestTitle.setOutputMarkupId(true);
- add(requestTitle);
-
- requestTitle.add(new Label("title", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return getPullRequest().getTitle();
- }
-
- }) {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(!editingTitle);
- }
-
- });
-
- requestTitle.add(new Label("id", "#" + request.getId()) {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(!editingTitle);
- }
-
- });
-
- requestTitle.add(new AjaxLink<Void>("editLink") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- editingTitle = true;
-
- target.add(requestTitle);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(!editingTitle && SecurityUtils.canModify(getPullRequest()));
- }
-
- });
-
- Form<?> form = new Form<Void>("editForm") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(editingTitle);
- }
-
- };
- requestTitle.add(form);
-
- form.add(new TextField<String>("title", new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- if (StringUtils.isNotBlank(getPullRequest().getTitle()))
- return getPullRequest().getTitle();
- else
- return "";
- }
-
- @Override
- public void setObject(String object) {
- getPullRequest().setTitle(object);
- }
-
- }));
-
- form.add(new AjaxButton("save") {
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- super.onSubmit(target, form);
-
- if (StringUtils.isNotBlank(getPullRequest().getTitle())) {
- GitPlex.getInstance(Dao.class).persist(getPullRequest());
- editingTitle = false;
- }
-
- target.add(requestTitle);
- }
-
- });
-
- form.add(new AjaxLink<Void>("cancel") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- editingTitle = false;
-
- target.add(requestTitle);
- }
-
- });
-
- add(newStatusAndBranchesContainer());
-
- WebMarkupContainer summaryContainer = new WebMarkupContainer("requestSummary") {
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- pullRequestChanged.getPartialPageRequestHandler().add(this);
- }
- }
-
- };
- summaryContainer.setOutputMarkupPlaceholderTag(true);
- add(summaryContainer);
-
- summaryContainer.add(newDiscardedNoteContainer());
- summaryContainer.add(newPendingUpdateNoteContainer());
- summaryContainer.add(newPendingApprovalNoteContainer());
- summaryContainer.add(newIntegratedNoteContainer());
- summaryContainer.add(newStatusReasonsContainer());
- summaryContainer.add(newIntegrationPreviewContainer());
- summaryContainer.add(newOperationsContainer());
-
- List<Tab> tabs = new ArrayList<>();
-
- tabs.add(new RequestTab("Overview", RequestOverviewPage.class));
- tabs.add(new RequestTab("Updates", RequestUpdatesPage.class));
- tabs.add(new RequestTab("Compare", RequestComparePage.class) {
-
- @Override
- public Component render(String componentId) {
- return new PageTabLink(componentId, this) {
-
- @Override
- protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {
- PageParameters params = RequestComparePage.paramsOf(getPullRequest(),
- RequestComparePage.REV_BASE, RequestComparePage.REV_LAST_UPDATE_PREFIX+"1");
- return new BookmarkablePageLink<Void>(linkId, pageClass, params);
- }
-
- };
- }
-
- });
- tabs.add(new RequestTab("Attachments", RequestAttachmentsPage.class));
-
- add(new Tabbable("requestTabs", tabs).setOutputMarkupId(true));
-
- add(new BackToTop("backToTop"));
-
- add(new PullRequestChangeRenderer() {
-
- @Override
- protected PullRequest getPullRequest() {
- return RequestDetailPage.this.getPullRequest();
- }
-
- });
- }
-
- private WebMarkupContainer newStatusAndBranchesContainer() {
- WebMarkupContainer statusAndBranchesContainer = new WebMarkupContainer("statusAndBranches");
-
- PullRequest request = getPullRequest();
-
- statusAndBranchesContainer.add(new Label("status", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return getPullRequest().getStatus().toString();
- }
-
- }) {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- setOutputMarkupId(true);
-
- add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- PullRequest.Status status = getPullRequest().getStatus();
- if (status == Status.DISCARDED)
- return " label-danger";
- else if (status == Status.INTEGRATED)
- return " label-success";
- else
- return " label-warning";
- }
-
- }));
- }
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- pullRequestChanged.getPartialPageRequestHandler().add(this);
- }
- }
-
- });
-
- if (request.getStatus() == Status.INTEGRATED) {
- statusAndBranchesContainer.add(new AccountLink("user", request.getCloseInfo().getClosedBy()));
-
- int commitCount = 0;
- for (PullRequestUpdate update: request.getUpdates())
- commitCount += update.getCommits().size();
-
- statusAndBranchesContainer.add(new Label("action", "integrated " + commitCount + " commits"));
- statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getCloseInfo().getCloseDate())));
- } else {
- statusAndBranchesContainer.add(new AccountLink("user", request.getSubmitter()));
- statusAndBranchesContainer.add(new Label("action", "wants to integrate"));
- statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getSubmitDate())));
- }
-
- statusAndBranchesContainer.add(new BranchLink("target", request.getTarget()));
- if (request.getSourceDepot() != null) {
- statusAndBranchesContainer.add(new BranchLink("source", request.getSource()));
- } else {
- statusAndBranchesContainer.add(new Label("source", "unknown") {
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- tag.setName("span");
- }
-
- });
- }
- return statusAndBranchesContainer;
- }
-
- private WebMarkupContainer newIntegrationPreviewContainer() {
- WebMarkupContainer integrationPreviewContainer = new WebMarkupContainer("integrationPreview") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().isOpen());
- }
-
- };
- integrationPreviewContainer.setOutputMarkupId(true);
-
- integrationPreviewContainer.add(new WebMarkupContainer("calculating") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getIntegrationPreview() == null);
- }
-
- });
- integrationPreviewContainer.add(new WebMarkupContainer("conflict") {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new DropdownLink("resolveInstructionsTrigger") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getSource() != null);
- }
-
- @Override
- protected Component newContent(String id) {
- return new ResolveConflictInstructionPanel(id, new EntityModel<PullRequest>(getPullRequest()));
- }
-
- });
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- IntegrationPreview preview = getPullRequest().getIntegrationPreview();
- setVisible(preview != null && preview.getIntegrated() == null);
- }
-
- });
- integrationPreviewContainer.add(new WebMarkupContainer("noConflict") {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- Link<Void> link = new Link<Void>("preview") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getIntegrationPreview();
- setVisible(!preview.getIntegrated().equals(preview.getRequestHead()));
- }
-
- @Override
- public void onClick() {
- PullRequest request = getPullRequest();
- PageParameters params = RequestComparePage.paramsOf(request,
- RequestComparePage.REV_TARGET_BRANCH, RequestComparePage.REV_INTEGRATION_PREVIEW);
- setResponsePage(RequestComparePage.class, params);
- }
-
- };
- add(link);
-
- add(new VerificationStatusPanel("verification", requestModel, new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getIntegrationPreview();
- if (preview != null)
- return preview.getIntegrated();
- else
- return null;
- }
-
- }) {
-
- @Override
- protected Component newStatusComponent(String id, final IModel<Verification.Status> statusModel) {
- return new Label(id, new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- if (statusModel.getObject() == Verification.Status.PASSED)
- return "successful <i class='caret'></i>";
- else if (statusModel.getObject() == Verification.Status.ONGOING)
- return "running <i class='caret'></i>";
- else if (statusModel.getObject() == Verification.Status.NOT_PASSED)
- return "failed <i class='caret'></i>";
- else
- return "";
- }
-
- }) {
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
-
- if (statusModel.getObject() == Verification.Status.PASSED)
- tag.put("class", "label label-success");
- else if (statusModel.getObject() == Verification.Status.ONGOING)
- tag.put("class", "label label-warning");
- else if (statusModel.getObject() == Verification.Status.NOT_PASSED)
- tag.put("class", "label label-danger");
- }
-
- @Override
- protected void onDetach() {
- statusModel.detach();
-
- super.onDetach();
- }
-
- }.setEscapeModelStrings(false);
- }
-
- });
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- IntegrationPreview preview = getPullRequest().getIntegrationPreview();
- setVisible(preview != null && preview.getIntegrated() != null);
- }
-
- });
-
- return integrationPreviewContainer;
- }
-
- private WebMarkupContainer newOperationsContainer() {
- final WebMarkupContainer operationsContainer = new WebMarkupContainer("operations") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- boolean hasVisibleChildren = false;
- for (int i=0; i<size(); i++) {
- @SuppressWarnings("deprecation")
- Component child = get(i);
- child.configure();
- if (child.isVisible()) {
- hasVisibleChildren = true;
- break;
- }
- }
-
- setVisible(hasVisibleChildren);
- }
-
- };
- operationsContainer.setOutputMarkupId(true);
-
- final String confirmId = "confirm";
-
- operationsContainer.add(new AjaxLink<Void>("approve") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, APPROVE, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(APPROVE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
-
- operationsContainer.add(new AjaxLink<Void>("disapprove") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, DISAPPROVE, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(DISAPPROVE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
-
- operationsContainer.add(new AjaxLink<Void>("integrate") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, INTEGRATE, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(INTEGRATE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
-
- operationsContainer.add(new AjaxLink<Void>("discard") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, DISCARD, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(DISCARD.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
- operationsContainer.add(new AjaxLink<Void>("reopen") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, REOPEN, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(REOPEN.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
- operationsContainer.add(new AjaxLink<Void>("deleteSourceBranch") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, DELETE_SOURCE_BRANCH, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(DELETE_SOURCE_BRANCH.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
- operationsContainer.add(new AjaxLink<Void>("restoreSourceBranch") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, RESTORE_SOURCE_BRANCH, operationsContainer));
- target.add(operationsContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(RESTORE_SOURCE_BRANCH.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
-
- operationsContainer.add(new WebMarkupContainer(confirmId).setVisible(false));
-
- return operationsContainer;
- }
-
- private Component newOperationConfirm(final String id, final PullRequestOperation operation,
- final WebMarkupContainer operationsContainer) {
- PullRequest request = getPullRequest();
-
- final Fragment fragment = new Fragment(id, "operationConfirmFrag", this);
- Form<?> form = new Form<Void>("form");
- fragment.add(form);
- final FormComponent<String> noteInput;
-
- DepotAndBranch source = request.getSource();
- Preconditions.checkNotNull(source);
-
- if (operation != INTEGRATE) {
- form.add(noteInput = new CommentInput("note", requestModel, Model.of("")));
- noteInput.add(AttributeModifier.replace("placeholder", "Leave a comment"));
- } else {
- IntegrationPreview preview = request.getIntegrationPreview();
- if (preview == null || preview.getIntegrated() == null) {
- Session.get().warn("Unable to integrate now as integration preview has to be recalculated");
- return new WebMarkupContainer(id).setVisible(false);
- }
- IntegrationStrategy strategy = preview.getIntegrationStrategy();
- if (strategy == REBASE_SOURCE_ONTO_TARGET
- || strategy == REBASE_TARGET_ONTO_SOURCE
- || preview.getIntegrated().equals(preview.getRequestHead())) {
- form.add(noteInput = new CommentInput("note", requestModel, Model.of("")));
- noteInput.add(AttributeModifier.replace("placeholder", "Leave a comment"));
- } else {
- form.add(noteInput = new TextArea<String>("note", Model.of("")));
- noteInput.add(AttributeModifier.replace("placeholder", "Commit message"));
- }
- }
- form.add(new NotificationPanel("feedback", form));
- form.add(new AjaxButton("submit") {
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- super.onSubmit(target, form);
-
- String actionName = operation.name().toLowerCase();
-
- InheritableThreadLocalData.set(new PageId(getPage().getPageId()));
- PullRequest request = getPullRequest();
- try {
- operation.operate(request, noteInput.getModelObject());
- setResponsePage(getPage().getClass(), paramsOf(getPullRequest()));
- } catch (Exception e) {
- error("Unable to " + actionName + ": " + e.getMessage());
- target.add(operationsContainer);
- } finally {
- InheritableThreadLocalData.clear();
- }
- }
-
- }.add(AttributeModifier.replace("value", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return "Confirm " + WordUtils.capitalizeFully(operation.name()).replace("_", " ").toLowerCase();
- }
-
- })).add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- if (operation == INTEGRATE)
- return "btn-success";
- else if (operation == DISCARD)
- return "btn-danger";
- else
- return "btn-primary";
- }
-
- })));
- form.add(new AjaxLink<Void>("cancel") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- fragment.replaceWith(new WebMarkupContainer(id).setVisible(false));
- target.add(operationsContainer);
- }
-
- });
-
- return fragment;
- }
-
- private WebMarkupContainer newDiscardedNoteContainer() {
- WebMarkupContainer discardedNoteContainer = new WebMarkupContainer("discardedNote") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.DISCARDED);
- }
-
- };
- return discardedNoteContainer;
- }
-
- private WebMarkupContainer newPendingUpdateNoteContainer() {
- WebMarkupContainer pendingUpdateNoteContainer = new WebMarkupContainer("pendingUpdateNote") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.PENDING_UPDATE);
- }
-
- };
- return pendingUpdateNoteContainer;
- }
-
- private WebMarkupContainer newPendingApprovalNoteContainer() {
- WebMarkupContainer pendingApprovalNoteContainer = new WebMarkupContainer("pendingApprovalNote") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.PENDING_APPROVAL);
- }
-
- };
- return pendingApprovalNoteContainer;
- }
-
- private WebMarkupContainer newIntegratedNoteContainer() {
- WebMarkupContainer integratedNoteContainer = new WebMarkupContainer("integratedNote") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.INTEGRATED);
- }
-
- };
- integratedNoteContainer.setOutputMarkupId(true);
-
- integratedNoteContainer.add(new WebMarkupContainer("fastForwarded") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null && preview.getRequestHead().equals(preview.getIntegrated()));
- }
-
- });
- integratedNoteContainer.add(new WebMarkupContainer("merged") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && (preview.getIntegrationStrategy() == MERGE_ALWAYS || preview.getIntegrationStrategy() == MERGE_IF_NECESSARY));
- }
-
- });
- integratedNoteContainer.add(new WebMarkupContainer("mergedOutside") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(getPullRequest().getLastIntegrationPreview() == null);
- }
-
- });
- integratedNoteContainer.add(new WebMarkupContainer("squashed") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == MERGE_WITH_SQUASH);
- }
-
- });
-
- integratedNoteContainer.add(new WebMarkupContainer("sourceRebased") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == REBASE_SOURCE_ONTO_TARGET);
- }
-
- });
-
- integratedNoteContainer.add(new WebMarkupContainer("targetRebased") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == REBASE_TARGET_ONTO_SOURCE);
- }
-
- });
-
- return integratedNoteContainer;
- }
-
- private WebMarkupContainer newStatusReasonsContainer() {
- WebMarkupContainer statusReasonsContainer = new WebMarkupContainer("statusReasons") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- PullRequest.Status status = getPullRequest().getStatus();
- setVisible(status == Status.PENDING_APPROVAL || status == Status.PENDING_UPDATE);
- }
-
- };
- statusReasonsContainer.setOutputMarkupId(true);
-
- statusReasonsContainer.add(new ListView<String>("reasons", new AbstractReadOnlyModel<List<String>>() {
-
- @Override
- public List<String> getObject() {
- return getPullRequest().getCheckResult().getReasons();
- }
-
- }) {
-
- @Override
- protected void populateItem(ListItem<String> item) {
- item.add(new Label("reason", item.getModelObject()));
- }
-
- });
-
- return statusReasonsContainer;
- }
-
- @Override
- protected void onDetach() {
- requestModel.detach();
- super.onDetach();
- }
-
- public static PageParameters paramsOf(PullRequest request) {
- PageParameters params = DepotPage.paramsOf(request.getTarget().getDepot());
- params.set("request", request.getId());
- return params;
- }
-
- private class RequestTab extends PageTab {
-
- public RequestTab(String title, Class<? extends Page> pageClass) {
- super(Model.of(title), pageClass);
- }
-
- @Override
- public Component render(String componentId) {
- return new PageTabLink(componentId, this) {
-
- @Override
- protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {
- return new BookmarkablePageLink<Void>(linkId, pageClass, paramsOf(getPullRequest()));
- }
-
- };
- }
-
- }
-
- public PullRequest getPullRequest() {
- return requestModel.getObject();
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
-
- response.render(CssHeaderItem.forReference(
- new CssResourceReference(RequestDetailPage.class, "request-detail.css")));
- }
-
+package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail;
+
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.APPROVE;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DELETE_SOURCE_BRANCH;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DISAPPROVE;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DISCARD;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.INTEGRATE;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.REOPEN;
+import static com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.PullRequestOperation.RESTORE_SOURCE_BRANCH;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.text.WordUtils;
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.RestartResponseException;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+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.event.IEvent;
+import org.apache.wicket.markup.ComponentTag;
+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.FormComponent;
+import org.apache.wicket.markup.html.form.TextArea;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.link.Link;
+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.model.AbstractReadOnlyModel;
+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 com.google.common.base.Preconditions;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.loader.InheritableThreadLocalData;
+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
+import com.pmease.commons.wicket.component.DropdownLink;
+import com.pmease.commons.wicket.component.backtotop.BackToTop;
+import com.pmease.commons.wicket.component.tabbable.PageTab;
+import com.pmease.commons.wicket.component.tabbable.PageTabLink;
+import com.pmease.commons.wicket.component.tabbable.Tab;
+import com.pmease.commons.wicket.component.tabbable.Tabbable;
+import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
+import com.pmease.gitplex.core.entity.PullRequest.Status;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.entity.Verification;
+import com.pmease.gitplex.core.entity.component.DepotAndBranch;
+import com.pmease.gitplex.core.entity.component.IntegrationPreview;
+import com.pmease.gitplex.core.security.SecurityUtils;
+import com.pmease.gitplex.web.component.AccountLink;
+import com.pmease.gitplex.web.component.BranchLink;
+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
+import com.pmease.gitplex.web.component.comment.CommentInput;
+import com.pmease.gitplex.web.component.pullrequest.verificationstatus.VerificationStatusPanel;
+import com.pmease.gitplex.web.model.EntityModel;
+import com.pmease.gitplex.web.page.depot.DepotPage;
+import com.pmease.gitplex.web.page.depot.NoCommitsPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.compare.RequestComparePage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.updates.RequestUpdatesPage;
+import com.pmease.gitplex.web.util.DateUtils;
+import com.pmease.gitplex.web.websocket.PullRequestChangeRenderer;
+import com.pmease.gitplex.web.websocket.PullRequestChanged;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+public abstract class RequestDetailPage extends PullRequestPage {
+
+ protected IModel<PullRequest> requestModel;
+
+ private boolean editingTitle;
+
+ public RequestDetailPage(final PageParameters params) {
+ super(params);
+
+ if (!getDepot().git().hasRefs())
+ throw new RestartResponseException(NoCommitsPage.class, paramsOf(getDepot()));
+
+ requestModel = new LoadableDetachableModel<PullRequest>() {
+
+ @Override
+ protected PullRequest load() {
+ return GitPlex.getInstance(Dao.class).load(PullRequest.class, params.get("request").toLong());
+ }
+
+ };
+
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ PullRequest request = getPullRequest();
+
+ final WebMarkupContainer requestTitle = new WebMarkupContainer("requestHead");
+ requestTitle.setOutputMarkupId(true);
+ add(requestTitle);
+
+ requestTitle.add(new Label("title", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return getPullRequest().getTitle();
+ }
+
+ }) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!editingTitle);
+ }
+
+ });
+
+ requestTitle.add(new Label("id", "#" + request.getId()) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!editingTitle);
+ }
+
+ });
+
+ requestTitle.add(new AjaxLink<Void>("editLink") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ editingTitle = true;
+
+ target.add(requestTitle);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(!editingTitle && SecurityUtils.canModify(getPullRequest()));
+ }
+
+ });
+
+ Form<?> form = new Form<Void>("editForm") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(editingTitle);
+ }
+
+ };
+ requestTitle.add(form);
+
+ form.add(new TextField<String>("title", new IModel<String>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public String getObject() {
+ if (StringUtils.isNotBlank(getPullRequest().getTitle()))
+ return getPullRequest().getTitle();
+ else
+ return "";
+ }
+
+ @Override
+ public void setObject(String object) {
+ getPullRequest().setTitle(object);
+ }
+
+ }));
+
+ form.add(new AjaxButton("save") {
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ if (StringUtils.isNotBlank(getPullRequest().getTitle())) {
+ GitPlex.getInstance(Dao.class).persist(getPullRequest());
+ editingTitle = false;
+ }
+
+ target.add(requestTitle);
+ }
+
+ });
+
+ form.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ editingTitle = false;
+
+ target.add(requestTitle);
+ }
+
+ });
+
+ add(newStatusAndBranchesContainer());
+
+ WebMarkupContainer summaryContainer = new WebMarkupContainer("requestSummary") {
+
+ @Override
+ public void onEvent(IEvent<?> event) {
+ super.onEvent(event);
+
+ if (event.getPayload() instanceof PullRequestChanged) {
+ PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
+ pullRequestChanged.getPartialPageRequestHandler().add(this);
+ }
+ }
+
+ };
+ summaryContainer.setOutputMarkupPlaceholderTag(true);
+ add(summaryContainer);
+
+ summaryContainer.add(newDiscardedNoteContainer());
+ summaryContainer.add(newPendingUpdateNoteContainer());
+ summaryContainer.add(newPendingApprovalNoteContainer());
+ summaryContainer.add(newIntegratedNoteContainer());
+ summaryContainer.add(newStatusReasonsContainer());
+ summaryContainer.add(newIntegrationPreviewContainer());
+ summaryContainer.add(newOperationsContainer());
+
+ List<Tab> tabs = new ArrayList<>();
+
+ tabs.add(new RequestTab("Overview", RequestOverviewPage.class));
+ tabs.add(new RequestTab("Updates", RequestUpdatesPage.class));
+ tabs.add(new RequestTab("Compare", RequestComparePage.class) {
+
+ @Override
+ public Component render(String componentId) {
+ return new PageTabLink(componentId, this) {
+
+ @Override
+ protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {
+ PageParameters params = RequestComparePage.paramsOf(getPullRequest(),
+ RequestComparePage.REV_BASE, RequestComparePage.REV_LAST_UPDATE_PREFIX+"1");
+ return new BookmarkablePageLink<Void>(linkId, pageClass, params);
+ }
+
+ };
+ }
+
+ });
+
+ add(new Tabbable("requestTabs", tabs).setOutputMarkupId(true));
+
+ add(new BackToTop("backToTop"));
+
+ add(new PullRequestChangeRenderer() {
+
+ @Override
+ protected PullRequest getPullRequest() {
+ return RequestDetailPage.this.getPullRequest();
+ }
+
+ });
+ }
+
+ private WebMarkupContainer newStatusAndBranchesContainer() {
+ WebMarkupContainer statusAndBranchesContainer = new WebMarkupContainer("statusAndBranches");
+
+ PullRequest request = getPullRequest();
+
+ statusAndBranchesContainer.add(new Label("status", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return getPullRequest().getStatus().toString();
+ }
+
+ }) {
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ setOutputMarkupId(true);
+
+ add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ PullRequest.Status status = getPullRequest().getStatus();
+ if (status == Status.DISCARDED)
+ return " label-danger";
+ else if (status == Status.INTEGRATED)
+ return " label-success";
+ else
+ return " label-warning";
+ }
+
+ }));
+ }
+
+ @Override
+ public void onEvent(IEvent<?> event) {
+ super.onEvent(event);
+
+ if (event.getPayload() instanceof PullRequestChanged) {
+ PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
+ pullRequestChanged.getPartialPageRequestHandler().add(this);
+ }
+ }
+
+ });
+
+ if (request.getStatus() == Status.INTEGRATED) {
+ statusAndBranchesContainer.add(new AccountLink("user", request.getCloseInfo().getClosedBy()));
+
+ int commitCount = 0;
+ for (PullRequestUpdate update: request.getUpdates())
+ commitCount += update.getCommits().size();
+
+ statusAndBranchesContainer.add(new Label("action", "integrated " + commitCount + " commits"));
+ statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getCloseInfo().getCloseDate())));
+ } else {
+ statusAndBranchesContainer.add(new AccountLink("user", request.getSubmitter()));
+ statusAndBranchesContainer.add(new Label("action", "wants to integrate"));
+ statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getSubmitDate())));
+ }
+
+ statusAndBranchesContainer.add(new BranchLink("target", request.getTarget()));
+ if (request.getSourceDepot() != null) {
+ statusAndBranchesContainer.add(new BranchLink("source", request.getSource()));
+ } else {
+ statusAndBranchesContainer.add(new Label("source", "unknown") {
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+ tag.setName("span");
+ }
+
+ });
+ }
+ return statusAndBranchesContainer;
+ }
+
+ private WebMarkupContainer newIntegrationPreviewContainer() {
+ WebMarkupContainer integrationPreviewContainer = new WebMarkupContainer("integrationPreview") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().isOpen());
+ }
+
+ };
+ integrationPreviewContainer.setOutputMarkupId(true);
+
+ integrationPreviewContainer.add(new WebMarkupContainer("calculating") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getIntegrationPreview() == null);
+ }
+
+ });
+ integrationPreviewContainer.add(new WebMarkupContainer("conflict") {
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new DropdownLink("resolveInstructionsTrigger") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getSource() != null);
+ }
+
+ @Override
+ protected Component newContent(String id) {
+ return new ResolveConflictInstructionPanel(id, new EntityModel<PullRequest>(getPullRequest()));
+ }
+
+ });
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ IntegrationPreview preview = getPullRequest().getIntegrationPreview();
+ setVisible(preview != null && preview.getIntegrated() == null);
+ }
+
+ });
+ integrationPreviewContainer.add(new WebMarkupContainer("noConflict") {
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ Link<Void> link = new Link<Void>("preview") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getIntegrationPreview();
+ setVisible(!preview.getIntegrated().equals(preview.getRequestHead()));
+ }
+
+ @Override
+ public void onClick() {
+ PullRequest request = getPullRequest();
+ PageParameters params = RequestComparePage.paramsOf(request,
+ RequestComparePage.REV_TARGET_BRANCH, RequestComparePage.REV_INTEGRATION_PREVIEW);
+ setResponsePage(RequestComparePage.class, params);
+ }
+
+ };
+ add(link);
+
+ add(new VerificationStatusPanel("verification", requestModel, new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getIntegrationPreview();
+ if (preview != null)
+ return preview.getIntegrated();
+ else
+ return null;
+ }
+
+ }) {
+
+ @Override
+ protected Component newStatusComponent(String id, final IModel<Verification.Status> statusModel) {
+ return new Label(id, new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ if (statusModel.getObject() == Verification.Status.PASSED)
+ return "successful <i class='caret'></i>";
+ else if (statusModel.getObject() == Verification.Status.ONGOING)
+ return "running <i class='caret'></i>";
+ else if (statusModel.getObject() == Verification.Status.NOT_PASSED)
+ return "failed <i class='caret'></i>";
+ else
+ return "";
+ }
+
+ }) {
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+
+ if (statusModel.getObject() == Verification.Status.PASSED)
+ tag.put("class", "label label-success");
+ else if (statusModel.getObject() == Verification.Status.ONGOING)
+ tag.put("class", "label label-warning");
+ else if (statusModel.getObject() == Verification.Status.NOT_PASSED)
+ tag.put("class", "label label-danger");
+ }
+
+ @Override
+ protected void onDetach() {
+ statusModel.detach();
+
+ super.onDetach();
+ }
+
+ }.setEscapeModelStrings(false);
+ }
+
+ });
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ IntegrationPreview preview = getPullRequest().getIntegrationPreview();
+ setVisible(preview != null && preview.getIntegrated() != null);
+ }
+
+ });
+
+ return integrationPreviewContainer;
+ }
+
+ private WebMarkupContainer newOperationsContainer() {
+ final WebMarkupContainer operationsContainer = new WebMarkupContainer("operations") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ boolean hasVisibleChildren = false;
+ for (int i=0; i<size(); i++) {
+ @SuppressWarnings("deprecation")
+ Component child = get(i);
+ child.configure();
+ if (child.isVisible()) {
+ hasVisibleChildren = true;
+ break;
+ }
+ }
+
+ setVisible(hasVisibleChildren);
+ }
+
+ };
+ operationsContainer.setOutputMarkupId(true);
+
+ final String confirmId = "confirm";
+
+ operationsContainer.add(new AjaxLink<Void>("approve") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, APPROVE, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(APPROVE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+
+ operationsContainer.add(new AjaxLink<Void>("disapprove") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, DISAPPROVE, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(DISAPPROVE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+
+ operationsContainer.add(new AjaxLink<Void>("integrate") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, INTEGRATE, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(INTEGRATE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+
+ operationsContainer.add(new AjaxLink<Void>("discard") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, DISCARD, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(DISCARD.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+ operationsContainer.add(new AjaxLink<Void>("reopen") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, REOPEN, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(REOPEN.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+ operationsContainer.add(new AjaxLink<Void>("deleteSourceBranch") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, DELETE_SOURCE_BRANCH, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(DELETE_SOURCE_BRANCH.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+ operationsContainer.add(new AjaxLink<Void>("restoreSourceBranch") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ operationsContainer.replace(newOperationConfirm(confirmId, RESTORE_SOURCE_BRANCH, operationsContainer));
+ target.add(operationsContainer);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(RESTORE_SOURCE_BRANCH.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
+ }
+
+ });
+
+ operationsContainer.add(new WebMarkupContainer(confirmId).setVisible(false));
+
+ return operationsContainer;
+ }
+
+ private Component newOperationConfirm(final String id, final PullRequestOperation operation,
+ final WebMarkupContainer operationsContainer) {
+ PullRequest request = getPullRequest();
+
+ final Fragment fragment = new Fragment(id, "operationConfirmFrag", this);
+ Form<?> form = new Form<Void>("form");
+ fragment.add(form);
+ final FormComponent<String> noteInput;
+
+ DepotAndBranch source = request.getSource();
+ Preconditions.checkNotNull(source);
+
+ if (operation != INTEGRATE) {
+ form.add(noteInput = new CommentInput("note", Model.of("")) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(requestModel.getObject().getTargetDepot());
+ }
+
+ });
+ noteInput.add(AttributeModifier.replace("placeholder", "Leave a comment"));
+ } else {
+ IntegrationPreview preview = request.getIntegrationPreview();
+ if (preview == null || preview.getIntegrated() == null) {
+ Session.get().warn("Unable to integrate now as integration preview has to be recalculated");
+ return new WebMarkupContainer(id).setVisible(false);
+ }
+ IntegrationStrategy strategy = preview.getIntegrationStrategy();
+ if (strategy == REBASE_SOURCE_ONTO_TARGET
+ || strategy == REBASE_TARGET_ONTO_SOURCE
+ || preview.getIntegrated().equals(preview.getRequestHead())) {
+ form.add(noteInput = new CommentInput("note", Model.of("")) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(requestModel.getObject().getTargetDepot());
+ }
+
+ });
+ noteInput.add(AttributeModifier.replace("placeholder", "Leave a comment"));
+ } else {
+ form.add(noteInput = new TextArea<String>("note", Model.of("")));
+ noteInput.add(AttributeModifier.replace("placeholder", "Commit message"));
+ }
+ }
+ form.add(new NotificationPanel("feedback", form));
+ form.add(new AjaxButton("submit") {
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ String actionName = operation.name().toLowerCase();
+
+ InheritableThreadLocalData.set(new PageId(getPage().getPageId()));
+ PullRequest request = getPullRequest();
+ try {
+ operation.operate(request, noteInput.getModelObject());
+ setResponsePage(getPage().getClass(), paramsOf(getPullRequest()));
+ } catch (Exception e) {
+ error("Unable to " + actionName + ": " + e.getMessage());
+ target.add(operationsContainer);
+ } finally {
+ InheritableThreadLocalData.clear();
+ }
+ }
+
+ }.add(AttributeModifier.replace("value", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return "Confirm " + WordUtils.capitalizeFully(operation.name()).replace("_", " ").toLowerCase();
+ }
+
+ })).add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ if (operation == INTEGRATE)
+ return "btn-success";
+ else if (operation == DISCARD)
+ return "btn-danger";
+ else
+ return "btn-primary";
+ }
+
+ })));
+ form.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ fragment.replaceWith(new WebMarkupContainer(id).setVisible(false));
+ target.add(operationsContainer);
+ }
+
+ });
+
+ return fragment;
+ }
+
+ private WebMarkupContainer newDiscardedNoteContainer() {
+ WebMarkupContainer discardedNoteContainer = new WebMarkupContainer("discardedNote") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() == Status.DISCARDED);
+ }
+
+ };
+ return discardedNoteContainer;
+ }
+
+ private WebMarkupContainer newPendingUpdateNoteContainer() {
+ WebMarkupContainer pendingUpdateNoteContainer = new WebMarkupContainer("pendingUpdateNote") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() == Status.PENDING_UPDATE);
+ }
+
+ };
+ return pendingUpdateNoteContainer;
+ }
+
+ private WebMarkupContainer newPendingApprovalNoteContainer() {
+ WebMarkupContainer pendingApprovalNoteContainer = new WebMarkupContainer("pendingApprovalNote") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() == Status.PENDING_APPROVAL);
+ }
+
+ };
+ return pendingApprovalNoteContainer;
+ }
+
+ private WebMarkupContainer newIntegratedNoteContainer() {
+ WebMarkupContainer integratedNoteContainer = new WebMarkupContainer("integratedNote") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() == Status.INTEGRATED);
+ }
+
+ };
+ integratedNoteContainer.setOutputMarkupId(true);
+
+ integratedNoteContainer.add(new WebMarkupContainer("fastForwarded") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getLastIntegrationPreview();
+ setVisible(preview != null && preview.getRequestHead().equals(preview.getIntegrated()));
+ }
+
+ });
+ integratedNoteContainer.add(new WebMarkupContainer("merged") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getLastIntegrationPreview();
+ setVisible(preview != null
+ && !preview.getRequestHead().equals(preview.getIntegrated())
+ && (preview.getIntegrationStrategy() == MERGE_ALWAYS || preview.getIntegrationStrategy() == MERGE_IF_NECESSARY));
+ }
+
+ });
+ integratedNoteContainer.add(new WebMarkupContainer("mergedOutside") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(getPullRequest().getLastIntegrationPreview() == null);
+ }
+
+ });
+ integratedNoteContainer.add(new WebMarkupContainer("squashed") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getLastIntegrationPreview();
+ setVisible(preview != null
+ && !preview.getRequestHead().equals(preview.getIntegrated())
+ && preview.getIntegrationStrategy() == MERGE_WITH_SQUASH);
+ }
+
+ });
+
+ integratedNoteContainer.add(new WebMarkupContainer("sourceRebased") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getLastIntegrationPreview();
+ setVisible(preview != null
+ && !preview.getRequestHead().equals(preview.getIntegrated())
+ && preview.getIntegrationStrategy() == REBASE_SOURCE_ONTO_TARGET);
+ }
+
+ });
+
+ integratedNoteContainer.add(new WebMarkupContainer("targetRebased") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getLastIntegrationPreview();
+ setVisible(preview != null
+ && !preview.getRequestHead().equals(preview.getIntegrated())
+ && preview.getIntegrationStrategy() == REBASE_TARGET_ONTO_SOURCE);
+ }
+
+ });
+
+ return integratedNoteContainer;
+ }
+
+ private WebMarkupContainer newStatusReasonsContainer() {
+ WebMarkupContainer statusReasonsContainer = new WebMarkupContainer("statusReasons") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ PullRequest.Status status = getPullRequest().getStatus();
+ setVisible(status == Status.PENDING_APPROVAL || status == Status.PENDING_UPDATE);
+ }
+
+ };
+ statusReasonsContainer.setOutputMarkupId(true);
+
+ statusReasonsContainer.add(new ListView<String>("reasons", new AbstractReadOnlyModel<List<String>>() {
+
+ @Override
+ public List<String> getObject() {
+ return getPullRequest().getCheckResult().getReasons();
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(ListItem<String> item) {
+ item.add(new Label("reason", item.getModelObject()));
+ }
+
+ });
+
+ return statusReasonsContainer;
+ }
+
+ @Override
+ protected void onDetach() {
+ requestModel.detach();
+ super.onDetach();
+ }
+
+ public static PageParameters paramsOf(PullRequest request) {
+ PageParameters params = DepotPage.paramsOf(request.getTarget().getDepot());
+ params.set("request", request.getId());
+ return params;
+ }
+
+ private class RequestTab extends PageTab {
+
+ public RequestTab(String title, Class<? extends Page> pageClass) {
+ super(Model.of(title), pageClass);
+ }
+
+ @Override
+ public Component render(String componentId) {
+ return new PageTabLink(componentId, this) {
+
+ @Override
+ protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {
+ return new BookmarkablePageLink<Void>(linkId, pageClass, paramsOf(getPullRequest()));
+ }
+
+ };
+ }
+
+ }
+
+ public PullRequest getPullRequest() {
+ return requestModel.getObject();
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+
+ response.render(CssHeaderItem.forReference(
+ new CssResourceReference(RequestDetailPage.class, "request-detail.css")));
+ }
+
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/RequestAttachmentsPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/RequestAttachmentsPage.html
deleted file mode 100644
index 051f470b4e..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/RequestAttachmentsPage.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<wicket:extend>
- <div class="attachments">
- <div class="upload">
- <form wicket:id="form">
- <span class="btn btn-primary btn-file">
- Select file to upload... <input wicket:id="file" type="file"></input>
- </span>
- <div wicket:id="feedback" class="feedback"></div>
- </form>
- </div>
- <table wicket:id="available" class="available table table-striped">
- <thead>
- <tr>
- <th>Attachment</th>
- <th>Size</th>
- <th>&nbsp;</th>
- </tr>
- </thead>
- <tr wicket:id="attachments">
- <td class="attachment"><a wicket:id="link"><span wicket:id="label"></span></a></td>
- <td class="size"><span wicket:id="size"></span></td>
- <td class="operations"><a wicket:id="delete"><i class="fa fa-trash"></i></a></td>
- </tr>
- </table>
- </div>
-</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/RequestAttachmentsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/RequestAttachmentsPage.java
deleted file mode 100644
index f0e399fe7b..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/RequestAttachmentsPage.java
+++ /dev/null
@@ -1,167 +0,0 @@
-package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.attachments;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
-import org.apache.commons.fileupload.FileUploadException;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-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.upload.FileUpload;
-import org.apache.wicket.markup.html.form.upload.FileUploadField;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.link.ResourceLink;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.request.resource.CssResourceReference;
-import org.apache.wicket.util.lang.Bytes;
-
-import com.pmease.commons.util.FileUtils;
-import com.pmease.commons.wicket.ajaxlistener.ConfirmListener;
-import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.web.component.comment.CommentAttachmentSupport;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.RequestListPage;
-import com.pmease.gitplex.web.resource.AttachmentResource;
-import com.pmease.gitplex.web.resource.AttachmentResourceReference;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-public class RequestAttachmentsPage extends RequestDetailPage {
-
- private final AttachmentSupport attachmentSupport;
-
- public RequestAttachmentsPage(PageParameters params) {
- super(params);
-
- attachmentSupport = new CommentAttachmentSupport(getPullRequest().getId());
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- final FileUploadField uploadField = new FileUploadField("file");
-
- final WebMarkupContainer available = new WebMarkupContainer("available") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(!attachmentSupport.getAttachments().isEmpty());
- }
-
- };
- available.setOutputMarkupPlaceholderTag(true);
- add(available);
-
- final Form<?> form = new Form<Void>("form") {
-
- @Override
- protected void onFileUploadException(FileUploadException e, Map<String, Object> model) {
- if (e instanceof SizeLimitExceededException)
- error("Upload must be less than " + FileUtils.byteCountToDisplaySize(getMaxSize().bytes()));
- }
-
- };
- form.setMaxSize(Bytes.bytes(attachmentSupport.getAttachmentMaxSize()));
- form.setMultiPart(true);
-
- uploadField.add(new AjaxFormSubmitBehavior("change") {
-
- @Override
- protected void onSubmit(AjaxRequestTarget target) {
- super.onSubmit(target);
- FileUpload upload = uploadField.getFileUpload();
- if (upload != null) {
- try (InputStream is = upload.getInputStream()) {
- attachmentSupport.saveAttachment(upload.getClientFileName(), is);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- form.success("File has been uploaded.");
- target.add(form);
- target.add(available);
- }
- }
-
- @Override
- protected void onError(AjaxRequestTarget target) {
- super.onError(target);
- target.add(form);
- }
-
- });
-
- form.add(uploadField);
- form.add(new NotificationPanel("feedback", form));
- form.setOutputMarkupId(true);
- add(form);
-
- available.add(new ListView<String>("attachments", new LoadableDetachableModel<List<String>>() {
-
- @Override
- protected List<String> load() {
- return attachmentSupport.getAttachments();
- }
-
- }) {
-
- @Override
- protected void populateItem(ListItem<String> item) {
- final String attachment = item.getModelObject();
- Link<Void> link = new ResourceLink<Void>("link", new AttachmentResourceReference(),
- AttachmentResource.paramsOf(getPullRequest(), attachment));
- link.add(new Label("label", attachment));
- item.add(link);
-
- long attachmentSize = attachmentSupport.getAttachmentSize(attachment);
- item.add(new Label("size", FileUtils.byteCountToDisplaySize(attachmentSize)));
-
- item.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 attachment " + attachment + "?"));
- }
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- attachmentSupport.deleteAttachemnt(attachment);
- target.add(available);
- }
-
- });
- }
-
- });
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(
- new CssResourceReference(RequestAttachmentsPage.class, "request-attachments.css")));
- }
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot) {
- setResponsePage(RequestListPage.class, paramsOf(depot));
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/request-attachments.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/request-attachments.css
deleted file mode 100644
index bfb52eb273..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/attachments/request-attachments.css
+++ /dev/null
@@ -1,9 +0,0 @@
-#request-detail>.attachments>.upload {
- margin-bottom: 8px;
-}
-#request-detail>.attachments>.upload>form>.feedback {
- margin-top: 16px;
-}
-#request-detail>.attachments>.available {
- margin-top: 20px;
-}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/OpenActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/OpenActivityPanel.java
index d15bdfb29a..3406160cc3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/OpenActivityPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/OpenActivityPanel.java
@@ -1,187 +1,195 @@
-package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.commons.lang3.StringUtils;
-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.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.panel.Fragment;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.hibernate.StaleObjectStateException;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
-import com.pmease.commons.wicket.component.markdownviewer.MarkdownViewer;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.security.SecurityUtils;
-import com.pmease.gitplex.web.component.AccountLink;
-import com.pmease.gitplex.web.component.comment.CommentInput;
-import com.pmease.gitplex.web.util.DateUtils;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-class OpenActivityPanel extends AbstractActivityPanel {
-
- private static final String BODY_ID = "body";
-
- private static final String FORM_ID = "form";
-
- public OpenActivityPanel(String id, RenderableActivity activity) {
- super(id, activity);
- }
-
- private Fragment renderForView() {
- final Fragment fragment = new Fragment(BODY_ID, "viewFrag", this);
-
- final NotificationPanel feedback = new NotificationPanel("feedback", fragment);
- feedback.setOutputMarkupPlaceholderTag(true);
- fragment.add(feedback);
- String description = requestModel.getObject().getDescription();
- if (StringUtils.isNotBlank(description)) {
- final AtomicLong lastVersionRef = new AtomicLong(requestModel.getObject().getVersion());
- fragment.add(new MarkdownViewer("description", new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- return requestModel.getObject().getDescription();
- }
-
- @Override
- public void setObject(String object) {
- AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
- Preconditions.checkNotNull(target);
- PullRequest request = requestModel.getObject();
- try {
- if (request.getVersion() != lastVersionRef.get())
- throw new StaleObjectStateException(PullRequest.class.getName(), request.getId());
- request.setDescription(object);
- GitPlex.getInstance(Dao.class).persist(request);
- target.add(feedback); // clear the feedback
- } catch (StaleObjectStateException e) {
- fragment.warn("Some one changed the content you are editing. The content has now been "
- + "reloaded, please try again.");
- target.add(fragment);
- }
- lastVersionRef.set(request.getVersion());
- }
-
- }, SecurityUtils.canModify(requestModel.getObject())));
- } else {
- fragment.add(new Label("description", "<i>No description</i>").setEscapeModelStrings(false));
- }
- fragment.setOutputMarkupId(true);
-
- return fragment;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- final WebMarkupContainer head = new WebMarkupContainer("head");
- head.setOutputMarkupId(true);
- add(head);
-
- head.add(new AccountLink("user", userModel.getObject()));
- head.add(new Label("age", DateUtils.formatAge(activity.getDate())));
-
- head.add(new AjaxLink<Void>("edit") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- Fragment fragment = new Fragment(BODY_ID, "editFrag", OpenActivityPanel.this);
-
- final Form<?> form = new Form<Void>(FORM_ID);
- form.setOutputMarkupId(true);
- fragment.add(form);
-
- final NotificationPanel feedback = new NotificationPanel("feedback", form);
- feedback.setOutputMarkupPlaceholderTag(true);
- form.add(feedback);
-
- final long lastVersion = requestModel.getObject().getVersion();
- final CommentInput input = new CommentInput("input", requestModel,
- Model.of(requestModel.getObject().getDescription()));
- form.add(input);
-
- 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) {
- try {
- PullRequest request = requestModel.getObject();
- if (request.getVersion() != lastVersion)
- throw new StaleObjectStateException(PullRequest.class.getName(), request.getId());
- request.setDescription(input.getModelObject());
- GitPlex.getInstance(Dao.class).persist(request);
-
- Fragment fragment = renderForView();
- OpenActivityPanel.this.replace(fragment);
- target.add(fragment);
- target.add(head);
- } catch (StaleObjectStateException e) {
- error("Some one changed the content you are editing. Reload the page and try again.");
- target.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) {
- Fragment fragment = renderForView();
- OpenActivityPanel.this.replace(fragment);
- target.add(fragment);
- target.add(head);
- }
-
- });
-
- OpenActivityPanel.this.replace(fragment);
-
- target.add(fragment);
- target.add(head);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(SecurityUtils.canModify(requestModel.getObject())
- && OpenActivityPanel.this.get(BODY_ID).get(FORM_ID) == null);
- }
-
- });
-
- add(renderForView());
- }
-
-}
+package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.commons.lang3.StringUtils;
+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.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.panel.Fragment;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.hibernate.StaleObjectStateException;
+
+import com.google.common.base.Preconditions;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
+import com.pmease.commons.wicket.component.markdownviewer.MarkdownViewer;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.security.SecurityUtils;
+import com.pmease.gitplex.web.component.AccountLink;
+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
+import com.pmease.gitplex.web.component.comment.CommentInput;
+import com.pmease.gitplex.web.util.DateUtils;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+class OpenActivityPanel extends AbstractActivityPanel {
+
+ private static final String BODY_ID = "body";
+
+ private static final String FORM_ID = "form";
+
+ public OpenActivityPanel(String id, RenderableActivity activity) {
+ super(id, activity);
+ }
+
+ private Fragment renderForView() {
+ final Fragment fragment = new Fragment(BODY_ID, "viewFrag", this);
+
+ final NotificationPanel feedback = new NotificationPanel("feedback", fragment);
+ feedback.setOutputMarkupPlaceholderTag(true);
+ fragment.add(feedback);
+ String description = requestModel.getObject().getDescription();
+ if (StringUtils.isNotBlank(description)) {
+ final AtomicLong lastVersionRef = new AtomicLong(requestModel.getObject().getVersion());
+ fragment.add(new MarkdownViewer("description", new IModel<String>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public String getObject() {
+ return requestModel.getObject().getDescription();
+ }
+
+ @Override
+ public void setObject(String object) {
+ AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
+ Preconditions.checkNotNull(target);
+ PullRequest request = requestModel.getObject();
+ try {
+ if (request.getVersion() != lastVersionRef.get())
+ throw new StaleObjectStateException(PullRequest.class.getName(), request.getId());
+ request.setDescription(object);
+ GitPlex.getInstance(Dao.class).persist(request);
+ target.add(feedback); // clear the feedback
+ } catch (StaleObjectStateException e) {
+ fragment.warn("Some one changed the content you are editing. The content has now been "
+ + "reloaded, please try again.");
+ target.add(fragment);
+ }
+ lastVersionRef.set(request.getVersion());
+ }
+
+ }, SecurityUtils.canModify(requestModel.getObject())));
+ } else {
+ fragment.add(new Label("description", "<i>No description</i>").setEscapeModelStrings(false));
+ }
+ fragment.setOutputMarkupId(true);
+
+ return fragment;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ final WebMarkupContainer head = new WebMarkupContainer("head");
+ head.setOutputMarkupId(true);
+ add(head);
+
+ head.add(new AccountLink("user", userModel.getObject()));
+ head.add(new Label("age", DateUtils.formatAge(activity.getDate())));
+
+ head.add(new AjaxLink<Void>("edit") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ Fragment fragment = new Fragment(BODY_ID, "editFrag", OpenActivityPanel.this);
+
+ final Form<?> form = new Form<Void>(FORM_ID);
+ form.setOutputMarkupId(true);
+ fragment.add(form);
+
+ final NotificationPanel feedback = new NotificationPanel("feedback", form);
+ feedback.setOutputMarkupPlaceholderTag(true);
+ form.add(feedback);
+
+ long lastVersion = requestModel.getObject().getVersion();
+ CommentInput input = new CommentInput("input", Model.of(requestModel.getObject().getDescription())) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(requestModel.getObject().getTargetDepot());
+ }
+
+ };
+ form.add(input);
+
+ 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) {
+ try {
+ PullRequest request = requestModel.getObject();
+ if (request.getVersion() != lastVersion)
+ throw new StaleObjectStateException(PullRequest.class.getName(), request.getId());
+ request.setDescription(input.getModelObject());
+ GitPlex.getInstance(Dao.class).persist(request);
+
+ Fragment fragment = renderForView();
+ OpenActivityPanel.this.replace(fragment);
+ target.add(fragment);
+ target.add(head);
+ } catch (StaleObjectStateException e) {
+ error("Some one changed the content you are editing. Reload the page and try again.");
+ target.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) {
+ Fragment fragment = renderForView();
+ OpenActivityPanel.this.replace(fragment);
+ target.add(fragment);
+ target.add(head);
+ }
+
+ });
+
+ OpenActivityPanel.this.replace(fragment);
+
+ target.add(fragment);
+ target.add(head);
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(SecurityUtils.canModify(requestModel.getObject())
+ && OpenActivityPanel.this.get(BODY_ID).get(FORM_ID) == null);
+ }
+
+ });
+
+ add(renderForView());
+ }
+
+}
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.java
index b1cb0c8ba3..8c0b37400f 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,654 +1,663 @@
-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.MetaDataKey;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
-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.cycle.RequestCycle;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.request.resource.CssResourceReference;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.wicket.behavior.TooltipBehavior;
-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.PullRequestActivity;
-import com.pmease.gitplex.core.entity.PullRequestReference;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.entity.PullRequestVisit;
-import com.pmease.gitplex.core.entity.PullRequestWatch;
-import com.pmease.gitplex.core.entity.Review;
-import com.pmease.gitplex.core.entity.ReviewInvitation;
-import com.pmease.gitplex.core.manager.AccountManager;
-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.event.CommentRemoved;
-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.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 class ActivityRendered extends MetaDataKey<RenderableActivity> {
- };
-
- private static final ActivityRendered RENDERED_ACTIVITY = new ActivityRendered();
-
- private static final String DETAIL_ID = "detail";
-
- 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(final String id, RenderableActivity activity) {
- final 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);
-
- WebMarkupContainer avatarColumn = new WebMarkupContainer("avatar");
- avatarColumn.add(new AvatarLink("avatar", activity.getUser(), null));
- row.add(avatarColumn);
-
- if (row.get(DETAIL_ID) == null)
- row.add(activity.render(DETAIL_ID));
-
- if (activity instanceof OpenPullRequest)
- row.add(AttributeAppender.append("class", " discussion"));
- else
- row.add(AttributeAppender.append("class", " non-discussion"));
-
- if (activity instanceof UpdatePullRequest)
- row.add(AttributeAppender.append("class", " update"));
- else
- row.add(AttributeAppender.append("class", " non-update"));
-
- return row;
- }
-
- private List<RenderableActivity> getActivities() {
- PullRequest request = getPullRequest();
- List<RenderableActivity> renderableActivities = new ArrayList<>();
-
- for (PullRequestUpdate update: request.getUpdates())
- renderableActivities.add(new UpdatePullRequest(update));
-
- for (PullRequestReference reference: request.getReferencedBy()) {
- renderableActivities.add(new ReferencePullRequest(request, reference.getUser(),
- reference.getDate(), reference.getReferencedBy()));
- }
-
- for (PullRequestActivity activity: request.getActivities()) {
- if (activity.getAction() == PullRequestActivity.Action.OPEN) {
- renderableActivities.add(new OpenPullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.INTEGRATE) {
- renderableActivities.add(new IntegratePullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.DISCARD) {
- renderableActivities.add(new DiscardPullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.APPROVE) {
- renderableActivities.add(new ApprovePullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.DISAPPROVE) {
- renderableActivities.add(new DisapprovePullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.UNDO_REVIEW) {
- renderableActivities.add(new UndoReviewPullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.REOPEN) {
- renderableActivities.add(new ReopenPullRequest(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.DELETE_SOURCE_BRANCH) {
- renderableActivities.add(new DeleteSourceBranch(activity));
- } else if (activity.getAction() == PullRequestActivity.Action.RESTORE_SOURCE_BRANCH) {
- renderableActivities.add(new RestoreSourceBranch(activity));
- } else {
- throw new IllegalStateException("Unexpected activity: " + activity.getAction());
- }
- }
-
- renderableActivities.sort((o1, o2) -> {
- if (o1.getDate().before(o2.getDate()))
- return -1;
- else if (o1.getDate().after(o2.getDate()))
- return 1;
- else if (o1 instanceof OpenPullRequest)
- return -1;
- else
- return 1;
- });
-
- return renderableActivities;
- }
-
- private Component newActivitiesView() {
- activitiesView = new RepeatingView("requestActivities") {
-
- @Override
- protected void onDetach() {
- RenderableActivity activity = RequestCycle.get().getMetaData(RENDERED_ACTIVITY);
-
- if (activity != null) {
- // this logic prevents visit to be saved multiple times as
- // onDetach can be called multiple times at end of a request cycle
- RequestCycle.get().setMetaData(RENDERED_ACTIVITY, null);
-
- Account user = getLoginUser();
- if (user != null) {
- PullRequestVisit visit = getPullRequest().getVisit(user);
- if (visit == null) {
- visit = new PullRequestVisit();
- visit.setRequest(getPullRequest());
- visit.setUser(user);
- getPullRequest().getVisits().add(visit);
- } else {
- visit.setDate(new Date());
- }
- GitPlex.getInstance(Dao.class).persist(visit);
- }
- }
- super.onDetach();
- }
-
- };
- activitiesView.setOutputMarkupId(true);
-
- List<RenderableActivity> activities = getActivities();
-
- for (RenderableActivity activity: activities)
- activitiesView.add(newActivityRow(activitiesView.newChildId(), activity));
-
- return activitiesView;
- }
-
- @Override
- protected void onBeforeRender() {
- addOrReplace(newActivitiesView());
-
- super.onBeforeRender();
- }
-
- @Override
- public void detachModels() {
- super.detachModels();
- }
-
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- IPartialPageRequestHandler partialPageRequestHandler = pullRequestChanged.getPartialPageRequestHandler();
- List<RenderableActivity> activities = getActivities();
- @SuppressWarnings("deprecation")
- Component lastActivityRow = activitiesView.get(activitiesView.size()-1);
- RenderableActivity lastAcvitity = (RenderableActivity) lastActivityRow.getDefaultModelObject();
- for (RenderableActivity activity: activities) {
- if (activity.getDate().after(lastAcvitity.getDate())) {
- Component newActivityRow = newActivityRow(activitiesView.newChildId(), activity);
- activitiesView.add(newActivityRow);
-
- String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",
- newActivityRow.getMarkupId(), lastActivityRow.getMarkupId());
- partialPageRequestHandler.prependJavaScript(script);
- partialPageRequestHandler.add(newActivityRow);
- lastActivityRow = newActivityRow;
- }
- }
- }
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- final WebMarkupContainer addComment = new WebMarkupContainer("addComment") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(GitPlex.getInstance(AccountManager.class).getCurrent() != null);
- }
-
- };
- addComment.setOutputMarkupId(true);
- add(addComment);
-
- Form<?> form = new Form<Void>("form");
- addComment.add(form);
-
- final CommentInput input = new CommentInput("input", requestModel, Model.of(""));
- input.setRequired(true);
- form.add(input);
-
- form.add(new NotificationPanel("feedback", input));
-
- 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(), PullRequest.Event.INTEGRATION_STRATEGY_CHANGED));
- }
-
- });
- 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).onAssigneeChange(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<ReviewInvitation>("reviewers", new ReviewersModel(requestModel)) {
-
- @Override
- protected void populateItem(ListItem<ReviewInvitation> item) {
- ReviewInvitation 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(), PullRequest.Event.REVIEWER_CHANGED));
- }
-
- });
-
- List<Review> userReviews = new ArrayList<>();
- for (Review review: getPullRequest().getReviews()) {
- if (review.getReviewer().equals(invitation.getReviewer()))
- userReviews.add(review);
- }
- if (!userReviews.isEmpty()) {
- Review review = userReviews.get(userReviews.size()-1);
- item.add(new ReviewResultIcon("result", new EntityModel<Review>(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(), PullRequest.Event.REVIEWER_CHANGED));
- }
-
- });
-
- 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.MetaDataKey;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
+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.cycle.RequestCycle;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.CssResourceReference;
+
+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.PullRequestActivity;
+import com.pmease.gitplex.core.entity.PullRequestReference;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.entity.PullRequestVisit;
+import com.pmease.gitplex.core.entity.PullRequestWatch;
+import com.pmease.gitplex.core.entity.Review;
+import com.pmease.gitplex.core.entity.ReviewInvitation;
+import com.pmease.gitplex.core.manager.AccountManager;
+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.DepotAttachmentSupport;
+import com.pmease.gitplex.web.component.comment.CommentInput;
+import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
+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.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 class ActivityRendered extends MetaDataKey<RenderableActivity> {
+ };
+
+ private static final ActivityRendered RENDERED_ACTIVITY = new ActivityRendered();
+
+ private static final String DETAIL_ID = "detail";
+
+ 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(final String id, RenderableActivity activity) {
+ final 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);
+
+ WebMarkupContainer avatarColumn = new WebMarkupContainer("avatar");
+ avatarColumn.add(new AvatarLink("avatar", activity.getUser(), null));
+ row.add(avatarColumn);
+
+ if (row.get(DETAIL_ID) == null)
+ row.add(activity.render(DETAIL_ID));
+
+ if (activity instanceof OpenPullRequest)
+ row.add(AttributeAppender.append("class", " discussion"));
+ else
+ row.add(AttributeAppender.append("class", " non-discussion"));
+
+ if (activity instanceof UpdatePullRequest)
+ row.add(AttributeAppender.append("class", " update"));
+ else
+ row.add(AttributeAppender.append("class", " non-update"));
+
+ return row;
+ }
+
+ private List<RenderableActivity> getActivities() {
+ PullRequest request = getPullRequest();
+ List<RenderableActivity> renderableActivities = new ArrayList<>();
+
+ for (PullRequestUpdate update: request.getUpdates())
+ renderableActivities.add(new UpdatePullRequest(update));
+
+ for (PullRequestReference reference: request.getReferencedBy()) {
+ renderableActivities.add(new ReferencePullRequest(request, reference.getUser(),
+ reference.getDate(), reference.getReferencedBy()));
+ }
+
+ for (PullRequestActivity activity: request.getActivities()) {
+ if (activity.getAction() == PullRequestActivity.Action.OPEN) {
+ renderableActivities.add(new OpenPullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.INTEGRATE) {
+ renderableActivities.add(new IntegratePullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.DISCARD) {
+ renderableActivities.add(new DiscardPullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.APPROVE) {
+ renderableActivities.add(new ApprovePullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.DISAPPROVE) {
+ renderableActivities.add(new DisapprovePullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.UNDO_REVIEW) {
+ renderableActivities.add(new UndoReviewPullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.REOPEN) {
+ renderableActivities.add(new ReopenPullRequest(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.DELETE_SOURCE_BRANCH) {
+ renderableActivities.add(new DeleteSourceBranch(activity));
+ } else if (activity.getAction() == PullRequestActivity.Action.RESTORE_SOURCE_BRANCH) {
+ renderableActivities.add(new RestoreSourceBranch(activity));
+ } else {
+ throw new IllegalStateException("Unexpected activity: " + activity.getAction());
+ }
+ }
+
+ renderableActivities.sort((o1, o2) -> {
+ if (o1.getDate().before(o2.getDate()))
+ return -1;
+ else if (o1.getDate().after(o2.getDate()))
+ return 1;
+ else if (o1 instanceof OpenPullRequest)
+ return -1;
+ else
+ return 1;
+ });
+
+ return renderableActivities;
+ }
+
+ private Component newActivitiesView() {
+ activitiesView = new RepeatingView("requestActivities") {
+
+ @Override
+ protected void onDetach() {
+ RenderableActivity activity = RequestCycle.get().getMetaData(RENDERED_ACTIVITY);
+
+ if (activity != null) {
+ // this logic prevents visit to be saved multiple times as
+ // onDetach can be called multiple times at end of a request cycle
+ RequestCycle.get().setMetaData(RENDERED_ACTIVITY, null);
+
+ Account user = getLoginUser();
+ if (user != null) {
+ PullRequestVisit visit = getPullRequest().getVisit(user);
+ if (visit == null) {
+ visit = new PullRequestVisit();
+ visit.setRequest(getPullRequest());
+ visit.setUser(user);
+ getPullRequest().getVisits().add(visit);
+ } else {
+ visit.setDate(new Date());
+ }
+ GitPlex.getInstance(Dao.class).persist(visit);
+ }
+ }
+ super.onDetach();
+ }
+
+ };
+ activitiesView.setOutputMarkupId(true);
+
+ List<RenderableActivity> activities = getActivities();
+
+ for (RenderableActivity activity: activities)
+ activitiesView.add(newActivityRow(activitiesView.newChildId(), activity));
+
+ return activitiesView;
+ }
+
+ @Override
+ protected void onBeforeRender() {
+ addOrReplace(newActivitiesView());
+
+ super.onBeforeRender();
+ }
+
+ @Override
+ public void detachModels() {
+ super.detachModels();
+ }
+
+ @Override
+ public void onEvent(IEvent<?> event) {
+ super.onEvent(event);
+
+ if (event.getPayload() instanceof PullRequestChanged) {
+ PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
+ IPartialPageRequestHandler partialPageRequestHandler = pullRequestChanged.getPartialPageRequestHandler();
+ List<RenderableActivity> activities = getActivities();
+ @SuppressWarnings("deprecation")
+ Component lastActivityRow = activitiesView.get(activitiesView.size()-1);
+ RenderableActivity lastAcvitity = (RenderableActivity) lastActivityRow.getDefaultModelObject();
+ for (RenderableActivity activity: activities) {
+ if (activity.getDate().after(lastAcvitity.getDate())) {
+ Component newActivityRow = newActivityRow(activitiesView.newChildId(), activity);
+ activitiesView.add(newActivityRow);
+
+ String script = String.format("$(\"<tr id='%s'></tr>\").insertAfter('#%s');",
+ newActivityRow.getMarkupId(), lastActivityRow.getMarkupId());
+ partialPageRequestHandler.prependJavaScript(script);
+ partialPageRequestHandler.add(newActivityRow);
+ lastActivityRow = newActivityRow;
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ WebMarkupContainer addComment = new WebMarkupContainer("addComment") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(GitPlex.getInstance(AccountManager.class).getCurrent() != 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(requestModel.getObject().getTargetDepot());
+ }
+
+ };
+ input.setRequired(true);
+ form.add(input);
+
+ form.add(new NotificationPanel("feedback", input));
+
+ 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(), PullRequest.Event.INTEGRATION_STRATEGY_CHANGED));
+ }
+
+ });
+ 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).onAssigneeChange(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<ReviewInvitation>("reviewers", new ReviewersModel(requestModel)) {
+
+ @Override
+ protected void populateItem(ListItem<ReviewInvitation> item) {
+ ReviewInvitation 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(), PullRequest.Event.REVIEWER_CHANGED));
+ }
+
+ });
+
+ List<Review> userReviews = new ArrayList<>();
+ for (Review review: getPullRequest().getReviews()) {
+ if (review.getReviewer().equals(invitation.getReviewer()))
+ userReviews.add(review);
+ }
+ if (!userReviews.isEmpty()) {
+ Review review = userReviews.get(userReviews.size()-1);
+ item.add(new ReviewResultIcon("result", new EntityModel<Review>(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(), PullRequest.Event.REVIEWER_CHANGED));
+ }
+
+ });
+
+ 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")));
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
index 27317b5e36..e62b5eecbe 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
@@ -1,5 +1,3 @@
<wicket:extend>
- <div style="padding: 100px; background: white;">
- <i class="fa fa-ext fa-gitplex-logo" style="font-size: 64px;"></i>
- </div>
+ <a wicket:id="account"></a>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index 4da0c1875f..2225a55ba2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -1,13 +1,17 @@
-package com.pmease.gitplex.web.page.test;
-
-import com.pmease.gitplex.web.page.base.BasePage;
-
-@SuppressWarnings("serial")
-public class TestPage extends BasePage {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
- }
-
-}
+package com.pmease.gitplex.web.page.test;
+
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.web.component.AccountLink;
+import com.pmease.gitplex.web.page.base.BasePage;
+
+@SuppressWarnings("serial")
+public class TestPage extends BasePage {
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new AccountLink("account", (Account)null));
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/resource/AttachmentResource.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/resource/AttachmentResource.java
index 04ee1adc5d..c3050abfda 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/resource/AttachmentResource.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/resource/AttachmentResource.java
@@ -1,120 +1,109 @@
-package com.pmease.gitplex.web.resource;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.nio.file.Files;
-
-import javax.persistence.EntityNotFoundException;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shiro.authz.UnauthorizedException;
-import org.apache.tika.io.IOUtils;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.request.resource.AbstractResource;
-import org.eclipse.jgit.lib.Constants;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.manager.DepotManager;
-import com.pmease.gitplex.core.manager.StorageManager;
-import com.pmease.gitplex.core.security.SecurityUtils;
-
-public class AttachmentResource extends AbstractResource {
-
- private static final long serialVersionUID = 1L;
-
- private static final String PARAM_ACCOUNT = "account";
-
- private static final String PARAM_DEPOT = "depot";
-
- private static final String PARAM_REQUEST = "request";
-
- private static final String PARAM_ATTACHMENT = "attachment";
-
- @Override
- protected ResourceResponse newResourceResponse(Attributes attributes) {
- PageParameters params = attributes.getParameters();
-
- String userName = params.get(PARAM_ACCOUNT).toString();
- if (StringUtils.isBlank(userName))
- throw new IllegalArgumentException("account name has to be specified");
-
- String repoName = Preconditions.checkNotNull(params.get(PARAM_DEPOT).toString());
- if (StringUtils.isBlank(repoName))
- throw new IllegalArgumentException("repository name has to be specified");
-
- if (repoName.endsWith(Constants.DOT_GIT_EXT))
- repoName = repoName.substring(0, repoName.length() - Constants.DOT_GIT_EXT.length());
-
- final Depot depot = GitPlex.getInstance(DepotManager.class).findBy(userName, repoName);
-
- if (depot == null)
- throw new EntityNotFoundException("Unable to find repository " + userName + "/" + repoName);
-
- Long requestId = params.get(PARAM_REQUEST).toOptionalLong();
- if (requestId == null)
- throw new IllegalArgumentException("request parameter has to be specified");
-
- PullRequest request = GitPlex.getInstance(Dao.class).load(PullRequest.class, requestId);
-
- String attachment = params.get(PARAM_ATTACHMENT).toString();
- if (StringUtils.isBlank(attachment))
- throw new IllegalArgumentException("attachment parameter has to be specified");
-
- if (!SecurityUtils.canRead(depot))
- throw new UnauthorizedException();
-
- final File attachmentFile = new File(getAttachmentsDir(request), attachment);
-
- ResourceResponse response = new ResourceResponse();
- response.setContentLength(attachmentFile.length());
- try {
- response.setContentType(Files.probeContentType(attachmentFile.toPath()));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- try {
- response.setFileName(URLEncoder.encode(attachment, Charsets.UTF_8.name()));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- response.setWriteCallback(new WriteCallback() {
-
- @Override
- public void writeData(Attributes attributes) throws IOException {
- try (InputStream is = new FileInputStream(attachmentFile);) {
- IOUtils.copy(is, attributes.getResponse().getOutputStream());
- }
- }
-
- });
-
- return response;
- }
-
- private static File getAttachmentsDir(PullRequest request) {
- return GitPlex.getInstance(StorageManager.class).getAttachmentsDir(request);
- }
-
- public static PageParameters paramsOf(PullRequest request, String attachment) {
- PageParameters params = new PageParameters();
- params.add(PARAM_ACCOUNT, request.getTargetDepot().getAccount().getName());
- params.set(PARAM_DEPOT, request.getTargetDepot().getName());
- params.set(PARAM_REQUEST, request.getId());
- params.set(PARAM_ATTACHMENT, attachment);
- final File attachmentFile = new File(getAttachmentsDir(request), attachment);
- params.set("v", attachmentFile.lastModified());
-
- return params;
- }
-
-}
+package com.pmease.gitplex.web.resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.file.Files;
+
+import javax.persistence.EntityNotFoundException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.authz.UnauthorizedException;
+import org.apache.tika.io.IOUtils;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.AbstractResource;
+import org.eclipse.jgit.lib.Constants;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.manager.DepotManager;
+import com.pmease.gitplex.core.manager.StorageManager;
+import com.pmease.gitplex.core.security.SecurityUtils;
+
+public class AttachmentResource extends AbstractResource {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String PARAM_ACCOUNT = "account";
+
+ private static final String PARAM_DEPOT = "depot";
+
+ private static final String PARAM_ATTACHMENT = "attachment";
+
+ @Override
+ protected ResourceResponse newResourceResponse(Attributes attributes) {
+ PageParameters params = attributes.getParameters();
+
+ String userName = params.get(PARAM_ACCOUNT).toString();
+ if (StringUtils.isBlank(userName))
+ throw new IllegalArgumentException("account name has to be specified");
+
+ String repoName = Preconditions.checkNotNull(params.get(PARAM_DEPOT).toString());
+ if (StringUtils.isBlank(repoName))
+ throw new IllegalArgumentException("repository name has to be specified");
+
+ if (repoName.endsWith(Constants.DOT_GIT_EXT))
+ repoName = repoName.substring(0, repoName.length() - Constants.DOT_GIT_EXT.length());
+
+ Depot depot = GitPlex.getInstance(DepotManager.class).findBy(userName, repoName);
+
+ if (depot == null)
+ throw new EntityNotFoundException("Unable to find repository " + userName + "/" + repoName);
+
+ String attachment = params.get(PARAM_ATTACHMENT).toString();
+ if (StringUtils.isBlank(attachment))
+ throw new IllegalArgumentException("attachment parameter has to be specified");
+
+ if (!SecurityUtils.canRead(depot))
+ throw new UnauthorizedException();
+
+ File attachmentFile = new File(getAttachmentsDir(depot), attachment);
+
+ ResourceResponse response = new ResourceResponse();
+ response.setContentLength(attachmentFile.length());
+ try {
+ response.setContentType(Files.probeContentType(attachmentFile.toPath()));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ try {
+ response.setFileName(URLEncoder.encode(attachment, Charsets.UTF_8.name()));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ response.setWriteCallback(new WriteCallback() {
+
+ @Override
+ public void writeData(Attributes attributes) throws IOException {
+ try (InputStream is = new FileInputStream(attachmentFile);) {
+ IOUtils.copy(is, attributes.getResponse().getOutputStream());
+ }
+ }
+
+ });
+
+ return response;
+ }
+
+ private static File getAttachmentsDir(Depot depot) {
+ return GitPlex.getInstance(StorageManager.class).getAttachmentsDir(depot);
+ }
+
+ public static PageParameters paramsOf(Depot depot, String attachment) {
+ PageParameters params = new PageParameters();
+ params.add(PARAM_ACCOUNT, depot.getAccount().getName());
+ params.set(PARAM_DEPOT, depot.getName());
+ params.set(PARAM_ATTACHMENT, attachment);
+ final File attachmentFile = new File(getAttachmentsDir(depot), attachment);
+ params.set("v", attachmentFile.lastModified());
+
+ return params;
+ }
+
+}