The Unified and Autonomous Development Platform
Refine RequestComparePage.
robin shine5c7347c28f22
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.cssindex bcd88f1b17..12b96cc248 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.css@@ -83,23 +83,23 @@ table td, table th {text-align: left;}border-top: 7px solid transparent; border-left: 7px solid rgba(0, 0, 0, 0.2); left: 100%;}.dropdown-panel>.indicator.right:first-child {border-bottom: 7px solid transparent; border-top: 7px solid transparent;border-right: 7px solid rgba(0, 0, 0, 0.2); left: -7px;}-.nav-tabs .dropdown-toggle.dropdown-hover:hover, .nav-pills .dropdown-toggle.dropdown-hover:hover {+.nav-tabs .dropdown-trigger.dropdown-hover:hover, .nav-pills .dropdown-trigger.dropdown-hover:hover {background-color: #999; border-color: #999; color: #FFF;}.nav li.dropdown .dropdown-hover:hover .caret {border-bottom-color: #FFF; border-top-color: #FFF; opacity: 1;}-.dropdown-toggle.pill {border-radius: 4px; margin: 2px 2px 2px 0; padding: 4px 6px; line-height: 12px;}-.dropdown-toggle.pill .caret {border-bottom-color: #0088CC; border-top-color: #0088CC; margin-top: 8px;}-.dropdown-toggle.pill:hover {background-color: #EEE; text-decoration: none;}-.dropdown-toggle.pill:hover .caret {border-bottom-color: #005580; border-top-color: #005580;}-.dropdown-toggle.pill.open, .dropdown-toggle.dropdown-hover.pill:hover {background-color: #999; border-color: #999; color: #FFF;}-.dropdown-toggle.pill.open .caret, .dropdown-toggle.pill.dropdown-hover:hover .caret {border-bottom-color: #FFF; border-top-color: #FFF; opacity: 1;}--.piped>a.dropdown-toggle {border-radius: 4px; margin: 2px 2px 2px -5px; padding: 3px 6px; line-height: 11px;}-.piped .dropdown-toggle .caret {border-bottom-color: #0088CC; border-top-color: #0088CC; margin-top: 9px;}-.piped .dropdown-toggle:hover {background-color: #EEE; text-decoration: none;}-.piped .dropdown-toggle:hover .caret {border-bottom-color: #005580; border-top-color: #005580;}-.piped .dropdown-toggle.open, .piped .dropdown-toggle.dropdown-hover:hover {background-color: #999; border-color: #999; color: #FFF;}-.piped .dropdown-toggle.open .caret, .piped .dropdown-toggle.dropdown-hover:hover .caret {border-bottom-color: #FFF; border-top-color: #FFF; opacity: 1;}+.dropdown-trigger.pill {border-radius: 4px; margin: 2px 2px 2px 0; padding: 4px 6px; line-height: 12px;}+.dropdown-trigger.pill .caret {border-bottom-color: #0088CC; border-top-color: #0088CC; margin-top: 8px;}+.dropdown-trigger.pill:hover {background-color: #EEE; text-decoration: none;}+.dropdown-trigger.pill:hover .caret {border-bottom-color: #005580; border-top-color: #005580;}+.dropdown-trigger.pill.open, .dropdown-trigger.dropdown-hover.pill:hover {background-color: #999; border-color: #999; color: #FFF;}+.dropdown-trigger.pill.open .caret, .dropdown-trigger.pill.dropdown-hover:hover .caret {border-bottom-color: #FFF; border-top-color: #FFF; opacity: 1;}++.piped>a.dropdown-trigger {border-radius: 4px; margin: 2px 2px 2px -5px; padding: 3px 6px; line-height: 11px;}+.piped .dropdown-trigger .caret {border-bottom-color: #0088CC; border-top-color: #0088CC; margin-top: 9px;}+.piped .dropdown-trigger {background-color: #EEE; text-decoration: none;}+.piped .dropdown-trigger .caret {border-bottom-color: #005580; border-top-color: #005580;}+.piped .dropdown-trigger.open, .piped .dropdown-trigger.dropdown-hover:hover {background-color: #999; border-color: #999; color: #FFF;}+.piped .dropdown-trigger.open .caret, .piped .dropdown-trigger.dropdown-hover:hover .caret {border-bottom-color: #FFF; border-top-color: #FFF; opacity: 1;}/* Menu */.dropdown-panel.menu .content {padding: 4px 0; min-width: 120px;}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.jsindex f70f61e064..f3685da677 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js@@ -229,7 +229,7 @@ pmease.commons = {if (!trigger[0])return;- trigger.addClass("dropdown-toggle");+ trigger.addClass("dropdown-trigger");if (hoverDelay >= 0)trigger.addClass("dropdown-hover");@@ -477,7 +477,7 @@ pmease.commons = {setupDropdownAndModel: function() {$(document).mousedown(function(event) {var source = $(event.target);- if (!source.closest(".dropdown-toggle")[0])+ if (!source.closest(".dropdown-trigger")[0])pmease.commons.dropdown.hideExcept(source);});diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.javadeleted file mode 100644index 19a5632606..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.java+++ /dev/null@@ -1,22 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.List;--import javax.annotation.Nullable;--import com.pmease.commons.git.BlobInfo;--public interface BlobLoader {-- /**- * Load content of specified blob and convert to lines.- *- * @param blobInfo- * blob info to load- * @return- * lines of the blob, or null if the blob content can not be- * converted to text- */- @Nullable- List<String> loadBlob(BlobInfo blobInfo);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.javadeleted file mode 100644index 060599b628..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.java+++ /dev/null@@ -1,9 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.List;--import com.pmease.commons.git.Change;--public interface ChangeLoader {- List<Change> loadChanges(String fromRev, String toRev);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.javaindex fe9e0bdf92..14b60df911 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.java@@ -2,240 +2,152 @@ package com.pmease.gitplex.core.comment;import java.util.ArrayList;import java.util.HashMap;-import java.util.HashSet;+import java.util.Iterator;import java.util.List;import java.util.Map;-import java.util.Set;+import java.util.Map.Entry;import javax.annotation.Nullable;-import com.pmease.commons.git.BlobInfo;-import com.pmease.commons.git.Commit;+import com.google.common.base.Preconditions;import com.pmease.commons.git.RevAwareChange;-import com.pmease.commons.util.Pair;-import com.pmease.commons.util.diff.DiffUtils;+import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.manager.CommitCommentManager;import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;+import com.pmease.gitplex.core.model.Repository;@SuppressWarnings("serial")public class CommentAwareChange extends RevAwareChange {- private final List<Commit> commits;+ private final Map<Integer, List<CommitComment>> oldComments;- private Map<Integer, List<CommitComment>> oldComments;+ private final Map<Integer, List<CommitComment>> newComments;- private Map<Integer, List<CommitComment>> newComments;+ private final CommitComment concernedComment;- public CommentAwareChange(RevAwareChange change, List<Commit> commits,- CommentLoader commentLoader, BlobLoader blobLoader) {+ public CommentAwareChange(Repository repo, RevAwareChange change, boolean enableOldComments,+ boolean enableNewComments, @Nullable CommitComment concernedComment) {super(change);-- Map<String, Map<String, List<CommitComment>>> comments = new HashMap<>();- Map<BlobInfo, List<String>> blobs = new HashMap<>();-- this.commits = commits;-- List<String> commitHashes = new ArrayList<>();- for (Commit commit: commits)- commitHashes.add(commit.getHash());-- int end = -1;- if (change.getNewPath() != null) {- end = commitHashes.indexOf(change.getNewRevision());- if (end != -1 && getBlob(blobs, change.getNewBlobInfo(), blobLoader).isEmpty())- end = -1;- }-- int begin = -1;- if (change.getOldPath() != null) {- begin = commitHashes.indexOf(change.getOldRevision());- if (begin != -1 && getBlob(blobs, change.getOldBlobInfo(), blobLoader).isEmpty())- begin = -1;- }- if (end != -1) {- newComments = new HashMap<>();-- for (int i=end-1; i>begin; i--) {- String commit = commitHashes.get(i);- Map<String, List<CommitComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, commentLoader);- BlobInfo blobInfo = null;- List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getNewPath());- if (commentsOnFile != null) {- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());- } else {- commentsOnFile = commentsOnCommit.get(change.getOldPath());- if (commentsOnFile != null)- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());- }-- if (blobInfo != null) {- List<String> fileContent = getBlob(blobs, blobInfo, blobLoader);- if (!fileContent.isEmpty()) {- List<String> newContent = getBlob(blobs, change.getNewBlobInfo(), blobLoader);- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);- for (CommitComment comment: commentsOnFile) {- Integer lineNo = lineMap.get(comment.getPosition().getLineNo());- if (lineNo != null)- addLineComment(newComments, lineNo, comment);- }+ this.concernedComment = concernedComment;++ if (enableOldComments && getOldPath() != null) {+ oldComments = new HashMap<>();+ CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);+ for (CommitComment comment: manager.findByCommitAndFile(repo, getOldRevision(), getOldPath())) {+ CommentPosition position = comment.getPosition();+ if (position != null && position.getLineNo() != null+ && position.getFilePath().equals(getOldPath())) {+ List<CommitComment> lineComments = oldComments.get(position.getLineNo());+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ oldComments.put(position.getLineNo(), lineComments);}+ lineComments.add(comment);}}-- List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), commentLoader).get(change.getNewPath());- if (commentsOnFile != null) {- for (CommitComment comment: commentsOnFile)- addLineComment(newComments, comment.getPosition().getLineNo(), comment);- }+ } else {+ oldComments = null;}- if (begin != -1) {- oldComments = new HashMap<>();-- Set<CommentKey> appliedComments = new HashSet<>();- if (newComments != null) {- for (List<CommitComment> list: newComments.values()) {- for (CommitComment comment: list)- appliedComments.add(new CommentKey(comment.getCommit(), comment.getPosition()));- }- }-- for (int i=begin+1; i<(end!=-1?end:commits.size()); i++) {- String commit = commitHashes.get(i);- Map<String, List<CommitComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, commentLoader);- BlobInfo blobInfo = null;- List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getOldPath());- if (commentsOnFile != null) {- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());- } else {- commentsOnFile = commentsOnCommit.get(change.getNewPath());- if (commentsOnFile != null)- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());- }-- if (blobInfo != null) {- boolean allApplied = true;- for (CommitComment comment: commentsOnFile) {- CommentKey key = new CommentKey(comment.getCommit(), comment.getPosition());- if (!appliedComments.contains(key)) {- allApplied = false;- break;- }- }- if (!allApplied) {- List<String> fileContent = blobLoader.loadBlob(blobInfo);- if (!fileContent.isEmpty()) {- List<String> oldContent = getBlob(blobs, change.getOldBlobInfo(), blobLoader);- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, oldContent);- for (CommitComment comment: commentsOnFile) {- CommentKey key = new CommentKey(comment.getCommit(), comment.getPosition());- Integer lineNo = lineMap.get(comment.getPosition().getLineNo());- if (!appliedComments.contains(key) && lineNo != null)- addLineComment(oldComments, lineNo, comment);- }- }+ if (enableNewComments && getNewPath() != null) {+ newComments = new HashMap<>();+ CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);+ for (CommitComment comment: manager.findByCommitAndFile(repo, getNewRevision(), getNewPath())) {+ CommentPosition position = comment.getPosition();+ if (position != null && position.getLineNo() != null+ && position.getFilePath().equals(getOldPath())) {+ List<CommitComment> lineComments = newComments.get(position.getLineNo());+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ newComments.put(position.getLineNo(), lineComments);}+ lineComments.add(comment);}}-- List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), commentLoader).get(change.getOldPath());- if (commentsOnFile != null) {- for (CommitComment comment: commentsOnFile)- addLineComment(oldComments, comment.getPosition().getLineNo(), comment);- }- }-- }-- private void addLineComment(Map<Integer, List<CommitComment>> comments, int lineNo, CommitComment comment) {- List<CommitComment> commentsOnLine = comments.get(lineNo);- if (commentsOnLine == null) {- commentsOnLine = new ArrayList<>();- comments.put(lineNo, commentsOnLine);+ } else {+ newComments = null;}- commentsOnLine.add(comment);}-- private Map<String, List<CommitComment>> getCommentsOnCommit(Map<String, Map<String, List<CommitComment>>> comments,- String commit, CommentLoader commentLoader) {- Map<String, List<CommitComment>> commentsOnCommit = comments.get(commit);- if (commentsOnCommit == null) {- commentsOnCommit = new HashMap<>();- for (CommitComment each: commentLoader.loadComments(commit)) {- if (each.getPosition() != null && each.getPosition().getLineNo() != null) {- List<CommitComment> commentsOnFile = commentsOnCommit.get(each.getPosition().getFilePath());- if (commentsOnFile == null) {- commentsOnFile = new ArrayList<>();- commentsOnCommit.put(each.getPosition().getFilePath(), commentsOnFile);- }- commentsOnFile.add(each);- }- }- comments.put(commit, commentsOnCommit);- }- return commentsOnCommit;++ public CommitComment getConcernedComment() {+ return concernedComment;}- @Nullablepublic Map<Integer, List<CommitComment>> getOldComments() {return oldComments;}- @Nullablepublic Map<Integer, List<CommitComment>> getNewComments() {return newComments;}-- public List<Commit> getCommits() {- return commits;- }- private List<String> getBlob(Map<BlobInfo, List<String>> blobs, BlobInfo blobInfo, BlobLoader blobLoader) {- List<String> blob = blobs.get(blobInfo);- if (blob == null) {- blob = blobLoader.loadBlob(blobInfo);- if (blob == null)- blob = new ArrayList<>();- blobs.put(blobInfo, blob);+ public void saveComment(CommitComment comment) {+ boolean isNew = comment.isNew();+ GitPlex.getInstance(Dao.class).persist(comment);++ if (isNew) {+ if (comment.getCommit().equals(getOldRevision())) {+ addComment(Preconditions.checkNotNull(oldComments), comment);+ } else if (comment.getCommit().equals(getNewRevision())) {+ addComment(Preconditions.checkNotNull(newComments), comment);+ } else {+ throw new IllegalStateException();+ }}- return blob;}public boolean contains(CommitComment comment) {- if (getOldComments() != null) {- for (List<CommitComment> lineComments: getOldComments().values()) {- for (CommitComment each: lineComments) {- if (each.getId().equals(comment.getId()))+ if (oldComments != null) {+ for (List<CommitComment> lineComments: oldComments.values()) {+ for (CommitComment lineComment: lineComments) {+ if (lineComment.equals(comment))return true;}}}- if (getNewComments() != null) {- for (List<CommitComment> lineComments: getNewComments().values()) {- for (CommitComment each: lineComments) {- if (each.getId().equals(comment.getId()))+ if (newComments != null) {+ for (List<CommitComment> lineComments: newComments.values()) {+ for (CommitComment lineComment: lineComments) {+ if (lineComment.equals(comment))return true;}}}return false;}-- public Commit getCommit(String hash) {- for (Commit each: commits) {- if (hash.equals(each.getHash()))- return each;++ public void removeComment(CommitComment comment) {+ GitPlex.getInstance(Dao.class).remove(comment);++ if (comment.getCommit().equals(getOldRevision())) {+ removeComment(Preconditions.checkNotNull(oldComments), comment);+ } else if (comment.getCommit().equals(getNewRevision())) {+ removeComment(Preconditions.checkNotNull(newComments), comment);+ } else {+ throw new IllegalStateException();}- throw new RuntimeException("Unable to find specified commit.");}- private static class CommentKey extends Pair<String, CommentPosition> {-- public CommentKey(String commit, CommentPosition position) {- super(commit, position);+ private void removeComment(Map<Integer, List<CommitComment>> comments, CommitComment comment) {+ for (Iterator<Entry<Integer, List<CommitComment>>> it = comments.entrySet().iterator(); it.hasNext();) {+ Entry<Integer, List<CommitComment>> entry = it.next();+ entry.getValue().remove(comment);+ if (entry.getValue().isEmpty())+ it.remove();}-}-++ private void addComment(Map<Integer, List<CommitComment>> comments, CommitComment comment) {+ int lineNo = comment.getPosition().getLineNo();+ List<CommitComment> lineComments = comments.get(lineNo);+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ comments.put(lineNo, lineComments);+ }+ lineComments.add(comment);+ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.javadeleted file mode 100644index b82edabbfb..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.java+++ /dev/null@@ -1,20 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.List;--import com.pmease.gitplex.core.model.CommitComment;--public interface CommentLoader {- /**- * Load list of comments on specified commit, ordered by comment id.- *- * @param commit- * commit to load comments for- * @return- * list of commit comments on specified commit ordered by comment id,- * including comments on commit itself, comments on files in the commit,- * and comments on file lines in the commit. Empty list should be- * returned if there are no any comments on specified commit- */- List<CommitComment> loadComments(String commit);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.javaindex 10983f01a2..a8c03f7dfb 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java@@ -9,7 +9,9 @@ import com.google.inject.ImplementedBy;import com.pmease.gitplex.core.manager.impl.DefaultCommentVisitManager;import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommentVisit;+import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.Repository;+import com.pmease.gitplex.core.model.User;@ImplementedBy(DefaultCommentVisitManager.class)public interface CommentVisitManager {@@ -26,10 +28,15 @@ public interface CommentVisitManager {* @return* list of found comment visits*/- List<CommentVisit> findByCommitDates(Repository repository, @Nullable Date fromDate, @Nullable Date toDate);-- List<CommentVisit> findByCommitOrDates(Repository repository, String commit,+ List<CommentVisit> findByCommitDates(Repository repository, User user,@Nullable Date fromDate, @Nullable Date toDate);++ List<CommentVisit> findByCommitOrDates(Repository repository, User user,+ String commit, @Nullable Date fromDate, @Nullable Date toDate);- CommentVisit find(Repository repository, String commit, @Nullable CommentPosition position);+ CommentVisit find(Repository repository, User user,+ String commit, @Nullable CommentPosition position);++ void visitComment(Repository repository, User user, CommitComment comment);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.javaindex 2fefddc6ca..b3cd5ec8a4 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java@@ -2,6 +2,7 @@ package com.pmease.gitplex.core.manager;import java.util.Date;import java.util.List;+import java.util.Map;import javax.annotation.Nullable;@@ -68,4 +69,5 @@ public interface CommitCommentManager {List<CommitComment> findByCommitOrDates(Repository repository, String commit,@Nullable Date fromDate, @Nullable Date toDate);+ Map<Integer, List<CommitComment>> findLineComments(Repository repository, String commit, String filePath);}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.javaindex b1bf62f403..601afd09c0 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java@@ -12,11 +12,12 @@ import org.hibernate.criterion.Restrictions;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.hibernate.dao.EntityCriteria;+import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.manager.CommentVisitManager;-import com.pmease.gitplex.core.manager.UserManager;import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.CommentVisit;+import com.pmease.gitplex.core.model.CommitComment;+import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@Singleton@@ -24,18 +25,15 @@ public class DefaultCommentVisitManager implements CommentVisitManager {private final Dao dao;- private final UserManager userManager;-@Inject- public DefaultCommentVisitManager(Dao dao, UserManager userManager) {+ public DefaultCommentVisitManager(Dao dao) {this.dao = dao;- this.userManager = userManager;}@Override- public List<CommentVisit> findByCommitDates(Repository repository, Date fromDate, Date toDate) {+ public List<CommentVisit> findByCommitDates(Repository repository, User user,+ Date fromDate, Date toDate) {EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);- User user = userManager.getCurrent();criteria.add(Restrictions.eq("user", user));criteria.add(Restrictions.eq("repository", repository));if (fromDate != null)@@ -47,10 +45,9 @@ public class DefaultCommentVisitManager implements CommentVisitManager {}@Override- public List<CommentVisit> findByCommitOrDates(Repository repository,+ public List<CommentVisit> findByCommitOrDates(Repository repository, User user,String commit, Date fromDate, Date toDate) {EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);- User user = userManager.getCurrent();criteria.add(Restrictions.eq("user", user));criteria.add(Restrictions.eq("repository", repository));Conjunction conjunction = Restrictions.conjunction();@@ -64,9 +61,8 @@ public class DefaultCommentVisitManager implements CommentVisitManager {}@Override- public CommentVisit find(Repository repository, String commit, CommentPosition position) {+ public CommentVisit find(Repository repository, User user, String commit, CommentPosition position) {EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);- User user = userManager.getCurrent();criteria.add(Restrictions.eq("user", user));criteria.add(Restrictions.eq("repository", repository));criteria.add(Restrictions.eq("commit", commit));@@ -75,4 +71,19 @@ public class DefaultCommentVisitManager implements CommentVisitManager {return dao.find(criteria);}+ @Override+ public void visitComment(Repository repository, User user, CommitComment comment) {+ CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);+ CommentVisit visit = manager.find(repository, user, comment.getCommit(), comment.getPosition());+ if (visit == null) {+ visit = new CommentVisit();+ visit.setCommit(comment.getCommit());+ visit.setCommitDate(repository.getCommit(comment.getCommit()).getCommitter().getWhen());+ visit.setPosition(comment.getPosition());+ visit.setRepository(repository);+ visit.setUser(user);+ }+ visit.setVisitDate(comment.getCommentDate());+ GitPlex.getInstance(Dao.class).persist(visit);+ }}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.javaindex 6954f87731..4aa15da145 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java@@ -1,7 +1,10 @@package com.pmease.gitplex.core.manager.impl;+import java.util.ArrayList;import java.util.Date;+import java.util.HashMap;import java.util.List;+import java.util.Map;import javax.inject.Inject;import javax.inject.Singleton;@@ -13,7 +16,9 @@ import org.hibernate.criterion.Restrictions;import com.pmease.commons.hibernate.Sessional;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.hibernate.dao.EntityCriteria;+import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.manager.CommitCommentManager;+import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.Repository;@@ -81,4 +86,22 @@ public class DefaultCommitCommentManager implements CommitCommentManager {return dao.query(criteria, 0, 0);}+ @Override+ public Map<Integer, List<CommitComment>> findLineComments(Repository repository,+ String commit, String filePath) {+ Map<Integer, List<CommitComment>> comments = new HashMap<>();+ CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);+ for (CommitComment comment: manager.findByCommitAndFile(repository, commit, filePath)) {+ CommentPosition position = comment.getPosition();+ if (position.getLineNo() != null && position.getFilePath().equals(filePath)) {+ List<CommitComment> lineComments = comments.get(position.getLineNo());+ if (lineComments == null) {+ lineComments = new ArrayList<>();+ comments.put(position.getLineNo(), lineComments);+ }+ lineComments.add(comment);+ }+ }+ return comments;+ }}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.javaindex 43a8e23ead..138ca9e5a2 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java@@ -32,6 +32,10 @@ public class CommitComment extends AbstractEntity {@Column(nullable=false)private Date commentDate = new Date();++ private String oldCommit;++ private String newCommit;@Column(nullable=false)private String content;@@ -96,6 +100,22 @@ public class CommitComment extends AbstractEntity {this.position = position;}+ public String getOldCommit() {+ return oldCommit;+ }++ public void setOldCommit(String oldCommit) {+ this.oldCommit = oldCommit;+ }++ public String getNewCommit() {+ return newCommit;+ }++ public void setNewCommit(String newCommit) {+ this.newCommit = newCommit;+ }+@Overridepublic String toString() {return Objects.toStringHelper(CommitComment.class)diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.javaindex ffbbc5c2bc..e01eebae33 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java@@ -40,6 +40,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitplex.core.manager.CommentVisitManager;import com.pmease.gitplex.core.manager.CommitCommentManager;+import com.pmease.gitplex.core.manager.UserManager;@SuppressWarnings("serial")@Entity@@ -125,7 +126,7 @@ public class PullRequest extends AbstractEntity {private transient Map<String, Map<CommentPosition, Date>> commentVisits;- private transient List<Commit> commits;+ private transient List<String> commits;/*** Get title of this merge request.@@ -551,45 +552,41 @@ public class PullRequest extends AbstractEntity {public Map<String, Map<CommentPosition, Date>> getCommentVisits() {if (commentVisits == null) {commentVisits = new HashMap<>();- Map<String, Date> commits = new HashMap<>();- for (PullRequestUpdate update: updates) {- for (Commit commit: update.getCommits())- commits.put(commit.getHash(), commit.getCommitter().getWhen());- }- CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);- for (CommentVisit visit: manager.findByCommitOrDates(getTarget().getRepository(),- getBaseCommit(), Collections.min(commits.values()), Collections.max(commits.values()))) {- if (visit.getCommit().equals(getBaseCommit()) || commits.containsKey(visit.getCommit())) {- Map<CommentPosition, Date> visits = commentVisits.get(visit.getCommit());- if (visits == null) {- visits = new HashMap<>();- commentVisits.put(visit.getCommit(), visits);++ User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();+ if (currentUser != null) {+ Map<String, Date> commits = new HashMap<>();+ for (PullRequestUpdate update: updates) {+ for (Commit commit: update.getCommits())+ commits.put(commit.getHash(), commit.getCommitter().getWhen());+ }+ CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);+ for (CommentVisit visit: manager.findByCommitOrDates(getTarget().getRepository(), currentUser,+ getBaseCommit(), Collections.min(commits.values()), Collections.max(commits.values()))) {+ if (visit.getCommit().equals(getBaseCommit()) || commits.containsKey(visit.getCommit())) {+ Map<CommentPosition, Date> visits = commentVisits.get(visit.getCommit());+ if (visits == null) {+ visits = new HashMap<>();+ commentVisits.put(visit.getCommit(), visits);+ }+ visits.put(visit.getPosition(), visit.getVisitDate());}- visits.put(visit.getPosition(), visit.getVisitDate());}}}return commentVisits;}- public List<Commit> getCommits() {+ public List<String> getCommits() {if (commits == null) {commits = new ArrayList<>();- commits.add(getTarget().getRepository().git().showRevision(getBaseCommit()));+ commits.add(getBaseCommit());for (int i=getSortedUpdates().size()-1; i>=0; i--) {for (Commit commit: getSortedUpdates().get(i).getCommits())- commits.add(commit);+ commits.add(commit.getHash());}}return commits;}- public Commit getCommit(String hash) {- for (Commit each: getCommits()) {- if (hash.equals(each.getHash()))- return each;- }- throw new RuntimeException("Unable to find specified commit.");- }-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.javaindex cae76791b7..af5d0b736a 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java@@ -306,6 +306,8 @@ public class PullRequestUpdate extends AbstractEntity {}}+ getRequest().getTarget().getRepository().cacheCommits(commits);+Collections.reverse(commits);}return commits;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.javaindex 29f9cd178b..57ba1a655d 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java@@ -27,9 +27,10 @@ import org.hibernate.validator.constraints.NotEmpty;import com.google.common.base.Optional;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.git.BlobInfo;+import com.pmease.commons.git.BlobText;import com.pmease.commons.git.Change;+import com.pmease.commons.git.Commit;import com.pmease.commons.git.Git;-import com.pmease.commons.git.BlobText;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.loader.AppLoader;import com.pmease.commons.util.FileUtils;@@ -103,6 +104,8 @@ public class Repository extends AbstractEntity implements UserBelonging {private transient Map<CommitRange, List<Change>> changesCache = new HashMap<>();+ private transient Map<String, Commit> commitCache = new HashMap<>();+public User getOwner() {return owner;}@@ -407,10 +410,25 @@ public class Repository extends AbstractEntity implements UserBelonging {}return changes;}++ public Commit getCommit(String commitHash) {+ Commit commit = commitCache.get(commitHash);+ if (commit == null) {+ commit = git().showRevision(commitHash);+ commitCache.put(commitHash, commit);+ }+ return commit;+ }++ public void cacheCommits(List<Commit> commits) {+ for (Commit commit: commits)+ commitCache.put(commit.getHash(), commit);+ }private static class CommitRange extends Pair<String, String> {CommitRange(String fromCommit, String toCommit) {super(fromCommit, toCommit);}}+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.javaindex c6435143ba..bbed2776e6 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java@@ -43,7 +43,7 @@ public class User extends AbstractUser implements ProtectedObject {private Collection<CommitComment> commitComments = new ArrayList<>();@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)- private Collection<CommentVisit> threadVisits = new ArrayList<>();+ private Collection<CommentVisit> commentVisits = new ArrayList<>();@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)private Collection<Membership> memberships = new ArrayList<>();@@ -129,12 +129,12 @@ public class User extends AbstractUser implements ProtectedObject {this.commitComments = commitComments;}- public Collection<CommentVisit> getThreadVisits() {- return threadVisits;+ public Collection<CommentVisit> getCommentVisits() {+ return commentVisits;}- public void setThreadVisits(Collection<CommentVisit> threadVisits) {- this.threadVisits = threadVisits;+ public void setCommentVisits(Collection<CommentVisit> commentVisits) {+ this.commentVisits = commentVisits;}public Collection<Membership> getMemberships() {diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.javadeleted file mode 100644index 7ef8d94566..0000000000--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.java+++ /dev/null@@ -1,195 +0,0 @@-package com.pmease.gitplex.core.comment;--import static org.junit.Assert.assertEquals;--import java.io.ByteArrayInputStream;-import java.io.IOException;-import java.util.ArrayList;-import java.util.List;--import org.apache.commons.io.IOUtils;-import org.junit.Test;--import com.pmease.commons.git.AbstractGitTest;-import com.pmease.commons.git.BlobInfo;-import com.pmease.commons.git.Change;-import com.pmease.commons.git.Commit;-import com.pmease.commons.git.RevAwareChange;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;--public class CommentAwareChangeTest extends AbstractGitTest {-- @Test- public void test() {- final List<String> fileRevs = new ArrayList<>();- fileRevs.add(""- + "11\n" //comment1- + "22\n"- + "33\n"- + "44\n"- + "55\n" //comment3, comment6- + "66\n"- + "77\n"- + "88\n" //comment4- + "99\n");- fileRevs.add(""- + "111\n"- + "222\n"- + "33\n"- + "44\n"- + "55\n"- + "66\n"- + "77\n"- + "88\n"- + "99\n");- fileRevs.add(""- + "111\n"- + "222\n"- + "33\n"- + "44\n"- + "55\n"- + "66\n"- + "77\n"- + "888\n"- + "999\n");- fileRevs.add(""- + "111\n"- + "222\n" //comment2- + "33\n"- + "44\n" //comment5- + "555\n"- + "66\n"- + "77\n"- + "8888\n"- + "999\n"); //comment8, comment9-- addFileAndCommit("file1", fileRevs.get(0), "add file1");-- addFileAndCommit("file1", fileRevs.get(1), "modify file1");-- addFileAndCommit("file1", fileRevs.get(2), "modify file1");-- addFileAndCommit("file1", fileRevs.get(3), "modify file1");-- final List<Commit> commits = new ArrayList<>();- commits.add(git.showRevision("master~3"));- commits.add(git.showRevision("master~2"));- commits.add(git.showRevision("master~1"));- commits.add(git.showRevision("master"));-- CommentLoader commentLoader = new CommentLoader() {-- @Override- public List<CommitComment> loadComments(String commit) {- List<CommitComment> comments = new ArrayList<>();-- List<String> commitHashes = new ArrayList<>();- for (Commit each: commits)- commitHashes.add(each.getHash());-- int index = commitHashes.indexOf(commit);- if (index == 0) {- CommitComment comment = new CommitComment();- comment.setId(1L);- comment.setCommit(commit);- comment.setContent("comment1");- comment.setPosition(new CommentPosition("file1", 0));- comments.add(comment);- } else if (index == 1) {- CommitComment comment = new CommitComment();- comment.setId(2L);- comment.setCommit(commit);- comment.setContent("comment2");- comment.setPosition(new CommentPosition("file1", 1));- comments.add(comment);-- comment = new CommitComment();- comment.setId(3L);- comment.setCommit(commit);- comment.setContent("comment3");- comment.setPosition(new CommentPosition("file1", 4));- comments.add(comment);-- comment = new CommitComment();- comment.setId(4L);- comment.setCommit(commit);- comment.setContent("comment4");- comment.setPosition(new CommentPosition("file1", 7));- comments.add(comment);- } else if (index == 2) {- CommitComment comment = new CommitComment();- comment.setId(5L);- comment.setCommit(commit);- comment.setContent("comment5");- comment.setPosition(new CommentPosition("file1", 3));- comments.add(comment);-- comment = new CommitComment();- comment.setId(6L);- comment.setCommit(commit);- comment.setContent("comment6");- comment.setPosition(new CommentPosition("file1", 4));- comments.add(comment);-- comment = new CommitComment();- comment.setId(7L);- comment.setCommit(commit);- comment.setContent("comment7");- comment.setPosition(new CommentPosition("file1", 7));- comments.add(comment);-- comment = new CommitComment();- comment.setId(8L);- comment.setCommit(commit);- comment.setContent("comment8");- comment.setPosition(new CommentPosition("file1", 8));- comments.add(comment);- } else if (index == 3) {- CommitComment comment = new CommitComment();- comment.setId(9L);- comment.setCommit(commit);- comment.setContent("comment9");- comment.setPosition(new CommentPosition("file1", 8));- comments.add(comment);- }- return comments;- }-- };-- BlobLoader fileLoader = new BlobLoader() {-- @Override- public List<String> loadBlob(BlobInfo blobInfo) {- List<String> commitHashes = new ArrayList<>();- for (Commit each: commits)- commitHashes.add(each.getHash());-- int index = commitHashes.indexOf(blobInfo.getRevision());- String content = fileRevs.get(index);- try {- return IOUtils.readLines(new ByteArrayInputStream(content.getBytes()));- } catch (IOException e) {- throw new RuntimeException(e);- }- }-- };-- RevAwareChange change = new RevAwareChange(Change.Status.MODIFIED, "file1", "file1",- 0, 0, commits.get(0).getHash(), commits.get(3).getHash());-- CommentAwareChange commentAwareChange = new CommentAwareChange(change, commits, commentLoader, fileLoader);-- assertEquals("comment1", commentAwareChange.getOldComments().get(0).get(0).getContent());- assertEquals("comment2", commentAwareChange.getNewComments().get(1).get(0).getContent());- assertEquals("comment3", commentAwareChange.getOldComments().get(4).get(0).getContent());- assertEquals("comment4", commentAwareChange.getOldComments().get(7).get(0).getContent());- assertEquals("comment5", commentAwareChange.getNewComments().get(3).get(0).getContent());- assertEquals("comment6", commentAwareChange.getOldComments().get(4).get(1).getContent());- assertEquals("comment8", commentAwareChange.getNewComments().get(8).get(0).getContent());- assertEquals("comment9", commentAwareChange.getNewComments().get(8).get(1).getContent());- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.cssindex 2e419c2d70..62d2538ae6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css@@ -783,8 +783,6 @@ h2.section-title { margin: 18px 0; font-size: 16px; }.table-diff>tbody>tr>td {padding: 2px 8px;}.table-diff>tbody>tr>td.text, .table-diff>tbody>tr>td.detail, .table-diff>tbody>tr>td.new {border-left: 1px solid #E5E5E5;}-.table-diff .line.comments>td {border-top: 1px solid #E5E5E5; border-bottom: 1px solid #E5E5E5;- padding: 12px 0;}.table-diff .old.line.content>td.line-no {background: #faa; color: #8f0000;}.table-diff .old.line.content {background: #fdd;}.table-diff .old.line.content .emphasize {background: #FC9090;}@@ -795,8 +793,11 @@ h2.section-title { margin: 18px 0; font-size: 16px; }.table-diff .line.content:hover>td.line-no {background: #FBDE6D;}.table-diff table.content {width: 100%;}+.table-diff .line.comments>td {border-top: 1px solid #E5E5E5;+ border-bottom: 1px solid #E5E5E5; padding: 12px 0;}+.table-diff .line.comments>td.summary {padding: 12px;}+.table-diff .line.comments>td.summary .fa-bookmark {margin-bottom: 12px; color: #3A88F6; font-size: 24px;}.table-diff .line.comments>td.detail {padding: 12px;}-table.line-comments>tbody>tr>td {border-top: 1px dotted #BBB; padding-top: 12px;}table.line-comments>tbody>tr:FIRST-CHILD>td {border-top: none; padding-top: 0;}table.line-comments>tbody>tr>.avatar {width: 1%;}@@ -841,7 +842,7 @@ ul.diff-alerts {padding-left: 12px;}.comment-input>.tab-pane {padding: 12px 0;}.comment-input>.tab-pane>.preview {display: none;}-ul.threads li {border-left: 4px solid #F0F0F0; padding-left: 8px;}+ul.threads li {border-left: 4px solid #E5E5E5; padding-left: 8px;}ul.threads li.unread {border-color: #70AEFA;}ul.threads li a {color: #444; cursor: pointer;}ul.threads li .markdown {color: #888; margin-top: 4px;}@@ -910,7 +911,6 @@ ul.status-help li:last-child .description {border-bottom: none;}.request-detail>.status .check-result.alert-info .fa.fa-info-circle {display: inline;}.request-detail>.actions>div, .request-detail>.actions>.confirm>form>div {margin-bottom: 20px;}-.request-detail>.actions .btn {margin-right: 8px;}.request-detail .activities>tbody>tr>td {@@ -931,9 +931,7 @@ ul.status-help li:last-child .description {border-bottom: none;}.request-detail .base-threads>.content {margin-left: 6px;}.request-detail .compare>.head .comment {margin-right: 20px;}-.request-detail .compare>.head .old {margin-right: 20px;}.request-detail .compare>.head {border-bottom: 1px dashed #BBB; padding-bottom: 16px;}-.content>.commit-choice {max-height: 600px; padding: 8px 0; overflow-y: scroll;}.content>.commit-choice a {text-decoration: none; color: #333; display: block; padding: 8px;}.content>.commit-choice li {border-bottom: 1px dotted #BBB;}@@ -941,6 +939,10 @@ ul.status-help li:last-child .description {border-bottom: none;}.content>.commit-choice a .commit {font-family: Consolas, 'Liberation Mono', Courier, monospace;}.content>.commit-choice a .name {font-weight: bold;}.content>.commit-choice a .subject {font-size: 12px; color: #999;}+table.old-vs-new td {border-bottom: 1px dotted #BBB; padding: 0 8px;}+table.old-vs-new td.old {width: 140px; text-align: left;}+table.old-vs-new td.new {width: 140px; text-align: right;}+table.old-vs-new td.vs {width: 1px; text-align: center; font-weight: bold;}.request-detail .compare>.body {margin-top: 16px;}.request-detail .compare>.body>tbody>tr>td.nav {width: 1%;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.javaindex b053f04ec2..fd98ce3b1b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java@@ -29,7 +29,7 @@ public class BlobDiffPanel extends Panel {private final CommentAwareChange change;- public BlobDiffPanel(String id, IModel<Repository> repoModel, CommentAwareChange change, int lineNo) {+ public BlobDiffPanel(String id, IModel<Repository> repoModel, CommentAwareChange change) {super(id);this.repoModel = repoModel;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.htmlindex c5b212f26b..ddebfbb040 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html@@ -37,7 +37,8 @@</tr><tr wicket:id="commentsRow" class="line comments"><td colspan="2" class="summary">- <i class="fa fa-comment"></i> <span wicket:id="commentCount"></span>+ <div><i wicket:id="concernedFlag" class="fa fa-bookmark concerned-comments" title="Concerned"></i></div>+ <div><i class="fa fa-comment"></i> <span wicket:id="commentCount"></span></div></td><td class="detail"><table class="line-comments">diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.javaindex f4ebb7bb9d..464152042d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java@@ -16,6 +16,8 @@ import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.event.Broadcast;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.Form;@@ -28,6 +30,7 @@ import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;+import com.google.common.base.Preconditions;import com.pmease.commons.git.BlobText;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.util.diff.DiffLine;@@ -44,6 +47,7 @@ import com.pmease.commons.wicket.behavior.menu.MenuPanel;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.comment.CommentAwareChange;import com.pmease.gitplex.core.manager.AuthorizationManager;+import com.pmease.gitplex.core.manager.CommentVisitManager;import com.pmease.gitplex.core.manager.UserManager;import com.pmease.gitplex.core.model.CommentPosition;import com.pmease.gitplex.core.model.CommitComment;@@ -95,12 +99,15 @@ public class TextDiffPanel extends Panel {private List<DiffLine> diffs;- public TextDiffPanel(String id, final IModel<Repository> repoModel, BlobText oldText, BlobText newText,- CommentAwareChange change) {+ public TextDiffPanel(String id, final IModel<Repository> repoModel,+ BlobText oldText, BlobText newText, CommentAwareChange change) {super(id);this.repoModel = repoModel;- this.change= change;++ Preconditions.checkArgument(!change.getOldRevision().equals(change.getNewRevision()));++ this.change = change;this.oldText = oldText;this.newText = newText;@@ -226,7 +233,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((change.getOldComments() != null || change.getNewComments() != null) && showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && showComments);}}.add(new ScrollBehavior(head, ".comments.line", 50, false)));@@ -236,7 +243,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((change.getOldComments() != null || change.getNewComments() != null) && showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && showComments);}}.add(new ScrollBehavior(head, ".comments.line", 50, true)));@@ -251,7 +258,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((change.getOldComments() != null || change.getNewComments() != null) && !showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && !showComments);}});@@ -265,7 +272,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((change.getOldComments() != null || change.getNewComments() != null) && showComments);+ setVisible((getOldComments() != null || getNewComments() != null) && showComments);}});@@ -420,31 +427,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected List<CommitComment> load() {- List<CommitComment> oldLineComments = null;- if (change.getOldComments() != null)- oldLineComments = change.getOldComments().get(diffLine.getOldLineNo());-- if (oldLineComments == null)- oldLineComments = new ArrayList<>();-- List<CommitComment> newLineComments = null;- if (change.getNewComments() != null)- newLineComments = change.getNewComments().get(diffLine.getNewLineNo());-- if (newLineComments == null)- newLineComments = new ArrayList<>();-- if (diffLine.getAction() == DELETE) {- return oldLineComments;- } else if (diffLine.getAction() == ADD) {- return newLineComments;- } else {- List<CommitComment> comments = new ArrayList<>();- comments.addAll(oldLineComments);- comments.addAll(newLineComments);- Collections.sort(comments);- return comments;- }+ return getLineComments(diffLine);}};@@ -476,6 +459,16 @@ public class TextDiffPanel extends Panel {}}));+ commentsRow.add(new WebMarkupContainer("concernedFlag") {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(lineCommentsModel.getObject().contains(change.getConcernedComment()));+ }++ });commentsRow.add(new ListView<CommitComment>("comments", lineCommentsModel) {@Override@@ -553,20 +546,20 @@ public class TextDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {GitPlex.getInstance(Dao.class).remove(comment);- if (change.getOldComments() != null) {- List<CommitComment> lineComments = change.getOldComments().get(diffLine.getOldLineNo());+ if (getOldComments() != null) {+ List<CommitComment> lineComments = getOldComments().get(diffLine.getOldLineNo());if (lineComments != null) {lineComments.remove(comment);if (lineComments.isEmpty())- change.getOldComments().remove(diffLine.getOldLineNo());+ getOldComments().remove(diffLine.getOldLineNo());}}- if (change.getNewComments() != null) {- List<CommitComment> lineComments = change.getNewComments().get(diffLine.getNewLineNo());+ if (getNewComments() != null) {+ List<CommitComment> lineComments = getNewComments().get(diffLine.getNewLineNo());if (lineComments != null) {lineComments.remove(comment);if (lineComments.isEmpty())- change.getOldComments().remove(diffLine.getNewLineNo());+ getOldComments().remove(diffLine.getNewLineNo());}}target.add(commentsRow);@@ -666,6 +659,22 @@ public class TextDiffPanel extends Panel {return commentsRow.get(NEW_COMMENT_ID) instanceof Fragment;}+ private List<CommitComment> getLineComments(DiffLine line) {+ List<CommitComment> lineComments = new ArrayList<>();+ if (getOldComments() != null+ && getOldComments().containsKey(line.getOldLineNo())+ && line.getAction() != ADD) {+ lineComments.addAll(getOldComments().get(line.getOldLineNo()));+ }+ if (getNewComments() != null+ && getNewComments().containsKey(line.getNewLineNo())+ && line.getAction() != DELETE) {+ lineComments.addAll(getNewComments().get(line.getNewLineNo()));+ }+ Collections.sort(lineComments);+ return lineComments;+ }+private class AddCommentLink extends AjaxLink<Void> {private final ListItem<DiffLine> item;@@ -713,7 +722,8 @@ public class TextDiffPanel extends Panel {super.onSubmit(target, form);CommitComment comment = new CommitComment();comment.setRepository(repoModel.getObject());- comment.setUser(GitPlex.getInstance(UserManager.class).getCurrent());+ User currentUser = Preconditions.checkNotNull(GitPlex.getInstance(UserManager.class).getCurrent());+ comment.setUser(currentUser);String commit;CommentPosition position;if (diffLine.getAction() == DELETE) {@@ -722,28 +732,36 @@ public class TextDiffPanel extends Panel {} else if (diffLine.getAction() == ADD) {commit = change.getNewRevision();position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());- } else if (change.getNewComments() != null) {- commit = change.getNewRevision();- position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());} else {- commit = change.getOldRevision();- position = new CommentPosition(change.getOldPath(), diffLine.getOldLineNo());- }+ List<CommitComment> comments = getLineComments(diffLine);+ if (comments.isEmpty()) {+ if (getNewComments() != null) {+ commit = change.getNewRevision();+ position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());+ } else {+ commit = change.getOldRevision();+ position = new CommentPosition(change.getOldPath(), diffLine.getOldLineNo());+ }+ } else {+ CommitComment lastComment = comments.get(comments.size()-1);+ commit = lastComment.getCommit();+ position = lastComment.getPosition();+ }+ }comment.setCommit(commit);comment.setPosition(position);comment.setContent(input.getModelObject());comment.setCommentDate(new Date());- comment.setCommitDate(change.getCommit(commit).getCommitter().getWhen());- GitPlex.getInstance(Dao.class).persist(comment);+ comment.setCommitDate(repoModel.getObject().getCommit(commit).getCommitter().getWhen());+ if (commit.equals(change.getOldRevision()))+ comment.setNewCommit(change.getNewRevision());+ else+ comment.setOldCommit(change.getOldRevision());- if (diffLine.getAction() == DELETE)- addToComments(change.getOldComments(), diffLine.getOldLineNo(), comment);- else if (diffLine.getAction() == ADD)- addToComments(change.getNewComments(), diffLine.getNewLineNo(), comment);- else if (change.getNewComments() != null)- addToComments(change.getNewComments(), diffLine.getNewLineNo(), comment);- else- addToComments(change.getOldComments(), diffLine.getOldLineNo(), comment);+ change.saveComment(comment);++ GitPlex.getInstance(CommentVisitManager.class).visitComment(repoModel.getObject(),+ currentUser, comment);commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));target.add(commentsRow);@@ -761,15 +779,6 @@ public class TextDiffPanel extends Panel {target.add(commentsRow);}- private void addToComments(Map<Integer, List<CommitComment>> comments, int lineNo, CommitComment comment) {- List<CommitComment> lineComments = comments.get(lineNo);- if (lineComments == null) {- lineComments = new ArrayList<>();- comments.put(lineNo, lineComments);- }- lineComments.add(comment);- }-@Overrideprotected void onConfigure() {super.onConfigure();@@ -779,16 +788,38 @@ public class TextDiffPanel extends Panel {} else {DiffLine.Action action = item.getModelObject().getAction();if (action == DELETE)- setVisible(change.getOldComments() != null);+ setVisible(getOldComments() != null);else if (action == ADD)- setVisible(change.getNewComments() != null);+ setVisible(getNewComments() != null);else- setVisible(change.getOldComments() != null || change.getNewComments() != null);+ setVisible(getOldComments() != null || getNewComments() != null);}}}+ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);++ String cssClass;+ if (change.getConcernedComment() != null)+ cssClass = ".concerned-comments";+ else+ cssClass = ".diff-block:first";+ String script = String.format("pmease.commons.scroll.next('%s', '%s', %d);",+ get(HEAD_ID).getMarkupId(), cssClass, SCROLL_MARGIN);+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ private Map<Integer, List<CommitComment>> getOldComments() {+ return change.getOldComments();+ }++ private Map<Integer, List<CommitComment>> getNewComments() {+ return change.getNewComments();+ }+@Overrideprotected void onDetach() {repoModel.detach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/markdown/MarkdownPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/markdown/MarkdownPanel.javaindex cd6c2e5217..0efa6bd40a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/markdown/MarkdownPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/markdown/MarkdownPanel.java@@ -10,6 +10,7 @@ import org.apache.wicket.model.LoadableDetachableModel;import org.pegdown.LinkRenderer;import org.pegdown.PegDownProcessor;+import com.google.common.base.Strings;import com.pmease.gitplex.web.page.repository.info.code.blob.renderer.highlighter.AceHighlighter;@SuppressWarnings("serial")@@ -29,8 +30,12 @@ public class MarkdownPanel extends Panel {@Overrideprotected String load() {String markdown = MarkdownPanel.this.getDefaultModelObjectAsString();- PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);- return pd.markdownToHtml(markdown, new LinkRenderer());+ if (!Strings.isNullOrEmpty(markdown)) {+ PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);+ return pd.markdownToHtml(markdown, new LinkRenderer());+ } else {+ return "<i>Nothing to preview.</i>";+ }}}).setEscapeModelStrings(false));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.htmlindex 6e5edafc4a..dda3243eab 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.html@@ -4,7 +4,7 @@<a wicket:id="link"><span wicket:id="userAvatar" class="avatar"></span><span wicket:id="userName"></span>- commented on <span wicket:id="position"></span>+ commented on <em wicket:id="position"></em><span wicket:id="age"></span>,<span wicket:id="stats"></span> <i class="fa fa-arrow-slim-right"></i>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.javaindex 436360e299..d4e9fc9cfa 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java@@ -15,15 +15,11 @@ import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;import org.apache.wicket.request.mapper.parameter.PageParameters;-import com.pmease.commons.git.BriefCommit;-import com.pmease.commons.git.Commit;-import com.pmease.commons.hibernate.dao.Dao;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.comment.CommentThread;import com.pmease.gitplex.core.manager.CommentVisitManager;import com.pmease.gitplex.core.manager.UserManager;import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommentVisit;import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;@@ -38,18 +34,15 @@ public class CommentThreadPanel extends Panel {private final IModel<PullRequest> requestModel;- private final BriefCommit commit;-private final IModel<List<CommentThread>> threadsModel;private final IModel<Map<CommentPosition, Date>> visitsModel;- public CommentThreadPanel(String id, final IModel<PullRequest> requestModel, Commit commit,+ public CommentThreadPanel(String id, final IModel<PullRequest> requestModel,final IModel<List<CommentThread>> threadsModel,final IModel<Map<CommentPosition, Date>> visitsModel) {super(id);- this.commit = commit;this.requestModel = requestModel;this.visitsModel = visitsModel;this.threadsModel = threadsModel;@@ -76,17 +69,7 @@ public class CommentThreadPanel extends Panel {if (currentUser != null) {Repository repo = requestModel.getObject().getTarget().getRepository();CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);- CommentVisit visit = manager.find(repo, commit.getHash(), thread.getPosition());- if (visit == null) {- visit = new CommentVisit();- visit.setCommit(commit.getHash());- visit.setCommitDate(commit.getCommitter().getWhen());- visit.setPosition(thread.getPosition());- visit.setRepository(repo);- visit.setUser(currentUser);- }- visit.setVisitDate(thread.getLastComment().getCommentDate());- GitPlex.getInstance(Dao.class).persist(visit);+ manager.visitComment(repo, currentUser, thread.getLastComment());}if (thread.getPosition() == null) {// TODO: navigate to commit comments page@@ -95,7 +78,7 @@ public class CommentThreadPanel extends Panel {} else {PageParameters params = RequestComparePage.paramsOf(requestModel.getObject(),- null, null, null, thread.getLastComment().getId());+ null, null, null, thread.getLastComment());setResponsePage(RequestComparePage.class, params);}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.htmlindex 939587c4a0..17e446104b 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.html@@ -1,23 +1,23 @@<wicket:extend><div class="compare"><div wicket:id="compareHead" class="head clearfix">- <button wicket:id="locateComment" class="comment btn pull-left">- <i class="fa fa-comments"></i> <span wicket:id="label"></span>+ <button wicket:id="concernComment" class="comment btn pull-left">+ <span wicket:id="label"></span></button>- <div class="old pull-left">- <label>Original:</label>- <span class="btn btn-default" wicket:id="oldSelector">+ <div class="pull-left btn-group">+ <span class="btn btn-default old" wicket:id="oldSelector"><i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i></span>- <div wicket:id="oldChoices"></div>- </div>- <div class="new pull-left">- <label>Revised:</label>- <span class="btn btn-default" wicket:id="newSelector">+ <span wicket:id="comparisonSelector" class="btn btn-default" title="Commonly used comparisons">+ <i class="fa fa-arrow-left"></i> <i class="caret"></i> <i class="fa fa-arrow-right"></i>+ </span>+ <span class="btn btn-default new" wicket:id="newSelector"><i class="fa fa-commit"></i> <span wicket:id="label"></span> <i class="caret"></i></span>- <div wicket:id="newChoices"></div></div>+ <div wicket:id="oldChoices"></div>+ <div wicket:id="newChoices"></div>+ <div wicket:id="comparisonChoices"></div></div><table class="body"><tr>@@ -49,4 +49,15 @@</li></ul></wicket:fragment>+ <wicket:fragment wicket:id="comparisonChoiceFrag">+ <a wicket:id="link">+ <table class="old-vs-new">+ <tr>+ <td wicket:id="old" class="old"></td>+ <td class="vs">-vs-</td>+ <td wicket:id="new" class="new"></td>+ </tr>+ </table>+ </a>+ </wicket:fragment></wicket:extend>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.javaindex 469f939c8b..1a7e540641 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java@@ -31,12 +31,11 @@ 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.eclipse.jgit.lib.FileMode;import com.google.common.base.Preconditions;-import com.pmease.commons.git.BlobInfo;-import com.pmease.commons.git.BlobText;import com.pmease.commons.git.Change;import com.pmease.commons.git.Commit;import com.pmease.commons.git.GitUtils;@@ -46,10 +45,11 @@ import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.wicket.behavior.TooltipBehavior;import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;+import com.pmease.commons.wicket.behavior.menu.MenuBehavior;+import com.pmease.commons.wicket.behavior.menu.MenuItem;+import com.pmease.commons.wicket.behavior.menu.MenuPanel;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.BlobLoader;import com.pmease.gitplex.core.comment.CommentAwareChange;-import com.pmease.gitplex.core.comment.CommentLoader;import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.IntegrationInfo;import com.pmease.gitplex.core.model.PullRequest;@@ -64,7 +64,7 @@ public class RequestComparePage extends RequestDetailPage {private static final String HEAD_ID = "compareHead";- private static final String LOCATE_COMMENT_ID = "locateComment";+ private static final String CONCERN_COMMENT_ID = "concernComment";private static final String COMPARE_RESULT_ID = "compareResult";@@ -76,19 +76,9 @@ public class RequestComparePage extends RequestDetailPage {private String filePath;- private Long commentId;+ private final IModel<CommitComment> concernedCommentModel;- private IModel<CommitComment> commentModel = new LoadableDetachableModel<CommitComment>() {-- @Override- protected CommitComment load() {- Preconditions.checkNotNull(commentId);- return GitPlex.getInstance(Dao.class).load(CommitComment.class, commentId);- }-- };-- private IModel<Map<String, CommitDescription>> commitsModel =+ private final IModel<Map<String, CommitDescription>> commitsModel =new LoadableDetachableModel<Map<String, CommitDescription>>() {@Override@@ -97,8 +87,8 @@ public class RequestComparePage extends RequestDetailPage {PullRequest request = getPullRequest();String concernedCommit;- if (commentId != null)- concernedCommit = commentModel.getObject().getCommit();+ if (getConcernedComment() != null)+ concernedCommit = getConcernedComment().getCommit();elseconcernedCommit = null;@@ -155,7 +145,19 @@ public class RequestComparePage extends RequestDetailPage {super(params);filePath = params.get("path").toString();- commentId = params.get("comment").toOptionalLong();+ final Long concernedCommentId = params.get("comment").toOptionalLong();++ concernedCommentModel = new LoadableDetachableModel<CommitComment>() {++ @Override+ protected CommitComment load() {+ if (concernedCommentId != null)+ return GitPlex.getInstance(Dao.class).load(CommitComment.class, concernedCommentId);+ else+ return null;+ }++ };oldCommit = params.get("original").toString();newCommit = params.get("revised").toString();@@ -185,29 +187,25 @@ public class RequestComparePage extends RequestDetailPage {head.setOutputMarkupId(true);add(head);- AjaxLink<Void> link = new AjaxLink<Void>(LOCATE_COMMENT_ID) {+ AjaxLink<Void> link = new AjaxLink<Void>(CONCERN_COMMENT_ID) {@Overridepublic void onClick(AjaxRequestTarget target) {filePath = null;- CommitComment comment = commentModel.getObject();- CommentAwareChange change = getActiveChange();- if (change == null || !change.contains(comment)) {- change = locateChange(comment);- if (change != null) {- Component compareResult = newCompareResult(change.getStatus() != UNCHANGED);- getPage().replace(compareResult);- target.add(compareResult);-- BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change, -1);- getPage().replace(diffPanel);- target.add(diffPanel);-- target.add(this);- } else {- PageParameters params = paramsOf(getPullRequest(), null, null, null, commentId);- setResponsePage(RequestComparePage.class, params);- }+ CommentAwareChange change = resolveChange(getConcernedComment());+ if (change != null) {+ Component compareResult = newCompareResult(change.getStatus() != UNCHANGED);+ getPage().replace(compareResult);+ target.add(compareResult);++ BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change);+ getPage().replace(diffPanel);+ target.add(diffPanel);++ target.add(this);+ } else {+ PageParameters params = paramsOf(getPullRequest(), null, null, null, getConcernedComment());+ setResponsePage(RequestComparePage.class, params);}}@@ -215,7 +213,7 @@ public class RequestComparePage extends RequestDetailPage {protected void onConfigure() {super.onConfigure();- setVisible(commentId != null);+ setVisible(getConcernedComment() != null);}};@@ -226,11 +224,11 @@ public class RequestComparePage extends RequestDetailPage {Component panel = getPage().get(BLOB_DIFF_ID);if (panel instanceof BlobDiffPanel) {CommentAwareChange change = ((BlobDiffPanel) panel).getChange();- if (change.contains(commentModel.getObject()))- return "Displaying concerned comment line by comparing";+ if (change.contains(getConcernedComment()))+ return "Displaying concerned comments by comparing";}- return "Click to display concerned comment line";+ return "Click to display concerned comments";}}));@@ -241,8 +239,8 @@ public class RequestComparePage extends RequestDetailPage {Component panel = getPage().get(BLOB_DIFF_ID);if (panel instanceof BlobDiffPanel) {CommentAwareChange change = ((BlobDiffPanel) panel).getChange();- if (change.contains(commentModel.getObject()))- return "btn-default";+ if (change.contains(getConcernedComment()))+ return "btn-primary";}return "btn-warning";@@ -265,7 +263,17 @@ public class RequestComparePage extends RequestDetailPage {return GitUtils.abbreviateSHA(oldCommit);}- }));+ }).add(new TooltipBehavior(new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ CommitDescription description = commitsModel.getObject().get(oldCommit);+ Preconditions.checkNotNull(description);+ return description.getSubject();+ }++ })));+DropdownPanel oldChoicesDropdown = new DropdownPanel("oldChoices", false) {@Override@@ -277,17 +285,6 @@ public class RequestComparePage extends RequestDetailPage {head.add(oldChoicesDropdown);oldSelector.add(new DropdownBehavior(oldChoicesDropdown).alignWithTrigger(0, 0, 0, 100));- oldSelector.add(new TooltipBehavior(new LoadableDetachableModel<String>() {-- @Override- protected String load() {- CommitDescription description = commitsModel.getObject().get(oldCommit);- Preconditions.checkNotNull(description);- return description.getSubject();- }-- }));-WebMarkupContainer newSelector = new WebMarkupContainer("newSelector");head.add(newSelector);newSelector.add(new Label("label", new LoadableDetachableModel<String>() {@@ -303,7 +300,16 @@ public class RequestComparePage extends RequestDetailPage {return GitUtils.abbreviateSHA(newCommit);}- }));+ }).add(new TooltipBehavior(new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ CommitDescription description = commitsModel.getObject().get(newCommit);+ Preconditions.checkNotNull(description);+ return description.getSubject();+ }++ })));DropdownPanel newChoicesDropdown = new DropdownPanel("newChoices", false) {@Override@@ -314,19 +320,115 @@ public class RequestComparePage extends RequestDetailPage {};head.add(newChoicesDropdown);newSelector.add(new DropdownBehavior(newChoicesDropdown).alignWithTrigger(0, 0, 0, 100));-- newSelector.add(new TooltipBehavior(new LoadableDetachableModel<String>() {++ MenuPanel commonComparisons = new MenuPanel("comparisonChoices") {@Override- protected String load() {- CommitDescription description = commitsModel.getObject().get(newCommit);- Preconditions.checkNotNull(description);- return description.getSubject();+ protected List<MenuItem> getMenuItems() {+ List<MenuItem> items = new ArrayList<>();+ if (getConcernedComment() != null) {+ final String latestCommit = getPullRequest().getLatestUpdate().getHeadCommit();+ if (!getConcernedComment().getCommit().equals(latestCommit)) {+ items.add(new ComparisonChoiceItem("Concerned", "Latest") {++ @Override+ protected void onSelect() {+ PageParameters params = paramsOf(getPullRequest(),+ getConcernedComment().getCommit(), latestCommit, null, getConcernedComment());+ setResponsePage(RequestComparePage.class, params);+ }++ });+ }+ final String baseCommit = getPullRequest().getBaseCommit();+ if (!getConcernedComment().getCommit().equals(baseCommit)) {+ items.add(new ComparisonChoiceItem("Base", "Concerned") {++ @Override+ protected void onSelect() {+ PageParameters params = paramsOf(getPullRequest(),+ baseCommit, getConcernedComment().getCommit(), null, getConcernedComment());+ setResponsePage(RequestComparePage.class, params);+ }++ });+ }+ }+ items.add(new ComparisonChoiceItem("Base", "Latest") {++ @Override+ protected void onSelect() {+ PageParameters params = paramsOf(getPullRequest(),+ getPullRequest().getBaseCommit(),+ getPullRequest().getLatestUpdate().getHeadCommit(),+ filePath, getConcernedComment());+ setResponsePage(RequestComparePage.class, params);+ }++ });++ final IntegrationInfo integrationInfo = getPullRequest().getIntegrationInfo();+ if (getPullRequest().isOpen()+ && integrationInfo.getIntegrationHead() != null+ && !integrationInfo.getIntegrationHead().equals(integrationInfo.getRequestHead())) {+ items.add(new ComparisonChoiceItem("Latest", "Integration Preview") {++ @Override+ protected void onSelect() {+ PageParameters params = paramsOf(getPullRequest(),+ getPullRequest().getLatestUpdate().getHeadCommit(),+ integrationInfo.getIntegrationHead(),+ filePath, getConcernedComment());+ setResponsePage(RequestComparePage.class, params);+ }++ });+ }++ for (int i=0; i<getPullRequest().getSortedUpdates().size(); i++) {+ PullRequestUpdate update = getPullRequest().getSortedUpdates().get(i);+ final String baseCommit = update.getBaseCommit();+ final String headCommit = update.getHeadCommit();+ int index = getPullRequest().getSortedUpdates().size()-i;+ String oldLabel;+ if (index > 1)+ oldLabel = "Update #" + (index-1);+ else+ oldLabel = "Base";++ items.add(new ComparisonChoiceItem(oldLabel, "Update #" + index) {++ @Override+ protected void onSelect() {+ PageParameters params = paramsOf(getPullRequest(),+ baseCommit, headCommit, filePath, getConcernedComment());+ setResponsePage(RequestComparePage.class, params);+ }++ });+ }++ return items;}- }));-- add(new CheckBox("changesOnly").add(new OnChangeAjaxBehavior() {+ };++ head.add(commonComparisons);+ head.add(new WebMarkupContainer("comparisonSelector")+ .add(new MenuBehavior(commonComparisons)+ .alignWithTrigger(50, 100, 50, 0)));++ CommentAwareChange change = resolveChange();+ if (change != null) {+ BlobDiffPanel blobDiffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change);+ blobDiffPanel.setOutputMarkupId(true);+ add(blobDiffPanel);+ } else {+ add(new WebMarkupContainer(BLOB_DIFF_ID).setOutputMarkupId(true));+ }++ boolean changesOnly = (change == null || change.getStatus() != UNCHANGED);+ add(new CheckBox("changesOnly", Model.of(changesOnly)).add(new OnChangeAjaxBehavior() {@Overrideprotected void onUpdate(AjaxRequestTarget target) {@@ -338,80 +440,81 @@ public class RequestComparePage extends RequestDetailPage {}));- CommentAwareChange change = locateChange();- if (change != null) {- BlobDiffPanel blobDiffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change, -1);- blobDiffPanel.setOutputMarkupId(true);- add(blobDiffPanel);- } else {- add(new WebMarkupContainer(BLOB_DIFF_ID).setOutputMarkupId(true));- }-- add(newCompareResult(change == null || change.getStatus() != UNCHANGED));+ add(newCompareResult(changesOnly));}- private CommentAwareChange locateChange() {+ private CommentAwareChange resolveChange() {CommentAwareChange change = null;if (oldCommit != null) {if (filePath != null) {- change = locateChange(filePath);+ change = resolveChange(filePath);} else {- if (commentId != null)- change = locateChange(commentModel.getObject());+ if (getConcernedComment() != null)+ change = resolveChange(getConcernedComment());if (change == null) {List<Change> changes = getRepository().getChanges(oldCommit, newCommit);if (!changes.isEmpty())change = loadComments(new RevAwareChange(changes.get(0), oldCommit, newCommit));}}- } else if (commentId == null) {+ } else if (getConcernedComment() == null) {oldCommit = getPullRequest().getBaseCommit();newCommit = getPullRequest().getLatestUpdate().getHeadCommit();List<Change> changes = getRepository().getChanges(oldCommit, newCommit);if (!changes.isEmpty())change = loadComments(new RevAwareChange(changes.get(0), oldCommit, newCommit));} else {- CommitComment comment = commentModel.getObject();- oldCommit = getPullRequest().getBaseCommit();- newCommit = getPullRequest().getLatestUpdate().getHeadCommit();- change = locateChange(comment);- if (change == null) {+ CommitComment comment = getConcernedComment();+ if (commitsModel.getObject().containsKey(comment.getOldCommit())) {+ oldCommit = comment.getOldCommit();+ newCommit = comment.getCommit();+ } else if (commitsModel.getObject().containsKey(comment.getNewCommit())) {+ newCommit = comment.getNewCommit();+ oldCommit = comment.getCommit();+ } else if (!comment.getCommit().equals(getPullRequest().getLatestUpdate().getHeadCommit())) {oldCommit = comment.getCommit();newCommit = getPullRequest().getLatestUpdate().getHeadCommit();- change = locateChange(comment);- Preconditions.checkNotNull(change);+ } else {+ oldCommit = getPullRequest().getBaseCommit();+ newCommit = comment.getCommit();}+ change = resolveChange(comment);+ Preconditions.checkNotNull(change);}return change;}-- private CommentAwareChange locateChange(CommitComment comment) {++ @Nullable+ private CommentAwareChange resolveChange(CommitComment comment) {+ if (!comment.getCommit().equals(oldCommit) && !comment.getCommit().equals(newCommit))+ return null;++ boolean enableOldComments = getPullRequest().getCommits().contains(oldCommit);++ boolean enableNewComments = getPullRequest().getCommits().contains(newCommit);+String path = comment.getPosition().getFilePath();for (Change each: getRepository().getChanges(oldCommit, newCommit)) {if (path.equals(each.getPath())) {- CommentAwareChange change = loadComments(new RevAwareChange(each, oldCommit, newCommit));- if (change.contains(comment))- return change;- else- return null;+ CommentAwareChange change = new CommentAwareChange(+ getPullRequest().getTarget().getRepository(),+ new RevAwareChange(each, oldCommit, newCommit),+ enableOldComments, enableNewComments, comment);+ return change;}}List<TreeNode> nodes = getRepository().git().listTree(newCommit, comment.getPosition().getFilePath());- if (!nodes.isEmpty() && nodes.get(0).getMode() != FileMode.TYPE_TREE) {- RevAwareChange change = new RevAwareChange(UNCHANGED, path, path,- nodes.get(0).getMode(), nodes.get(0).getMode(), oldCommit, newCommit);- CommentAwareChange commentAwareChange = loadComments(change);- if (commentAwareChange.contains(comment))- return commentAwareChange;- else- return null;- } else {- return null;- }+ Preconditions.checkState(!nodes.isEmpty() && nodes.get(0).getMode() != FileMode.TYPE_TREE);+ RevAwareChange change = new RevAwareChange(UNCHANGED, path, path,+ nodes.get(0).getMode(), nodes.get(0).getMode(), oldCommit, newCommit);+ CommentAwareChange commentAwareChange = new CommentAwareChange(+ getPullRequest().getTarget().getRepository(), change,+ enableOldComments, enableNewComments, comment);+ return commentAwareChange;}- private CommentAwareChange locateChange(String filePath) {+ private CommentAwareChange resolveChange(String filePath) {for (Change each: getRepository().getChanges(oldCommit, newCommit)) {if (filePath.equals(each.getPath()))return loadComments(new RevAwareChange(each, oldCommit, newCommit));@@ -471,39 +574,13 @@ public class RequestComparePage extends RequestDetailPage {@Overridepublic void onDetach() {commitsModel.detach();- commentModel.detach();+ concernedCommentModel.detach();super.onDetach();}- private CommentAwareChange loadComments(RevAwareChange change) {- BlobLoader blobLoader = new BlobLoader() {-- @Override- public List<String> loadBlob(BlobInfo blobInfo) {- BlobText blobText = repoModel.getObject().getBlobText(blobInfo);- return blobText!=null?blobText.getLines():null;- }-- };- CommentLoader commentLoader = new CommentLoader() {-- @Override- public List<CommitComment> loadComments(String commit) {- List<CommitComment> comments = getPullRequest().getCommitComments().get(commit);- if (comments == null)- return new ArrayList<>();- else- return comments;- }-- };-- return new CommentAwareChange(change, getPullRequest().getCommits(), commentLoader, blobLoader);- }-public static PageParameters paramsOf(PullRequest request, @Nullable String oldCommit,- @Nullable String newCommit, @Nullable String filePath, @Nullable Long commentId) {+ @Nullable String newCommit, @Nullable String filePath, @Nullable CommitComment concernedComment) {PageParameters params = RequestDetailPage.params4(request);if (oldCommit != null)@@ -512,18 +589,44 @@ public class RequestComparePage extends RequestDetailPage {params.set("revised", newCommit);if (filePath != null)params.set("path", filePath);- if (commentId != null)- params.set("comment", commentId);+ if (concernedComment != null)+ params.set("comment", concernedComment.getId());return params;}+ private CommentAwareChange loadComments(RevAwareChange change) {+ boolean enableOldComments = getPullRequest().getCommits().contains(change.getOldRevision());+ boolean enableNewComments = getPullRequest().getCommits().contains(change.getNewRevision());+ return new CommentAwareChange(getRepository(), change, enableOldComments,+ enableNewComments, getConcernedComment());+ }++ @Override+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);++ if (event.getPayload() instanceof CommitCommentRemoved) {+ CommitCommentRemoved commitCommentRemoved = (CommitCommentRemoved) event.getPayload();+ CommitComment comment = commitCommentRemoved.getComment();+ if (comment.equals(getConcernedComment())) {+ PageParameters params = paramsOf(getPullRequest(), oldCommit, newCommit,+ comment.getPosition().getFilePath(), null);+ setResponsePage(RequestComparePage.class, params);+ }+ }+ }++ private CommitComment getConcernedComment() {+ return concernedCommentModel.getObject();+ }+private static class CommitDescription implements Serializable {private final String name;private final String subject;- public CommitDescription(final @Nullable String name, final String subject) {+ CommitDescription(final @Nullable String name, final String subject) {this.name = name;this.subject = subject;}@@ -542,7 +645,7 @@ public class RequestComparePage extends RequestDetailPage {private final boolean forBase;- public CommitChoicePanel(String id, boolean forBase) {+ CommitChoicePanel(String id, boolean forBase) {super(id, "commitChoiceFrag", RequestComparePage.this);this.forBase = forBase;@@ -576,10 +679,10 @@ public class RequestComparePage extends RequestDetailPage {Map.Entry<String, CommitDescription> entry = item.getModelObject();if (forBase) {setResponsePage(RequestComparePage.class,- paramsOf(getPullRequest(), entry.getKey(), newCommit, filePath, commentId));+ paramsOf(getPullRequest(), entry.getKey(), newCommit, filePath, getConcernedComment()));} else {setResponsePage(RequestComparePage.class,- paramsOf(getPullRequest(), oldCommit, entry.getKey(), filePath, commentId));+ paramsOf(getPullRequest(), oldCommit, entry.getKey(), filePath, getConcernedComment()));}}@@ -616,7 +719,7 @@ public class RequestComparePage extends RequestDetailPage {private final Change change;- public BlobLink(String id, Change change) {+ BlobLink(String id, Change change) {super(id);this.change = change;@@ -639,8 +742,7 @@ public class RequestComparePage extends RequestDetailPage {filePath = change.getPath();RevAwareChange revAwareChange = new RevAwareChange(change, oldCommit, newCommit);- BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel,- loadComments(revAwareChange), -1);+ BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, loadComments(revAwareChange));getPage().replace(diffPanel);target.add(diffPanel);@@ -651,25 +753,42 @@ public class RequestComparePage extends RequestDetailPage {target.add(this);- if (commentId != null)- target.add(getPage().get(HEAD_ID).get(LOCATE_COMMENT_ID));+ if (getConcernedComment() != null)+ target.add(getPage().get(HEAD_ID).get(CONCERN_COMMENT_ID));}}- @Override- public void onEvent(IEvent<?> event) {- super.onEvent(event);+ private abstract class ComparisonChoiceItem extends MenuItem {++ private final String oldName;- if (event.getPayload() instanceof CommitCommentRemoved) {- CommitCommentRemoved commitCommentRemoved = (CommitCommentRemoved) event.getPayload();- CommitComment comment = commitCommentRemoved.getComment();- if (comment.getId().equals(commentId)) {- PageParameters params = paramsOf(getPullRequest(), oldCommit, newCommit,- comment.getPosition().getFilePath(), null);- setResponsePage(RequestComparePage.class, params);- }+ private final String newName;++ ComparisonChoiceItem(String oldName, String newName) {+ this.oldName = oldName;+ this.newName = newName;+ }++ protected abstract void onSelect();++ @Override+ public Component newContent(String componentId) {+ Fragment fragment = new Fragment(componentId, "comparisonChoiceFrag", RequestComparePage.this);+ Link<Void> link = new Link<Void>("link") {++ @Override+ public void onClick() {+ onSelect();+ }++ };+ fragment.add(link);++ link.add(new Label("old", oldName));+ link.add(new Label("new", newName));++ return fragment;}}-}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.javaindex 2b032cc9df..2d61389576 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/UpdateCommitsPanel.java@@ -102,7 +102,7 @@ public class UpdateCommitsPanel extends Panel {return getUpdate().getRequest();}- }, commit, new LoadableDetachableModel<List<CommentThread>>() {+ }, new LoadableDetachableModel<List<CommentThread>>() {@Overrideprotected List<CommentThread> load() {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.javaindex f16b7fd17a..b766e68914 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/OpenActivityPanel.java@@ -18,7 +18,6 @@ import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;-import com.pmease.commons.git.Commit;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.comment.CommentThread;@@ -137,10 +136,7 @@ public class OpenActivityPanel extends Panel {super.onInitialize();add(renderForView());- PullRequest request = requestModel.getObject();- Commit baseCommit = request.getCommit(request.getBaseCommit());-- add(new CommentThreadPanel("baseThreads", requestModel, baseCommit, new LoadableDetachableModel<List<CommentThread>>() {+ add(new CommentThreadPanel("baseThreads", requestModel, new LoadableDetachableModel<List<CommentThread>>() {@Overrideprotected List<CommentThread> load() {