James Moger
2011-11-18 309c55b5a9670e7c327ad8d4e5d94b8af840d00f
src/com/gitblit/wicket/panels/RepositoriesPanel.java
@@ -31,6 +31,7 @@
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.repeater.Item;
@@ -43,6 +44,7 @@
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
import com.gitblit.SyndicationServlet;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
@@ -57,11 +59,23 @@
   private static final long serialVersionUID = 1L;
   public RepositoriesPanel(String wicketId, final boolean showAdmin,
         List<RepositoryModel> models,
         final Map<AccessRestrictionType, String> accessRestrictionTranslations) {
      super(wicketId);
      final boolean linksActive;
      final boolean showSize = GitBlit.getBoolean(Keys.web.showRepositorySizes, true);
      final UserModel user = GitBlitWebSession.get().getUser();
      List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);
      if (models == null) {
         linksActive = true;
         models = GitBlit.self().getRepositoryModels(user);
      } else {
         // disable links if the repositories are already provided
         // the repositories are most likely from a proposal
         linksActive = false;
      }
      final IDataProvider<RepositoryModel> dp;
      Fragment adminLinks = new Fragment("adminPanel", "adminLinks", this);
@@ -69,23 +83,35 @@
      add(adminLinks.setVisible(showAdmin));
      if (GitBlit.getString(Keys.web.repositoryListType, "flat").equalsIgnoreCase("grouped")) {
         List<RepositoryModel> rootRepositories = new ArrayList<RepositoryModel>();
         Map<String, List<RepositoryModel>> groups = new HashMap<String, List<RepositoryModel>>();
         for (RepositoryModel model : models) {
            String rootPath = StringUtils.getRootPath(model.name);
            if (StringUtils.isEmpty(rootPath)) {
               rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " ");
               // root repository
               rootRepositories.add(model);
            } else {
               // non-root, grouped repository
               if (!groups.containsKey(rootPath)) {
                  groups.put(rootPath, new ArrayList<RepositoryModel>());
               }
               groups.get(rootPath).add(model);
            }
            if (!groups.containsKey(rootPath)) {
               groups.put(rootPath, new ArrayList<RepositoryModel>());
            }
            groups.get(rootPath).add(model);
         }
         List<String> roots = new ArrayList<String>(groups.keySet());
         Collections.sort(roots);
         if (rootRepositories.size() > 0) {
            // inject the root repositories at the top of the page
            String rootPath = GitBlit.getString(Keys.web.repositoryRootGroupName, " ");
            roots.add(0, rootPath);
            groups.put(rootPath, rootRepositories);
         }
         List<RepositoryModel> groupedModels = new ArrayList<RepositoryModel>();
         for (String root : roots) {
            List<RepositoryModel> subModels = groups.get(root);
            groupedModels.add(new GroupRepositoryModel(root, subModels.size()));
            Collections.sort(subModels);
            groupedModels.addAll(subModels);
         }
         dp = new RepositoriesProvider(groupedModels);
@@ -93,9 +119,13 @@
         dp = new SortableRepositoriesProvider(models);
      }
      final String baseUrl = WicketUtils.getGitblitURL(getRequest());
      final boolean showSwatch = GitBlit.getBoolean(Keys.web.repositoryListSwatches, true);
      DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("row", dp) {
         private static final long serialVersionUID = 1L;
         int counter;
         String currGroupName;
         @Override
         protected void onBeforeRender() {
@@ -106,26 +136,48 @@
         public void populateItem(final Item<RepositoryModel> item) {
            final RepositoryModel entry = item.getModelObject();
            if (entry instanceof GroupRepositoryModel) {
               currGroupName = entry.name;
               Fragment row = new Fragment("rowContent", "groupRepositoryRow", this);
               item.add(row);
               row.add(new Label("groupName", entry.toString()));
               WicketUtils.setCssClass(item, "group");
               // reset counter so that first row is light background
               counter = 0;
               return;
            }
            Fragment row = new Fragment("rowContent", "repositoryRow", this);
            item.add(row);
            if (entry.hasCommits) {
               // Existing repository
            // try to strip group name for less cluttered list
            String repoName = entry.name;
            if (!StringUtils.isEmpty(currGroupName) && (repoName.indexOf('/') > -1)) {
               repoName = repoName.substring(currGroupName.length() + 1);
            }
            // repository swatch
            Label swatch = new Label("repositorySwatch", " ");
            WicketUtils.setCssBackground(swatch, entry.name);
            row.add(swatch);
            swatch.setVisible(showSwatch);
            if (entry.hasCommits && linksActive) {
               PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);
               row.add(new LinkPanel("repositoryName", "list", entry.name, SummaryPage.class,
                     pp));
               row.add(new LinkPanel("repositoryName", "list", repoName, SummaryPage.class, pp));
               row.add(new LinkPanel("repositoryDescription", "list", entry.description,
                     SummaryPage.class, pp));
            } else {
               // New repository
               row.add(new Label("repositoryName", entry.name
                     + "<span class='empty'>(empty)</span>").setEscapeModelStrings(false));
               // new/empty repository OR proposed repository
               row.add(new Label("repositoryName", repoName));
               row.add(new Label("repositoryDescription", entry.description));
            }
            if (entry.hasCommits) {
               // Existing repository
               row.add(new Label("repositorySize", entry.size).setVisible(showSize));
            } else {
               // New repository
               row.add(new Label("repositorySize", "<span class='empty'>(empty)</span>")
                     .setEscapeModelStrings(false));
            }
            if (entry.useTickets) {
@@ -147,6 +199,13 @@
                     getString("gb.isFrozen")));
            } else {
               row.add(WicketUtils.newClearPixel("frozenIcon").setVisible(false));
            }
            if (entry.isFederated) {
               row.add(WicketUtils.newImage("federatedIcon", "federated_16x16.png",
                     getString("gb.isFederated")));
            } else {
               row.add(WicketUtils.newClearPixel("federatedIcon").setVisible(false));
            }
            switch (entry.accessRestriction) {
            case NONE:
@@ -170,7 +229,12 @@
            row.add(new Label("repositoryOwner", entry.owner));
            String lastChange = TimeUtils.timeAgo(entry.lastChange);
            String lastChange;
            if (entry.lastChange.getTime() == 0) {
               lastChange = "--";
            } else {
               lastChange = TimeUtils.timeAgo(entry.lastChange);
            }
            Label lastChangeLabel = new Label("repositoryLastChange", lastChange);
            row.add(lastChangeLabel);
            WicketUtils.setCssClass(lastChangeLabel, TimeUtils.timeAgoCss(entry.lastChange));
@@ -215,6 +279,8 @@
            } else {
               row.add(new Label("repositoryLinks"));
            }
            row.add(new ExternalLink("syndication", SyndicationServlet.asLink(baseUrl,
                  entry.name, null, 0)).setVisible(linksActive));
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
         }