| | |
| | | */
|
| | | package com.gitblit.wicket.pages;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.text.DateFormat;
|
| | | import java.text.MessageFormat;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Collection;
|
| | |
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | |
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.DailyLogEntry;
|
| | | import com.gitblit.models.Menu.ParameterMenuItem;
|
| | | import com.gitblit.models.NavLink.DropDownPageMenuNavLink;
|
| | | import com.gitblit.models.Metric;
|
| | | import com.gitblit.models.NavLink;
|
| | | import com.gitblit.models.RefLogEntry;
|
| | | import com.gitblit.models.RepositoryCommit;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | |
| | | import com.gitblit.utils.RefLogUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.GitBlitWebApp;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.PageRegistration.DropDownMenuItem;
|
| | | import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;
|
| | | import com.gitblit.wicket.charting.GoogleChart;
|
| | | import com.gitblit.wicket.charting.GoogleCharts;
|
| | | import com.gitblit.wicket.charting.GooglePieChart;
|
| | | import com.gitblit.wicket.ng.NgController;
|
| | | import com.gitblit.wicket.charting.Chart;
|
| | | import com.gitblit.wicket.charting.Charts;
|
| | | import com.gitblit.wicket.charting.Flotr2Charts;
|
| | | import com.gitblit.wicket.panels.DigestsPanel;
|
| | | import com.gitblit.wicket.panels.LinkPanel;
|
| | |
|
| | |
| | | c.add(Calendar.DATE, -1*daysBack);
|
| | | Date minimumDate = c.getTime();
|
| | | TimeZone timezone = getTimeZone();
|
| | | |
| | |
|
| | | // create daily commit digest feed
|
| | | List<DailyLogEntry> digests = new ArrayList<DailyLogEntry>();
|
| | | for (RepositoryModel model : repositories) {
|
| | | Repository repository = GitBlit.self().getRepository(model.name);
|
| | | List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone);
|
| | | digests.addAll(entries);
|
| | | repository.close();
|
| | | if (model.isCollectingGarbage) {
|
| | | continue;
|
| | | }
|
| | | if (model.hasCommits && model.lastChange.after(minimumDate)) {
|
| | | Repository repository = app().repositories().getRepository(model.name);
|
| | | List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone);
|
| | | digests.addAll(entries);
|
| | | repository.close();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | Fragment activityFragment = new Fragment("activity", "activityFragment", this);
|
| | | add(activityFragment);
|
| | | activityFragment.add(new Label("feedTitle", feedTitle));
|
| | |
| | | // quiet or no starred repositories
|
| | | if (repositories.size() == 0) {
|
| | | if (UserModel.ANONYMOUS.equals(user)) {
|
| | | activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack))); |
| | | if (daysBack == 1) {
|
| | | activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
|
| | | } else {
|
| | | activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
|
| | | }
|
| | | } else {
|
| | | activityFragment.add(new LinkPanel("digests", null, getString("gb.findSomeRepositories"), RepositoriesPage.class));
|
| | | }
|
| | | } else {
|
| | | activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
|
| | | if (daysBack == 1) {
|
| | | activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
|
| | | } else {
|
| | | activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // show daily commit digest feed
|
| | |
| | | DigestsPanel digestsPanel = new DigestsPanel("digests", digests);
|
| | | activityFragment.add(digestsPanel);
|
| | | }
|
| | | |
| | |
|
| | | // add the nifty charts
|
| | | if (!ArrayUtils.isEmpty(digests)) {
|
| | | // aggregate author exclusions
|
| | | Set<String> authorExclusions = new TreeSet<String>();
|
| | | for (String author : GitBlit.getStrings(Keys.web.metricAuthorExclusions)) {
|
| | | for (String author : app().settings().getStrings(Keys.web.metricAuthorExclusions)) {
|
| | | authorExclusions.add(author.toLowerCase());
|
| | | }
|
| | | for (RepositoryModel model : repositories) {
|
| | |
| | | activityFragment.add(new Label("feedheader").setVisible(false));
|
| | | }
|
| | | }
|
| | | |
| | | protected Fragment createNgList(String wicketId, String fragmentId, String ngController, List<RepositoryModel> repositories) {
|
| | | String format = GitBlit.getString(Keys.web.datestampShortFormat, "MM/dd/yy");
|
| | | final DateFormat df = new SimpleDateFormat(format);
|
| | | df.setTimeZone(getTimeZone());
|
| | |
|
| | | Fragment fragment = new Fragment(wicketId, fragmentId, this);
|
| | | |
| | | List<RepoListItem> list = new ArrayList<RepoListItem>();
|
| | | for (RepositoryModel repo : repositories) {
|
| | | String name = StringUtils.stripDotGit(repo.name); |
| | | String path = "";
|
| | | if (name.indexOf('/') > -1) {
|
| | | path = name.substring(0, name.lastIndexOf('/') + 1);
|
| | | name = name.substring(name.lastIndexOf('/') + 1);
|
| | | }
|
| | | |
| | | RepoListItem item = new RepoListItem();
|
| | | item.n = name;
|
| | | item.p = path;
|
| | | item.r = repo.name;
|
| | | item.i = repo.description;
|
| | | item.s = GitBlit.self().getStarCount(repo);
|
| | | item.t = getTimeUtils().timeAgo(repo.lastChange);
|
| | | item.d = df.format(repo.lastChange);
|
| | | item.c = StringUtils.getColor(StringUtils.stripDotGit(repo.name));
|
| | | item.wc = repo.isBare ? 0 : 1;
|
| | | list.add(item);
|
| | | }
|
| | | |
| | | // inject an AngularJS controller with static data
|
| | | NgController ctrl = new NgController(ngController);
|
| | | ctrl.addVariable(wicketId, list);
|
| | | add(new HeaderContributor(ctrl));
|
| | | |
| | | return fragment;
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void addDropDownMenus(List<PageRegistration> pages) {
|
| | | protected void addDropDownMenus(List<NavLink> navLinks) {
|
| | | PageParameters params = getPageParameters();
|
| | |
|
| | | DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters",
|
| | | GitBlitWebApp.HOME_PAGE_CLASS);
|
| | | // preserve time filter option on repository choices
|
| | | menu.menuItems.addAll(getRepositoryFilterItems(params));
|
| | | DropDownPageMenuNavLink menu = new DropDownPageMenuNavLink("gb.filters",
|
| | | GitBlitWebApp.get().getHomePage());
|
| | |
|
| | | // preserve repository filter option on time choices
|
| | | menu.menuItems.addAll(getTimeFilterItems(params));
|
| | |
|
| | | if (menu.menuItems.size() > 0) {
|
| | | // Reset Filter
|
| | | menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));
|
| | | menu.menuItems.add(new ParameterMenuItem(getString("gb.reset")));
|
| | | }
|
| | |
|
| | | pages.add(menu);
|
| | | navLinks.add(menu);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * Creates the daily activity line chart, the active repositories pie chart,
|
| | | * and the active authors pie chart
|
| | | * |
| | | *
|
| | | * @param recentChanges
|
| | | * @param authorExclusions
|
| | | * @param daysBack
|
| | |
| | | repositoryMetrics.put(repository, new Metric(repository));
|
| | | }
|
| | | repositoryMetrics.get(repository).count += 1;
|
| | | |
| | |
|
| | | for (RepositoryCommit commit : change.getCommits()) {
|
| | | totalCommits++;
|
| | | String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | frag.add(new Label("feedheader", MessageFormat.format(getString("gb.recentActivityStats"),
|
| | |
|
| | | String headerPattern;
|
| | | if (daysBack == 1) {
|
| | | // today
|
| | | if (totalCommits == 0) {
|
| | | headerPattern = getString("gb.todaysActivityNone");
|
| | | } else {
|
| | | headerPattern = getString("gb.todaysActivityStats");
|
| | | }
|
| | | } else {
|
| | | // multiple days
|
| | | if (totalCommits == 0) {
|
| | | headerPattern = getString("gb.recentActivityNone");
|
| | | } else {
|
| | | headerPattern = getString("gb.recentActivityStats");
|
| | | }
|
| | | }
|
| | | frag.add(new Label("feedheader", MessageFormat.format(headerPattern,
|
| | | daysBack, totalCommits, authorMetrics.size())));
|
| | |
|
| | | // build google charts
|
| | | GoogleCharts charts = new GoogleCharts();
|
| | | if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
|
| | | // build google charts
|
| | | Charts charts = new Flotr2Charts();
|
| | |
|
| | | // active repositories pie chart
|
| | | GoogleChart chart = new GooglePieChart("chartRepositories", getString("gb.activeRepositories"),
|
| | | getString("gb.repository"), getString("gb.commits"));
|
| | | for (Metric metric : repositoryMetrics.values()) {
|
| | | chart.addValue(metric.name, metric.count);
|
| | | // active repositories pie chart
|
| | | Chart chart = charts.createPieChart("chartRepositories", getString("gb.activeRepositories"),
|
| | | getString("gb.repository"), getString("gb.commits"));
|
| | | for (Metric metric : repositoryMetrics.values()) {
|
| | | chart.addValue(metric.name, metric.count);
|
| | | }
|
| | | chart.setShowLegend(false);
|
| | | String url = urlFor(SummaryPage.class, null).toString() + "?r=";
|
| | | chart.setClickUrl(url);
|
| | | charts.addChart(chart);
|
| | |
|
| | | // active authors pie chart
|
| | | chart = charts.createPieChart("chartAuthors", getString("gb.activeAuthors"),
|
| | | getString("gb.author"), getString("gb.commits"));
|
| | | for (Metric metric : authorMetrics.values()) {
|
| | | chart.addValue(metric.name, metric.count);
|
| | | }
|
| | | chart.setShowLegend(false);
|
| | | charts.addChart(chart);
|
| | |
|
| | | add(new HeaderContributor(charts));
|
| | | frag.add(new Fragment("charts", "chartsFragment", this));
|
| | | } else {
|
| | | frag.add(new Label("charts").setVisible(false));
|
| | | }
|
| | | chart.setShowLegend(false);
|
| | | charts.addChart(chart);
|
| | |
|
| | | // active authors pie chart
|
| | | chart = new GooglePieChart("chartAuthors", getString("gb.activeAuthors"),
|
| | | getString("gb.author"), getString("gb.commits"));
|
| | | for (Metric metric : authorMetrics.values()) {
|
| | | chart.addValue(metric.name, metric.count);
|
| | | }
|
| | | chart.setShowLegend(false);
|
| | | charts.addChart(chart);
|
| | |
|
| | | add(new HeaderContributor(charts)); |
| | | frag.add(new Fragment("charts", "chartsFragment", this));
|
| | | }
|
| | | |
| | | protected class RepoListItem implements Serializable {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | | |
| | | String r; // repository
|
| | | String n; // name
|
| | | String p; // project/path
|
| | | String t; // time ago
|
| | | String d; // last updated
|
| | | String i; // information/description
|
| | | long s; // stars
|
| | | String c; // html color
|
| | | int wc; // working copy, 1 = true
|
| | | }
|
| | | }
|