Search in sources :

Example 46 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.

the class TicketPage method createCopyFragment.

protected Fragment createCopyFragment(String wicketId, String text) {
    if (app().settings().getBoolean(Keys.web.allowFlashCopyToClipboard, true)) {
        // clippy: flash-based copy & paste
        Fragment copyFragment = new Fragment(wicketId, "clippyPanel", this);
        String baseUrl = WicketUtils.getGitblitURL(getRequest());
        ShockWaveComponent clippy = new ShockWaveComponent("clippy", baseUrl + "/clippy.swf");
        clippy.setValue("flashVars", "text=" + StringUtils.encodeURL(text));
        copyFragment.add(clippy);
        return copyFragment;
    } else {
        // javascript: manual copy & paste with modal browser prompt dialog
        Fragment copyFragment = new Fragment(wicketId, "jsPanel", this);
        ContextImage img = WicketUtils.newImage("copyIcon", "clippy.png");
        img.add(new JavascriptTextPrompt("onclick", "Copy to Clipboard (Ctrl+C, Enter)", text));
        copyFragment.add(img);
        return copyFragment;
    }
}
Also used : ShockWaveComponent(com.gitblit.wicket.panels.ShockWaveComponent) ContextImage(org.apache.wicket.markup.html.image.ContextImage) JavascriptTextPrompt(com.gitblit.wicket.panels.BasePanel.JavascriptTextPrompt) Fragment(org.apache.wicket.markup.html.panel.Fragment)

Example 47 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment 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)

Example 48 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.

the class AccessPolicyPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    AccessPolicy anonymousPolicy = new AccessPolicy(getString("gb.anonymousPolicy"), getString("gb.anonymousPolicyDescription"), "blank.png", AuthorizationControl.AUTHENTICATED, AccessRestrictionType.NONE);
    AccessPolicy authenticatedPushPolicy = new AccessPolicy(getString("gb.authenticatedPushPolicy"), getString("gb.authenticatedPushPolicyDescription"), "lock_go_16x16.png", AuthorizationControl.AUTHENTICATED, AccessRestrictionType.PUSH);
    AccessPolicy namedPushPolicy = new AccessPolicy(getString("gb.namedPushPolicy"), getString("gb.namedPushPolicyDescription"), "lock_go_16x16.png", AuthorizationControl.NAMED, AccessRestrictionType.PUSH);
    AccessPolicy clonePolicy = new AccessPolicy(getString("gb.clonePolicy"), getString("gb.clonePolicyDescription"), "lock_pull_16x16.png", AuthorizationControl.NAMED, AccessRestrictionType.CLONE);
    AccessPolicy viewPolicy = new AccessPolicy(getString("gb.viewPolicy"), getString("gb.viewPolicyDescription"), "shield_16x16.png", AuthorizationControl.NAMED, AccessRestrictionType.VIEW);
    List<AccessPolicy> policies = new ArrayList<AccessPolicy>();
    if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {
        policies.add(anonymousPolicy);
    }
    policies.add(authenticatedPushPolicy);
    policies.add(namedPushPolicy);
    policies.add(clonePolicy);
    policies.add(viewPolicy);
    AccessRestrictionType defaultRestriction = repository.accessRestriction;
    if (defaultRestriction == null) {
        defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
    }
    AuthorizationControl defaultControl = repository.authorizationControl;
    if (defaultControl == null) {
        defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl, AuthorizationControl.NAMED.name()));
    }
    AccessPolicy defaultPolicy = namedPushPolicy;
    for (AccessPolicy policy : policies) {
        if (policy.type == defaultRestriction && policy.control == defaultControl) {
            defaultPolicy = policy;
        }
    }
    policiesGroup = new RadioGroup<>("policiesGroup", new Model<AccessPolicy>(defaultPolicy));
    ListView<AccessPolicy> policiesList = new ListView<AccessPolicy>("policies", policies) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<AccessPolicy> item) {
            AccessPolicy p = item.getModelObject();
            item.add(new Radio<AccessPolicy>("radio", item.getModel()));
            item.add(WicketUtils.newImage("image", p.image));
            item.add(new Label("name", p.name));
            item.add(new Label("description", p.description));
        }
    };
    policiesGroup.add(policiesList);
    if (callback != null) {
        policiesGroup.add(callback);
        policiesGroup.setOutputMarkupId(true);
    }
    add(policiesGroup);
    if (app().settings().getBoolean(Keys.web.allowForking, true)) {
        Fragment fragment = new Fragment("allowForks", "allowForksFragment", this);
        fragment.add(new BooleanOption("allowForks", getString("gb.allowForks"), getString("gb.allowForksDescription"), new PropertyModel<Boolean>(repository, "allowForks")));
        add(fragment);
    } else {
        add(new Label("allowForks").setVisible(false));
    }
    setOutputMarkupId(true);
}
Also used : ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) ListView(org.apache.wicket.markup.html.list.ListView) Model(org.apache.wicket.model.Model) RepositoryModel(com.gitblit.models.RepositoryModel) PropertyModel(org.apache.wicket.model.PropertyModel) AccessRestrictionType(com.gitblit.Constants.AccessRestrictionType) AuthorizationControl(com.gitblit.Constants.AuthorizationControl) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 49 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.

