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 |
|
77c38a
|
18 |
import java.io.OutputStream;
|
5fe7df
|
19 |
import java.util.List;
|
JM |
20 |
|
|
21 |
import org.apache.wicket.PageParameters;
|
|
22 |
import org.apache.wicket.markup.html.basic.Label;
|
1a3fc5
|
23 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
ff17f7
|
24 |
import org.apache.wicket.markup.html.link.ExternalLink;
|
77c38a
|
25 |
import org.apache.wicket.markup.html.link.Link;
|
1a3fc5
|
26 |
import org.apache.wicket.markup.html.panel.Fragment;
|
5fe7df
|
27 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
28 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
29 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
77c38a
|
30 |
import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
|
PM |
31 |
import org.apache.wicket.util.resource.AbstractResourceStreamWriter;
|
|
32 |
import org.apache.wicket.util.resource.IResourceStream;
|
f08c1c
|
33 |
import org.eclipse.jgit.lib.FileMode;
|
5fe7df
|
34 |
import org.eclipse.jgit.lib.Repository;
|
JM |
35 |
import org.eclipse.jgit.revwalk.RevCommit;
|
|
36 |
|
1f9dae
|
37 |
import com.gitblit.models.PathModel;
|
eb870f
|
38 |
import com.gitblit.models.SubmoduleModel;
|
77c38a
|
39 |
import com.gitblit.models.UserModel;
|
ff17f7
|
40 |
import com.gitblit.servlet.RawServlet;
|
5fe7df
|
41 |
import com.gitblit.utils.ByteFormat;
|
JM |
42 |
import com.gitblit.utils.JGitUtils;
|
a7db57
|
43 |
import com.gitblit.wicket.CacheControl;
|
77c38a
|
44 |
import com.gitblit.wicket.GitBlitWebSession;
|
a7db57
|
45 |
import com.gitblit.wicket.CacheControl.LastModified;
|
5fe7df
|
46 |
import com.gitblit.wicket.WicketUtils;
|
c1c3c6
|
47 |
import com.gitblit.wicket.panels.CommitHeaderPanel;
|
59b817
|
48 |
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
|
1f9dae
|
49 |
import com.gitblit.wicket.panels.LinkPanel;
|
5fe7df
|
50 |
import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
|
JM |
51 |
|
a7db57
|
52 |
@CacheControl(LastModified.BOOT)
|
5fe7df
|
53 |
public class TreePage extends RepositoryPage {
|
JM |
54 |
|
|
55 |
public TreePage(PageParameters params) {
|
cebf45
|
56 |
super(params);
|
5fe7df
|
57 |
|
f602a2
|
58 |
final String path = WicketUtils.getPath(params);
|
5fe7df
|
59 |
|
JM |
60 |
Repository r = getRepository();
|
bc9d4a
|
61 |
RevCommit commit = getCommit();
|
a9a2ff
|
62 |
List<PathModel> paths = JGitUtils.getFilesInPath2(r, path, commit);
|
5fe7df
|
63 |
|
JM |
64 |
// tree page links
|
2a7306
|
65 |
add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
|
JM |
66 |
WicketUtils.newPathParameter(repositoryName, objectId, path)));
|
59b817
|
67 |
add(new CompressedDownloadsPanel("compressedLinks", getRequest()
|
JM |
68 |
.getRelativePathPrefixToContextRoot(), repositoryName, objectId, path));
|
608ece
|
69 |
|
c1c3c6
|
70 |
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
|
5fe7df
|
71 |
|
JM |
72 |
// breadcrumbs
|
f602a2
|
73 |
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
|
JM |
74 |
if (path != null && path.trim().length() > 0) {
|
28d6b2
|
75 |
// add .. parent path entry
|
JM |
76 |
String parentPath = null;
|
|
77 |
if (path.lastIndexOf('/') > -1) {
|
|
78 |
parentPath = path.substring(0, path.lastIndexOf('/'));
|
|
79 |
}
|
46f33f
|
80 |
PathModel model = new PathModel("..", parentPath, null, 0, FileMode.TREE.getBits(), null, objectId);
|
28d6b2
|
81 |
model.isParentPath = true;
|
JM |
82 |
paths.add(0, model);
|
5fe7df
|
83 |
}
|
JM |
84 |
|
ab1e11
|
85 |
final String id = getBestCommitId(commit);
|
46f33f
|
86 |
|
5fe7df
|
87 |
final ByteFormat byteFormat = new ByteFormat();
|
2179fb
|
88 |
final String baseUrl = WicketUtils.getGitblitURL(getRequest());
|
JM |
89 |
|
155bf7
|
90 |
// changed paths list
|
5fe7df
|
91 |
ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
|
JM |
92 |
DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
|
|
93 |
private static final long serialVersionUID = 1L;
|
2a7306
|
94 |
int counter;
|
5fe7df
|
95 |
|
699e71
|
96 |
@Override
|
5fe7df
|
97 |
public void populateItem(final Item<PathModel> item) {
|
77c38a
|
98 |
final PathModel entry = item.getModelObject();
|
46f33f
|
99 |
|
5fe7df
|
100 |
item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
|
5bb79f
|
101 |
item.add(WicketUtils.setHtmlTooltip(new Label("filestore", ""), getString("gb.filestore"))
|
PM |
102 |
.setVisible(entry.isFilestoreItem()));
|
|
103 |
|
5fe7df
|
104 |
if (entry.isParentPath) {
|
JM |
105 |
// parent .. path
|
1e8390
|
106 |
item.add(WicketUtils.newBlankImage("pathIcon"));
|
fc8426
|
107 |
item.add(new Label("pathSize", ""));
|
2a7306
|
108 |
item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
|
5bb79f
|
109 |
WicketUtils.newPathParameter(repositoryName, id, entry.path)));
|
1a3fc5
|
110 |
item.add(new Label("pathLinks", ""));
|
5fe7df
|
111 |
} else {
|
JM |
112 |
if (entry.isTree()) {
|
|
113 |
// folder/tree link
|
1e8390
|
114 |
item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
|
fc8426
|
115 |
item.add(new Label("pathSize", ""));
|
2a7306
|
116 |
item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
|
ab1e11
|
117 |
WicketUtils.newPathParameter(repositoryName, id,
|
a2709d
|
118 |
entry.path)));
|
155bf7
|
119 |
|
1a3fc5
|
120 |
// links
|
JM |
121 |
Fragment links = new Fragment("pathLinks", "treeLinks", this);
|
2a7306
|
122 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
ab1e11
|
123 |
WicketUtils.newPathParameter(repositoryName, id,
|
2a7306
|
124 |
entry.path)));
|
JM |
125 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
126 |
WicketUtils.newPathParameter(repositoryName, id,
|
699e71
|
127 |
entry.path)));
|
59b817
|
128 |
links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
|
JM |
129 |
repositoryName, objectId, entry.path));
|
|
130 |
|
1a3fc5
|
131 |
item.add(links);
|
eb870f
|
132 |
} else if (entry.isSubmodule()) {
|
JM |
133 |
// submodule
|
699e71
|
134 |
String submoduleId = entry.objectId;
|
eb870f
|
135 |
String submodulePath;
|
JM |
136 |
boolean hasSubmodule = false;
|
|
137 |
SubmoduleModel submodule = getSubmodule(entry.path);
|
|
138 |
submodulePath = submodule.gitblitPath;
|
|
139 |
hasSubmodule = submodule.hasSubmodule;
|
699e71
|
140 |
|
eb870f
|
141 |
item.add(WicketUtils.newImage("pathIcon", "git-orange-16x16.png"));
|
JM |
142 |
item.add(new Label("pathSize", ""));
|
699e71
|
143 |
item.add(new LinkPanel("pathName", "list", entry.name + " @ " +
|
eb870f
|
144 |
getShortObjectId(submoduleId), TreePage.class,
|
JM |
145 |
WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
|
699e71
|
146 |
|
eb870f
|
147 |
Fragment links = new Fragment("pathLinks", "submoduleLinks", this);
|
JM |
148 |
links.add(new BookmarkablePageLink<Void>("view", SummaryPage.class,
|
|
149 |
WicketUtils.newRepositoryParameter(submodulePath)).setEnabled(hasSubmodule));
|
|
150 |
links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
|
151 |
WicketUtils.newPathParameter(submodulePath, submoduleId,
|
|
152 |
"")).setEnabled(hasSubmodule));
|
|
153 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
154 |
WicketUtils.newPathParameter(repositoryName, id,
|
9cc56a
|
155 |
entry.path)));
|
59b817
|
156 |
links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
|
JM |
157 |
submodulePath, submoduleId, "").setEnabled(hasSubmodule));
|
699e71
|
158 |
item.add(links);
|
5fe7df
|
159 |
} else {
|
JM |
160 |
// blob link
|
7670a0
|
161 |
String displayPath = entry.name;
|
e5662e
|
162 |
String path = entry.path;
|
JM |
163 |
if (entry.isSymlink()) {
|
|
164 |
path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
|
7670a0
|
165 |
displayPath = entry.name + " -> " + path;
|
e5662e
|
166 |
}
|
c1c3c6
|
167 |
item.add(WicketUtils.getFileImage("pathIcon", entry.name));
|
5fe7df
|
168 |
item.add(new Label("pathSize", byteFormat.format(entry.size)));
|
46f33f
|
169 |
|
1a3fc5
|
170 |
// links
|
JM |
171 |
Fragment links = new Fragment("pathLinks", "blobLinks", this);
|
46f33f
|
172 |
|
PM |
173 |
if (entry.isFilestoreItem()) {
|
77c38a
|
174 |
item.add(new LinkPanel("pathName", "list", displayPath, new Link<Object>("link", null) {
|
PM |
175 |
|
|
176 |
private static final long serialVersionUID = 1L;
|
|
177 |
|
|
178 |
@Override
|
|
179 |
public void onClick() {
|
|
180 |
|
|
181 |
IResourceStream resourceStream = new AbstractResourceStreamWriter() {
|
|
182 |
|
|
183 |
private static final long serialVersionUID = 1L;
|
|
184 |
|
|
185 |
@Override
|
|
186 |
public void write(OutputStream output) {
|
|
187 |
UserModel user = GitBlitWebSession.get().getUser();
|
|
188 |
user = user == null ? UserModel.ANONYMOUS : user;
|
|
189 |
|
|
190 |
app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
|
|
191 |
}
|
|
192 |
};
|
|
193 |
|
|
194 |
|
|
195 |
getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
|
|
196 |
}}));
|
46f33f
|
197 |
|
77c38a
|
198 |
links.add(new Link<Object>("view", null) {
|
PM |
199 |
|
|
200 |
private static final long serialVersionUID = 1L;
|
|
201 |
|
|
202 |
@Override
|
|
203 |
public void onClick() {
|
|
204 |
|
|
205 |
IResourceStream resourceStream = new AbstractResourceStreamWriter() {
|
|
206 |
|
|
207 |
private static final long serialVersionUID = 1L;
|
|
208 |
|
|
209 |
@Override
|
|
210 |
public void write(OutputStream output) {
|
|
211 |
UserModel user = GitBlitWebSession.get().getUser();
|
|
212 |
user = user == null ? UserModel.ANONYMOUS : user;
|
|
213 |
|
|
214 |
app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
|
|
215 |
}
|
|
216 |
};
|
|
217 |
|
|
218 |
|
|
219 |
getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
|
|
220 |
}});
|
|
221 |
|
|
222 |
links.add(new Link<Object>("raw", null) {
|
|
223 |
|
|
224 |
private static final long serialVersionUID = 1L;
|
|
225 |
|
|
226 |
@Override
|
|
227 |
public void onClick() {
|
|
228 |
|
|
229 |
IResourceStream resourceStream = new AbstractResourceStreamWriter() {
|
|
230 |
|
|
231 |
private static final long serialVersionUID = 1L;
|
|
232 |
|
|
233 |
@Override
|
|
234 |
public void write(OutputStream output) {
|
|
235 |
UserModel user = GitBlitWebSession.get().getUser();
|
|
236 |
user = user == null ? UserModel.ANONYMOUS : user;
|
|
237 |
|
|
238 |
app().filestore().downloadBlob(entry.getFilestoreOid(), user, getRepositoryModel(), output);
|
|
239 |
}
|
|
240 |
};
|
|
241 |
|
|
242 |
|
|
243 |
getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream, entry.path));
|
|
244 |
}});
|
46f33f
|
245 |
|
PM |
246 |
} else {
|
|
247 |
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
|
|
248 |
WicketUtils.newPathParameter(repositoryName, id,
|
|
249 |
path)));
|
|
250 |
|
|
251 |
links.add(new BookmarkablePageLink<Void>("view", BlobPage.class,
|
|
252 |
WicketUtils.newPathParameter(repositoryName, id,
|
|
253 |
path)));
|
|
254 |
String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, id, path);
|
|
255 |
links.add(new ExternalLink("raw", rawUrl));
|
|
256 |
}
|
|
257 |
|
716745
|
258 |
links.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
|
ab1e11
|
259 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
260 |
path)));
|
2a7306
|
261 |
links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
|
ab1e11
|
262 |
WicketUtils.newPathParameter(repositoryName, id,
|
e5662e
|
263 |
path)));
|
1a3fc5
|
264 |
item.add(links);
|
5fe7df
|
265 |
}
|
JM |
266 |
}
|
1a3fc5
|
267 |
WicketUtils.setAlternatingBackground(item, counter);
|
5fe7df
|
268 |
counter++;
|
JM |
269 |
}
|
|
270 |
};
|
|
271 |
add(pathsView);
|
|
272 |
}
|
155bf7
|
273 |
|
cebf45
|
274 |
@Override
|
JM |
275 |
protected String getPageName() {
|
1e47ab
|
276 |
return getString("gb.tree");
|
cebf45
|
277 |
}
|
5d5e55
|
278 |
|
JM |
279 |
@Override
|
|
280 |
protected boolean isCommitPage() {
|
|
281 |
return true;
|
|
282 |
}
|
|
283 |
|
5fe7df
|
284 |
}
|