commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
5fe7df
|
16 |
package com.gitblit.wicket.pages;
|
JM |
17 |
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
import org.apache.wicket.PageParameters;
|
|
21 |
import org.apache.wicket.markup.html.basic.Label;
|
1a3fc5
|
22 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
ff17f7
|
23 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
1a3fc5
|
24 |
import org.apache.wicket.markup.html.panel.Fragment;
|
5fe7df
|
25 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
26 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
27 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
f08c1c
|
28 |
import org.eclipse.jgit.lib.FileMode;
|
5fe7df
|
29 |
import org.eclipse.jgit.lib.Repository;
|
JM |
30 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
31 |
|
1f9dae
|
32 |
import com.gitblit.models.PathModel;
|
eb870f
|
33 |
import com.gitblit.models.SubmoduleModel;
|
ff17f7
|
34 |
import com.gitblit.servlet.RawServlet;
|
5fe7df
|
35 |
import com.gitblit.utils.ByteFormat;
|
JM |
36 |
import com.gitblit.utils.JGitUtils;
|
a7db57
|
37 |
import com.gitblit.wicket.CacheControl;
|
JM |
38 |
import com.gitblit.wicket.CacheControl.LastModified;
|
5fe7df
|
39 |
import com.gitblit.wicket.WicketUtils;
|
c1c3c6
|
40 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
59b817
|
41 |
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
|
1f9dae
|
42 |
import com.gitblit.wicket.panels.LinkPanel;
|
5fe7df
|
43 |
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
|
JM |
44 |
|
a7db57
|
45 |
@CacheControl(LastModified.BOOT)
|
5fe7df
|
46 |
public class TreePage extends RepositoryPage {
|
JM |
47 |
|
|
48 |
public TreePage(PageParameters params) {
|
cebf45
|
49 |
super(params);
|
5fe7df
|
50 |
|
f602a2
|
51 |
final String path = WicketUtils.getPath(params);
|
5fe7df
|
52 |
|
JM |
53 |
Repository r = getRepository();
|
bc9d4a
|
54 |
RevCommit commit = getCommit();
|
a9a2ff
|
55 |
List<PathModel> paths = JGitUtils.getFilesInPath2(r, path, commit);
|
5fe7df
|
56 |
|
JM |
57 |
// tree page links
|
2a7306
|
58 |
add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
|
JM |
59 |
WicketUtils.newPathParameter(repositoryName, objectId, path)));
|
59b817
|
60 |
add(new CompressedDownloadsPanel("compressedLinks", getRequest()
|
JM |
61 |
.getRelativePathPrefixToContextRoot(), repositoryName, objectId, path));
|
608ece
|
62 |
|
c1c3c6
|
63 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
5fe7df
|
64 |
|
JM |
65 |
// breadcrumbs
|
f602a2
|
66 |
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
|
JM |
67 |
if (path != null && path.trim().length() > 0) {
|
28d6b2
|
68 |
// add .. parent path entry
|
JM |
69 |
String parentPath = null;
|
|
70 |
if (path.lastIndexOf('/') > -1) {
|
|
71 |
parentPath = path.substring(0, path.lastIndexOf('/'));
|
|
72 |
}
|
eb870f
|
73 |
PathModel model = new PathModel("..", parentPath, 0, FileMode.TREE.getBits(), null, objectId);
|
28d6b2
|
74 |
model.isParentPath = true;
|
JM |
75 |
paths.add(0, model);
|
5fe7df
|
76 |
}
|
JM |
77 |
|
ab1e11
|
78 |
final String id = getBestCommitId(commit);
|
5fe7df
|
79 |
final ByteFormat byteFormat = new ByteFormat();
|
2179fb
|
80 |
final String baseUrl = WicketUtils.getGitblitURL(getRequest());
|
JM |
81 |
|
155bf7
|
82 |
// changed paths list
|
5fe7df
|
83 |
ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
|
JM |
84 |
DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
|
|
85 |
private static final long serialVersionUID = 1L;
|
2a7306
|
86 |
int counter;
|
5fe7df
|
87 |
|
699e71
|
88 |
@Override
|
5fe7df
|
89 |
public void populateItem(final Item<PathModel> item) {
|
JM |
90 |
PathModel entry = item.getModelObject();
|
|
91 |
item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
|
|
92 |
if (entry.isParentPath) {
|
|
93 |
// parent .. path
|
1e8390
|
94 |
item.add(WicketUtils.newBlankImage("pathIcon"));
|
fc8426
|
95 |
item.add(new Label("pathSize", ""));
|
2a7306
|
96 |
item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
|
a2709d
|
97 |
WicketUtils
|
ab1e11
|
98 |
.newPathParameter(repositoryName, id, entry.path)));
|
1a3fc5
|
99 |
item.add(new Label("pathLinks", ""));
|
5fe7df
|
100 |
} else {
|
JM |
101 |
if (entry.isTree()) {
|
|
102 |
// folder/tree link
|
1e8390
|
103 |
item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
|
fc8426
|
104 |
item.add(new Label("pathSize", ""));
|
2a7306
|
105 |
item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
|
ab1e11
|
106 |
WicketUtils.newPathParameter(repositoryName, id,
|
a2709d
|
107 |
entry.path)));
|
155bf7
|
108 |
|
1a3fc5
|
109 |
// links
|
JM |
110 |
Fragment links = new Fragment("pathLinks", "treeLinks", this);
|
2a7306
|
111 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
ab1e11
|
112 |
WicketUtils.newPathParameter(repositoryName, id,
|
2a7306
|
113 |
entry.path)));
|
JM |
114 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
115 |
WicketUtils.newPathParameter(repositoryName, id,
|
699e71
|
116 |
entry.path)));
|
59b817
|
117 |
links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
|
JM |
118 |
repositoryName, objectId, entry.path));
|
|
119 |
|
1a3fc5
|
120 |
item.add(links);
|
eb870f
|
121 |
} else if (entry.isSubmodule()) {
|
JM |
122 |
// submodule
|
699e71
|
123 |
String submoduleId = entry.objectId;
|
eb870f
|
124 |
String submodulePath;
|
JM |
125 |
boolean hasSubmodule = false;
|
|
126 |
SubmoduleModel submodule = getSubmodule(entry.path);
|
|
127 |
submodulePath = submodule.gitblitPath;
|
|
128 |
hasSubmodule = submodule.hasSubmodule;
|
699e71
|
129 |
|
eb870f
|
130 |
item.add(WicketUtils.newImage("pathIcon", "git-orange-16x16.png"));
|
JM |
131 |
item.add(new Label("pathSize", ""));
|
699e71
|
132 |
item.add(new LinkPanel("pathName", "list", entry.name + " @ " +
|
eb870f
|
133 |
getShortObjectId(submoduleId), TreePage.class,
|
JM |
134 |
WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
|
699e71
|
135 |
|
eb870f
|
136 |
Fragment links = new Fragment("pathLinks", "submoduleLinks", this);
|
JM |
137 |
links.add(new BookmarkablePageLink<Void>("view", SummaryPage.class,
|
|
138 |
WicketUtils.newRepositoryParameter(submodulePath)).setEnabled(hasSubmodule));
|
|
139 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
|
140 |
WicketUtils.newPathParameter(submodulePath, submoduleId,
|
|
141 |
"")).setEnabled(hasSubmodule));
|
|
142 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
143 |
WicketUtils.newPathParameter(repositoryName, id,
|
9cc56a
|
144 |
entry.path)));
|
59b817
|
145 |
links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
|
JM |
146 |
submodulePath, submoduleId, "").setEnabled(hasSubmodule));
|
699e71
|
147 |
item.add(links);
|
5fe7df
|
148 |
} else {
|
JM |
149 |
// blob link
|
7670a0
|
150 |
String displayPath = entry.name;
|
e5662e
|
151 |
String path = entry.path;
|
JM |
152 |
if (entry.isSymlink()) {
|
|
153 |
path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
|
7670a0
|
154 |
displayPath = entry.name + " -> " + path;
|
e5662e
|
155 |
}
|
c1c3c6
|
156 |
item.add(WicketUtils.getFileImage("pathIcon", entry.name));
|
5fe7df
|
157 |
item.add(new Label("pathSize", byteFormat.format(entry.size)));
|
e5662e
|
158 |
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
|
ab1e11
|
159 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
160 |
path)));
|
155bf7
|
161 |
|
1a3fc5
|
162 |
// links
|
JM |
163 |
Fragment links = new Fragment("pathLinks", "blobLinks", this);
|
2a7306
|
164 |
links.add(new BookmarkablePageLink<Void>("view", BlobPage.class,
|
ab1e11
|
165 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
166 |
path)));
|
ff17f7
|
167 |
String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, id, path);
|
JM |
168 |
links.add(new ExternalLink("raw", rawUrl));
|
716745
|
169 |
links.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
|
ab1e11
|
170 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
171 |
path)));
|
2a7306
|
172 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
173 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
174 |
path)));
|
1a3fc5
|
175 |
item.add(links);
|
5fe7df
|
176 |
}
|
JM |
177 |
}
|
1a3fc5
|
178 |
WicketUtils.setAlternatingBackground(item, counter);
|
5fe7df
|
179 |
counter++;
|
JM |
180 |
}
|
|
181 |
};
|
|
182 |
add(pathsView);
|
|
183 |
}
|
155bf7
|
184 |
|
cebf45
|
185 |
@Override
|
JM |
186 |
protected String getPageName() {
|
1e47ab
|
187 |
return getString("gb.tree");
|
cebf45
|
188 |
}
|
5d5e55
|
189 |
|
JM |
190 |
@Override
|
|
191 |
protected boolean isCommitPage() {
|
|
192 |
return true;
|
|
193 |
}
|
|
194 |
|
5fe7df
|
195 |
}
|