the class RepositoryUrlPanel method createRepositoryIndicators.

protected Component createRepositoryIndicators(RepositoryModel repository) {
    Fragment fragment = new Fragment("repositoryIndicators", "indicatorsFragment", this);
    if (repository.isBare) {
        fragment.add(new Label("workingCopyIndicator").setVisible(false));
    } else {
        Fragment wc = new Fragment("workingCopyIndicator", "workingCopyFragment", this);
        Label lbl = new Label("workingCopy", getString("gb.workingCopy"));
        WicketUtils.setHtmlTooltip(lbl, getString("gb.workingCopyWarning"));
        wc.add(lbl);
        fragment.add(wc);
    }
    boolean allowForking = app().settings().getBoolean(Keys.web.allowForking, true);
    if (!allowForking || user == null || !user.isAuthenticated) {
        // must be logged-in to fork, hide all fork controls
        fragment.add(new Label("forksProhibitedIndicator").setVisible(false));
    } else {
        String fork = app().repositories().getFork(user.username, repository.name);
        boolean hasFork = fork != null;
        boolean canFork = user.canFork(repository);
        if (hasFork || !canFork) {
            if (user.canFork() && !repository.allowForks) {
                // show forks prohibited indicator
                Fragment wc = new Fragment("forksProhibitedIndicator", "forksProhibitedFragment", this);
                Label lbl = new Label("forksProhibited", getString("gb.forksProhibited"));
                WicketUtils.setHtmlTooltip(lbl, getString("gb.forksProhibitedWarning"));
                wc.add(lbl);
                fragment.add(wc);
            } else {
                // can not fork, no need for forks prohibited indicator
                fragment.add(new Label("forksProhibitedIndicator").setVisible(false));
            }
        } else if (canFork) {
            // can fork and we do not have one
            fragment.add(new Label("forksProhibitedIndicator").setVisible(false));
        }
    }
    return fragment;
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) Fragment(org.apache.wicket.markup.html.panel.Fragment)

Example 50 with Fragment

use of org.apache.wicket.markup.html.panel.Fragment in project gitblit by gitblit.

the class DashboardPage method addCharts.

/**
 * Creates the daily activity line chart, the active repositories pie chart,
 * and the active authors pie chart
 *
 * @param recentChanges
 * @param authorExclusions
 * @param daysBack
 */
