Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.Component;
  19. import org.apache.wicket.PageParameters;
  20. import org.apache.wicket.behavior.SimpleAttributeModifier;
  21. import org.apache.wicket.markup.html.basic.Label;
  22. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  23. import org.apache.wicket.markup.html.link.ExternalLink;
  24. import org.apache.wicket.markup.html.panel.Fragment;
  25. import org.apache.wicket.markup.repeater.Item;
  26. import org.apache.wicket.markup.repeater.data.DataView;
  27. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  28. import org.eclipse.jgit.lib.Repository;
  29. import org.eclipse.jgit.revwalk.RevCommit;
  30. import com.gitblit.GitBlit;
  31. import com.gitblit.models.PathModel;
  32. import com.gitblit.utils.ByteFormat;
  33. import com.gitblit.utils.JGitUtils;
  34. import com.gitblit.utils.StringUtils;
  35. import com.gitblit.wicket.CacheControl;
  36. import com.gitblit.wicket.CacheControl.LastModified;
  37. import com.gitblit.wicket.MarkupProcessor;
  38. import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
  39. import com.gitblit.wicket.MarkupProcessor.MarkupSyntax;
  40. import com.gitblit.wicket.WicketUtils;
  41. import com.gitblit.wicket.panels.LinkPanel;
  42. @CacheControl(LastModified.REPOSITORY)
  43. public class DocsPage extends RepositoryPage {
  44. public DocsPage(PageParameters params) {
  45. super(params);
  46. MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings());
  47. Repository r = getRepository();
  48. RevCommit head = JGitUtils.getCommit(r, null);
  49. final String commitId = getBestCommitId(head);
  50. List<String> extensions = processor.getAllExtensions();
  51. List<PathModel> paths = JGitUtils.getDocuments(r, extensions);
  52. List<MarkupDocument> roots = processor.getRootDocs(r, repositoryName, commitId);
  53. Fragment fragment = null;
  54. if (roots.isEmpty()) {
  55. // no identified root documents just show the standard document list
  56. fragment = new Fragment("docs", "noIndexFragment", this);
  57. } else {
  58. // root documents, use tabbed ui of index/root and document list
  59. fragment = new Fragment("docs", "tabsFragment", this);
  60. ListDataProvider<MarkupDocument> docDp = new ListDataProvider<MarkupDocument>(roots);
  61. // tab titles
  62. DataView<MarkupDocument> tabTitles = new DataView<MarkupDocument>("tabTitle", docDp) {
  63. private static final long serialVersionUID = 1L;
  64. int counter;
  65. @Override
  66. public void populateItem(final Item<MarkupDocument> item) {
  67. MarkupDocument doc = item.getModelObject();
  68. String file = StringUtils.getLastPathElement(doc.documentPath);
  69. file = StringUtils.stripFileExtension(file);
  70. String name = file.replace('_', ' ').replace('-', ' ');
  71. ExternalLink link = new ExternalLink("link", "#" + file);
  72. link.add(new Label("label", name.toUpperCase()).setRenderBodyOnly(true));
  73. item.add(link);
  74. if (counter == 0) {
  75. counter++;
  76. item.add(new SimpleAttributeModifier("class", "active"));
  77. }
  78. }
  79. };
  80. fragment.add(tabTitles);
  81. // tab content
  82. DataView<MarkupDocument> tabsView = new DataView<MarkupDocument>("tabContent", docDp) {
  83. private static final long serialVersionUID = 1L;
  84. int counter;
  85. @Override
  86. public void populateItem(final Item<MarkupDocument> item) {
  87. MarkupDocument doc = item.getModelObject();
  88. // document page links
  89. item.add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
  90. WicketUtils.newPathParameter(repositoryName, commitId, doc.documentPath)));
  91. item.add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
  92. WicketUtils.newPathParameter(repositoryName, commitId, doc.documentPath)));
  93. item.add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(
  94. repositoryName, commitId, doc.documentPath)));
  95. // document content
  96. String file = StringUtils.getLastPathElement(doc.documentPath);
  97. file = StringUtils.stripFileExtension(file);
  98. Component content = new Label("content", doc.html)
  99. .setEscapeModelStrings(false);
  100. if (!MarkupSyntax.PLAIN.equals(doc.syntax)) {
  101. content.add(new SimpleAttributeModifier("class", "markdown"));
  102. }
  103. item.add(content);
  104. item.add(new SimpleAttributeModifier("id", file));
  105. if (counter == 0) {
  106. counter++;
  107. item.add(new SimpleAttributeModifier("class", "tab-pane active"));
  108. }
  109. }
  110. };
  111. fragment.add(tabsView);
  112. }
  113. // document list
  114. final String id = getBestCommitId(head);
  115. final ByteFormat byteFormat = new ByteFormat();
  116. Fragment docs = new Fragment("documents", "documentsFragment", this);
  117. ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
  118. DataView<PathModel> pathsView = new DataView<PathModel>("document", pathsDp) {
  119. private static final long serialVersionUID = 1L;
  120. int counter;
  121. @Override
  122. public void populateItem(final Item<PathModel> item) {
  123. PathModel entry = item.getModelObject();
  124. item.add(WicketUtils.newImage("docIcon", "file_world_16x16.png"));
  125. item.add(new Label("docSize", byteFormat.format(entry.size)));
  126. item.add(new LinkPanel("docName", "list", entry.name, DocPage.class, WicketUtils
  127. .newPathParameter(repositoryName, id, entry.path)));
  128. // links
  129. item.add(new BookmarkablePageLink<Void>("view", DocPage.class, WicketUtils
  130. .newPathParameter(repositoryName, id, entry.path)));
  131. item.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils
  132. .newPathParameter(repositoryName, id, entry.path)));
  133. item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
  134. .newPathParameter(repositoryName, id, entry.path)));
  135. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
  136. .newPathParameter(repositoryName, id, entry.path)));
  137. WicketUtils.setAlternatingBackground(item, counter);
  138. counter++;
  139. }
  140. };
  141. docs.add(pathsView);
  142. fragment.add(docs);
  143. add(fragment);
  144. }
  145. @Override
  146. protected String getPageName() {
  147. return getString("gb.docs");
  148. }
  149. }