use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.
the class MyDashboardPage method setup.
private void setup(PageParameters params) {
setupPage("", "");
// check to see if we should display a login message
boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit");
String message = readMarkdown(messageSource, "login.mkd");
Component repositoriesMessage = new Label("repositoriesMessage", message);
add(repositoriesMessage.setEscapeModelStrings(false));
add(new Label("activity").setVisible(false));
add(new Label("repositoryTabs").setVisible(false));
return;
}
// Load the markdown welcome message
String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit");
String message = readMarkdown(messageSource, "welcome.mkd");
Component repositoriesMessage = new Label("repositoriesMessage", message).setEscapeModelStrings(false).setVisible(message.length() > 0);
add(repositoriesMessage);
UserModel user = GitBlitWebSession.get().getUser();
if (user == null) {
user = UserModel.ANONYMOUS;
}
// parameters
int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
if (daysBack < 1) {
daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
}
if (maxDaysBack > 0 && daysBack > maxDaysBack) {
daysBack = maxDaysBack;
}
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1 * daysBack);
Date minimumDate = c.getTime();
// build repo lists
List<RepositoryModel> starred = new ArrayList<RepositoryModel>();
List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
List<RepositoryModel> active = new ArrayList<RepositoryModel>();
for (RepositoryModel model : getRepositoryModels()) {
if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
owned.add(model);
}
if (user.getPreferences().isStarredRepository(model.name)) {
starred.add(model);
}
if (model.isShowActivity() && model.lastChange.after(minimumDate)) {
active.add(model);
}
}
Comparator<RepositoryModel> lastUpdateSort = new Comparator<RepositoryModel>() {
@Override
public int compare(RepositoryModel o1, RepositoryModel o2) {
return o2.lastChange.compareTo(o1.lastChange);
}
};
Collections.sort(owned, lastUpdateSort);
Collections.sort(starred, lastUpdateSort);
Collections.sort(active, lastUpdateSort);
String activityTitle;
Set<RepositoryModel> feed = new HashSet<RepositoryModel>();
feed.addAll(starred);
feed.addAll(owned);
if (feed.isEmpty()) {
// no starred or owned, go with recent activity
activityTitle = getString("gb.recentActivity");
feed.addAll(active);
} else if (starred.isEmpty()) {
// no starred, owned repos feed
activityTitle = getString("gb.owned");
} else if (owned.isEmpty()) {
// no owned, starred repos feed
activityTitle = getString("gb.starred");
} else {
// starred and owned repositories
activityTitle = getString("gb.starredAndOwned");
}
addActivity(user, feed, activityTitle, daysBack);
Fragment repositoryTabs;
if (UserModel.ANONYMOUS.equals(user)) {
repositoryTabs = new Fragment("repositoryTabs", "anonymousTabsFragment", this);
} else {
repositoryTabs = new Fragment("repositoryTabs", "authenticatedTabsFragment", this);
}
add(repositoryTabs);
// projects list
List<ProjectModel> projects = app().projects().getProjectModels(getRepositoryModels(), false);
repositoryTabs.add(new FilterableProjectList("projects", projects));
// active repository list
if (active.isEmpty()) {
repositoryTabs.add(new Label("active").setVisible(false));
} else {
FilterableRepositoryList repoList = new FilterableRepositoryList("active", active);
repoList.setTitle(getString("gb.activeRepositories"), "icon-time");
repositoryTabs.add(repoList);
}
// starred repository list
if (ArrayUtils.isEmpty(starred)) {
repositoryTabs.add(new Label("starred").setVisible(false));
} else {
FilterableRepositoryList repoList = new FilterableRepositoryList("starred", starred);
repoList.setTitle(getString("gb.starredRepositories"), "icon-star");
repositoryTabs.add(repoList);
}
// owned repository list
if (ArrayUtils.isEmpty(owned)) {
repositoryTabs.add(new Label("owned").setVisible(false));
} else {
FilterableRepositoryList repoList = new FilterableRepositoryList("owned", owned);
repoList.setTitle(getString("gb.myRepositories"), "icon-user");
repoList.setAllowCreate(user.canCreate() || user.canAdmin());
repositoryTabs.add(repoList);
}
}
use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.
the class DashboardPage method addActivity.
protected void addActivity(UserModel user, Collection<RepositoryModel> repositories, String feedTitle, int daysBack) {
Calendar c = Calendar.getInstance();
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) {
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));
if (digests.size() == 0) {
// quiet or no starred repositories
if (repositories.size() == 0) {
if (UserModel.ANONYMOUS.equals(user)) {
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 {
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
Collections.sort(digests);
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 : app().settings().getStrings(Keys.web.metricAuthorExclusions)) {
authorExclusions.add(author.toLowerCase());
}
for (RepositoryModel model : repositories) {
if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
for (String author : model.metricAuthorExclusions) {
authorExclusions.add(author.toLowerCase());
}
}
}
addCharts(activityFragment, digests, authorExclusions, daysBack);
} else {
activityFragment.add(new Label("charts").setVisible(false));
activityFragment.add(new Label("feedheader").setVisible(false));
}
}
use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.
the class RepositoryUrlPanel method createApplicationMenus.
protected Fragment createApplicationMenus(String wicketId, final UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) {
final List<GitClientApplication> displayedApps = new ArrayList<GitClientApplication>();
final String userAgent = ((WebClientInfo) GitBlitWebSession.get().getClientInfo()).getUserAgent();
if (user.canClone(repository)) {
for (GitClientApplication app : app().gitblit().getClientApplications()) {
if (app.isActive && app.allowsPlatform(userAgent)) {
displayedApps.add(app);
}
}
}
final String baseURL = WicketUtils.getGitblitURL(RequestCycle.get().getRequest());
ListDataProvider<GitClientApplication> displayedAppsDp = new ListDataProvider<GitClientApplication>(displayedApps);
DataView<GitClientApplication> appMenus = new DataView<GitClientApplication>("appMenus", displayedAppsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<GitClientApplication> item) {
final GitClientApplication clientApp = item.getModelObject();
// filter the urls for the client app
List<RepositoryUrl> urls = new ArrayList<RepositoryUrl>();
for (RepositoryUrl repoUrl : repositoryUrls) {
if (clientApp.minimumPermission == null || !repoUrl.hasPermission()) {
// no minimum permission or untracked permissions, assume it is satisfactory
if (clientApp.supportsTransport(repoUrl.url)) {
urls.add(repoUrl);
}
} else if (repoUrl.permission.atLeast(clientApp.minimumPermission)) {
// repo url meets minimum permission requirement
if (clientApp.supportsTransport(repoUrl.url)) {
urls.add(repoUrl);
}
}
}
if (urls.size() == 0) {
// do not show this app menu because there are no urls
item.add(new Label("appMenu").setVisible(false));
return;
}
Fragment appMenu = new Fragment("appMenu", "appMenuFragment", this);
appMenu.setRenderBodyOnly(true);
item.add(appMenu);
// menu button
appMenu.add(new Label("applicationName", clientApp.name));
// application icon
Component img;
if (StringUtils.isEmpty(clientApp.icon)) {
img = WicketUtils.newClearPixel("applicationIcon").setVisible(false);
} else {
if (clientApp.icon.contains("://")) {
// external image
img = new ExternalImage("applicationIcon", clientApp.icon);
} else {
// context image
img = WicketUtils.newImage("applicationIcon", clientApp.icon);
}
}
appMenu.add(img);
// application menu title, may be a link
if (StringUtils.isEmpty(clientApp.productUrl)) {
appMenu.add(new Label("applicationTitle", clientApp.toString()));
} else {
appMenu.add(new LinkPanel("applicationTitle", null, clientApp.toString(), clientApp.productUrl, true));
}
// brief application description
if (StringUtils.isEmpty(clientApp.description)) {
appMenu.add(new Label("applicationDescription").setVisible(false));
} else {
appMenu.add(new Label("applicationDescription", clientApp.description));
}
// brief application legal info, copyright, license, etc
if (StringUtils.isEmpty(clientApp.legal)) {
appMenu.add(new Label("applicationLegal").setVisible(false));
} else {
appMenu.add(new Label("applicationLegal", clientApp.legal));
}
// a nested repeater for all action items
ListDataProvider<RepositoryUrl> urlsDp = new ListDataProvider<RepositoryUrl>(urls);
DataView<RepositoryUrl> actionItems = new DataView<RepositoryUrl>("actionItems", urlsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RepositoryUrl> repoLinkItem) {
RepositoryUrl repoUrl = repoLinkItem.getModelObject();
Fragment fragment = new Fragment("actionItem", "actionFragment", this);
fragment.add(createPermissionBadge("permission", repoUrl));
if (!StringUtils.isEmpty(clientApp.cloneUrl)) {
// custom registered url
String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL, user.username, repository.name);
fragment.add(new LinkPanel("content", "applicationMenuItem", getString("gb.clone") + " " + repoUrl.url, url));
repoLinkItem.add(fragment);
fragment.add(new Label("copyFunction").setVisible(false));
} else if (!StringUtils.isEmpty(clientApp.command)) {
// command-line
String command = substitute(clientApp.command, repoUrl.url, baseURL, user.username, repository.name);
Label content = new Label("content", command);
WicketUtils.setCssClass(content, "commandMenuItem");
fragment.add(content);
repoLinkItem.add(fragment);
// copy function for command
fragment.add(createCopyFragment(command));
}
}
};
appMenu.add(actionItems);
}
};
Fragment applicationMenus = new Fragment(wicketId, "applicationMenusFragment", this);
applicationMenus.add(appMenus);
return applicationMenus;
}
use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.
the class RepositoryUrlPanel method createPrimaryUrlPanel.
protected Fragment createPrimaryUrlPanel(String wicketId, final RepositoryModel repository, List<RepositoryUrl> repositoryUrls) {
Fragment urlPanel = new Fragment(wicketId, "repositoryUrlFragment", this);
urlPanel.setRenderBodyOnly(true);
if (repositoryUrls.size() == 1) {
//
// Single repository url, no dropdown menu
//
urlPanel.add(new Label("menu").setVisible(false));
} else {
//
// Multiple repository urls, show url drop down menu
//
ListDataProvider<RepositoryUrl> urlsDp = new ListDataProvider<RepositoryUrl>(repositoryUrls);
DataView<RepositoryUrl> repoUrlMenuItems = new DataView<RepositoryUrl>("repoUrls", urlsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RepositoryUrl> item) {
RepositoryUrl repoUrl = item.getModelObject();
// repository url
Fragment fragment = new Fragment("repoUrl", "actionFragment", this);
Component content = new Label("content", repoUrl.url).setRenderBodyOnly(true);
WicketUtils.setCssClass(content, "commandMenuItem");
fragment.add(content);
item.add(fragment);
Label permissionLabel = new Label("permission", repoUrl.hasPermission() ? repoUrl.permission.toString() : externalPermission);
WicketUtils.setPermissionClass(permissionLabel, repoUrl.permission);
String tooltip = getProtocolPermissionDescription(repository, repoUrl);
WicketUtils.setHtmlTooltip(permissionLabel, tooltip);
fragment.add(permissionLabel);
fragment.add(createCopyFragment(repoUrl.url));
}
};
Fragment urlMenuFragment = new Fragment("menu", "urlProtocolMenuFragment", this);
urlMenuFragment.setRenderBodyOnly(true);
urlMenuFragment.add(new Label("menuText", getString("gb.url")));
urlMenuFragment.add(repoUrlMenuItems);
urlPanel.add(urlMenuFragment);
}
// access restriction icon and tooltip
if (repository.isMirror) {
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "mirror_16x16.png", getString("gb.isMirror")));
} else if (app().services().isServingRepositories()) {
switch(repository.accessRestriction) {
case NONE:
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
break;
case PUSH:
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png", getAccessRestrictions().get(repository.accessRestriction)));
break;
case CLONE:
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png", getAccessRestrictions().get(repository.accessRestriction)));
break;
case VIEW:
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png", getAccessRestrictions().get(repository.accessRestriction)));
break;
default:
if (repositoryUrls.size() == 1) {
// force left end cap to have some width
urlPanel.add(WicketUtils.newBlankIcon("accessRestrictionIcon"));
} else {
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
}
}
} else {
if (repositoryUrls.size() == 1) {
// force left end cap to have some width
urlPanel.add(WicketUtils.newBlankIcon("accessRestrictionIcon"));
} else {
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
}
}
urlPanel.add(new Label("primaryUrl", primaryUrl.url).setRenderBodyOnly(true));
Label permissionLabel = new Label("primaryUrlPermission", primaryUrl.hasPermission() ? primaryUrl.permission.toString() : externalPermission);
String tooltip = getProtocolPermissionDescription(repository, primaryUrl);
WicketUtils.setHtmlTooltip(permissionLabel, tooltip);
urlPanel.add(permissionLabel);
urlPanel.add(createCopyFragment(primaryUrl.url));
return urlPanel;
}
use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.
the class RepositoryUrlPanel method createCopyFragment.
protected Fragment createCopyFragment(String text) {
if (app().settings().getBoolean(Keys.web.allowFlashCopyToClipboard, true)) {
// clippy: flash-based copy & paste
Fragment copyFragment = new Fragment("copyFunction", "clippyPanel", this);
String baseUrl = WicketUtils.getGitblitURL(getRequest());
ShockWaveComponent clippy = new ShockWaveComponent("clippy", baseUrl + "/clippy.swf");
clippy.setValue("flashVars", "text=" + StringUtils.encodeURL(text));
copyFragment.add(clippy);
return copyFragment;
} else {
// javascript: manual copy & paste with modal browser prompt dialog
Fragment copyFragment = new Fragment("copyFunction", "jsPanel", this);
ContextImage img = WicketUtils.newImage("copyIcon", "clippy.png");
img.add(new JavascriptTextPrompt("onclick", "Copy to Clipboard (Ctrl+C, Enter)", text));
copyFragment.add(img);
return copyFragment;
}
}
Aggregations