protected void addCharts(Fragment frag, List<DailyLogEntry> recentChanges, Set<String> authorExclusions, int daysBack) {
    // activity metrics
    Map<String, Metric> repositoryMetrics = new HashMap<String, Metric>();
    Map<String, Metric> authorMetrics = new HashMap<String, Metric>();
    // aggregate repository and author metrics
    int totalCommits = 0;
    for (RefLogEntry change : recentChanges) {
        // aggregate repository metrics
        String repository = StringUtils.stripDotGit(change.repository);
        if (!repositoryMetrics.containsKey(repository)) {
            repositoryMetrics.put(repository, new Metric(repository));
        }
        repositoryMetrics.get(repository).count += 1;
        for (RepositoryCommit commit : change.getCommits()) {
            totalCommits++;
            String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
            String authorName = author.toLowerCase();
            String authorEmail = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();
            if (!authorExclusions.contains(authorName) && !authorExclusions.contains(authorEmail)) {
                if (!authorMetrics.containsKey(author)) {
                    authorMetrics.put(author, new Metric(author));
                }
                authorMetrics.get(author).count += 1;
            }
        }
    }
    String headerPattern;
    if (daysBack == 1) {
        // today
        if (totalCommits == 0) {
            headerPattern = getString("gb.todaysActivityNone");
        } else {
            headerPattern = getString("gb.todaysActivityStats");
        }
    } else {
        // multiple days
        if (totalCommits == 0) {
            headerPattern = getString("gb.recentActivityNone");
        } else {
            headerPattern = getString("gb.recentActivityStats");
        }
    }
    frag.add(new Label("feedheader", MessageFormat.format(headerPattern, daysBack, totalCommits, authorMetrics.size())));
    if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
        // build google charts
        Charts charts = new Flotr2Charts();
        // active repositories pie chart
        Chart chart = charts.createPieChart("chartRepositories", getString("gb.activeRepositories"), getString("gb.repository"), getString("gb.commits"));
        for (Metric metric : repositoryMetrics.values()) {
            chart.addValue(metric.name, metric.count);
        }
        chart.setShowLegend(false);
        String url = urlFor(SummaryPage.class, null).toString() + "?r=";
        chart.setClickUrl(url);
        charts.addChart(chart);
        // active authors pie chart
        chart = charts.createPieChart("chartAuthors", getString("gb.activeAuthors"), getString("gb.author"), getString("gb.commits"));
        for (Metric metric : authorMetrics.values()) {
            chart.addValue(metric.name, metric.count);
        }
        chart.setShowLegend(false);
        charts.addChart(chart);
        add(new HeaderContributor(charts));
        frag.add(new Fragment("charts", "chartsFragment", this));
    } else {
        frag.add(new Label("charts").setVisible(false));
    }
}
Also used : Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) HashMap(java.util.HashMap) Label(org.apache.wicket.markup.html.basic.Label) Charts(com.gitblit.wicket.charting.Charts) Flotr2Charts(com.gitblit.wicket.charting.Flotr2Charts) RepositoryCommit(com.gitblit.models.RepositoryCommit) Fragment(org.apache.wicket.markup.html.panel.Fragment) RefLogEntry(com.gitblit.models.RefLogEntry) HeaderContributor(org.apache.wicket.behavior.HeaderContributor) Metric(com.gitblit.models.Metric) Chart(com.gitblit.wicket.charting.Chart)

Aggregations

Fragment (org.apache.wicket.markup.html.panel.Fragment)51 Label (org.apache.wicket.markup.html.basic.Label)20 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 ArrayList (java.util.ArrayList)9 LinkPanel (com.gitblit.wicket.panels.LinkPanel)6 Component (org.apache.wicket.Component)6 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)6 RepositoryModel (com.gitblit.models.RepositoryModel)5 UserModel (com.gitblit.models.UserModel)5 Item (org.apache.wicket.markup.repeater.Item)5 DataView (org.apache.wicket.markup.repeater.data.DataView)5 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)5 ResourceModel (org.apache.wicket.model.ResourceModel)4 TicketLabel (com.gitblit.tickets.TicketLabel)3 List (java.util.List)3 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)3 IndicatingAjaxLink (org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink)3 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)3 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)2 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)2