Search in sources :

Example 1 with LabelInfo

use of com.google.gerrit.client.info.ChangeInfo.LabelInfo in project gerrit by GerritCodeReview.

the class QuickApprove method set.

void set(ChangeInfo info, String commit, ReplyAction action) {
    if (!info.hasPermittedLabels() || !info.status().isOpen()) {
        // Quick approve needs at least one label on an open change.
        setVisible(false);
        return;
    }
    if (info.revision(commit).isEdit() || info.revision(commit).draft()) {
        setVisible(false);
        return;
    }
    String qName = null;
    String qValueStr = null;
    short qValue = 0;
    int index = info.getMissingLabelIndex();
    if (index != -1) {
        LabelInfo label = Natives.asList(info.allLabels().values()).get(index);
        JsArrayString values = info.permittedValues(label.name());
        String s = values.get(values.length() - 1);
        short v = LabelInfo.parseValue(s);
        if (v > 0 && s.equals(label.maxValue())) {
            qName = label.name();
            qValueStr = s;
            qValue = v;
        }
    }
    if (qName != null) {
        changeId = info.legacyId();
        revision = commit;
        input = ReviewInput.create();
        input.drafts(DraftHandling.PUBLISH_ALL_REVISIONS);
        input.label(qName, qValue);
        replyAction = action;
        setText(qName + qValueStr);
        setVisible(true);
    } else {
        setVisible(false);
    }
}
Also used : LabelInfo(com.google.gerrit.client.info.ChangeInfo.LabelInfo) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 2 with LabelInfo

use of com.google.gerrit.client.info.ChangeInfo.LabelInfo in project gerrit by GerritCodeReview.

the class ChangeTable method populateChangeRow.

