| | |
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | |
| | | import org.apache.wicket.markup.html.form.DropDownChoice;
|
| | | import org.apache.wicket.markup.html.form.StatelessForm;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | | import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
| | | import org.apache.wicket.markup.html.link.ExternalLink;
|
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.apache.wicket.markup.repeater.Item;
|
| | | import org.apache.wicket.markup.repeater.data.DataView;
|
| | | import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
| | | import org.apache.wicket.model.IModel;
|
| | | import org.apache.wicket.model.Model;
|
| | | import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
| | |
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.SyndicationServlet;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.JGitUtils.SearchType;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.utils.TicgitUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.LinkPanel;
|
| | | import com.gitblit.wicket.panels.NavigationPanel;
|
| | | import com.gitblit.wicket.panels.RefsPanel;
|
| | |
|
| | | public abstract class RepositoryPage extends BasePage {
|
| | |
| | |
|
| | | private RepositoryModel m;
|
| | |
|
| | | private final Map<String, PageRegistration> registeredPages = new HashMap<String, PageRegistration>() {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | {
|
| | | put("summary", new PageRegistration("gb.summary", SummaryPage.class));
|
| | | put("log", new PageRegistration("gb.log", LogPage.class));
|
| | | put("branches", new PageRegistration("gb.branches", BranchesPage.class));
|
| | | put("tags", new PageRegistration("gb.tags", TagsPage.class));
|
| | | put("tree", new PageRegistration("gb.tree", TreePage.class));
|
| | | put("tickets", new PageRegistration("gb.tickets", TicketsPage.class));
|
| | | put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class));
|
| | | put("docs", new PageRegistration("gb.docs", DocsPage.class));
|
| | | }
|
| | | };
|
| | | private final Map<String, PageRegistration> registeredPages;
|
| | |
|
| | | public RepositoryPage(PageParameters params) {
|
| | | super(params);
|
| | |
| | | error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true);
|
| | | }
|
| | |
|
| | | Repository r = getRepository();
|
| | | RepositoryModel model = getRepositoryModel();
|
| | | if (!getRepositoryModel().hasCommits) {
|
| | | setResponsePage(EmptyRepositoryPage.class, params);
|
| | | }
|
| | |
|
| | | // register the available page links for this page and user
|
| | | registeredPages = registerPages();
|
| | |
|
| | | // standard page links
|
| | | addRegisteredPageLink("summary");
|
| | | addRegisteredPageLink("log");
|
| | | addRegisteredPageLink("branches");
|
| | | addRegisteredPageLink("tags");
|
| | | addRegisteredPageLink("tree");
|
| | |
|
| | | // per-repository extra page links
|
| | | List<String> extraPageLinks = new ArrayList<String>();
|
| | | if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
|
| | | extraPageLinks.add("tickets");
|
| | | }
|
| | | if (model.useDocs) {
|
| | | extraPageLinks.add("docs");
|
| | | }
|
| | |
|
| | | final boolean showAdmin;
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | } else {
|
| | | showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | }
|
| | |
|
| | | // Conditionally add edit link
|
| | | if (showAdmin
|
| | | || GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()
|
| | | .getUser().username))) {
|
| | | extraPageLinks.add("edit");
|
| | | }
|
| | |
|
| | | final String pageName = getPageName();
|
| | | final String pageWicketId = getLinkWicketId(pageName);
|
| | | ListDataProvider<String> extrasDp = new ListDataProvider<String>(extraPageLinks);
|
| | | DataView<String> extrasView = new DataView<String>("extra", extrasDp) {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public void populateItem(final Item<String> item) {
|
| | | String extra = item.getModelObject();
|
| | | PageRegistration pageReg = registeredPages.get(extra);
|
| | | item.add(new Label("extraSeparator", " | "));
|
| | | item.add(new LinkPanel("extraLink", null, getString(pageReg.translationKey),
|
| | | pageReg.pageClass, WicketUtils.newRepositoryParameter(repositoryName))
|
| | | .setEnabled(!extra.equals(pageWicketId)));
|
| | | }
|
| | | };
|
| | | add(extrasView);
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>(registeredPages.values());
|
| | | NavigationPanel navigationPanel = new NavigationPanel("navPanel", getClass(), pages);
|
| | | add(navigationPanel);
|
| | |
|
| | | add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()
|
| | | .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));
|
| | |
|
| | | // disable current page
|
| | | disableRegisteredPageLink(pageName);
|
| | |
|
| | | // add floating search form
|
| | | SearchForm searchForm = new SearchForm("searchForm", repositoryName);
|
| | |
| | | setStatelessHint(true);
|
| | | }
|
| | |
|
| | | public String getLinkWicketId(String pageName) {
|
| | | for (String wicketId : registeredPages.keySet()) {
|
| | | String key = registeredPages.get(wicketId).translationKey;
|
| | | String linkName = getString(key);
|
| | | if (linkName.equals(pageName)) {
|
| | | return wicketId;
|
| | | }
|
| | | private Map<String, PageRegistration> registerPages() {
|
| | | PageParameters params = null;
|
| | | if (!StringUtils.isEmpty(repositoryName)) {
|
| | | params = WicketUtils.newRepositoryParameter(repositoryName);
|
| | | }
|
| | | return null;
|
| | | Map<String, PageRegistration> pages = new LinkedHashMap<String, PageRegistration>();
|
| | |
|
| | | // standard links
|
| | | pages.put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class));
|
| | | pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
|
| | | pages.put("log", new PageRegistration("gb.log", LogPage.class, params));
|
| | | pages.put("branches", new PageRegistration("gb.branches", BranchesPage.class, params));
|
| | | pages.put("tags", new PageRegistration("gb.tags", TagsPage.class, params));
|
| | | pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
|
| | |
|
| | | // conditional links
|
| | | Repository r = getRepository();
|
| | | RepositoryModel model = getRepositoryModel();
|
| | |
|
| | | // per-repository extra page links
|
| | | if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
|
| | | pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params));
|
| | | }
|
| | | if (model.useDocs) {
|
| | | pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params));
|
| | | }
|
| | | // Conditionally add edit link
|
| | | final boolean showAdmin;
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | } else {
|
| | | showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | }
|
| | | if (showAdmin
|
| | | || GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()
|
| | | .getUser().username))) {
|
| | | pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));
|
| | | }
|
| | | return pages;
|
| | | }
|
| | |
|
| | | public void disableRegisteredPageLink(String pageName) {
|
| | | String wicketId = getLinkWicketId(pageName);
|
| | | if (!StringUtils.isEmpty(wicketId)) {
|
| | | Component c = get(wicketId);
|
| | | if (c != null) {
|
| | | c.setEnabled(false);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void addRegisteredPageLink(String key) {
|
| | | PageRegistration pageReg = registeredPages.get(key);
|
| | | add(new BookmarkablePageLink<Void>(key, pageReg.pageClass,
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | add(new LinkPanel("repositoryName", null, repositoryName, SummaryPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new Label("pageName", pageName));
|
| | |
|
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | |
|
| | | protected void addSyndicationDiscoveryLink() {
|
| | |
| | | protected abstract String getPageName();
|
| | |
|
| | | protected Component createPersonPanel(String wicketId, PersonIdent identity,
|
| | | SearchType searchType) {
|
| | | Constants.SearchType searchType) {
|
| | | String name = identity == null ? "" : identity.getName();
|
| | | String address = identity == null ? "" : identity.getEmailAddress();
|
| | | boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false);
|
| | | if (!showEmail || StringUtils.isEmpty(identity.getName())
|
| | | || StringUtils.isEmpty(identity.getEmailAddress())) {
|
| | | String value = identity.getName();
|
| | | if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) {
|
| | | String value = name;
|
| | | if (StringUtils.isEmpty(value)) {
|
| | | if (showEmail) {
|
| | | value = identity.getEmailAddress();
|
| | | value = address;
|
| | | } else {
|
| | | value = getString("gb.missingUsername");
|
| | | }
|
| | |
| | | return partial;
|
| | | } else {
|
| | | Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this);
|
| | | LinkPanel nameLink = new LinkPanel("personName", "list", identity.getName(),
|
| | | SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | identity.getName(), searchType));
|
| | | setPersonSearchTooltip(nameLink, identity.getName(), searchType);
|
| | | LinkPanel nameLink = new LinkPanel("personName", "list", name, SearchPage.class,
|
| | | WicketUtils.newSearchParameter(repositoryName, objectId, name, searchType));
|
| | | setPersonSearchTooltip(nameLink, name, searchType);
|
| | | fullPerson.add(nameLink);
|
| | |
|
| | | LinkPanel addressLink = new LinkPanel("personAddress", "list", "<"
|
| | | + identity.getEmailAddress() + ">", SearchPage.class,
|
| | | WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | identity.getEmailAddress(), searchType));
|
| | | setPersonSearchTooltip(addressLink, identity.getEmailAddress(), searchType);
|
| | | LinkPanel addressLink = new LinkPanel("personAddress", "list", "<" + address + ">",
|
| | | SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | address, searchType));
|
| | | setPersonSearchTooltip(addressLink, address, searchType);
|
| | | fullPerson.add(addressLink);
|
| | | return fullPerson;
|
| | | }
|
| | | }
|
| | |
|
| | | protected void setPersonSearchTooltip(Component component, String value, SearchType searchType) {
|
| | | if (searchType.equals(SearchType.AUTHOR)) {
|
| | | protected void setPersonSearchTooltip(Component component, String value, Constants.SearchType searchType) {
|
| | | if (searchType.equals(Constants.SearchType.AUTHOR)) {
|
| | | WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value);
|
| | | } else if (searchType.equals(SearchType.COMMITTER)) {
|
| | | } else if (searchType.equals(Constants.SearchType.COMMITTER)) {
|
| | | WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value);
|
| | | }
|
| | | }
|
| | |
| | | return WicketUtils.newObjectParameter(repositoryName, commitId);
|
| | | }
|
| | |
|
| | | private static class PageRegistration implements Serializable {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | final String translationKey;
|
| | | final Class<? extends BasePage> pageClass;
|
| | |
|
| | | PageRegistration(String translationKey, Class<? extends BasePage> pageClass) {
|
| | | this.translationKey = translationKey;
|
| | | this.pageClass = pageClass;
|
| | | }
|
| | | }
|
| | |
|
| | | private static class SearchForm extends StatelessForm<Void> implements Serializable {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | |
| | |
|
| | | private final IModel<String> searchBoxModel = new Model<String>("");
|
| | |
|
| | | private final IModel<SearchType> searchTypeModel = new Model<SearchType>(SearchType.COMMIT);
|
| | | private final IModel<Constants.SearchType> searchTypeModel = new Model<Constants.SearchType>(Constants.SearchType.COMMIT);
|
| | |
|
| | | public SearchForm(String id, String repositoryName) {
|
| | | super(id);
|
| | | this.repositoryName = repositoryName;
|
| | | DropDownChoice<SearchType> searchType = new DropDownChoice<SearchType>("searchType",
|
| | | Arrays.asList(SearchType.values()));
|
| | | DropDownChoice<Constants.SearchType> searchType = new DropDownChoice<Constants.SearchType>("searchType",
|
| | | Arrays.asList(Constants.SearchType.values()));
|
| | | searchType.setModel(searchTypeModel);
|
| | | add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false)));
|
| | | TextField<String> searchBox = new TextField<String>("searchBox", searchBoxModel);
|
| | |
| | |
|
| | | void setTranslatedAttributes() {
|
| | | WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip"));
|
| | | WicketUtils.setHtmlTooltip(get("searchBox"), getString("gb.searchTooltip"));
|
| | | WicketUtils.setHtmlTooltip(get("searchBox"),
|
| | | MessageFormat.format(getString("gb.searchTooltip"), repositoryName));
|
| | | WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void onSubmit() {
|
| | | SearchType searchType = searchTypeModel.getObject();
|
| | | Constants.SearchType searchType = searchTypeModel.getObject();
|
| | | String searchString = searchBoxModel.getObject();
|
| | | for (SearchType type : SearchType.values()) {
|
| | | if (searchString == null) {
|
| | | // FIXME IE intermittently has no searchString. Wicket bug?
|
| | | return;
|
| | | }
|
| | | for (Constants.SearchType type : Constants.SearchType.values()) {
|
| | | if (searchString.toLowerCase().startsWith(type.name().toLowerCase() + ":")) {
|
| | | searchType = type;
|
| | | searchString = searchString.substring(type.name().toLowerCase().length() + 1)
|