| | |
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.TreeSet;
|
| | | import java.util.concurrent.atomic.AtomicInteger;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import org.apache.wicket.MarkupContainer;
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.behavior.HeaderContributor;
|
| | | import org.apache.wicket.markup.html.IHeaderContributor;
|
| | | import org.apache.wicket.markup.html.IHeaderResponse;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.form.PasswordTextField;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | |
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ModelUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.PageRegistration.DropDownMenuItem;
|
| | | import com.gitblit.wicket.PageRegistration.DropDownToggleItem;
|
| | | import com.gitblit.wicket.SessionlessForm;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.GravatarImage;
|
| | |
| | | /**
|
| | | * Root page is a topbar, navigable page like Repositories, Users, or
|
| | | * Federation.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public abstract class RootPage extends BasePage {
|
| | |
|
| | |
| | |
|
| | | @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 = GitBlit.getString(Keys.web.headerBackgroundColor, null);
|
| | | if (!StringUtils.isEmpty(headerBackground)) {
|
| | | buffer.append(MessageFormat.format("background-color: {0};\n", headerBackground));
|
| | | }
|
| | | final String headerBorder = GitBlit.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 = GitBlit.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 = GitBlit.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 = GitBlit.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 = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);
|
| | | boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true);
|
| | |
| | | setStatelessHint(true);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (authenticateView || authenticateAdmin) {
|
| | | if (GitBlitWebSession.get().isLoggedIn()) {
|
| | | UserMenu userFragment = new UserMenu("userPanel", "userMenuFragment", RootPage.this);
|
| | |
| | | } else {
|
| | | add(new Label("userPanel").setVisible(false));
|
| | | }
|
| | | |
| | |
|
| | | boolean showRegistrations = GitBlit.canFederate()
|
| | | && GitBlit.getBoolean(Keys.web.showFederationRegistrations, false);
|
| | |
|
| | | // navigation links
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>();
|
| | | if (!authenticateView || (authenticateView && GitBlitWebSession.get().isLoggedIn())) {
|
| | | pages.add(new PageRegistration("gb.dashboard", DashboardPage.class,
|
| | | pages.add(new PageRegistration(GitBlitWebSession.get().isLoggedIn() ? "gb.myDashboard" : "gb.dashboard", MyDashboardPage.class,
|
| | | getRootPageParameters()));
|
| | | pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class,
|
| | | getRootPageParameters()));
|
| | |
| | | addDropDownMenus(pages);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | NavigationPanel navPanel = new NavigationPanel("navPanel", getRootNavPageClass(), pages);
|
| | | add(navPanel);
|
| | |
|
| | |
| | |
|
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | | |
| | |
|
| | | protected Class<? extends BasePage> getRootNavPageClass() {
|
| | | return getClass();
|
| | | }
|
| | |
| | |
|
| | | // remove days back parameter if it is the default value
|
| | | if (params.containsKey("db")
|
| | | && params.getInt("db") == GitBlit.getInteger(Keys.web.activityDuration, 14)) {
|
| | | && params.getInt("db") == GitBlit.getInteger(Keys.web.activityDuration, 7)) {
|
| | | params.remove("db");
|
| | | }
|
| | | return params;
|
| | | } |
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | protected List<RepositoryModel> getRepositoryModels() {
|
| | | if (repositoryModels.isEmpty()) {
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | |
| | | List<String> sets = new ArrayList<String>(setMap.keySet());
|
| | | Collections.sort(sets);
|
| | | for (String set : sets) {
|
| | | filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", set,
|
| | | filters.add(new DropDownToggleItem(MessageFormat.format("{0} ({1})", set,
|
| | | setMap.get(set).get()), "set", set, params));
|
| | | }
|
| | | // divider
|
| | |
| | | List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);
|
| | | Collections.sort(teams);
|
| | | for (TeamModel team : teams) {
|
| | | filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", team.name,
|
| | | filters.add(new DropDownToggleItem(MessageFormat.format("{0} ({1})", team.name,
|
| | | team.repositories.size()), "team", team.name, params));
|
| | | }
|
| | | // divider
|
| | |
| | | for (String expression : expressions) {
|
| | | if (!StringUtils.isEmpty(expression)) {
|
| | | addedExpression = true;
|
| | | filters.add(new DropDownMenuItem(null, "x", expression, params));
|
| | | filters.add(new DropDownToggleItem(null, "x", expression, params));
|
| | | }
|
| | | }
|
| | | // if we added any custom expressions, add a divider
|
| | |
| | |
|
| | | protected List<DropDownMenuItem> getTimeFilterItems(PageParameters params) {
|
| | | // days back choices - additive parameters
|
| | | int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14);
|
| | | int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7);
|
| | | int maxDaysBack = GitBlit.getInteger(Keys.web.activityDurationMaximum, 30);
|
| | | if (daysBack < 1) {
|
| | | daysBack = 14;
|
| | | daysBack = 7;
|
| | | }
|
| | | if (daysBack > maxDaysBack) {
|
| | | daysBack = maxDaysBack;
|
| | | }
|
| | | PageParameters clonedParams;
|
| | | if (params == null) {
|
| | | clonedParams = new PageParameters();
|
| | | } else {
|
| | | clonedParams = new PageParameters(params);
|
| | | }
|
| | |
|
| | | if (!clonedParams.containsKey("db")) {
|
| | | clonedParams.put("db", daysBack);
|
| | | }
|
| | |
|
| | | List<DropDownMenuItem> items = new ArrayList<DropDownMenuItem>();
|
| | | Set<Integer> choicesSet = new HashSet<Integer>(Arrays.asList(daysBack, 14, 28, 60, 90, 180));
|
| | | Set<Integer> choicesSet = new TreeSet<Integer>(GitBlit.getIntegers(Keys.web.activityDurationChoices));
|
| | | if (choicesSet.isEmpty()) {
|
| | | choicesSet.addAll(Arrays.asList(1, 3, 7, 14, 21, 28));
|
| | | }
|
| | | List<Integer> choices = new ArrayList<Integer>(choicesSet);
|
| | | Collections.sort(choices);
|
| | | String lastDaysPattern = getString("gb.lastNDays");
|
| | | for (Integer db : choices) {
|
| | | String txt = MessageFormat.format(lastDaysPattern, db);
|
| | | items.add(new DropDownMenuItem(txt, "db", db.toString(), params));
|
| | | if (db == 1) {
|
| | | items.add(new DropDownMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));
|
| | | } else {
|
| | | String txt = MessageFormat.format(lastDaysPattern, db);
|
| | | items.add(new DropDownMenuItem(txt, "db", db.toString(), clonedParams));
|
| | | }
|
| | | }
|
| | | items.add(new DropDownMenuItem());
|
| | | return items;
|
| | |
| | | String userName = WicketUtils.getUsername(params);
|
| | | if (StringUtils.isEmpty(projectName)) {
|
| | | if (!StringUtils.isEmpty(userName)) {
|
| | | projectName = "~" + userName;
|
| | | projectName = ModelUtils.getPersonalPath(userName);
|
| | | }
|
| | | }
|
| | | String repositoryName = WicketUtils.getRepositoryName(params);
|
| | |
| | | String regex = WicketUtils.getRegEx(params);
|
| | | String team = WicketUtils.getTeam(params);
|
| | | int daysBack = params.getInt("db", 0);
|
| | | int maxDaysBack = GitBlit.getInteger(Keys.web.activityDurationMaximum, 30);
|
| | |
|
| | | List<RepositoryModel> availableModels = getRepositoryModels();
|
| | | Set<RepositoryModel> models = new HashSet<RepositoryModel>();
|
| | |
| | |
|
| | | if (!StringUtils.isEmpty(projectName)) {
|
| | | // try named project
|
| | | hasParameter = true; |
| | | hasParameter = true;
|
| | | if (projectName.equalsIgnoreCase(GitBlit.getString(Keys.web.repositoryRootGroupName, "main"))) {
|
| | | // root project/group
|
| | | for (RepositoryModel model : availableModels) {
|
| | |
| | |
|
| | | // time-filter the list
|
| | | if (daysBack > 0) {
|
| | | if (maxDaysBack > 0 && daysBack > maxDaysBack) {
|
| | | daysBack = maxDaysBack;
|
| | | }
|
| | | Calendar cal = Calendar.getInstance();
|
| | | cal.set(Calendar.HOUR_OF_DAY, 0);
|
| | | cal.set(Calendar.MINUTE, 0);
|
| | |
| | | }
|
| | | models = timeFiltered;
|
| | | }
|
| | | |
| | |
|
| | | List<RepositoryModel> list = new ArrayList<RepositoryModel>(models);
|
| | | Collections.sort(list);
|
| | | return list;
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Inline login form. |
| | | * Inline login form.
|
| | | */
|
| | | private class LoginForm extends Fragment {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
| | | add(loginForm);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Menu for the authenticated user.
|
| | | */
|
| | |
| | | }
|
| | |
|
| | | add(new Label("displayName", user.getDisplayName()));
|
| | | |
| | | add(new BookmarkablePageLink<Void>("myProfile", |
| | |
|
| | | add(new BookmarkablePageLink<Void>("newRepository",
|
| | | EditRepositoryPage.class).setVisible(user.canAdmin() || user.canCreate()));
|
| | |
|
| | | add(new BookmarkablePageLink<Void>("myProfile",
|
| | | UserPage.class, WicketUtils.newUsernameParameter(user.username)));
|
| | |
|
| | | add(new BookmarkablePageLink<Void>("changePassword", |
| | | add(new BookmarkablePageLink<Void>("changePassword",
|
| | | ChangePasswordPage.class).setVisible(editCredentials));
|
| | | |
| | |
|
| | | add(new BookmarkablePageLink<Void>("logout",
|
| | | LogoutPage.class).setVisible(standardLogin));
|
| | | }
|