You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DocsPage.java 3.0KB

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