use of org.apache.wicket.behavior.HeaderContributor in project gitblit by gitblit.
the class OverviewPage method insertActivityGraph.
private void insertActivityGraph(List<Metric> metrics) {
if ((metrics != null) && (metrics.size() > 0) && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
Charts charts = new Flotr2Charts();
// daily line chart
Chart chart = charts.createLineChart("chartDaily", "", "unit", getString("gb.commits"));
for (Metric metric : metrics) {
chart.addValue(metric.name, metric.count);
}
chart.setWidth(375);
chart.setHeight(150);
charts.addChart(chart);
add(new HeaderContributor(charts));
}
}
use of org.apache.wicket.behavior.HeaderContributor in project gitblit by gitblit.
the class FilterableRepositoryList method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
String id = getId();
String ngCtrl = id + "Ctrl";
String ngList = id + "List";
Map<String, Object> values = new HashMap<String, Object>();
values.put("ngCtrl", ngCtrl);
values.put("ngList", ngList);
// use Freemarker to setup an AngularJS/Wicket html snippet
FreemarkerPanel panel = new FreemarkerPanel("listComponent", "FilterableRepositoryList.fm", values);
panel.setParseGeneratedMarkup(true);
panel.setRenderBodyOnly(true);
add(panel);
// add the Wicket controls that are referenced in the snippet
String listTitle = StringUtils.isEmpty(title) ? getString("gb.repositories") : title;
panel.add(new Label(ngList + "Title", MessageFormat.format("{0} ({1})", listTitle, repositories.size())));
if (StringUtils.isEmpty(iconClass)) {
panel.add(new Label(ngList + "Icon").setVisible(false));
} else {
Label icon = new Label(ngList + "Icon");
WicketUtils.setCssClass(icon, iconClass);
panel.add(icon);
}
if (allowCreate) {
panel.add(new LinkPanel(ngList + "Button", "btn btn-mini", getString("gb.newRepository"), app().getNewRepositoryPage()));
} else {
panel.add(new Label(ngList + "Button").setVisible(false));
}
String format = app().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy");
final DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(getTimeZone());
// prepare the simplified repository models list
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 = app().repositories().getStarCount(repo);
item.t = getTimeUtils().timeAgo(repo.lastChange);
item.d = df.format(repo.lastChange);
item.c = StringUtils.getColor(StringUtils.stripDotGit(repo.name));
if (!repo.isBare) {
item.y = 3;
} else if (repo.isMirror) {
item.y = 2;
} else if (repo.isFork()) {
item.y = 1;
} else {
item.y = 0;
}
list.add(item);
}
// inject an AngularJS controller with static data
NgController ctrl = new NgController(ngCtrl);
ctrl.addVariable(ngList, list);
add(new HeaderContributor(ctrl));
}
use of org.apache.wicket.behavior.HeaderContributor in project gitblit by gitblit.
the class RootPage method setupPage.
@Override
protected void setupPage(String repositoryName, String pageName) {
// CSS header overrides
add(new HeaderContributor(new IHeaderContributor() {
private static final long serialVersionUID = 1L;
@Override
public void renderHead(IHeaderResponse response) {
StringBuilder buffer = new StringBuilder();
buffer.append("<style type=\"text/css\">\n");
buffer.append(".navbar-inner {\n");
final String headerBackground = app().settings().getString(Keys.web.headerBackgroundColor, null);
if (!StringUtils.isEmpty(headerBackground)) {
buffer.append(MessageFormat.format("background-color: {0};\n", headerBackground));
}
final String headerBorder = app().settings().getString(Keys.web.headerBorderColor, null);
if (!StringUtils.isEmpty(headerBorder)) {
buffer.append(MessageFormat.format("border-bottom: 1px solid {0} !important;\n", headerBorder));
}
buffer.append("}\n");
final String headerBorderFocus = app().settings().getString(Keys.web.headerBorderFocusColor, null);
if (!StringUtils.isEmpty(headerBorderFocus)) {
buffer.append(".navbar ul li:focus, .navbar .active {\n");
buffer.append(MessageFormat.format("border-bottom: 4px solid {0};\n", headerBorderFocus));
buffer.append("}\n");
}
final String headerForeground = app().settings().getString(Keys.web.headerForegroundColor, null);
if (!StringUtils.isEmpty(headerForeground)) {
buffer.append(".navbar ul.nav li a {\n");
buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
buffer.append("}\n");
buffer.append(".navbar ul.nav .active a {\n");
buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
buffer.append("}\n");
}
final String headerHover = app().settings().getString(Keys.web.headerHoverColor, null);
if (!StringUtils.isEmpty(headerHover)) {
buffer.append(".navbar ul.nav li a:hover {\n");
buffer.append(MessageFormat.format("color: {0} !important;\n", headerHover));
buffer.append("}\n");
}
buffer.append("</style>\n");
response.renderString(buffer.toString());
}
}));
boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, false);
boolean authenticateAdmin = app().settings().getBoolean(Keys.web.authenticateAdminPages, true);
boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, true);
boolean allowLucene = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
boolean displayUserPanel = app().settings().getBoolean(Keys.web.displayUserPanel, true);
boolean isLoggedIn = GitBlitWebSession.get().isLoggedIn();
if (authenticateAdmin) {
showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
// authentication requires state and session
setStatelessHint(false);
} else {
showAdmin = allowAdmin;
if (authenticateView) {
// authentication requires state and session
setStatelessHint(false);
} else {
// no authentication required, no state and no session required
setStatelessHint(true);
}
}
if (displayUserPanel && (authenticateView || authenticateAdmin)) {
if (isLoggedIn) {
UserMenu userFragment = new UserMenu("userPanel", "userMenuFragment", RootPage.this);
add(userFragment);
} else {
LoginForm loginForm = new LoginForm("userPanel", "loginFormFragment", RootPage.this);
add(loginForm);
}
} else {
add(new Label("userPanel").setVisible(false));
}
// navigation links
List<NavLink> navLinks = new ArrayList<NavLink>();
if (!authenticateView || (authenticateView && isLoggedIn)) {
UserModel user = UserModel.ANONYMOUS;
if (isLoggedIn) {
user = GitBlitWebSession.get().getUser();
}
navLinks.add(new PageNavLink(isLoggedIn ? "gb.myDashboard" : "gb.dashboard", MyDashboardPage.class, getRootPageParameters()));
if (isLoggedIn && app().tickets().isReady()) {
navLinks.add(new PageNavLink("gb.myTickets", MyTicketsPage.class));
}
navLinks.add(new PageNavLink("gb.repositories", RepositoriesPage.class, getRootPageParameters()));
navLinks.add(new PageNavLink("gb.filestore", FilestorePage.class, getRootPageParameters()));
navLinks.add(new PageNavLink("gb.activity", ActivityPage.class, getRootPageParameters()));
if (allowLucene) {
navLinks.add(new PageNavLink("gb.search", LuceneSearchPage.class));
}
if (!authenticateView || (authenticateView && isLoggedIn)) {
addDropDownMenus(navLinks);
}
// add nav link extensions
List<NavLinkExtension> extensions = app().plugins().getExtensions(NavLinkExtension.class);
for (NavLinkExtension ext : extensions) {
navLinks.addAll(ext.getNavLinks(user));
}
}
NavigationPanel navPanel = new NavigationPanel("navPanel", getRootNavPageClass(), navLinks);
add(navPanel);
// display an error message cached from a redirect
String cachedMessage = GitBlitWebSession.get().clearErrorMessage();
if (!StringUtils.isEmpty(cachedMessage)) {
error(cachedMessage);
} else if (showAdmin) {
int pendingProposals = app().federation().getPendingFederationProposals().size();
if (pendingProposals == 1) {
info(getString("gb.OneProposalToReview"));
} else if (pendingProposals > 1) {
info(MessageFormat.format(getString("gb.nFederationProposalsToReview"), pendingProposals));
}
}
super.setupPage(repositoryName, pageName);
}
use of org.apache.wicket.behavior.HeaderContributor in project gitblit by gitblit.
the class FilterableProjectList method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
String id = getId();
String ngCtrl = id + "Ctrl";
String ngList = id + "List";
Map<String, Object> values = new HashMap<String, Object>();
values.put("ngCtrl", ngCtrl);
values.put("ngList", ngList);
// use Freemarker to setup an AngularJS/Wicket html snippet
FreemarkerPanel panel = new FreemarkerPanel("listComponent", "FilterableProjectList.fm", values);
panel.setParseGeneratedMarkup(true);
panel.setRenderBodyOnly(true);
add(panel);
// add the Wicket controls that are referenced in the snippet
String listTitle = StringUtils.isEmpty(title) ? getString("gb.projects") : title;
panel.add(new Label(ngList + "Title", MessageFormat.format("{0} ({1})", listTitle, projects.size())));
if (StringUtils.isEmpty(iconClass)) {
panel.add(new Label(ngList + "Icon").setVisible(false));
} else {
Label icon = new Label(ngList + "Icon");
WicketUtils.setCssClass(icon, iconClass);
panel.add(icon);
}
String format = app().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy");
final DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(getTimeZone());
Collections.sort(projects, new Comparator<ProjectModel>() {
@Override
public int compare(ProjectModel o1, ProjectModel o2) {
return o2.lastChange.compareTo(o1.lastChange);
}
});
List<ProjectListItem> list = new ArrayList<ProjectListItem>();
for (ProjectModel proj : projects) {
if (proj.isUserProject() || proj.repositories.isEmpty()) {
// exclude user projects from list
continue;
}
ProjectListItem item = new ProjectListItem();
item.p = proj.name;
item.n = StringUtils.isEmpty(proj.title) ? proj.name : proj.title;
item.i = proj.description;
item.t = getTimeUtils().timeAgo(proj.lastChange);
item.d = df.format(proj.lastChange);
item.c = proj.repositories.size();
list.add(item);
}
// inject an AngularJS controller with static data
NgController ctrl = new NgController(ngCtrl);
ctrl.addVariable(ngList, list);
add(new HeaderContributor(ctrl));
}
use of org.apache.wicket.behavior.HeaderContributor in project gitblit by gitblit.
the class DashboardPage method addCharts.
/**
* Creates the daily activity line chart, the active repositories pie chart,
* and the active authors pie chart
*
* @param recentChanges
* @param authorExclusions
* @param daysBack
*/
protected void addCharts(Fragment frag, List<DailyLogEntry> recentChanges, Set<String> authorExclusions, int daysBack) {
// activity metrics
Map<String, Metric> repositoryMetrics = new HashMap<String, Metric>();
Map<String, Metric> authorMetrics = new HashMap<String, Metric>();
// aggregate repository and author metrics
int totalCommits = 0;
for (RefLogEntry change : recentChanges) {
// aggregate repository metrics
String repository = StringUtils.stripDotGit(change.repository);
if (!repositoryMetrics.containsKey(repository)) {
repositoryMetrics.put(repository, new Metric(repository));
}
repositoryMetrics.get(repository).count += 1;
for (RepositoryCommit commit : change.getCommits()) {
totalCommits++;
String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
String authorName = author.toLowerCase();
String authorEmail = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();
if (!authorExclusions.contains(authorName) && !authorExclusions.contains(authorEmail)) {
if (!authorMetrics.containsKey(author)) {
authorMetrics.put(author, new Metric(author));
}
authorMetrics.get(author).count += 1;
}
}
}
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())));
if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
// build google charts
Charts charts = new Flotr2Charts();
// 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));
}
}
Aggregations