Search in sources :

Example 1 with ApprovalInfo

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

the class Labels method renderUsers.

private Widget renderUsers(LabelInfo label, Set<Integer> removable) {
    Map<Integer, List<ApprovalInfo>> m = new HashMap<>(4);
    int approved = 0;
    int rejected = 0;
    for (ApprovalInfo ai : Natives.asList(label.all())) {
        if (ai.value() != 0) {
            List<ApprovalInfo> l = m.get(Integer.valueOf(ai.value()));
            if (l == null) {
                l = new ArrayList<>(label.all().length());
                m.put(Integer.valueOf(ai.value()), l);
            }
            l.add(ai);
            if (isRejected(label, ai)) {
                rejected = ai.value();
            } else if (isApproved(label, ai)) {
                approved = ai.value();
            }
        }
    }
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    for (Integer v : sort(m.keySet(), approved, rejected)) {
        if (!html.isEmpty()) {
            html.br();
        }
        String val = LabelValue.formatValue(v.shortValue());
        html.openSpan();
        html.setAttribute("title", label.valueText(val));
        if (v.intValue() == approved) {
            html.setStyleName(style.label_ok());
        } else if (v.intValue() == rejected) {
            html.setStyleName(style.label_reject());
        }
        html.append(val).append(" ");
        html.append(formatUserList(style, m.get(v), removable, label.name(), null));
        html.closeSpan();
    }
    return html.toBlockWidget();
}
Also used : ApprovalInfo(com.google.gerrit.client.info.ChangeInfo.ApprovalInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)

Example 2 with ApprovalInfo

use of com.google.gerrit.client.info.ChangeInfo.ApprovalInfo 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 3 with ApprovalInfo

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

the class ReplyBox method renderCheckBox.

private void renderCheckBox(int row, LabelAndValues lv) {
    ApprovalInfo self = Gerrit.isSignedIn() ? lv.info.forUser(Gerrit.getUserAccount().getId().get()) : null;
    final String id = lv.info.name();
    final CheckBox b = new CheckBox();
    b.setText(id);
    b.setEnabled(lv.permitted.contains((short) 1));
    if (self != null && self.value() == 1) {
        b.setValue(true);
    }
    b.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            in.label(id, event.getValue() ? (short) 1 : (short) 0);
        }
    });
    b.setStyleName(style.label_name());
    labelsTable.setWidget(row, 0, b);
    CellFormatter fmt = labelsTable.getCellFormatter();
    fmt.setStyleName(row, labelHelpColumn, style.label_help());
    labelsTable.setText(row, labelHelpColumn, lv.info.valueText("+1"));
}
Also used : ApprovalInfo(com.google.gerrit.client.info.ChangeInfo.ApprovalInfo) CheckBox(com.google.gwt.user.client.ui.CheckBox) JsArrayString(com.google.gwt.core.client.JsArrayString) CellFormatter(com.google.gwt.user.client.ui.HTMLTable.CellFormatter)

Example 4 with ApprovalInfo

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

the class ReplyBox method renderRadio.

private void renderRadio(int row, List<Short> columns, LabelAndValues lv) {
    String id = lv.info.name();
    Short dv = normalizeDefaultValue(lv.info.defaultValue(), lv.permitted);
    labelHelpColumn = 1 + columns.size();
    labelsTable.setText(row, 0, id);
    CellFormatter fmt = labelsTable.getCellFormatter();
    fmt.setStyleName(row, 0, style.label_name());
    fmt.setStyleName(row, labelHelpColumn, style.label_help());
    ApprovalInfo self = Gerrit.isSignedIn() ? lv.info.forUser(Gerrit.getUserAccount().getId().get()) : null;
    final LabelRadioGroup group = new LabelRadioGroup(row, id, lv.permitted.size());
    for (int i = 0; i < columns.size(); i++) {
        Short v = columns.get(i);
        if (lv.permitted.contains(v)) {
            String text = lv.info.valueText(LabelValue.formatValue(v));
            LabelRadioButton b = new LabelRadioButton(group, text, v);
            if ((self != null && v == self.value()) || (self == null && v.equals(dv))) {
                b.setValue(true);
                group.select(b);
                in.label(group.label, v);
                labelsTable.setText(row, labelHelpColumn, b.text);
            }
            group.buttons.add(b);
            labelsTable.setWidget(row, 1 + i, b);
        }
    }
}
Also used : ApprovalInfo(com.google.gerrit.client.info.ChangeInfo.ApprovalInfo) JsArrayString(com.google.gwt.core.client.JsArrayString) CellFormatter(com.google.gwt.user.client.ui.HTMLTable.CellFormatter)

Aggregations

ApprovalInfo (com.google.gerrit.client.info.ChangeInfo.ApprovalInfo)4 JsArrayString (com.google.gwt.core.client.JsArrayString)2 CellFormatter (com.google.gwt.user.client.ui.HTMLTable.CellFormatter)2 HashMap (java.util.HashMap)2 LabelInfo (com.google.gerrit.client.info.ChangeInfo.LabelInfo)1 NativeString (com.google.gerrit.client.rpc.NativeString)1 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 SafeHtmlBuilder (com.google.gwtexpui.safehtml.client.SafeHtmlBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1