Search in sources :

Example 1 with UserTitlePanel

use of com.gitblit.wicket.panels.UserTitlePanel 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)

Aggregations

ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)1 RepositoryModel (com.gitblit.models.RepositoryModel)1 UserModel (com.gitblit.models.UserModel)1 GitblitRedirectException (com.gitblit.wicket.GitblitRedirectException)1 ProjectRepositoryPanel (com.gitblit.wicket.panels.ProjectRepositoryPanel)1 UserTitlePanel (com.gitblit.wicket.panels.UserTitlePanel)1 Label (org.apache.wicket.markup.html.basic.Label)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