Esempio n. 1
0
  public SummaryPage(PageParameters params) {
    super(params);

    int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
    if (numberCommits <= 0) {
      numberCommits = 20;
    }
    int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);

    Repository r = getRepository();
    RepositoryModel model = getRepositoryModel();

    List<Metric> metrics = null;
    Metric metricsTotal = null;
    if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
      metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
      metricsTotal = metrics.remove(0);
    }

    addSyndicationDiscoveryLink();

    // repository description
    add(new Label("repositoryDescription", getRepositoryModel().description));
    add(new Label("repositoryOwner", getRepositoryModel().owner));

    add(
        WicketUtils.createTimestampLabel(
            "repositoryLastChange", JGitUtils.getLastChange(r), getTimeZone()));
    if (metricsTotal == null) {
      add(new Label("branchStats", ""));
    } else {
      add(
          new Label(
              "branchStats",
              MessageFormat.format(
                  "{0} commits and {1} tags in {2}",
                  metricsTotal.count,
                  metricsTotal.tag,
                  TimeUtils.duration(metricsTotal.duration))));
    }
    add(
        new BookmarkablePageLink<Void>(
            "metrics", MetricsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));

    List<String> repositoryUrls = new ArrayList<String>();

    if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {
      AccessRestrictionType accessRestriction = getRepositoryModel().accessRestriction;
      switch (accessRestriction) {
        case NONE:
          add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
          break;
        case PUSH:
          add(
              WicketUtils.newImage(
                  "accessRestrictionIcon",
                  "lock_go_16x16.png",
                  getAccessRestrictions().get(accessRestriction)));
          break;
        case CLONE:
          add(
              WicketUtils.newImage(
                  "accessRestrictionIcon",
                  "lock_pull_16x16.png",
                  getAccessRestrictions().get(accessRestriction)));
          break;
        case VIEW:
          add(
              WicketUtils.newImage(
                  "accessRestrictionIcon",
                  "shield_16x16.png",
                  getAccessRestrictions().get(accessRestriction)));
          break;
        default:
          add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
      }
      // add the Gitblit repository url
      repositoryUrls.add(getRepositoryUrl(getRepositoryModel()));
    } else {
      add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
    }
    repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));

    String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.remove(0);
    add(new RepositoryUrlPanel("repositoryCloneUrl", primaryUrl));

    add(
        new Label("otherUrls", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
            .setEscapeModelStrings(false));

    add(
        new LogPanel(
            "commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0));
    add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
    add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty());

    if (getRepositoryModel().showReadme) {
      String htmlText = null;
      String readme = null;
      try {
        RevCommit head = JGitUtils.getCommit(r, null);
        List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
        List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
        for (PathModel path : paths) {
          if (!path.isTree()) {
            String name = path.name.toLowerCase();

            if (name.startsWith("readme")) {
              if (name.indexOf('.') > -1) {
                String ext = name.substring(name.lastIndexOf('.') + 1);
                if (markdownExtensions.contains(ext)) {
                  readme = path.name;
                  break;
                }
              }
            }
          }
        }
        if (!StringUtils.isEmpty(readme)) {
          String markdownText = JGitUtils.getStringContent(r, head.getTree(), readme);
          htmlText = MarkdownUtils.transformMarkdown(markdownText);
        }
      } catch (ParseException p) {
        error(p.getMessage());
      }
      Fragment fragment = new Fragment("readme", "markdownPanel");
      fragment.add(new Label("readmeFile", readme));
      // Add the html to the page
      Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);
      fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));
      add(fragment);
    } else {
      add(new Label("readme").setVisible(false));
    }

    // Display an activity line graph
    insertActivityGraph(metrics);
  }
