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.

ForksPage.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2012 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.ArrayList;
  18. import java.util.List;
  19. import org.apache.wicket.Component;
  20. import org.apache.wicket.PageParameters;
  21. import org.apache.wicket.markup.html.basic.Label;
  22. import org.apache.wicket.markup.repeater.Item;
  23. import org.apache.wicket.markup.repeater.data.DataView;
  24. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  25. import org.eclipse.jgit.lib.PersonIdent;
  26. import com.gitblit.GitBlit;
  27. import com.gitblit.Keys;
  28. import com.gitblit.models.RepositoryModel;
  29. import com.gitblit.models.UserModel;
  30. import com.gitblit.utils.ArrayUtils;
  31. import com.gitblit.utils.StringUtils;
  32. import com.gitblit.wicket.GitBlitWebSession;
  33. import com.gitblit.wicket.WicketUtils;
  34. import com.gitblit.wicket.panels.GravatarImage;
  35. import com.gitblit.wicket.panels.LinkPanel;
  36. public class ForksPage extends RepositoryPage {
  37. public ForksPage(PageParameters params) {
  38. super(params);
  39. RepositoryModel model = getRepositoryModel();
  40. RepositoryModel origin;
  41. List<String> list;
  42. if (ArrayUtils.isEmpty(model.forks)) {
  43. // origin repository has forks
  44. origin = GitBlit.self().getRepositoryModel(model.originRepository);
  45. list = new ArrayList<String>(origin.forks);
  46. } else {
  47. // this repository has forks
  48. origin = model;
  49. list = new ArrayList<String>(model.forks);
  50. }
  51. if (origin.isPersonalRepository()) {
  52. // personal repository
  53. UserModel user = GitBlit.self().getUserModel(origin.projectPath.substring(1));
  54. PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress);
  55. add(new GravatarImage("forkSourceAvatar", ident, 20));
  56. add(new Label("forkSourceSwatch").setVisible(false));
  57. add(new LinkPanel("forkSourceProject", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(user.username)));
  58. } else {
  59. // standard repository
  60. add(new GravatarImage("forkSourceAvatar", new PersonIdent("", ""), 20).setVisible(false));
  61. Component swatch;
  62. if (origin.isBare){
  63. swatch = new Label("forkSourceSwatch", "&nbsp;").setEscapeModelStrings(false);
  64. } else {
  65. swatch = new Label("forkSourceSwatch", "!");
  66. WicketUtils.setHtmlTooltip(swatch, getString("gb.workingCopyWarning"));
  67. }
  68. WicketUtils.setCssBackground(swatch, origin.toString());
  69. add(swatch);
  70. final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);
  71. swatch.setVisible(showSwatch);
  72. String projectName = origin.projectPath;
  73. if (StringUtils.isEmpty(projectName)) {
  74. projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
  75. }
  76. add(new LinkPanel("forkSourceProject", null, projectName, ProjectPage.class, WicketUtils.newProjectParameter(origin.projectPath)));
  77. }
  78. String source = StringUtils.getLastPathElement(origin.name);
  79. add(new LinkPanel("forkSource", null, StringUtils.stripDotGit(source), SummaryPage.class, WicketUtils.newRepositoryParameter(origin.name)));
  80. // only display user-accessible forks
  81. UserModel user = GitBlitWebSession.get().getUser();
  82. List<RepositoryModel> forks = new ArrayList<RepositoryModel>();
  83. for (String aFork : list) {
  84. RepositoryModel fork = GitBlit.self().getRepositoryModel(user, aFork);
  85. if (fork != null) {
  86. forks.add(fork);
  87. }
  88. }
  89. ListDataProvider<RepositoryModel> forksDp = new ListDataProvider<RepositoryModel>(forks);
  90. DataView<RepositoryModel> forksList = new DataView<RepositoryModel>("fork", forksDp) {
  91. private static final long serialVersionUID = 1L;
  92. public void populateItem(final Item<RepositoryModel> item) {
  93. RepositoryModel fork = item.getModelObject();
  94. if (fork.isPersonalRepository()) {
  95. UserModel user = GitBlit.self().getUserModel(fork.projectPath.substring(1));
  96. PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress);
  97. item.add(new GravatarImage("anAvatar", ident, 20));
  98. item.add(new LinkPanel("aProject", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(user.username)));
  99. } else {
  100. PersonIdent ident = new PersonIdent(fork.name, fork.name);
  101. item.add(new GravatarImage("anAvatar", ident, 20));
  102. item.add(new LinkPanel("aProject", null, fork.projectPath, ProjectPage.class, WicketUtils.newProjectParameter(fork.projectPath)));
  103. }
  104. String repo = StringUtils.getLastPathElement(fork.name);
  105. item.add(new LinkPanel("aFork", null, StringUtils.stripDotGit(repo), SummaryPage.class, WicketUtils.newRepositoryParameter(fork.name)));
  106. WicketUtils.setCssStyle(item, "margin-left:25px;");
  107. }
  108. };
  109. add(forksList);
  110. }
  111. @Override
  112. protected String getPageName() {
  113. return getString("gb.forks");
  114. }
  115. }