*/\r
package com.gitblit.wicket.pages;\r
\r
-import java.text.MessageFormat;\r
+import java.io.Serializable;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import org.apache.wicket.Component;\r
import org.apache.wicket.PageParameters;\r
import org.apache.wicket.markup.html.basic.Label;\r
-import org.apache.wicket.markup.html.panel.Fragment;\r
import org.apache.wicket.markup.repeater.Item;\r
import org.apache.wicket.markup.repeater.data.DataView;\r
import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.ForkModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
-import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
public ForksPage(PageParameters params) {\r
super(params);\r
\r
- UserModel user = GitBlitWebSession.get().getUser();\r
- RepositoryModel model = getRepositoryModel();\r
- RepositoryModel origin = model;\r
- List<String> list;\r
- if (ArrayUtils.isEmpty(model.forks)) {\r
- if (!StringUtils.isEmpty(model.originRepository)) {\r
- // try origin repository\r
- origin = GitBlit.self().getRepositoryModel(model.originRepository);\r
- }\r
- if (origin == null || origin.forks == null) {\r
- list = new ArrayList<String>();\r
- } else {\r
- list = new ArrayList<String>(origin.forks);\r
- }\r
- } else {\r
- // this repository has forks\r
- list = new ArrayList<String>(model.forks);\r
- }\r
- \r
- if (origin.isPersonalRepository()) {\r
- // personal repository\r
- UserModel originUser = GitBlit.self().getUserModel(origin.projectPath.substring(1));\r
- PersonIdent ident = new PersonIdent(originUser.getDisplayName(), originUser.emailAddress);\r
- add(new GravatarImage("forkSourceAvatar", ident, 20));\r
- add(new Label("forkSourceSwatch").setVisible(false));\r
- add(new LinkPanel("forkSourceProject", null, originUser.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(originUser.username)));\r
- } else {\r
- // standard repository\r
- add(new GravatarImage("forkSourceAvatar", new PersonIdent("", ""), 20).setVisible(false));\r
- Component swatch;\r
- if (origin.isBare){\r
- swatch = new Label("forkSourceSwatch", " ").setEscapeModelStrings(false);\r
- } else {\r
- swatch = new Label("forkSourceSwatch", "!");\r
- WicketUtils.setHtmlTooltip(swatch, getString("gb.workingCopyWarning"));\r
- }\r
- WicketUtils.setCssBackground(swatch, origin.toString());\r
- add(swatch);\r
- final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);\r
- swatch.setVisible(showSwatch);\r
- \r
- String projectName = origin.projectPath;\r
- if (StringUtils.isEmpty(projectName)) {\r
- projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");\r
- }\r
- add(new LinkPanel("forkSourceProject", null, projectName, ProjectPage.class, WicketUtils.newProjectParameter(origin.projectPath)));\r
- }\r
+ final RepositoryModel pageRepository = getRepositoryModel();\r
\r
- String source = StringUtils.getLastPathElement(origin.name);\r
- if (user != null && user.canViewRepository(origin)) {\r
- // user can view the origin\r
- add(new LinkPanel("forkSource", null, StringUtils.stripDotGit(source), SummaryPage.class, WicketUtils.newRepositoryParameter(origin.name)));\r
- } else {\r
- // user can not view the origin\r
- add(new Label("forkSource", StringUtils.stripDotGit(source)));\r
- }\r
- \r
- // superOrigin?\r
- if (StringUtils.isEmpty(origin.originRepository)) {\r
- // origin is root\r
- add(new Label("forkSourceOrigin").setVisible(false));\r
- } else {\r
- // origin has an origin\r
- RepositoryModel superOrigin = GitBlit.self().getRepositoryModel(origin.originRepository);\r
- if (!user.canViewRepository(superOrigin)) {\r
- // show superOrigin repository without link\r
- Fragment forkFrag = new Fragment("forkSourceOrigin", "originFragment", this);\r
- forkFrag.add(new Label("originRepository", StringUtils.stripDotGit(superOrigin.name)));\r
- add(forkFrag);\r
- } else {\r
- // link to superOrigin repository\r
- Fragment forkFrag = new Fragment("forkSourceOrigin", "originFragment", this);\r
- forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(superOrigin.name), \r
- SummaryPage.class, WicketUtils.newRepositoryParameter(superOrigin.name)));\r
- add(forkFrag);\r
- }\r
- }\r
-\r
- // only display user-accessible forks\r
- List<RepositoryModel> forks = new ArrayList<RepositoryModel>();\r
- for (String aFork : list) {\r
- RepositoryModel fork = GitBlit.self().getRepositoryModel(user, aFork);\r
- if (fork != null) {\r
- forks.add(fork);\r
- }\r
- }\r
+ ForkModel root = GitBlit.self().getForkNetwork(pageRepository.name);\r
+ List<FlatFork> network = flatten(root);\r
\r
- ListDataProvider<RepositoryModel> forksDp = new ListDataProvider<RepositoryModel>(forks);\r
- DataView<RepositoryModel> forksList = new DataView<RepositoryModel>("fork", forksDp) {\r
+ ListDataProvider<FlatFork> forksDp = new ListDataProvider<FlatFork>(network);\r
+ DataView<FlatFork> forksList = new DataView<FlatFork>("fork", forksDp) {\r
private static final long serialVersionUID = 1L;\r
\r
- public void populateItem(final Item<RepositoryModel> item) {\r
- RepositoryModel fork = item.getModelObject();\r
+ public void populateItem(final Item<FlatFork> item) {\r
+ FlatFork fork = item.getModelObject();\r
+ RepositoryModel repository = fork.repository;\r
\r
- if (fork.isPersonalRepository()) {\r
- UserModel user = GitBlit.self().getUserModel(fork.projectPath.substring(1));\r
+ if (repository.isPersonalRepository()) {\r
+ UserModel user = GitBlit.self().getUserModel(repository.projectPath.substring(1));\r
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress);\r
item.add(new GravatarImage("anAvatar", ident, 20));\r
- item.add(new LinkPanel("aProject", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(user.username)));\r
+ if (pageRepository.equals(repository)) {\r
+ // do not link to self\r
+ item.add(new Label("aProject", user.getDisplayName()));\r
+ } else {\r
+ item.add(new LinkPanel("aProject", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(user.username)));\r
+ }\r
} else {\r
- PersonIdent ident = new PersonIdent(fork.name, fork.name);\r
- item.add(new GravatarImage("anAvatar", ident, 20));\r
- item.add(new LinkPanel("aProject", null, fork.projectPath, ProjectPage.class, WicketUtils.newProjectParameter(fork.projectPath)));\r
+ Component swatch;\r
+ if (repository.isBare){\r
+ swatch = new Label("anAvatar", " ").setEscapeModelStrings(false);\r
+ } else {\r
+ swatch = new Label("anAvatar", "!");\r
+ WicketUtils.setHtmlTooltip(swatch, getString("gb.workingCopyWarning"));\r
+ }\r
+ WicketUtils.setCssClass(swatch, "repositorySwatch");\r
+ WicketUtils.setCssBackground(swatch, repository.toString());\r
+ item.add(swatch);\r
+ String projectName = repository.projectPath;\r
+ if (StringUtils.isEmpty(projectName)) {\r
+ projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");\r
+ }\r
+ if (pageRepository.equals(repository)) {\r
+ // do not link to self\r
+ item.add(new Label("aProject", projectName));\r
+ } else {\r
+ item.add(new LinkPanel("aProject", null, projectName, ProjectPage.class, WicketUtils.newProjectParameter(projectName)));\r
+ }\r
}\r
\r
- String repo = StringUtils.getLastPathElement(fork.name);\r
- item.add(new LinkPanel("aFork", null, StringUtils.stripDotGit(repo), SummaryPage.class, WicketUtils.newRepositoryParameter(fork.name)));\r
+ String repo = StringUtils.getLastPathElement(repository.name);\r
+ UserModel user = GitBlitWebSession.get().getUser();\r
+ if (user == null) {\r
+ user = UserModel.ANONYMOUS;\r
+ }\r
+ if (user.canViewRepository(repository)) {\r
+ if (pageRepository.equals(repository)) {\r
+ // do not link to self\r
+ item.add(new Label("aFork", StringUtils.stripDotGit(repo)));\r
+ } else {\r
+ item.add(new LinkPanel("aFork", null, StringUtils.stripDotGit(repo), SummaryPage.class, WicketUtils.newRepositoryParameter(repository.name)));\r
+ }\r
+ item.add(WicketUtils.createDateLabel("lastChange", repository.lastChange, getTimeZone(), getTimeUtils()));\r
+ } else {\r
+ item.add(new Label("aFork", repo));\r
+ item.add(new Label("lastChange").setVisible(false));\r
+ }\r
\r
- if (ArrayUtils.isEmpty(fork.forks)) {\r
- // repository is a leaf\r
- Component icon = new Label("anIcon", "<i class=\"icon-leaf\" ></i>").setEscapeModelStrings(false);\r
- WicketUtils.setHtmlTooltip(icon, MessageFormat.format(getString("gb.noForks"), fork.name));\r
- item.add(icon);\r
+ WicketUtils.setCssStyle(item, "margin-left:" + (32*fork.level) + "px;");\r
+ if (fork.level == 0) {\r
+ WicketUtils.setCssClass(item, "forkSource");\r
} else {\r
- // show forks link\r
- item.add(new LinkPanel("anIcon", null, "(" + getString("gb.forks") + ")", ForksPage.class, WicketUtils.newRepositoryParameter(fork.name)));\r
+ WicketUtils.setCssClass(item, "forkEntry");\r
}\r
}\r
};\r
\r
add(forksList);\r
-\r
}\r
\r
@Override\r
protected String getPageName() {\r
return getString("gb.forks");\r
}\r
+ \r
+ protected List<FlatFork> flatten(ForkModel root) {\r
+ List<FlatFork> list = new ArrayList<FlatFork>();\r
+ list.addAll(flatten(root, 0));\r
+ return list;\r
+ }\r
+ \r
+ protected List<FlatFork> flatten(ForkModel node, int level) {\r
+ List<FlatFork> list = new ArrayList<FlatFork>();\r
+ list.add(new FlatFork(node.repository, level));\r
+ if (!node.isLeaf()) {\r
+ for (ForkModel fork : node.forks) {\r
+ list.addAll(flatten(fork, level + 1));\r
+ }\r
+ }\r
+ return list;\r
+ }\r
+ \r
+ private class FlatFork implements Serializable {\r
+ \r
+ private static final long serialVersionUID = 1L;\r
+\r
+ public final RepositoryModel repository;\r
+ public final int level;\r
+ \r
+ public FlatFork(RepositoryModel repository, int level) {\r
+ this.repository = repository;\r
+ this.level = level;\r
+ }\r
+ }\r
}\r