Skip to content

Commit 8da5f6d

Browse files
Add repositoryListType tree. Addresses #725, 527 and includes #1224
1 parent 6c06165 commit 8da5f6d

File tree

7 files changed

+437
-37
lines changed

7 files changed

+437
-37
lines changed

src/main/java/com/gitblit/wicket/panels/TreeNodeModel.java renamed to src/main/java/com/gitblit/models/TreeNodeModel.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
package com.gitblit.wicket.panels;
1+
package com.gitblit.models;
22

33
import java.io.Serializable;
44
import java.util.ArrayList;
5+
import java.util.Collections;
56
import java.util.List;
67

7-
import com.gitblit.models.RepositoryModel;
88
import com.gitblit.utils.StringUtils;
99

10-
public class TreeNodeModel implements Serializable {
10+
public class TreeNodeModel implements Serializable, Comparable<TreeNodeModel> {
1111

1212
private static final long serialVersionUID = 1L;
1313
final TreeNodeModel parent;
1414
final String name;
15-
private final List<TreeNodeModel> subFolders = new ArrayList<>();
16-
private final List<RepositoryModel> repositories = new ArrayList<>();
15+
final List<TreeNodeModel> subFolders = new ArrayList<>();
16+
final List<RepositoryModel> repositories = new ArrayList<>();
1717

1818
/**
1919
* Create a new tree root
2020
*/
2121
public TreeNodeModel() {
22-
this.name = "";
22+
this.name = "/";
2323
this.parent = null;
2424
}
2525

@@ -45,6 +45,7 @@ public int getDepth() {
4545
public TreeNodeModel add(String subFolder) {
4646
TreeNodeModel n = new TreeNodeModel(subFolder, this);
4747
subFolders.add(n);
48+
Collections.sort(subFolders);
4849
return n;
4950
}
5051

@@ -55,6 +56,7 @@ public TreeNodeModel add(String subFolder) {
5556
*/
5657
public void add(RepositoryModel repo) {
5758
repositories.add(repo);
59+
Collections.sort(repositories);
5860
}
5961

6062
/**
@@ -98,8 +100,21 @@ public TreeNodeModel getSubFolder(String path) {
98100
return getSubTreeNode(this, path, false);
99101
}
100102

103+
public List<Serializable> getTreeAsListForFrontend(){
104+
List<Serializable> l = new ArrayList<>();
105+
getTreeAsListForFrontend(l, this);
106+
return l;
107+
}
101108

102-
109+
private static void getTreeAsListForFrontend(List<Serializable> list, TreeNodeModel node) {
110+
list.add(node);
111+
for(TreeNodeModel t : node.subFolders) {
112+
getTreeAsListForFrontend(list, t);
113+
}
114+
for(RepositoryModel r : node.repositories) {
115+
list.add(r);
116+
}
117+
}
103118

104119
private static TreeNodeModel getSubTreeNode(TreeNodeModel node, String path, boolean create) {
105120
if(!StringUtils.isEmpty(path)) {
@@ -117,7 +132,7 @@ private static TreeNodeModel getSubTreeNode(TreeNodeModel node, String path, boo
117132
}
118133
}else {
119134
//traverse into subFolder
120-
String folderInCurrentHierarchyLevel = path.substring(0, path.indexOf('/'));
135+
String folderInCurrentHierarchyLevel = StringUtils.getFirstPathElement(path);
121136

122137
for(TreeNodeModel t : node.subFolders) {
123138
if(t.name.equals(folderInCurrentHierarchyLevel) ) {
@@ -139,4 +154,25 @@ private static TreeNodeModel getSubTreeNode(TreeNodeModel node, String path, boo
139154
private static boolean containsSubFolder(TreeNodeModel node, String path) {
140155
return getSubTreeNode(node, path, false) != null;
141156
}
157+
158+
@Override
159+
public int compareTo(TreeNodeModel t) {
160+
return StringUtils.compareRepositoryNames(name, t.name);
161+
}
162+
163+
public TreeNodeModel getParent() {
164+
return parent;
165+
}
166+
167+
public String getName() {
168+
return name;
169+
}
170+
171+
public List<TreeNodeModel> getSubFolders() {
172+
return subFolders;
173+
}
174+
175+
public List<RepositoryModel> getRepositories() {
176+
return repositories;
177+
}
142178
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
4+
xml:lang="en" lang="en">
5+
6+
<body>
7+
<wicket:panel>
8+
<tr style="background-color: #bbb" wicket:id="nodeHeader" data-row-type="folder"></tr>
9+
<tr wicket:id="subFolders">
10+
<span wicket:id="rowContent"></span>
11+
</tr>
12+
<wicket:container wicket:id="repositories">
13+
<tr wicket:id="rowContent" data-row-type="repo">
14+
<td wicket:id="firstColumn" class="left"
15+
style="padding-left: 3px;">
16+
<div style="border-left: 1px solid black; margin-left:6px; width: 19px;display: inline-block;float: left;"
17+
wicket:id="depth">&nbsp;</div>
18+
<span wicket:id="repoIcon"></span><span
19+
style="padding-left: 3px;" wicket:id="repositoryName">[repository
20+
name]</span>
21+
</td>
22+
<td class="hidden-phone"><span class="list"
23+
wicket:id="repositoryDescription">[repository description]</span></td>
24+
<td class="hidden-tablet hidden-phone author"><span
25+
wicket:id="repositoryOwner">[repository owner]</span></td>
26+
<td class="hidden-phone"
27+
style="text-align: right; padding-right: 10px;"><img
28+
class="inlineIcon" wicket:id="sparkleshareIcon" /><img
29+
class="inlineIcon" wicket:id="frozenIcon" /><img class="inlineIcon"
30+
wicket:id="federatedIcon" /><img class="inlineIcon"
31+
wicket:id="accessRestrictionIcon" /></td>
32+
<td><span wicket:id="repositoryLastChange">[last change]</span></td>
33+
<td class="rightAlign hidden-phone"
34+
style="text-align: right; padding-right: 15px;"><span
35+
style="font-size: 0.8em;" wicket:id="repositorySize">[repository
36+
size]</span></td>
37+
</tr>
38+
</wicket:container>
39+
40+
<wicket:fragment wicket:id="emptyFragment">
41+
</wicket:fragment>
42+
43+
<wicket:fragment wicket:id="repoIconFragment">
44+
<span class="octicon octicon-centered octicon-repo"></span>
45+
</wicket:fragment>
46+
47+
<wicket:fragment wicket:id="mirrorIconFragment">
48+
<span class="octicon octicon-centered octicon-mirror"></span>
49+
</wicket:fragment>
50+
51+
<wicket:fragment wicket:id="forkIconFragment">
52+
<span class="octicon octicon-centered octicon-repo-forked"></span>
53+
</wicket:fragment>
54+
55+
<wicket:fragment wicket:id="cloneIconFragment">
56+
<span class="octicon octicon-centered octicon-repo-push"
57+
wicket:message="title:gb.workingCopyWarning"></span>
58+
</wicket:fragment>
59+
60+
<wicket:fragment wicket:id="tableGroupMinusCollapsible">
61+
<i title="Click to expand/collapse" class="fa fa-minus-square-o table-group-collapsible" aria-hidden="true" style="padding-right:3px;cursor:pointer;"></i>
62+
</wicket:fragment>
63+
64+
<wicket:fragment wicket:id="tableGroupPlusCollapsible">
65+
<i title="Click to expand/collapse" class="fa fa-plus-square-o table-group-collapsible" aria-hidden="true" style="padding-right:3px;cursor:pointer;"></i>
66+
</wicket:fragment>
67+
68+
<wicket:fragment wicket:id="tableAllCollapsible">
69+
<i title="Click to expand all"
70+
class="fa fa-plus-square-o table-openall-collapsible"
71+
aria-hidden="true" style="padding-right: 3px; cursor: pointer;"></i>
72+
<i title="Click to collapse all"
73+
class="fa fa-minus-square-o table-closeall-collapsible"
74+
aria-hidden="true" style="padding-right: 3px; cursor: pointer;"></i>
75+
</wicket:fragment>
76+
77+
<wicket:fragment wicket:id="groupRepositoryHeader">
78+
<tr>
79+
<th class="left"><span wicket:id="allCollapsible"></span> <img
80+
style="vertical-align: middle;" src="git-black-16x16.png" /> <wicket:message
81+
key="gb.repository">Repository</wicket:message></th>
82+
<th class="hidden-phone"><span><wicket:message
83+
key="gb.description">Description</wicket:message></span></th>
84+
<th class="hidden-tablet hidden-phone"><span><wicket:message
85+
key="gb.owner">Owner</wicket:message></span></th>
86+
<th class="hidden-phone"></th>
87+
<th><wicket:message key="gb.lastChange">Last Change</wicket:message></th>
88+
<th class="right hidden-phone"></th>
89+
</tr>
90+
</wicket:fragment>
91+
92+
<wicket:fragment wicket:id="groupRepositoryRow">
93+
<td wicket:id="firstColumn" style="" colspan="1">
94+
<div style="border-left: 1px solid black; margin-left:6px; width: 19px; display: inline-block;float: left;"
95+
wicket:id="depth">&nbsp;</div>
96+
<span
97+
wicket:id="groupCollapsible"></span><span wicket:id="groupName">[group
98+
name]</span></td>
99+
<td colspan="6" style="padding: 2px;"><span class="hidden-phone"
100+
style="font-weight: normal; color: #666;"
101+
wicket:id="groupDescription">[description]</span></td>
102+
</wicket:fragment>
103+
104+
</wicket:panel>
105+
</body>
106+
</html>

0 commit comments

Comments
 (0)