Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: frontend/client/src/autotest/planner/triage/TriagePopup.java

Issue 1595019: Merge remote branch 'origin/upstream' into tempbranch (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package autotest.planner.triage;
2
3 import autotest.common.JsonRpcCallback;
4 import autotest.common.JsonRpcProxy;
5 import autotest.common.StaticDataRepository;
6 import autotest.common.ui.SimplifiedList;
7
8 import com.google.gwt.event.dom.client.ClickEvent;
9 import com.google.gwt.event.dom.client.ClickHandler;
10 import com.google.gwt.event.dom.client.HasClickHandlers;
11 import com.google.gwt.event.logical.shared.CloseEvent;
12 import com.google.gwt.event.logical.shared.CloseHandler;
13 import com.google.gwt.event.logical.shared.HasCloseHandlers;
14 import com.google.gwt.json.client.JSONArray;
15 import com.google.gwt.json.client.JSONBoolean;
16 import com.google.gwt.json.client.JSONNumber;
17 import com.google.gwt.json.client.JSONObject;
18 import com.google.gwt.json.client.JSONString;
19 import com.google.gwt.json.client.JSONValue;
20 import com.google.gwt.user.client.ui.HasText;
21 import com.google.gwt.user.client.ui.HasValue;
22 import com.google.gwt.user.client.ui.PopupPanel;
23
24 public class TriagePopup implements ClickHandler, CloseHandler<PopupPanel> {
25 public static interface Display extends HasCloseHandlers<PopupPanel> {
26 public HasClickHandlers getCloseButton();
27 public HasText getLabelsField();
28 public HasText getKeyvalsField();
29 public HasText getBugsField();
30 public HasText getReasonField();
31 public SimplifiedList getHostActionField();
32 public SimplifiedList getTestActionField();
33 public HasValue<Boolean> getInvalidateField();
34 public HasClickHandlers getApplyButton();
35 public void center();
36 public void hide();
37 }
38
39 public static interface Listener {
40 public void onTriage(TriagePopup source);
41 }
42
43 private Display display;
44 private Listener listener;
45 private int id;
46 private boolean triaged = false;
47
48 public TriagePopup(Listener listener, int id) {
49 this.listener = listener;
50 this.id = id;
51 }
52
53 public void bindDisplay(Display display) {
54 this.display = display;
55 display.addCloseHandler(this);
56 populateActionsFields();
57 setHandlers();
58 }
59
60 public void render() {
61 display.center();
62 }
63
64 public int getId() {
65 return id;
66 }
67
68 private void populateActionsFields() {
69 populateList("host_actions", display.getHostActionField());
70 populateList("test_actions", display.getTestActionField());
71 }
72
73 private void populateList(String staticDataKey, SimplifiedList list) {
74 JSONArray choices = StaticDataRepository.getRepository().getData(staticD ataKey).isArray();
75 for (int i = 0; i < choices.size(); i++) {
76 String item = choices.get(i).isString().stringValue();
77 list.addItem(item, item);
78 }
79 }
80
81 private void setHandlers() {
82 display.getCloseButton().addClickHandler(this);
83 display.getApplyButton().addClickHandler(this);
84 }
85
86 @Override
87 public void onClick(ClickEvent event) {
88 if (event.getSource() == display.getCloseButton()) {
89 display.hide();
90 } else {
91 assert event.getSource() == display.getApplyButton();
92 JsonRpcProxy proxy = JsonRpcProxy.getProxy();
93
94 JSONObject params = getParams();
95
96 proxy.rpcCall("process_failure", params, new JsonRpcCallback() {
97 @Override
98 public void onSuccess(JSONValue result) {
99 triaged = true;
100 display.hide();
101 }
102 });
103 }
104 }
105
106 private JSONObject getParams() {
107 JSONObject params = new JSONObject();
108 params.put("failure_id", new JSONNumber(id));
109 params.put("host_action", new JSONString(display.getHostActionField().ge tSelectedName()));
110 params.put("test_action", new JSONString(display.getTestActionField().ge tSelectedName()));
111
112 if (!display.getLabelsField().getText().trim().equals("")) {
113 params.put("labels", parseCommaDelimited(display.getLabelsField().ge tText()));
114 }
115
116 if (!display.getKeyvalsField().getText().trim().equals("")) {
117 JSONObject keyvals = new JSONObject();
118 for (String keyval : display.getKeyvalsField().getText().split("\n") ) {
119 String split[] = keyval.split("=", 2);
120 keyvals.put(split[0].trim(), new JSONString(split[1].trim()));
121 }
122 params.put("keyvals", keyvals);
123 }
124
125 if (!display.getBugsField().getText().trim().equals("")) {
126 params.put("bugs", parseCommaDelimited(display.getBugsField().getTex t()));
127 }
128
129 if (!display.getReasonField().getText().trim().equals("")) {
130 params.put("reason", new JSONString(display.getReasonField().getText ()));
131 }
132
133 params.put("invalidate", JSONBoolean.getInstance(display.getInvalidateFi eld().getValue()));
134
135 return params;
136 }
137
138 private JSONArray parseCommaDelimited(String line) {
139 JSONArray values = new JSONArray();
140 for (String value : line.split(",")) {
141 values.set(values.size(), new JSONString(value.trim()));
142 }
143 return values;
144 }
145
146 @Override
147 public void onClose(CloseEvent<PopupPanel> event) {
148 if (triaged) {
149 listener.onTriage(this);
150 }
151 }
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698