use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.
the class TicketPage method addUserAttributions.
protected void addUserAttributions(MarkupContainer container, Change entry, int avatarSize) {
UserModel commenter = app().users().getUserModel(entry.author);
if (commenter == null) {
// unknown user
container.add(new AvatarImage("changeAvatar", entry.author, entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
container.add(new Label("changeAuthor", entry.author.toLowerCase()));
} else {
// known user
container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(), commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null, avatarSize, true).setVisible(avatarSize > 0));
container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(commenter.username)));
}
}
use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.
the class TicketPage method createPatchsetPanel.
protected Fragment createPatchsetPanel(String wicketId, RepositoryModel repository, UserModel user) {
final Patchset currentPatchset = ticket.getCurrentPatchset();
List<Patchset> patchsets = new ArrayList<Patchset>(ticket.getPatchsetRevisions(currentPatchset.number));
patchsets.remove(currentPatchset);
Collections.reverse(patchsets);
Fragment panel = new Fragment(wicketId, "collapsiblePatchsetFragment", this);
// patchset header
String ps = "<b>" + currentPatchset.number + "</b>";
if (currentPatchset.rev == 1) {
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetN"), ps)).setEscapeModelStrings(false));
} else {
String rev = "<b>" + currentPatchset.rev + "</b>";
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetNRevisionN"), ps, rev)).setEscapeModelStrings(false));
}
panel.add(new LinkPanel("patchId", null, "rev " + currentPatchset.rev, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, currentPatchset.tip), true));
// compare menu
panel.add(new LinkPanel("compareMergeBase", null, getString("gb.compareToMergeBase"), ComparePage.class, WicketUtils.newRangeParameter(repositoryName, currentPatchset.base, currentPatchset.tip), true));
ListDataProvider<Patchset> compareMenuDp = new ListDataProvider<Patchset>(patchsets);
DataView<Patchset> compareMenu = new DataView<Patchset>("comparePatch", compareMenuDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Patchset> item) {
Patchset patchset = item.getModelObject();
LinkPanel link = new LinkPanel("compareLink", null, MessageFormat.format(getString("gb.compareToN"), patchset.number + "-" + patchset.rev), ComparePage.class, WicketUtils.newRangeParameter(getRepositoryModel().name, patchset.tip, currentPatchset.tip), true);
item.add(link);
}
};
panel.add(compareMenu);
// reviews
List<Change> reviews = ticket.getReviews(currentPatchset);
ListDataProvider<Change> reviewsDp = new ListDataProvider<Change>(reviews);
DataView<Change> reviewsView = new DataView<Change>("reviews", reviewsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Change> item) {
Change change = item.getModelObject();
final String username = change.author;
UserModel user = app().users().getUserModel(username);
if (user == null) {
item.add(new Label("reviewer", username));
} else {
item.add(new LinkPanel("reviewer", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(username)));
}
// indicate review score
Review review = change.review;
Label scoreLabel = new Label("score");
String scoreClass = getScoreClass(review.score);
String tooltip = getScoreDescription(review.score);
WicketUtils.setCssClass(scoreLabel, scoreClass);
if (!StringUtils.isEmpty(tooltip)) {
WicketUtils.setHtmlTooltip(scoreLabel, tooltip);
}
item.add(scoreLabel);
}
};
panel.add(reviewsView);
if (ticket.isOpen() && user.canReviewPatchset(repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
// can only review open tickets
Review myReview = null;
for (Change change : ticket.getReviews(currentPatchset)) {
if (change.author.equals(user.username)) {
myReview = change.review;
}
}
// user can review, add review controls
Fragment reviewControls = new Fragment("reviewControls", "reviewControlsFragment", this);
// show "approve" button if no review OR not current score
if (user.canApprovePatchset(repository) && (myReview == null || Score.approved != myReview.score)) {
reviewControls.add(createReviewLink("approveLink", Score.approved));
} else {
reviewControls.add(new Label("approveLink").setVisible(false));
}
// show "looks good" button if no review OR not current score
if (myReview == null || Score.looks_good != myReview.score) {
reviewControls.add(createReviewLink("looksGoodLink", Score.looks_good));
} else {
reviewControls.add(new Label("looksGoodLink").setVisible(false));
}
// show "needs improvement" button if no review OR not current score
if (myReview == null || Score.needs_improvement != myReview.score) {
reviewControls.add(createReviewLink("needsImprovementLink", Score.needs_improvement));
} else {
reviewControls.add(new Label("needsImprovementLink").setVisible(false));
}
// show "veto" button if no review OR not current score
if (user.canVetoPatchset(repository) && (myReview == null || Score.vetoed != myReview.score)) {
reviewControls.add(createReviewLink("vetoLink", Score.vetoed));
} else {
reviewControls.add(new Label("vetoLink").setVisible(false));
}
panel.add(reviewControls);
} else {
// user can not review
panel.add(new Label("reviewControls").setVisible(false));
}
String insertions = MessageFormat.format("<span style=\"color:darkGreen;font-weight:bold;\">+{0}</span>", ticket.insertions);
String deletions = MessageFormat.format("<span style=\"color:darkRed;font-weight:bold;\">-{0}</span>", ticket.deletions);
panel.add(new Label("patchsetStat", MessageFormat.format(StringUtils.escapeForHtml(getString("gb.diffStat"), false), insertions, deletions)).setEscapeModelStrings(false));
// changed paths list
List<PathChangeModel> paths = JGitUtils.getFilesInRange(getRepository(), currentPatchset.base, currentPatchset.tip);
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
private static final long serialVersionUID = 1L;
int counter;
@Override
public void populateItem(final Item<PathChangeModel> item) {
final PathChangeModel entry = item.getModelObject();
Label changeType = new Label("changeType", "");
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
setChangeTypeTooltip(changeType, entry.changeType);
item.add(changeType);
boolean hasSubmodule = false;
String submodulePath = null;
if (entry.isTree()) {
// tree
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path), true));
item.add(new Label("diffStat").setVisible(false));
} else if (entry.isSubmodule()) {
// submodule
String submoduleId = entry.objectId;
SubmoduleModel submodule = getSubmodule(entry.path);
submodulePath = submodule.gitblitPath;
hasSubmodule = submodule.hasSubmodule;
item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), TreePage.class, WicketUtils.newPathParameter(submodulePath, submoduleId, ""), true).setEnabled(hasSubmodule));
item.add(new Label("diffStat").setVisible(false));
} else {
// blob
String displayPath = entry.path;
String path = entry.path;
if (entry.isSymlink()) {
RevCommit commit = JGitUtils.getCommit(getRepository(), PatchsetCommand.getTicketBranch(ticket.number));
path = JGitUtils.getStringContent(getRepository(), commit.getTree(), path);
displayPath = entry.path + " -> " + path;
}
if (entry.changeType.equals(ChangeType.ADD)) {
// add show view
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
} else if (entry.changeType.equals(ChangeType.DELETE)) {
// delete, show label
item.add(new Label("pathName", displayPath));
} else {
// mod, show diff
item.add(new LinkPanel("pathName", "list", displayPath, BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
}
item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
}
// quick links
if (entry.isSubmodule()) {
// submodule
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD)));
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
} else {
// tree or blob
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newBlobDiffParameter(repositoryName, currentPatchset.base, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD) && !entry.changeType.equals(ChangeType.DELETE)));
item.add(setNewTarget(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
}
WicketUtils.setAlternatingBackground(item, counter);
counter++;
}
};
panel.add(pathsView);
addPtCheckoutInstructions(user, repository, panel);
addGitCheckoutInstructions(user, repository, panel);
return panel;
}
use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.
the class LuceneSearchPage method setup.
private void setup(PageParameters params) {
setupPage("", "");
// default values
ArrayList<String> repositories = new ArrayList<String>();
String query = "";
boolean allRepos = false;
int page = 1;
int pageSize = app().settings().getInteger(Keys.web.itemsPerPage, 50);
// display user-accessible selections
UserModel user = GitBlitWebSession.get().getUser();
List<String> availableRepositories = new ArrayList<String>();
for (RepositoryModel model : app().repositories().getRepositoryModels(user)) {
if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {
availableRepositories.add(model.name);
}
}
if (params != null) {
String repository = WicketUtils.getRepositoryName(params);
if (!StringUtils.isEmpty(repository)) {
repositories.add(repository);
}
page = WicketUtils.getPage(params);
if (params.containsKey("repositories")) {
String value = params.getString("repositories", "");
List<String> list = StringUtils.getStringsFromValue(value);
repositories.addAll(list);
}
allRepos = params.getAsBoolean("allrepos", false);
if (allRepos) {
repositories.addAll(availableRepositories);
}
if (params.containsKey("query")) {
query = params.getString("query", "");
} else {
String value = WicketUtils.getSearchString(params);
String type = WicketUtils.getSearchType(params);
com.gitblit.Constants.SearchType searchType = com.gitblit.Constants.SearchType.forName(type);
if (!StringUtils.isEmpty(value)) {
if (searchType == SearchType.COMMIT) {
query = "type:" + searchType.name().toLowerCase() + " AND \"" + value + "\"";
} else {
query = searchType.name().toLowerCase() + ":\"" + value + "\"";
}
}
}
}
boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
if (luceneEnabled) {
if (availableRepositories.size() == 0) {
info(getString("gb.noIndexedRepositoriesWarning"));
}
} else {
error(getString("gb.luceneDisabled"));
}
// enforce user-accessible repository selections
Set<String> uniqueRepositories = new LinkedHashSet<String>();
for (String selectedRepository : repositories) {
if (availableRepositories.contains(selectedRepository)) {
uniqueRepositories.add(selectedRepository);
}
}
ArrayList<String> searchRepositories = new ArrayList<String>(uniqueRepositories);
// search form
final Model<String> queryModel = new Model<String>(query);
final Model<ArrayList<String>> repositoriesModel = new Model<ArrayList<String>>(searchRepositories);
final Model<Boolean> allreposModel = new Model<Boolean>(allRepos);
SessionlessForm<Void> form = new SessionlessForm<Void>("searchForm", getClass()) {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
String q = queryModel.getObject();
if (StringUtils.isEmpty(q)) {
error(getString("gb.undefinedQueryWarning"));
return;
}
if (repositoriesModel.getObject().size() == 0 && !allreposModel.getObject()) {
error(getString("gb.noSelectedRepositoriesWarning"));
return;
}
PageParameters params = new PageParameters();
params.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
params.put("query", queryModel.getObject());
params.put("allrepos", allreposModel.getObject());
LuceneSearchPage page = new LuceneSearchPage(params);
setResponsePage(page);
}
};
ListMultipleChoice<String> selections = new ListMultipleChoice<String>("repositories", repositoriesModel, availableRepositories, new StringChoiceRenderer());
selections.setMaxRows(8);
form.add(selections.setEnabled(luceneEnabled));
form.add(new TextField<String>("query", queryModel).setEnabled(luceneEnabled));
form.add(new CheckBox("allrepos", allreposModel));
form.add(new ExternalLink("querySyntax", LUCENE_QUERY_SYNTAX_LINK));
add(form.setEnabled(luceneEnabled));
// execute search
final List<SearchResult> results = new ArrayList<SearchResult>();
if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
results.addAll(app().repositories().search(query, page, pageSize, searchRepositories));
}
// results header
if (results.size() == 0) {
if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
add(new Label("resultsHeader", query).setRenderBodyOnly(true));
add(new Label("resultsCount", getString("gb.noHits")).setRenderBodyOnly(true));
} else {
add(new Label("resultsHeader").setVisible(false));
add(new Label("resultsCount").setVisible(false));
}
} else {
add(new Label("resultsHeader", query).setRenderBodyOnly(true));
add(new Label("resultsCount", MessageFormat.format(getString("gb.queryResults"), results.get(0).hitId, results.get(results.size() - 1).hitId, results.get(0).totalHits)).setRenderBodyOnly(true));
}
// search results view
ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);
final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<SearchResult> item) {
final SearchResult sr = item.getModelObject();
switch(sr.type) {
case commit:
{
Label icon = WicketUtils.newIcon("type", "icon-refresh");
WicketUtils.setHtmlTooltip(icon, "commit");
item.add(icon);
item.add(new LinkPanel("summary", null, sr.summary, CommitPage.class, WicketUtils.newObjectParameter(sr.repository, sr.commitId)));
// show tags
Fragment fragment = new Fragment("tags", "tagsPanel", LuceneSearchPage.this);
List<String> tags = sr.tags;
if (tags == null) {
tags = new ArrayList<String>();
}
ListDataProvider<String> tagsDp = new ListDataProvider<String>(tags);
final DataView<String> tagsView = new DataView<String>("tag", tagsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<String> item) {
String tag = item.getModelObject();
Component c = new LinkPanel("tagLink", null, tag, TagPage.class, WicketUtils.newObjectParameter(sr.repository, Constants.R_TAGS + tag));
WicketUtils.setCssClass(c, "tagRef");
item.add(c);
}
};
fragment.add(tagsView);
item.add(fragment);
break;
}
case blob:
{
Label icon = WicketUtils.newIcon("type", "icon-file");
WicketUtils.setHtmlTooltip(icon, "blob");
item.add(icon);
item.add(new LinkPanel("summary", null, sr.path, BlobPage.class, WicketUtils.newPathParameter(sr.repository, sr.branch, sr.path)));
item.add(new Label("tags").setVisible(false));
break;
}
}
item.add(new Label("fragment", sr.fragment).setEscapeModelStrings(false).setVisible(!StringUtils.isEmpty(sr.fragment)));
item.add(new LinkPanel("repository", null, sr.repository, SummaryPage.class, WicketUtils.newRepositoryParameter(sr.repository)));
if (StringUtils.isEmpty(sr.branch)) {
item.add(new Label("branch", "null"));
} else {
item.add(new LinkPanel("branch", "branch", StringUtils.getRelativePath(Constants.R_HEADS, sr.branch), LogPage.class, WicketUtils.newObjectParameter(sr.repository, sr.branch)));
}
item.add(new Label("author", sr.author));
item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone(), getTimeUtils()));
}
};
add(resultsView.setVisible(results.size() > 0));
PageParameters pagerParams = new PageParameters();
pagerParams.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
pagerParams.put("query", queryModel.getObject());
boolean showPager = false;
int totalPages = 0;
if (results.size() > 0) {
totalPages = (results.get(0).totalHits / pageSize) + (results.get(0).totalHits % pageSize > 0 ? 1 : 0);
showPager = results.get(0).totalHits > pageSize;
}
add(new PagerPanel("topPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
add(new PagerPanel("bottomPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
}
use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.
the class ProjectsPage 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()) {
add(new Label("projectsPanel"));
return;
}
List<ProjectModel> projects = getProjects(params);
Collections.sort(projects);
ListDataProvider<ProjectModel> dp = new ListDataProvider<ProjectModel>(projects);
DataView<ProjectModel> dataView = new DataView<ProjectModel>("project", dp) {
private static final long serialVersionUID = 1L;
int counter;
@Override
protected void onBeforeRender() {
super.onBeforeRender();
counter = 0;
}
@Override
public void populateItem(final Item<ProjectModel> item) {
final ProjectModel entry = item.getModelObject();
PageParameters pp = WicketUtils.newProjectParameter(entry.name);
item.add(new LinkPanel("projectTitle", "list", entry.getDisplayName(), ProjectPage.class, pp));
item.add(new LinkPanel("projectDescription", "list", entry.description, ProjectPage.class, pp));
item.add(new Label("repositoryCount", entry.repositories.size() + " " + (entry.repositories.size() == 1 ? getString("gb.repository") : getString("gb.repositories"))));
String lastChange;
if (entry.lastChange.getTime() == 0) {
lastChange = "--";
} else {
lastChange = getTimeUtils().timeAgo(entry.lastChange);
}
Label lastChangeLabel = new Label("projectLastChange", lastChange);
item.add(lastChangeLabel);
WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
WicketUtils.setAlternatingBackground(item, counter);
counter++;
}
};
add(dataView);
}
use of com.gitblit.wicket.panels.LinkPanel in project gitblit by gitblit.
the class MyTicketsPage method buildPager.
protected void buildPager(final String query, final String milestone, final String[] states, final String assignedTo, final String sort, final boolean desc, final String repositoryId, final int page, int pageSize, int count, int total) {
boolean showNav = total > (2 * pageSize);
boolean allowPrev = page > 1;
boolean allowNext = (pageSize * (page - 1) + count) < total;
add(new BookmarkablePageLink<Void>("prevLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page - 1)).setEnabled(allowPrev).setVisible(showNav));
add(new BookmarkablePageLink<Void>("nextLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page + 1)).setEnabled(allowNext).setVisible(showNav));
if (total <= pageSize) {
add(new Label("pageLink").setVisible(false));
return;
}
// determine page numbers to display
int pages = count == 0 ? 0 : ((total / pageSize) + (total % pageSize == 0 ? 0 : 1));
// preferred number of pagelinks
int segments = 5;
if (pages < segments) {
// not enough data for preferred number of page links
segments = pages;
}
int minpage = Math.min(Math.max(1, page - 2), pages - (segments - 1));
int maxpage = Math.min(pages, minpage + (segments - 1));
List<Integer> sequence = new ArrayList<Integer>();
for (int i = minpage; i <= maxpage; i++) {
sequence.add(i);
}
ListDataProvider<Integer> pagesDp = new ListDataProvider<Integer>(sequence);
DataView<Integer> pagesView = new DataView<Integer>("pageLink", pagesDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Integer> item) {
final Integer i = item.getModelObject();
LinkPanel link = new LinkPanel("page", null, "" + i, MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, i));
link.setRenderBodyOnly(true);
if (i == page) {
WicketUtils.setCssClass(item, "active");
}
item.add(link);
}
};
add(pagesView);
}
Aggregations