private void populateChangeRow(final int row, final ChangeInfo c, boolean highlightUnreviewed) {
    CellFormatter fmt = table.getCellFormatter();
    if (Gerrit.isSignedIn()) {
        table.setWidget(row, C_STAR, StarredChanges.createIcon(c.legacyId(), c.starred()));
    }
    table.setWidget(row, C_ID, new TableChangeLink(String.valueOf(c.legacyId()), c));
    String subject = Util.cropSubject(c.subject());
    table.setWidget(row, C_SUBJECT, new TableChangeLink(subject, c));
    Change.Status status = c.status();
    if (status != Change.Status.NEW) {
        table.setText(row, C_STATUS, Util.toLongString(status) + (c.isPrivate() ? (" " + Util.C.isPrivate()) : ""));
    } else if (!c.mergeable()) {
        table.setText(row, C_STATUS, Util.C.changeTableNotMergeable() + (c.isPrivate() ? (" " + Util.C.isPrivate()) : ""));
    } else if (c.isPrivate()) {
        table.setText(row, C_STATUS, Util.C.isPrivate());
    }
    if (c.owner() != null) {
        table.setWidget(row, C_OWNER, AccountLinkPanel.withStatus(c.owner(), status));
    } else {
        table.setText(row, C_OWNER, "");
    }
    if (showAssignee) {
        if (c.assignee() != null) {
            table.setWidget(row, C_ASSIGNEE, AccountLinkPanel.forAssignee(c.assignee()));
            if (Gerrit.getUserPreferences().highlightAssigneeInChangeTable() && Objects.equals(c.assignee().getId(), Gerrit.getUserAccount().getId())) {
                table.getRowFormatter().addStyleName(row, Gerrit.RESOURCES.css().cASSIGNEDTOME());
            }
        } else {
            table.setText(row, C_ASSIGNEE, "");
        }
    }
    table.setWidget(row, C_PROJECT, new ProjectLink(c.projectNameKey()));
    table.setWidget(row, C_BRANCH, new BranchLink(c.projectNameKey(), c.status(), c.branch(), c.topic()));
    if (Gerrit.getUserPreferences().relativeDateInChangeTable()) {
        table.setText(row, C_LAST_UPDATE, relativeFormat(c.updated()));
    } else {
        table.setText(row, C_LAST_UPDATE, shortFormat(c.updated()));
    }
    int col = C_SIZE;
    if (!Gerrit.getUserPreferences().sizeBarInChangeTable()) {
        table.setText(row, col, Util.M.insertionsAndDeletions(c.insertions(), c.deletions()));
    } else {
        table.setWidget(row, col, getSizeWidget(c));
        fmt.getElement(row, col).setTitle(Util.M.insertionsAndDeletions(c.insertions(), c.deletions()));
    }
    col++;
    for (int idx = 0; idx < labelNames.size(); idx++, col++) {
        String name = labelNames.get(idx);
        LabelInfo label = c.label(name);
        if (label == null) {
            fmt.getElement(row, col).setTitle(Gerrit.C.labelNotApplicable());
            fmt.addStyleName(row, col, Gerrit.RESOURCES.css().labelNotApplicable());
            continue;
        }
        String user;
        String info;
        ReviewCategoryStrategy reviewCategoryStrategy = Gerrit.getUserPreferences().reviewCategoryStrategy();
        if (label.rejected() != null) {
            user = label.rejected().name();
            info = getReviewCategoryDisplayInfo(reviewCategoryStrategy, label.rejected());
            if (info != null) {
                FlowPanel panel = new FlowPanel();
                panel.add(new Image(Gerrit.RESOURCES.redNot()));
                panel.add(new InlineLabel(info));
                table.setWidget(row, col, panel);
            } else {
                table.setWidget(row, col, new Image(Gerrit.RESOURCES.redNot()));
            }
        } else if (label.approved() != null) {
            user = label.approved().name();
            info = getReviewCategoryDisplayInfo(reviewCategoryStrategy, label.approved());
            if (info != null) {
                FlowPanel panel = new FlowPanel();
                panel.add(new Image(Gerrit.RESOURCES.greenCheck()));
                panel.add(new InlineLabel(info));
                table.setWidget(row, col, panel);
            } else {
                table.setWidget(row, col, new Image(Gerrit.RESOURCES.greenCheck()));
            }
        } else if (label.disliked() != null) {
            user = label.disliked().name();
            info = getReviewCategoryDisplayInfo(reviewCategoryStrategy, label.disliked());
            String vstr = String.valueOf(label._value());
            if (info != null) {
                vstr = vstr + " " + info;
            }
            fmt.addStyleName(row, col, Gerrit.RESOURCES.css().negscore());
            table.setText(row, col, vstr);
        } else if (label.recommended() != null) {
            user = label.recommended().name();
            info = getReviewCategoryDisplayInfo(reviewCategoryStrategy, label.recommended());
            String vstr = "+" + label._value();
            if (info != null) {
                vstr = vstr + " " + info;
            }
            fmt.addStyleName(row, col, Gerrit.RESOURCES.css().posscore());
            table.setText(row, col, vstr);
        } else {
            table.clearCell(row, col);
            continue;
        }
        fmt.addStyleName(row, col, Gerrit.RESOURCES.css().singleLine());
        if (user != null) {
            // Some web browsers ignore the embedded newline; some like it;
            // so we include a space before the newline to accommodate both.
            fmt.getElement(row, col).setTitle(name + " \nby " + user);
        }
    }
    boolean needHighlight = false;
    if (highlightUnreviewed && !c.reviewed()) {
        needHighlight = true;
    }
    final Element tr = fmt.getElement(row, 0).getParentElement();
    UIObject.setStyleName(tr, Gerrit.RESOURCES.css().needsReview(), needHighlight);
    setRowItem(row, c);
}
Also used : ReviewCategoryStrategy(com.google.gerrit.extensions.client.GeneralPreferencesInfo.ReviewCategoryStrategy) Element(com.google.gwt.dom.client.Element) BranchLink(com.google.gerrit.client.ui.BranchLink) Change(com.google.gerrit.reviewdb.client.Change) CellFormatter(com.google.gwt.user.client.ui.HTMLTable.CellFormatter) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) Image(com.google.gwt.user.client.ui.Image) LabelInfo(com.google.gerrit.client.info.ChangeInfo.LabelInfo) ProjectLink(com.google.gerrit.client.ui.ProjectLink) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) InlineLabel(com.google.gwt.user.client.ui.InlineLabel)

Example 3 with LabelInfo

use of com.google.gerrit.client.info.ChangeInfo.LabelInfo in project gerrit by GerritCodeReview.

