Search in sources :

Example 1 with DiffStatPanel

use of com.gitblit.wicket.panels.DiffStatPanel 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;
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) TicketLabel(com.gitblit.tickets.TicketLabel) Patchset(com.gitblit.models.TicketModel.Patchset) Review(com.gitblit.models.TicketModel.Review) Fragment(org.apache.wicket.markup.html.panel.Fragment) LinkPanel(com.gitblit.wicket.panels.LinkPanel) UserModel(com.gitblit.models.UserModel) Item(org.apache.wicket.markup.repeater.Item) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffStatPanel(com.gitblit.wicket.panels.DiffStatPanel) PathChangeModel(com.gitblit.models.PathModel.PathChangeModel) SubmoduleModel(com.gitblit.models.SubmoduleModel) Change(com.gitblit.models.TicketModel.Change) BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink) DataView(org.apache.wicket.markup.repeater.data.DataView)

Aggregations

PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)1 SubmoduleModel (com.gitblit.models.SubmoduleModel)1 Change (com.gitblit.models.TicketModel.Change)1 Patchset (com.gitblit.models.TicketModel.Patchset)1 Review (com.gitblit.models.TicketModel.Review)1 UserModel (com.gitblit.models.UserModel)1 TicketLabel (com.gitblit.tickets.TicketLabel)1 DiffStatPanel (com.gitblit.wicket.panels.DiffStatPanel)1 LinkPanel (com.gitblit.wicket.panels.LinkPanel)1 ArrayList (java.util.ArrayList)1 Label (org.apache.wicket.markup.html.basic.Label)1 BookmarkablePageLink (org.apache.wicket.markup.html.link.BookmarkablePageLink)1 Fragment (org.apache.wicket.markup.html.panel.Fragment)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 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1