Skip to content

The Unified and Autonomous Development Platform

Polished tree list component.

robin shine3a5334eee51e
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitPath.java b/commons.git/src/main/java/com/pmease/commons/git/GitPath.java
new file mode 100644
index 0000000000..3b07fe59fa
--- /dev/null
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitPath.java
@@ -0,0 +1,111 @@
+package com.pmease.commons.git;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nullable;
+
+import org.eclipse.jgit.lib.FileMode;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+
+public class GitPath implements Serializable, Comparable<GitPath> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String name;
+
+ private final int mode;
+
+ public GitPath(String name, int mode) {
+ this.name = name;
+ this.mode = mode;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getMode() {
+ return mode;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof GitPath)
+ return name.equals(((GitPath)obj).getName());
+ else
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public int compareTo(GitPath path) {
+ if (FileMode.TREE.equals(mode)) {
+ if (FileMode.TREE.equals(path.mode))
+ return compare(name, path.name);
+ else
+ return -1;
+ } else if (FileMode.TREE.equals(path.mode)) {
+ return 1;
+ } else {
+ return compare(name, path.name);
+ }
+ }
+
+ public static int compare(@Nullable String path1, @Nullable String path2) {
+ List<String> segments1 = split(path1);
+ List<String> segments2 = split(path2);
+
+ int index = 0;
+ for (String segment1: segments1) {
+ if (index<segments2.size()) {
+ int result = segment1.compareTo(segments2.get(index));
+ if (result != 0)
+ return result;
+ } else {
+ return 1;
+ }
+ index++;
+ }
+ if (index<segments2.size())
+ return -1;
+ else
+ return 0;
+ }
+
+ public static List<String> split(@Nullable String path) {
+ List<String> pathElements = new ArrayList<>();
+ if (path != null) {
+ for (String element: Splitter.on("/").split(path)) {
+ if (element.length() != 0)
+ pathElements.add(element);
+ }
+ }
+ return pathElements;
+ }
+
+ public static @Nullable String join(List<String> pathSegments) {
+ List<String> nonEmptyElements = new ArrayList<>();
+ for (String element: pathSegments){
+ if (element.length() != 0)
+ nonEmptyElements.add(element);
+ }
+ if (!nonEmptyElements.isEmpty()) {
+ return Joiner.on("/").join(nonEmptyElements);
+ } else {
+ return null;
+ }
+ }
+
+ public static @Nullable String normalize(@Nullable String path) {
+ return GitPath.join(GitPath.split(path));
+ }
+
+}
\ No newline at end of file
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
index 4a3570637a..f26ac45716 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
@@ -1,8 +1,6 @@
package com.pmease.commons.git;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
@@ -13,7 +11,6 @@ import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.util.SystemReader;
-import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
@@ -109,54 +106,5 @@ public class GitUtils {
return newPersonIdent(name, email, when);
}
-
- public static List<String> splitPath(@Nullable String path) {
- List<String> pathElements = new ArrayList<>();
- if (path != null) {
- for (String element: Splitter.on("/").split(path)) {
- if (element.length() != 0)
- pathElements.add(element);
- }
- }
- return pathElements;
- }
-
- public static @Nullable String joinPath(List<String> pathElements) {
- List<String> nonEmptyElements = new ArrayList<>();
- for (String element: pathElements){
- if (element.length() != 0)
- nonEmptyElements.add(element);
- }
- if (!nonEmptyElements.isEmpty()) {
- return Joiner.on("/").join(nonEmptyElements);
- } else {
- return null;
- }
- }
-
- public static @Nullable String normalizePath(@Nullable String path) {
- return joinPath(splitPath(path));
- }
-
- public static int comparePath(@Nullable String path1, @Nullable String path2) {
- List<String> segments1 = GitUtils.splitPath(path1);
- List<String> segments2 = GitUtils.splitPath(path2);
-
- int index = 0;
- for (String segment1: segments1) {
- if (index<segments2.size()) {
- int result = segment1.compareTo(segments2.get(index));
- if (result != 0)
- return result;
- } else {
- return 1;
- }
- index++;
- }
- if (index<segments2.size())
- return -1;
- else
- return 0;
- }
}
diff --git a/commons.git/src/main/java/org/eclipse/jgit/revwalk/LastCommitsOfChildren.java b/commons.git/src/main/java/org/eclipse/jgit/revwalk/LastCommitsOfChildren.java
index aac2e728a4..c87ad07208 100644
--- a/commons.git/src/main/java/org/eclipse/jgit/revwalk/LastCommitsOfChildren.java
+++ b/commons.git/src/main/java/org/eclipse/jgit/revwalk/LastCommitsOfChildren.java
@@ -24,7 +24,7 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.RawParseUtils;
import com.google.common.base.Throwables;
-import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.git.GitPath;
/**
* This class calculates last commits of children of a git tree.
@@ -67,7 +67,7 @@ public final class LastCommitsOfChildren extends HashMap<String, Value> {
public LastCommitsOfChildren(final Repository repo, AnyObjectId until,
@Nullable String treePath, @Nullable final Cache cache) {
try {
- treePath = GitUtils.normalizePath(treePath);
+ treePath = GitPath.normalize(treePath);
if (treePath == null)
treePath = "";
diff --git a/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java b/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java
index f809746222..61e5bd7092 100644
--- a/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java
+++ b/commons.git/src/test/java/com/pmease/commons/git/GitUtilsTest.java
@@ -22,12 +22,12 @@ public class GitUtilsTest extends AbstractGitTest {
@Test
public void testComparePath() {
- assertTrue(GitUtils.comparePath("dir1", "dir1/")==0);
- assertTrue(GitUtils.comparePath("/dir1", "dir1/")==0);
- assertTrue(GitUtils.comparePath("dir1", "dir2")<0);
- assertTrue(GitUtils.comparePath("dir1", "dir1/dir2")<0);
- assertTrue(GitUtils.comparePath("dir1/dir2/dir3/file", "dir1/dir3/file")<0);
- assertTrue(GitUtils.comparePath("dir12", "dir1/dir2")>0);
+ assertTrue(GitPath.compare("dir1", "dir1/")==0);
+ assertTrue(GitPath.compare("/dir1", "dir1/")==0);
+ assertTrue(GitPath.compare("dir1", "dir2")<0);
+ assertTrue(GitPath.compare("dir1", "dir1/dir2")<0);
+ assertTrue(GitPath.compare("dir1/dir2/dir3/file", "dir1/dir3/file")<0);
+ assertTrue(GitPath.compare("dir12", "dir1/dir2")>0);
}
}
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.java
index 276b0c8782..6ca4ec53b3 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
@@ -473,7 +473,7 @@ public class Repository extends AbstractEntity implements UserBelonging {
}
}
- public LastCommitsOfChildren getLastCommitsOfChildren(String revision, String path) {
+ public LastCommitsOfChildren getLastCommitsOfChildren(String revision, @Nullable String path) {
if (path == null)
path = "";
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/PathInfo.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/PathInfo.java
deleted file mode 100644
index c082e7edeb..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/PathInfo.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.pmease.gitplex.web;
-
-import java.io.Serializable;
-
-public class PathInfo implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final String path;
-
- private final int mode;
-
- public PathInfo(String path, int mode) {
- this.path = path;
- this.mode = mode;
- }
-
- public String getPath() {
- return path;
- }
-
- public int getMode() {
- return mode;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof PathInfo)
- return path.equals(((PathInfo)obj).getPath());
- else
- return false;
- }
-
- @Override
- public int hashCode() {
- return path.hashCode();
- }
-
-}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.html
index 9d135eb3f6..6057bdd971 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.html
@@ -1,10 +1,10 @@
<wicket:panel>
<div class="path-navigator clearfix">
- <span wicket:id="paths">
+ <div wicket:id="paths" class="pull-left clearfix">
<a wicket:id="link" class="pull-left"><span wicket:id="label"></span></a>
<a wicket:id="subtreeDropdownTrigger" class="subtree-dropdown-trigger pull-left"></a>
<div wicket:id="subtreeDropdown" class="subtree-dropdown"></div>
- </span>
+ </div>
</div>
<wicket:fragment wicket:id="treeNodeFrag">
<i wicket:id="icon"></i> <a wicket:id="link"><span wicket:id="label"></span></a>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.java
index e0d3301a2e..a0bbff920a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathnavigator/PathNavigator.java
@@ -2,6 +2,7 @@ package com.pmease.gitplex.web.component.pathnavigator;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -32,11 +33,11 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
+import com.pmease.commons.git.GitPath;
import com.pmease.commons.util.StringUtils;
import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;
import com.pmease.commons.wicket.behavior.dropdown.DropdownPanel;
import com.pmease.gitplex.core.model.Repository;
-import com.pmease.gitplex.web.PathInfo;
@SuppressWarnings("serial")
public abstract class PathNavigator extends GenericPanel<String> {
@@ -84,7 +85,7 @@ public abstract class PathNavigator extends GenericPanel<String> {
}
};
- link.setEnabled(item.getIndex() != size()-1);
+ link.setEnabled(item.getIndex() != getViewSize()-1);
if (path.length() != 0) {
if (path.indexOf('/') != -1)
@@ -117,14 +118,14 @@ public abstract class PathNavigator extends GenericPanel<String> {
@Override
protected Component newContent(String id) {
- return new NestedTree<PathInfo>(id, new ITreeProvider<PathInfo>() {
+ return new NestedTree<GitPath>(id, new ITreeProvider<GitPath>() {
@Override
public void detach() {
}
@Override
- public Iterator<? extends PathInfo> getRoots() {
+ public Iterator<? extends GitPath> getRoots() {
org.eclipse.jgit.lib.Repository jgitRepo = getRepository().openAsJGitRepo();
try {
RevTree revTree = new RevWalk(jgitRepo).parseCommit(getCommitId()).getTree();
@@ -138,9 +139,10 @@ public abstract class PathNavigator extends GenericPanel<String> {
}
treeWalk.setRecursive(false);
- List<PathInfo> roots = new ArrayList<>();
+ List<GitPath> roots = new ArrayList<>();
while (treeWalk.next())
- roots.add(new PathInfo(treeWalk.getPathString(), treeWalk.getRawMode(0)));
+ roots.add(new GitPath(treeWalk.getPathString(), treeWalk.getRawMode(0)));
+ Collections.sort(roots);
return roots.iterator();
} catch (IOException e) {
throw new RuntimeException(e);
@@ -150,18 +152,18 @@ public abstract class PathNavigator extends GenericPanel<String> {
}
@Override
- public boolean hasChildren(PathInfo pathInfo) {
- return FileMode.TREE.equals(pathInfo.getMode());
+ public boolean hasChildren(GitPath path) {
+ return FileMode.TREE.equals(path.getMode());
}
@Override
- public Iterator<? extends PathInfo> getChildren(PathInfo pathInfo) {
- return PathNavigator.this.getChildren(pathInfo).iterator();
+ public Iterator<? extends GitPath> getChildren(GitPath path) {
+ return PathNavigator.this.getChildren(path).iterator();
}
@Override
- public IModel<PathInfo> model(PathInfo pathInfo) {
- return Model.of(pathInfo);
+ public IModel<GitPath> model(GitPath path) {
+ return Model.of(path);
}
}) {
@@ -173,17 +175,17 @@ public abstract class PathNavigator extends GenericPanel<String> {
}
@Override
- public void expand(PathInfo pathInfo) {
+ public void expand(GitPath pathInfo) {
super.expand(pathInfo);
- List<PathInfo> children = getChildren(pathInfo);
+ List<GitPath> children = getChildren(pathInfo);
if (children.size() == 1 && FileMode.TREE.equals(children.get(0).getMode()))
expand(children.get(0));
}
@Override
- protected Component newContentComponent(String id, final IModel<PathInfo> model) {
- PathInfo pathInfo = model.getObject();
+ protected Component newContentComponent(String id, final IModel<GitPath> model) {
+ GitPath pathInfo = model.getObject();
Fragment fragment = new Fragment(id, "treeNodeFrag", PathNavigator.this);
WebMarkupContainer icon = new WebMarkupContainer("icon");
@@ -204,15 +206,15 @@ public abstract class PathNavigator extends GenericPanel<String> {
@Override
public void onClick(AjaxRequestTarget target) {
- selectPath(target, model.getObject().getPath());
+ selectPath(target, model.getObject().getName());
hide(target);
}
};
- if (pathInfo.getPath().indexOf('/') != -1)
- link.add(new Label("label", StringUtils.substringAfterLast(pathInfo.getPath(), "/")));
+ if (pathInfo.getName().indexOf('/') != -1)
+ link.add(new Label("label", StringUtils.substringAfterLast(pathInfo.getName(), "/")));
else
- link.add(new Label("label", pathInfo.getPath()));
+ link.add(new Label("label", pathInfo.getName()));
fragment.add(link);
return fragment;
@@ -250,17 +252,18 @@ public abstract class PathNavigator extends GenericPanel<String> {
target.add(this);
}
- private List<PathInfo> getChildren(PathInfo pathInfo) {
+ private List<GitPath> getChildren(GitPath pathInfo) {
org.eclipse.jgit.lib.Repository jgitRepo = getRepository().openAsJGitRepo();
try {
RevTree revTree = new RevWalk(jgitRepo).parseCommit(getCommitId()).getTree();
- TreeWalk treeWalk = TreeWalk.forPath(jgitRepo, pathInfo.getPath(), revTree);
+ TreeWalk treeWalk = TreeWalk.forPath(jgitRepo, pathInfo.getName(), revTree);
treeWalk.setRecursive(false);
treeWalk.enterSubtree();
- List<PathInfo> children = new ArrayList<>();
+ List<GitPath> children = new ArrayList<>();
while (treeWalk.next())
- children.add(new PathInfo(treeWalk.getPathString(), treeWalk.getRawMode(0)));
+ children.add(new GitPath(treeWalk.getPathString(), treeWalk.getRawMode(0)));
+ Collections.sort(children);
return children;
} catch (IOException e) {
throw new RuntimeException(e);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.html
index 817f7c3d6d..1b40723f1d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.html
@@ -2,7 +2,7 @@
<table class="tree-list">
<tr wicket:id="parent" class="parent">
<td colspan="3">
- <i class="fa fa-level-up"></i> <a wicket:id="link">..</a>
+ <a wicket:id="link"><i class="fa fa-level-up"></i> <span>..</span></a>
</td>
</tr>
<tr wicket:id="children" class="child">
@@ -10,9 +10,9 @@
<i wicket:id="pathIcon"></i>
<a wicket:id="pathLink"><span wicket:id="label"></span></a>
</td>
- <td class="last-commit-summary">
+ <td class="last-commit summary">
</td>
- <td class="last-commit-date">
+ <td class="last-commit age">
</td>
</tr>
</table>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.java
index ddbb60abb3..fb6625a677 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/TreeList.java
@@ -2,12 +2,22 @@ package com.pmease.gitplex.web.component.treelist;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
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.head.JavaScriptHeaderItem;
+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.list.ListItem;
@@ -15,16 +25,25 @@ import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.LastCommitsOfChildren;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
-import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.git.GitPath;
+import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.model.Repository;
-import com.pmease.gitplex.web.PathInfo;
+import com.pmease.gitplex.web.page.repository.code.commit.RepoCommitPage;
+import com.pmease.gitplex.web.util.DateUtils;
@SuppressWarnings("serial")
public abstract class TreeList extends GenericPanel<String> {
@@ -34,7 +53,7 @@ public abstract class TreeList extends GenericPanel<String> {
}
private String getNormalizedPath() {
- return GitUtils.normalizePath(getModelObject());
+ return GitPath.normalize(getModelObject());
}
@Override
@@ -65,10 +84,10 @@ public abstract class TreeList extends GenericPanel<String> {
});
add(parent);
- add(new ListView<PathInfo>("children", new LoadableDetachableModel<List<PathInfo>>() {
+ add(new ListView<GitPath>("children", new LoadableDetachableModel<List<GitPath>>() {
@Override
- protected List<PathInfo> load() {
+ protected List<GitPath> load() {
String path = getNormalizedPath();
org.eclipse.jgit.lib.Repository jgitRepo = getRepository().openAsJGitRepo();
try {
@@ -87,9 +106,29 @@ public abstract class TreeList extends GenericPanel<String> {
treeWalk = new TreeWalk(jgitRepo);
treeWalk.addTree(revTree);
}
- List<PathInfo> children = new ArrayList<>();
+ List<GitPath> children = new ArrayList<>();
while (treeWalk.next())
- children.add(new PathInfo(treeWalk.getPathString(), treeWalk.getRawMode(0)));
+ children.add(new GitPath(treeWalk.getPathString(), treeWalk.getRawMode(0)));
+ for (int i=0; i<children.size(); i++) {
+ GitPath gitPath = children.get(i);
+ while (FileMode.TREE.equals(gitPath.getMode())) {
+ treeWalk = TreeWalk.forPath(jgitRepo, gitPath.getName(), revTree);
+ Preconditions.checkNotNull(treeWalk);
+ treeWalk.enterSubtree();
+ if (treeWalk.next()) {
+ GitPath childGitPath = new GitPath(treeWalk.getPathString(), treeWalk.getRawMode(0));
+ if (treeWalk.next())
+ break;
+ else
+ gitPath = childGitPath;
+ } else {
+ break;
+ }
+ }
+ children.set(i, gitPath);
+ }
+
+ Collections.sort(children);
return children;
} catch (IOException e) {
throw new RuntimeException(e);
@@ -101,8 +140,8 @@ public abstract class TreeList extends GenericPanel<String> {
}) {
@Override
- protected void populateItem(ListItem<PathInfo> item) {
- final PathInfo pathInfo = item.getModelObject();
+ protected void populateItem(ListItem<GitPath> item) {
+ final GitPath pathInfo = item.getModelObject();
WebMarkupContainer pathIcon = new WebMarkupContainer("pathIcon");
String iconClass;
@@ -122,19 +161,60 @@ public abstract class TreeList extends GenericPanel<String> {
@Override
public void onClick(AjaxRequestTarget target) {
- selectPath(target, pathInfo.getPath());
+ selectPath(target, pathInfo.getName());
}
};
- if (pathInfo.getPath().indexOf('/') != -1)
- pathLink.add(new Label("label", StringUtils.substringAfterLast(pathInfo.getPath(), "/")));
+
+ String parentPath = getNormalizedPath();
+ if (parentPath != null)
+ pathLink.add(new Label("label", pathInfo.getName().substring(parentPath.length()+1)));
else
- pathLink.add(new Label("label", pathInfo.getPath()));
+ pathLink.add(new Label("label", pathInfo.getName()));
item.add(pathLink);
}
});
+ add(new AbstractDefaultAjaxBehavior() {
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ LastCommitsOfChildren lastCommits = getRepository().getLastCommitsOfChildren(
+ getRevision(), getModelObject());
+
+ Map<String, LastCommitInfo> map = new HashMap<>();
+ for (Map.Entry<String, LastCommitsOfChildren.Value> entry: lastCommits.entrySet()) {
+ LastCommitInfo info = new LastCommitInfo();
+ PageParameters params = RepoCommitPage.paramsOf(
+ getRepository(), entry.getValue().getId().name());
+ info.url = RequestCycle.get().urlFor(RepoCommitPage.class, params).toString();
+ info.summary = entry.getValue().getSummary();
+ info.age = DateUtils.formatAge(new Date(entry.getValue().getTimestamp()*1000L));
+ map.put(entry.getKey(), info);
+ }
+ String json;
+ try {
+ json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(map);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ String script = String.format("gitplex.treelist.renderLastCommits('%s', %s);",
+ getMarkupId(), json);
+ target.appendJavaScript(script);
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+
+ response.render(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(TreeList.class, "tree-list.js")));
+ response.render(CssHeaderItem.forReference(new CssResourceReference(TreeList.class, "tree-list.css")));
+ response.render(OnDomReadyHeaderItem.forScript(getCallbackScript()));
+ }
+
+ });
+
setOutputMarkupId(true);
}
@@ -152,5 +232,13 @@ public abstract class TreeList extends GenericPanel<String> {
protected abstract Repository getRepository();
protected abstract String getRevision();
-
+
+ @SuppressWarnings("unused")
+ private static class LastCommitInfo {
+ String url;
+
+ String summary;
+
+ String age;
+ }
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/tree-list.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/tree-list.css
new file mode 100644
index 0000000000..502da9ac21
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/tree-list.css
@@ -0,0 +1,5 @@
+table.tree-list {width: 100%; border: 1px solid #DDD;}
+table.tree-list>tbody>tr>td {padding: 6px 8px; background: #F9F9F9; border-top: 1px solid #EEE; vertical-align: top;}
+table.tree-list>tbody>tr:first-child>td {border-top: none;}
+table.tree-list .last-commit a, .tree-list .last-commit {color: #666;}
+table.tree-list tr.parent td a span {font-size: 18px;}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/tree-list.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/tree-list.js
new file mode 100644
index 0000000000..f2ae92edff
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/treelist/tree-list.js
@@ -0,0 +1,17 @@
+gitplex.treelist = {
+ renderLastCommits: function(containerId, lastCommits) {
+ var $table = $("#" + containerId).find("table.tree-list");
+ $table.find("tr.child").each(function() {
+ var $row = $(this);
+ var path = $row.find("td.path span").text();
+ var index = path.indexOf('/');
+ if (index != -1)
+ path = path.substring(0, index);
+ var lastCommit = lastCommits[path];
+
+ var $summary = $row.children(".last-commit.summary");
+ $summary.append("<a href='" + lastCommit.url + "'>" + lastCommit.summary + "</a>");
+ $row.children(".last-commit.age").append(lastCommit.age);
+ });
+ }
+}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java
index 13239ab19c..5aff263190 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/RepositoryPage.java
@@ -23,7 +23,7 @@ import org.eclipse.jgit.lib.Constants;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.git.GitPath;
import com.pmease.commons.wicket.component.tabbable.Tab;
import com.pmease.commons.wicket.component.tabbable.Tabbable;
import com.pmease.gitplex.core.GitPlex;
@@ -108,8 +108,8 @@ public abstract class RepositoryPage extends AccountBasePage {
}
repoModel = new RepositoryModel(repository);
- currentRevision = GitUtils.normalizePath(params.get(PARAM_REVISION).toString());
- currentPath = GitUtils.normalizePath(params.get(PARAM_PATH).toString());
+ currentRevision = GitPath.normalize(params.get(PARAM_REVISION).toString());
+ currentPath = GitPath.normalize(params.get(PARAM_PATH).toString());
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/commits/RepoCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/commits/RepoCommitsPage.java
index 77c83dd31e..1123ed9b85 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/commits/RepoCommitsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/commits/RepoCommitsPage.java
@@ -15,7 +15,7 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
-import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.git.GitPath;
import com.pmease.commons.git.command.LogCommand;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.page.repository.NoCommitsPage;
@@ -87,7 +87,7 @@ public class RepoCommitsPage extends RepositoryPage {
// }));
add(newNavLink("home", -1));
- add(new ListView<String>("pathSegments", GitUtils.splitPath(currentPath)) {
+ add(new ListView<String>("pathSegments", GitPath.split(currentPath)) {
@Override
protected void populateItem(ListItem<String> item) {
@@ -110,7 +110,7 @@ public class RepoCommitsPage extends RepositoryPage {
}
private Component newNavLink(String id, final int pathNum) {
- List<String> all = GitUtils.splitPath(currentPath);
+ List<String> all = GitPath.split(currentPath);
BookmarkablePageLink<Void> link = new BookmarkablePageLink<Void>(id,
RepoCommitsPage.class,
@@ -123,7 +123,7 @@ public class RepoCommitsPage extends RepositoryPage {
if (pathNum < 0) {
return getRepository().getName();
} else {
- List<String> all = GitUtils.splitPath(currentPath);
+ List<String> all = GitPath.split(currentPath);
return all.get(pathNum);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/component/PathsBreadcrumb.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/component/PathsBreadcrumb.java
index 398d77275b..5ea37df544 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/component/PathsBreadcrumb.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/component/PathsBreadcrumb.java
@@ -9,7 +9,7 @@ import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
-import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.git.GitPath;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.page.repository.RepositoryPage;
import com.pmease.gitplex.web.page.repository.code.tree.RepoTreePage;
@@ -47,7 +47,7 @@ public class PathsBreadcrumb extends Panel {
}
}));
- ListView<String> pathsView = new ListView<String>("paths", GitUtils.splitPath(currentPath)) {
+ ListView<String> pathsView = new ListView<String>("paths", GitPath.split(currentPath)) {
@Override
protected void populateItem(ListItem<String> item) {
@@ -58,7 +58,7 @@ public class PathsBreadcrumb extends Panel {
RepoTreePage.class,
RepoTreePage.paramsOf(repoModel.getObject(),
currentRevision,
- GitUtils.joinPath(GitUtils.splitPath(currentPath).subList(0, item.getIndex() + 1))));
+ GitPath.join(GitPath.split(currentPath).subList(0, item.getIndex() + 1))));
item.add(link);
link.add(new Label("name", path));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/tree/RepoTreePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/tree/RepoTreePanel.java
index 4f41900c22..ee16777fb1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/tree/RepoTreePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/tree/RepoTreePanel.java
@@ -24,6 +24,7 @@ import org.eclipse.jgit.lib.FileMode;
import com.google.common.collect.Iterables;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
+import com.pmease.commons.git.GitPath;
import com.pmease.commons.git.GitUtils;
import com.pmease.commons.git.TreeNode;
import com.pmease.gitplex.core.model.Repository;
@@ -101,13 +102,13 @@ public class RepoTreePanel extends Panel {
}
}));
- List<String> pathElements = GitUtils.splitPath(currentPath);
+ List<String> pathElements = GitPath.split(currentPath);
if (pathElements.isEmpty()) {
add(new WebMarkupContainer("parent").setVisibilityAllowed(false));
} else {
BookmarkablePageLink<Void> link = new BookmarkablePageLink<Void>("parent",
RepoTreePage.class,
- RepoTreePage.paramsOf(repoModel.getObject(), currentRevision, GitUtils.joinPath(pathElements.subList(0, pathElements.size() - 1))));
+ RepoTreePage.paramsOf(repoModel.getObject(), currentRevision, GitPath.join(pathElements.subList(0, pathElements.size() - 1))));
add(link);
}
@@ -137,11 +138,11 @@ public class RepoTreePanel extends Panel {
return "fa-file-text-o";
}})));
- List<String> pathElements = GitUtils.splitPath(currentPath);
+ List<String> pathElements = GitPath.split(currentPath);
pathElements.add(node.getName());
PageParameters params = RepositoryPage.paramsOf(repoModel.getObject(),
- currentRevision, GitUtils.joinPath(pathElements));
+ currentRevision, GitPath.join(pathElements));
AbstractLink link;
if (node.getMode() == FileMode.TYPE_TREE) {