James Moger
2011-05-11 dfb88962fdbd29f59abe92178bb042738d57c3e1
commit | author | age
c1c3c6 1 package com.gitblit.wicket.pages;
JM 2
3 import java.util.List;
4
5 import org.apache.wicket.PageParameters;
6 import org.apache.wicket.markup.html.basic.Label;
7 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
8 import org.apache.wicket.markup.repeater.Item;
9 import org.apache.wicket.markup.repeater.data.DataView;
10 import org.apache.wicket.markup.repeater.data.ListDataProvider;
11 import org.eclipse.jgit.lib.Repository;
12
13 import com.gitblit.GitBlit;
14 import com.gitblit.Keys;
15 import com.gitblit.utils.ByteFormat;
16 import com.gitblit.utils.JGitUtils;
17 import com.gitblit.wicket.LinkPanel;
18 import com.gitblit.wicket.RepositoryPage;
19 import com.gitblit.wicket.WicketUtils;
20 import com.gitblit.wicket.models.PathModel;
21
22 public class DocsPage extends RepositoryPage {
23
24     public DocsPage(PageParameters params) {
25         super(params);
26
27         Repository r = getRepository();
28         List<String> extensions = GitBlit.self().settings().getStrings(Keys.web.markdownExtensions);
29         List<PathModel> paths = JGitUtils.getDocuments(r, extensions);
30
31         final ByteFormat byteFormat = new ByteFormat();
32
33         add(new Label("header", getString("gb.docs")));
34         
35         // documents list
36         ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
37         DataView<PathModel> pathsView = new DataView<PathModel>("document", pathsDp) {
38             private static final long serialVersionUID = 1L;
39             int counter = 0;
40
41             public void populateItem(final Item<PathModel> item) {
42                 PathModel entry = item.getModelObject();
43                 item.add(WicketUtils.newImage("docIcon", "file_world_16x16.png"));
44                 item.add(new Label("docSize", byteFormat.format(entry.size)));
45                 item.add(new LinkPanel("docName", "list", entry.name, BlobPage.class, newPathParameter(entry.path)));
46
47                 // links
48                 item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
49                 item.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
50                 item.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));
51                 item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));                
52                 WicketUtils.setAlternatingBackground(item, counter);
53                 counter++;
54             }
55         };
56         add(pathsView);
57     }
58
59     @Override
60     protected String getPageName() {
61         return getString("gb.docs");
62     }
63 }