Merge "ChangeScreen2: Show on which categories a reviewer can vote"

This commit is contained in:
Shawn Pearce 2014-01-30 00:37:38 +00:00 committed by Gerrit Code Review
commit ca86d74331
6 changed files with 101 additions and 7 deletions

View File

@ -205,6 +205,8 @@ group names.
To remove reviewers click on the 'x' icon in the reviewer's "chip". To remove reviewers click on the 'x' icon in the reviewer's "chip".
Votable categories are shown as a tooltip for each reviewer.
Key bindings: "c" to add a reviewer. "ESC" to close the drop down. Key bindings: "c" to add a reviewer. "ESC" to close the drop down.
[[auto-refresh]] [[auto-refresh]]

View File

@ -176,7 +176,7 @@ class Labels extends Grid {
} }
html.append(val).append(" "); html.append(val).append(" ");
html.append(formatUserList(style, m.get(v), html.append(formatUserList(style, m.get(v),
Collections.<Integer> emptySet())); Collections.<Integer> emptySet(), null));
html.closeSpan(); html.closeSpan();
} }
return html.toBlockWidget(); return html.toBlockWidget();
@ -222,7 +222,8 @@ class Labels extends Grid {
static SafeHtml formatUserList(ChangeScreen2.Style style, static SafeHtml formatUserList(ChangeScreen2.Style style,
Collection<? extends AccountInfo> in, Collection<? extends AccountInfo> in,
Set<Integer> removable) { Set<Integer> removable,
Map<Integer, VotableInfo> votable) {
List<AccountInfo> users = new ArrayList<>(in); List<AccountInfo> users = new ArrayList<>(in);
Collections.sort(users, new Comparator<AccountInfo>() { Collections.sort(users, new Comparator<AccountInfo>() {
@Override @Override
@ -261,13 +262,26 @@ class Labels extends Grid {
name = Integer.toString(ai._account_id()); name = Integer.toString(ai._account_id());
} }
String votableCategories = "";
if (votable != null) {
Set<String> s = votable.get(ai._account_id()).votableLabels();
if (!s.isEmpty()) {
StringBuilder sb = new StringBuilder(Util.C.votable());
sb.append(" ");
for (Iterator<String> it = s.iterator(); it.hasNext();) {
sb.append(it.next());
if (it.hasNext()) {
sb.append(", ");
}
}
votableCategories = sb.toString();
}
}
html.openSpan() html.openSpan()
.setAttribute("role", "listitem") .setAttribute("role", "listitem")
.setAttribute(DATA_ID, ai._account_id()) .setAttribute(DATA_ID, ai._account_id())
.setAttribute("title", getTitle(ai, votableCategories))
.setStyleName(style.label_user()); .setStyleName(style.label_user());
if (ai.email() != null) {
html.setAttribute("title", ai.email());
}
if (img != null) { if (img != null) {
html.openElement("img") html.openElement("img")
.setStyleName(style.avatar()) .setStyleName(style.avatar())
@ -295,4 +309,15 @@ class Labels extends Grid {
} }
return html; return html;
} }
private static String getTitle(AccountInfo ai, String votableCategories) {
String title = ai.email() != null ? ai.email() : "";
if (!votableCategories.isEmpty()) {
if (!title.isEmpty()) {
title += " ";
}
title += votableCategories;
}
return title;
}
} }

View File

@ -231,10 +231,35 @@ class Reviewers extends Composite {
} }
} }
SafeHtml rHtml = Labels.formatUserList(style, r.values(), removable); Map<Integer, VotableInfo> votable = votable(info);
SafeHtml ccHtml = Labels.formatUserList(style, cc.values(), removable);
SafeHtml rHtml = Labels.formatUserList(style,
r.values(), removable, votable);
SafeHtml ccHtml = Labels.formatUserList(style,
cc.values(), removable, votable);
reviewersText.setInnerSafeHtml(rHtml); reviewersText.setInnerSafeHtml(rHtml);
ccText.setInnerSafeHtml(ccHtml); ccText.setInnerSafeHtml(ccHtml);
} }
private static Map<Integer, VotableInfo> votable(ChangeInfo change) {
Map<Integer, VotableInfo> d = new HashMap<>();
for (String name : change.labels()) {
LabelInfo label = change.label(name);
if (label.all() != null) {
for (ApprovalInfo ai : Natives.asList(label.all())) {
int id = ai._account_id();
VotableInfo ad = d.get(id);
if (ad == null) {
ad = new VotableInfo();
d.put(id, ad);
}
if (ai.has_value()) {
ad.votable(name);
}
}
}
}
return d;
}
} }

View File

@ -0,0 +1,38 @@
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.change;
import java.util.HashSet;
import java.util.Set;
class VotableInfo {
private Set<String> votable;
void votable(String label) {
if (votable == null) {
votable = new HashSet<>();
}
votable.add(label);
}
Set<String> votableLabels() {
Set<String> s = new HashSet<>();
if (votable != null) {
s.addAll(votable);
}
return s;
}
}

View File

@ -211,4 +211,6 @@ public interface ChangeConstants extends Constants {
String oneWeekAgo(); String oneWeekAgo();
String oneMonthAgo(); String oneMonthAgo();
String oneYearAgo(); String oneYearAgo();
String votable();
} }

View File

@ -193,3 +193,5 @@ oneDayAgo = 1 day ago
oneWeekAgo = 1 week ago oneWeekAgo = 1 week ago
oneMonthAgo = 1 month ago oneMonthAgo = 1 month ago
oneYearAgo = 1 year ago oneYearAgo = 1 year ago
votable = Votable: