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