Esempio n. 2
0
  public BranchesPanel(
      String wicketId, final RepositoryModel model, Repository r, final int maxCount) {
    super(wicketId);

    // branches
    List<RefModel> branches = new ArrayList<RefModel>();
    branches.addAll(JGitUtils.getLocalBranches(r, false, maxCount));
    if (model.showRemoteBranches) {
      branches.addAll(JGitUtils.getRemoteBranches(r, false, maxCount));
    }
    Collections.sort(branches);
    Collections.reverse(branches);
    if (maxCount > 0 && branches.size() > maxCount) {
      branches = new ArrayList<RefModel>(branches.subList(0, maxCount));
    }

    if (maxCount > 0) {
      // summary page
      // show branches page link
      add(
          new LinkPanel(
              "branches",
              "title",
              new StringResourceModel("gb.branches", this, null),
              BranchesPage.class,
              WicketUtils.newRepositoryParameter(model.name)));
    } else {
      // branches page
      // show repository summary page link
      add(
          new LinkPanel(
              "branches",
              "title",
              model.name,
              SummaryPage.class,
              WicketUtils.newRepositoryParameter(model.name)));
    }

    ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
    DataView<RefModel> branchesView =
        new DataView<RefModel>("branch", branchesDp) {
          private static final long serialVersionUID = 1L;
          int counter;

          public void populateItem(final Item<RefModel> item) {
            final RefModel entry = item.getModelObject();

            item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));

            item.add(
                new LinkPanel(
                    "branchName",
                    "list name",
                    StringUtils.trimString(entry.displayName, 28),
                    LogPage.class,
                    WicketUtils.newObjectParameter(model.name, entry.getName())));

            String author = entry.getAuthorIdent().getName();
            LinkPanel authorLink =
                new LinkPanel(
                    "branchAuthor",
                    "list",
                    author,
                    SearchPage.class,
                    WicketUtils.newSearchParameter(
                        model.name, entry.getName(), author, SearchType.AUTHOR));
            setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
            item.add(authorLink);

            // short message
            String shortMessage = entry.getShortMessage();
            String trimmedMessage = StringUtils.trimShortLog(shortMessage);
            LinkPanel shortlog =
                new LinkPanel(
                    "branchLog",
                    "list subject",
                    trimmedMessage,
                    CommitPage.class,
                    WicketUtils.newObjectParameter(model.name, entry.getName()));
            if (!shortMessage.equals(trimmedMessage)) {
              WicketUtils.setHtmlTooltip(shortlog, shortMessage);
            }
            item.add(shortlog);

            if (maxCount <= 0) {
              Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);
              fragment.add(
                  new BookmarkablePageLink<Void>(
                      "log",
                      LogPage.class,
                      WicketUtils.newObjectParameter(model.name, entry.getName())));
              fragment.add(
                  new BookmarkablePageLink<Void>(
                      "tree",
                      TreePage.class,
                      WicketUtils.newObjectParameter(model.name, entry.getName())));
              fragment.add(
                  new BookmarkablePageLink<Void>(
                      "metrics",
                      MetricsPage.class,
                      WicketUtils.newObjectParameter(model.name, entry.getName())));
              fragment.add(
                  new ExternalLink(
                      "syndication",
                      SyndicationServlet.asLink(
                          getRequest().getRelativePathPrefixToContextRoot(),
                          model.name,
                          entry.getName(),
                          0)));
              item.add(fragment);
            } else {
              Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);
              fragment.add(
                  new BookmarkablePageLink<Void>(
                      "log",
                      LogPage.class,
                      WicketUtils.newObjectParameter(model.name, entry.getName())));
              fragment.add(
                  new BookmarkablePageLink<Void>(
                      "tree",
                      TreePage.class,
                      WicketUtils.newObjectParameter(model.name, entry.getName())));
              item.add(fragment);
            }
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
          }
        };
    add(branchesView);
    if (branches.size() < maxCount || maxCount <= 0) {
      add(new Label("allBranches", "").setVisible(false));
    } else {
      add(
          new LinkPanel(
              "allBranches",
              "link",
              new StringResourceModel("gb.allBranches", this, null),
              BranchesPage.class,
              WicketUtils.newRepositoryParameter(model.name)));
    }
    // We always have 1 branch
    hasBranches =
        (branches.size() > 1)
            || ((branches.size() == 1) && !branches.get(0).displayName.equalsIgnoreCase("master"));
  }
Esempio n. 3
0
  public OverviewPage(PageParameters params) {
    super(params);

    int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);

    Repository r = getRepository();
    final RepositoryModel model = getRepositoryModel();
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
      user = UserModel.ANONYMOUS;
    }

    List<Metric> metrics = null;
    Metric metricsTotal = null;
    if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
      metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
      metricsTotal = metrics.remove(0);
    }

    addSyndicationDiscoveryLink();

    // repository description
    add(new Label("repositoryDescription", getRepositoryModel().description));

    // owner links
    final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
    ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
    DataView<String> ownersView =
        new DataView<String>("repositoryOwners", ownersDp) {
          private static final long serialVersionUID = 1L;
          int counter = 0;

          public void populateItem(final Item<String> item) {
            String ownername = item.getModelObject();
            UserModel ownerModel = GitBlit.self().getUserModel(ownername);
            if (ownerModel != null) {
              item.add(
                  new LinkPanel(
                          "owner",
                          null,
                          ownerModel.getDisplayName(),
                          UserPage.class,
                          WicketUtils.newUsernameParameter(ownerModel.username))
                      .setRenderBodyOnly(true));
            } else {
              Label owner = new Label("owner", ownername);
              WicketUtils.setCssStyle(owner, "text-decoration: line-through;");
              WicketUtils.setHtmlTooltip(
                  owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername));
              item.add(owner);
            }
            counter++;
            item.add(new Label("comma", ",").setVisible(counter < owners.size()));
            item.setRenderBodyOnly(true);
          }
        };
    ownersView.setRenderBodyOnly(true);
    add(ownersView);

    add(
        WicketUtils.createTimestampLabel(
            "repositoryLastChange",
            JGitUtils.getLastChange(r).when,
            getTimeZone(),
            getTimeUtils()));
    add(new Label("repositorySize", model.size));

    if (metricsTotal == null) {
      add(new Label("branchStats", ""));
    } else {
      add(
          new Label(
              "branchStats",
              MessageFormat.format(
                  getString("gb.branchStats"),
                  metricsTotal.count,
                  metricsTotal.tag,
                  getTimeUtils().duration(metricsTotal.duration))));
    }
    add(
        new BookmarkablePageLink<Void>(
            "metrics", MetricsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));

    add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model));

    int reflogCount = GitBlit.getInteger(Keys.web.overviewReflogCount, 5);
    ReflogPanel reflog = new ReflogPanel("reflogPanel", getRepositoryModel(), r, reflogCount, 0);
    add(reflog);
    add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
    add(
        new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false)
            .hideIfEmpty());

    // Display an activity line graph
    insertActivityGraph(metrics);
  }