Search in sources :

Example 1 with GitblitRedirectException

use of com.gitblit.wicket.GitblitRedirectException in project gitblit by gitblit.

the class UserPage 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()) {
        authenticationError("Please login");
        return;
    }
    String userName = WicketUtils.getUsername(params);
    if (StringUtils.isEmpty(userName)) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    UserModel user = app().users().getUserModel(userName);
    if (user == null) {
        // construct a temporary user model
        user = new UserModel(userName);
    }
    add(new UserTitlePanel("userTitlePanel", user, user.username));
    UserModel sessionUser = GitBlitWebSession.get().getUser();
    boolean isMyProfile = sessionUser != null && sessionUser.equals(user);
    if (isMyProfile) {
        addPreferences(user);
        if (app().services().isServingSSH()) {
            // show the SSH key management tab
            addSshKeys(user);
        } else {
            // SSH daemon is disabled, hide keys tab
            add(new Label("sshKeysLink").setVisible(false));
            add(new Label("sshKeysTab").setVisible(false));
        }
    } else {
        // visiting user
        add(new Label("preferencesLink").setVisible(false));
        add(new Label("preferencesTab").setVisible(false));
        add(new Label("sshKeysLink").setVisible(false));
        add(new Label("sshKeysTab").setVisible(false));
    }
    List<RepositoryModel> repositories = getRepositories(params);
    Collections.sort(repositories, new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            // reverse-chronological sort
            return o2.lastChange.compareTo(o1.lastChange);
        }
    });
    final ListDataProvider<RepositoryModel> dp = new ListDataProvider<RepositoryModel>(repositories);
    DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("repositoryList", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RepositoryModel> item) {
            final RepositoryModel entry = item.getModelObject();
            ProjectRepositoryPanel row = new ProjectRepositoryPanel("repository", getLocalizer(), this, showAdmin, entry, getAccessRestrictions());
            item.add(row);
        }
    };
    add(dataView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) UserTitlePanel(com.gitblit.wicket.panels.UserTitlePanel) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) GitblitRedirectException(com.gitblit.wicket.GitblitRedirectException) UserModel(com.gitblit.models.UserModel) DataView(org.apache.wicket.markup.repeater.data.DataView) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) Item(org.apache.wicket.markup.repeater.Item) ProjectRepositoryPanel(com.gitblit.wicket.panels.ProjectRepositoryPanel)

Example 2 with GitblitRedirectException

use of com.gitblit.wicket.GitblitRedirectException in project gitblit by gitblit.

the class ProjectPage 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()) {
        authenticationError("Please login");
        return;
    }
    String projectName = params == null ? null : WicketUtils.getProjectName(params);
    if (StringUtils.isEmpty(projectName)) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    ProjectModel project = getProjectModel(projectName);
    if (project == null) {
        throw new GitblitRedirectException(GitBlitWebApp.get().getHomePage());
    }
    add(new Label("projectTitle", project.getDisplayName()));
    add(new Label("projectDescription", project.description));
    String feedLink = SyndicationServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), projectName, null, 0);
    add(new ExternalLink("syndication", feedLink));
    add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(project.getDisplayName(), null), feedLink));
    // project markdown message
    String pmessage = transformMarkdown(project.projectMarkdown);
    Component projectMessage = new Label("projectMessage", pmessage).setEscapeModelStrings(false).setVisible(pmessage.length() > 0);
    add(projectMessage);
    // markdown message above repositories list
    String rmessage = transformMarkdown(project.repositoriesMarkdown);
    Component repositoriesMessage = new Label("repositoriesMessage", rmessage).setEscapeModelStrings(false).setVisible(rmessage.length() > 0);
    add(repositoriesMessage);
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
        user = UserModel.ANONYMOUS;
    }
    int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
    if (daysBack < 1) {
        daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
    }
    // reflog utils.
    if (params != null) {
        params.remove("db");
    }
    List<RepositoryModel> repositories = getRepositories(params);
    Collections.sort(repositories, new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            // reverse-chronological sort
            return o2.lastChange.compareTo(o1.lastChange);
        }
    });
    addActivity(user, repositories, getString("gb.recentActivity"), daysBack);
    if (repositories.isEmpty()) {
        add(new Label("repositoryList").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("repositoryList", repositories);
        repoList.setAllowCreate(user.canCreate(project.name + "/"));
        add(repoList);
    }
}
Also used : FilterableRepositoryList(com.gitblit.wicket.panels.FilterableRepositoryList) Label(org.apache.wicket.markup.html.basic.Label) RepositoryModel(com.gitblit.models.RepositoryModel) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) GitblitRedirectException(com.gitblit.wicket.GitblitRedirectException) UserModel(com.gitblit.models.UserModel) ProjectModel(com.gitblit.models.ProjectModel) Component(org.apache.wicket.Component)

Aggregations

RepositoryModel (com.gitblit.models.RepositoryModel)2 UserModel (com.gitblit.models.UserModel)2 GitblitRedirectException (com.gitblit.wicket.GitblitRedirectException)2 Label (org.apache.wicket.markup.html.basic.Label)2 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)1 ProjectModel (com.gitblit.models.ProjectModel)1 FilterableRepositoryList (com.gitblit.wicket.panels.FilterableRepositoryList)1 ProjectRepositoryPanel (com.gitblit.wicket.panels.ProjectRepositoryPanel)1 UserTitlePanel (com.gitblit.wicket.panels.UserTitlePanel)1 Component (org.apache.wicket.Component)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 Item (org.apache.wicket.markup.repeater.Item)1 DataView (org.apache.wicket.markup.repeater.data.DataView)1 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)1