the class Reviewers method votable.

private static Map<Integer, VotableInfo> votable(ChangeInfo change) {
    Map<Integer, VotableInfo> d = new HashMap<>();
    for (String name : change.labels()) {
        LabelInfo label = change.label(name);
        Short labelMaxValue = label.valueSet().isEmpty() ? null : LabelInfo.parseValue(label.maxValue());
        if (label.all() != null) {
            for (ApprovalInfo ai : Natives.asList(label.all())) {
                int id = ai._accountId();
                VotableInfo ad = d.get(id);
                if (ad == null) {
                    ad = new VotableInfo();
                    d.put(id, ad);
                }
                if (labelMaxValue != null && ai.permittedVotingRange() != null && ai.permittedVotingRange().max() == labelMaxValue) {
                    ad.votable(name + " (" + label.maxValue() + ") ");
                } else if (ai.hasValue()) {
                    ad.votable(name);
                }
            }
        }
    }
    return d;
}
Also used : LabelInfo(com.google.gerrit.client.info.ChangeInfo.LabelInfo) ApprovalInfo(com.google.gerrit.client.info.ChangeInfo.ApprovalInfo) HashMap(java.util.HashMap) NativeString(com.google.gerrit.client.rpc.NativeString)

Example 4 with LabelInfo

use of com.google.gerrit.client.info.ChangeInfo.LabelInfo in project gerrit by GerritCodeReview.

the class Labels method set.

void set(ChangeInfo info) {
    List<String> names = new ArrayList<>(info.labels());
    Set<Integer> removable = info.removableReviewerIds();
    Collections.sort(names);
    resize(names.size(), 2);
    for (int row = 0; row < names.size(); row++) {
        String name = names.get(row);
        LabelInfo label = info.label(name);
        setText(row, 0, name);
        if (label.all() != null) {
            setWidget(row, 1, renderUsers(label, removable));
        }
        getCellFormatter().setStyleName(row, 0, style.labelName());
        getCellFormatter().addStyleName(row, 0, getStyleForLabel(label));
    }
}
Also used : LabelInfo(com.google.gerrit.client.info.ChangeInfo.LabelInfo) ArrayList(java.util.ArrayList)

Example 5 with LabelInfo

use of com.google.gerrit.client.info.ChangeInfo.LabelInfo in project gerrit by GerritCodeReview.

the class ChangeScreen method isSubmittable.

private boolean isSubmittable(ChangeInfo info) {
    boolean canSubmit = info.status().isOpen() && revision.equals(info.currentRevision()) && !info.revision(revision).draft();
    if (canSubmit && info.status() == Change.Status.NEW) {
        for (String name : info.labels()) {
            LabelInfo label = info.label(name);
            switch(label.status()) {
                case NEED:
                    statusText.setInnerText(Util.M.needs(name));
                    canSubmit = false;
                    break;
                case REJECT:
                case IMPOSSIBLE:
                    if (label.blocking()) {
                        statusText.setInnerText(Util.M.blockedOn(name));
                        canSubmit = false;
                    }
                    break;
                case MAY:
                case OK:
                default:
                    break;
            }
        }
    }
    return canSubmit;
}
Also used : LabelInfo(com.google.gerrit.client.info.ChangeInfo.LabelInfo) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

LabelInfo (com.google.gerrit.client.info.ChangeInfo.LabelInfo)5 JsArrayString (com.google.gwt.core.client.JsArrayString)2 ApprovalInfo (com.google.gerrit.client.info.ChangeInfo.ApprovalInfo)1 NativeString (com.google.gerrit.client.rpc.NativeString)1 BranchLink (com.google.gerrit.client.ui.BranchLink)1 ProjectLink (com.google.gerrit.client.ui.ProjectLink)1 ReviewCategoryStrategy (com.google.gerrit.extensions.client.GeneralPreferencesInfo.ReviewCategoryStrategy)1 Change (com.google.gerrit.reviewdb.client.Change)1 Element (com.google.gwt.dom.client.Element)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 CellFormatter (com.google.gwt.user.client.ui.HTMLTable.CellFormatter)1 Image (com.google.gwt.user.client.ui.Image)1 InlineLabel (com.google.gwt.user.client.ui.InlineLabel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1