| 2105 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
| 2126 |
ankur.sing |
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
4 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
|
|
5 |
|
| 2105 |
ankur.sing |
6 |
import com.google.gwt.core.client.GWT;
|
|
|
7 |
import com.google.gwt.event.dom.client.ClickEvent;
|
| 2359 |
ankur.sing |
8 |
import com.google.gwt.event.dom.client.ClickHandler;
|
| 2105 |
ankur.sing |
9 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
10 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiHandler;
|
| 2126 |
ankur.sing |
12 |
import com.google.gwt.user.client.Window;
|
|
|
13 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
| 2105 |
ankur.sing |
14 |
import com.google.gwt.user.client.ui.Button;
|
| 2359 |
ankur.sing |
15 |
import com.google.gwt.user.client.ui.DialogBox;
|
|
|
16 |
import com.google.gwt.user.client.ui.HorizontalPanel;
|
| 3884 |
chandransh |
17 |
import com.google.gwt.user.client.ui.Label;
|
| 2359 |
ankur.sing |
18 |
import com.google.gwt.user.client.ui.RadioButton;
|
| 2105 |
ankur.sing |
19 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
| 2359 |
ankur.sing |
20 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
| 2105 |
ankur.sing |
21 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
22 |
|
| 2427 |
ankur.sing |
23 |
/**
|
|
|
24 |
* Panel containing buttons for different actions on item.
|
|
|
25 |
* e.g. update item, add new item, change item status, mark/unmark risky, push prices to production etc.
|
|
|
26 |
* @author ankur
|
|
|
27 |
*
|
|
|
28 |
*/
|
| 2105 |
ankur.sing |
29 |
public class ItemActions extends ResizeComposite{
|
|
|
30 |
|
|
|
31 |
interface ItemActionsUiBinder extends UiBinder<Widget, ItemActions> {}
|
|
|
32 |
private static ItemActionsUiBinder uiBinder = GWT.create(ItemActionsUiBinder.class);
|
| 2126 |
ankur.sing |
33 |
private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
|
| 2105 |
ankur.sing |
34 |
|
| 2126 |
ankur.sing |
35 |
private ItemDetails itemDetails;
|
| 2105 |
ankur.sing |
36 |
|
| 2359 |
ankur.sing |
37 |
@UiField Button addItem, updateItem, pushItemToProd, phaseoutItem, activateItem, markAliveItem, pauseItem;
|
|
|
38 |
@UiField Button markRisky, unmarkRisky;
|
|
|
39 |
@UiField Button generateMasterSheet;
|
| 2105 |
ankur.sing |
40 |
|
|
|
41 |
public ItemActions(){
|
|
|
42 |
initWidget(uiBinder.createAndBindUi(this));
|
| 2427 |
ankur.sing |
43 |
//pushItemToProd.setEnabled(false);
|
| 2105 |
ankur.sing |
44 |
}
|
| 2427 |
ankur.sing |
45 |
|
| 2105 |
ankur.sing |
46 |
|
| 2126 |
ankur.sing |
47 |
@UiHandler("updateItem")
|
|
|
48 |
void updateItem(ClickEvent event) {
|
|
|
49 |
itemDetails.updateItem();
|
|
|
50 |
}
|
|
|
51 |
|
| 2427 |
ankur.sing |
52 |
/**
|
|
|
53 |
* creates a new form to fill up item details and displays the form.
|
|
|
54 |
* @param event
|
|
|
55 |
*/
|
| 2105 |
ankur.sing |
56 |
@UiHandler("addItem")
|
|
|
57 |
void addItem(ClickEvent event) {
|
| 2126 |
ankur.sing |
58 |
ItemForm itemForm = new ItemForm();
|
|
|
59 |
itemForm.center();
|
|
|
60 |
itemForm.show();
|
| 2105 |
ankur.sing |
61 |
}
|
|
|
62 |
|
|
|
63 |
@UiHandler("phaseoutItem")
|
|
|
64 |
void phaseoutItem(ClickEvent event) {
|
| 2126 |
ankur.sing |
65 |
final long itemId = validateStatusChange(Utils.PHASED_OUT);
|
|
|
66 |
if(itemId <= 0) {
|
|
|
67 |
return;
|
|
|
68 |
}
|
|
|
69 |
catalogService.phaseoutItem(itemId, new AsyncCallback<Void>() {
|
|
|
70 |
@Override
|
|
|
71 |
public void onSuccess(Void result) {
|
|
|
72 |
Window.alert("Item marked as PHASED OUT");
|
|
|
73 |
}
|
|
|
74 |
@Override
|
|
|
75 |
public void onFailure(Throwable caught) {
|
|
|
76 |
Window.alert("Error while marking item " + itemId + " PHASED OUT");
|
|
|
77 |
}
|
|
|
78 |
});
|
| 2105 |
ankur.sing |
79 |
}
|
|
|
80 |
|
|
|
81 |
@UiHandler("activateItem")
|
|
|
82 |
void activateItem(ClickEvent event) {
|
| 2126 |
ankur.sing |
83 |
final long itemId = validateStatusChange(Utils.ACTIVE);
|
|
|
84 |
if(itemId <= 0) {
|
|
|
85 |
return;
|
|
|
86 |
}
|
|
|
87 |
catalogService.activateItem(itemId, new AsyncCallback<Void>() {
|
|
|
88 |
@Override
|
|
|
89 |
public void onSuccess(Void result) {
|
|
|
90 |
Window.alert("Item marked as ACTIVE");
|
|
|
91 |
}
|
|
|
92 |
@Override
|
|
|
93 |
public void onFailure(Throwable caught) {
|
|
|
94 |
Window.alert("Error while marking item " + itemId + " ACTIVE");
|
|
|
95 |
}
|
|
|
96 |
});
|
| 2105 |
ankur.sing |
97 |
}
|
|
|
98 |
|
| 2126 |
ankur.sing |
99 |
@UiHandler("pauseItem")
|
|
|
100 |
void pauseItem(ClickEvent event) {
|
|
|
101 |
final long itemId = validateStatusChange(Utils.PAUSED);
|
|
|
102 |
if(itemId <= 0) {
|
|
|
103 |
return;
|
|
|
104 |
}
|
|
|
105 |
catalogService.pauseItem(itemId, new AsyncCallback<Void>() {
|
|
|
106 |
@Override
|
|
|
107 |
public void onSuccess(Void result) {
|
|
|
108 |
Window.alert("Item marked as PAUSED");
|
|
|
109 |
}
|
|
|
110 |
@Override
|
|
|
111 |
public void onFailure(Throwable caught) {
|
|
|
112 |
Window.alert("Error while marking item " + itemId + " PAUSED");
|
|
|
113 |
}
|
|
|
114 |
});
|
| 2105 |
ankur.sing |
115 |
}
|
| 2126 |
ankur.sing |
116 |
|
|
|
117 |
@UiHandler("markAliveItem")
|
|
|
118 |
void markAsAlive(ClickEvent event) {
|
|
|
119 |
final long itemId = validateStatusChange(Utils.IN_PROCESS);
|
|
|
120 |
if(itemId <= 0) {
|
|
|
121 |
return;
|
|
|
122 |
}
|
|
|
123 |
catalogService.markInProcess(itemId, new AsyncCallback<Void>() {
|
|
|
124 |
@Override
|
|
|
125 |
public void onSuccess(Void result) {
|
|
|
126 |
Window.alert("Item marked as IN PROCESS");
|
|
|
127 |
}
|
|
|
128 |
@Override
|
|
|
129 |
public void onFailure(Throwable caught) {
|
|
|
130 |
Window.alert("Error while marking item " + itemId + " IN PROCESS");
|
|
|
131 |
}
|
|
|
132 |
});
|
| 2105 |
ankur.sing |
133 |
}
|
| 2126 |
ankur.sing |
134 |
|
| 2427 |
ankur.sing |
135 |
/**
|
|
|
136 |
* Creates and pops up authentication dialog for push to production username and password
|
|
|
137 |
* @param event
|
|
|
138 |
*/
|
| 2359 |
ankur.sing |
139 |
@UiHandler("pushItemToProd")
|
|
|
140 |
void pushItemToProduction(ClickEvent event) {
|
|
|
141 |
if(itemDetails.getItem() == null) {
|
|
|
142 |
Window.alert("Please select an item to update");
|
|
|
143 |
return;
|
|
|
144 |
}
|
|
|
145 |
AuthenticateDialog authDialog = new AuthenticateDialog(itemDetails.getItem());
|
|
|
146 |
authDialog.show();
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
@UiHandler("markRisky")
|
|
|
150 |
void markRisky(ClickEvent event) {
|
|
|
151 |
changeRiskyFlag(true);
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
@UiHandler("unmarkRisky")
|
|
|
155 |
void unmarkRisky(ClickEvent event) {
|
|
|
156 |
changeRiskyFlag(false);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
@UiHandler("generateMasterSheet")
|
|
|
160 |
void generateMasterSheet(ClickEvent event) {
|
|
|
161 |
createDialog();
|
|
|
162 |
}
|
| 2427 |
ankur.sing |
163 |
|
|
|
164 |
/**
|
|
|
165 |
* Creates and pops up dialog box containing two options.
|
|
|
166 |
* 1) Handsets 2) Accessories
|
|
|
167 |
* Also creates submit and cancel buttons and add click event listeners to them.
|
|
|
168 |
* On submit button click, request is sent to <code>in.shop2020.catalog.dashboard.server.FileDownloadServlet<code>
|
|
|
169 |
*/
|
| 2359 |
ankur.sing |
170 |
private void createDialog() {
|
|
|
171 |
VerticalPanel vp = new VerticalPanel();
|
|
|
172 |
final DialogBox db = new DialogBox();
|
|
|
173 |
db.setText("Master Sheet Download");
|
| 3884 |
chandransh |
174 |
|
|
|
175 |
final Label categoryLabel = new Label("Category");
|
|
|
176 |
vp.add(categoryLabel);
|
|
|
177 |
|
| 2359 |
ankur.sing |
178 |
final RadioButton handsetsRB = new RadioButton("vendorCategory", "Handsets");
|
|
|
179 |
final RadioButton accRB = new RadioButton("vendorCategory", "Accessories");
|
|
|
180 |
handsetsRB.setValue(true);
|
| 3884 |
chandransh |
181 |
|
| 2359 |
ankur.sing |
182 |
HorizontalPanel hpRB = new HorizontalPanel();
|
|
|
183 |
hpRB.add(handsetsRB);
|
|
|
184 |
hpRB.add(accRB);
|
|
|
185 |
vp.add(hpRB);
|
|
|
186 |
|
| 3884 |
chandransh |
187 |
final Label vendorLabel = new Label("Vendor");
|
|
|
188 |
vp.add(vendorLabel);
|
|
|
189 |
|
|
|
190 |
final RadioButton hotspotRB = new RadioButton("vendor", "Hotspot");
|
|
|
191 |
final RadioButton sarvottamRB = new RadioButton("vendor", "Sarvottam");
|
|
|
192 |
final RadioButton tulipRB = new RadioButton("vendor", "Tulip");
|
|
|
193 |
hotspotRB.setValue(true);
|
|
|
194 |
|
|
|
195 |
HorizontalPanel vendorPanel = new HorizontalPanel();
|
|
|
196 |
vendorPanel.add(hotspotRB);
|
|
|
197 |
vendorPanel.add(tulipRB);
|
|
|
198 |
vendorPanel.add(sarvottamRB);
|
|
|
199 |
|
|
|
200 |
vp.add(vendorPanel);
|
|
|
201 |
|
| 2359 |
ankur.sing |
202 |
Button submitButton = new Button("OK");
|
|
|
203 |
Button cancelButton = new Button("Cancel");
|
|
|
204 |
HorizontalPanel hpButtons = new HorizontalPanel();
|
|
|
205 |
hpButtons.setSpacing(5);
|
|
|
206 |
hpButtons.add(submitButton);
|
|
|
207 |
hpButtons.add(cancelButton);
|
|
|
208 |
|
|
|
209 |
vp.add(hpButtons);
|
| 3884 |
chandransh |
210 |
|
| 2359 |
ankur.sing |
211 |
db.add(vp);
|
|
|
212 |
submitButton.addClickHandler(new ClickHandler() {
|
|
|
213 |
@Override
|
|
|
214 |
public void onClick(ClickEvent event) {
|
|
|
215 |
String vendorCategory;
|
|
|
216 |
if(handsetsRB.getValue()) {
|
|
|
217 |
vendorCategory = "Handsets";
|
|
|
218 |
} else {
|
|
|
219 |
vendorCategory = "Accessories";
|
|
|
220 |
}
|
| 3884 |
chandransh |
221 |
|
|
|
222 |
long vendorId = 1;
|
|
|
223 |
if(hotspotRB.getValue()) {
|
|
|
224 |
vendorId = 1;
|
|
|
225 |
} else if(sarvottamRB.getValue()) {
|
|
|
226 |
vendorId = 3;
|
|
|
227 |
} else if(tulipRB.getValue()) {
|
|
|
228 |
vendorId = 2;
|
|
|
229 |
}
|
|
|
230 |
|
| 2427 |
ankur.sing |
231 |
// Servlet mapping mastersheet/download is mapped to in.shop2020.catalog.dashboard.server.FileDownloadServlet
|
| 3884 |
chandransh |
232 |
String link = GWT.getHostPageBaseURL() + "mastersheet/download?vendorCategory=" + vendorCategory + "&vendorId=" + vendorId;
|
| 2359 |
ankur.sing |
233 |
Window.open(link, "_self", "Master Sheet Download");
|
|
|
234 |
db.hide();
|
|
|
235 |
}
|
|
|
236 |
});
|
|
|
237 |
cancelButton.addClickHandler(new ClickHandler() {
|
|
|
238 |
@Override
|
|
|
239 |
public void onClick(ClickEvent event) {
|
|
|
240 |
db.hide();
|
|
|
241 |
}
|
|
|
242 |
});
|
|
|
243 |
db.center();
|
|
|
244 |
db.setAnimationEnabled(true);
|
|
|
245 |
db.show();
|
|
|
246 |
}
|
|
|
247 |
|
| 2427 |
ankur.sing |
248 |
/**
|
|
|
249 |
* validates and then calls service method changeItemRiskyFlag to change risky flag.
|
|
|
250 |
* @param risky
|
|
|
251 |
*/
|
| 2359 |
ankur.sing |
252 |
private void changeRiskyFlag(boolean risky) {
|
|
|
253 |
Item item = itemDetails.getItem();
|
|
|
254 |
if(item == null) {
|
|
|
255 |
Window.alert("Please select an item to mark/unmark as risky");
|
|
|
256 |
return;
|
|
|
257 |
}
|
|
|
258 |
if(risky && item.isRisky()) {
|
|
|
259 |
Window.alert("Item already marked as risky");
|
|
|
260 |
return;
|
|
|
261 |
}
|
|
|
262 |
if(!risky && !item.isRisky()) {
|
|
|
263 |
Window.alert("Item not marked as risky");
|
|
|
264 |
return;
|
|
|
265 |
}
|
|
|
266 |
catalogService.changeItemRiskyFlag(item.getId(), risky, new AsyncCallback<Boolean>() {
|
|
|
267 |
@Override
|
|
|
268 |
public void onSuccess(Boolean result) {
|
|
|
269 |
if(result) {
|
|
|
270 |
Window.alert("Done!");
|
|
|
271 |
} else {
|
|
|
272 |
Window.alert("Error while marking/unmarking risky flag on staging/production server.");
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
@Override
|
|
|
276 |
public void onFailure(Throwable caught) {
|
|
|
277 |
Window.alert("Error");
|
|
|
278 |
}
|
|
|
279 |
});
|
|
|
280 |
}
|
|
|
281 |
|
| 2126 |
ankur.sing |
282 |
public void setItemDetails(ItemDetails itemDetails) {
|
|
|
283 |
this.itemDetails = itemDetails;
|
| 2105 |
ankur.sing |
284 |
}
|
| 2427 |
ankur.sing |
285 |
|
|
|
286 |
/**
|
|
|
287 |
* Validate item status change.
|
|
|
288 |
* @param toStatus
|
|
|
289 |
* @return item Id if validation is successful else -1
|
|
|
290 |
*/
|
| 2126 |
ankur.sing |
291 |
private long validateStatusChange(int toStatus) {
|
|
|
292 |
final Item item = itemDetails.getItem();
|
|
|
293 |
if(item == null) {
|
|
|
294 |
Window.alert(getAlertString(toStatus)[0]);
|
|
|
295 |
return -1;
|
|
|
296 |
}
|
|
|
297 |
if(!Utils.validateStatusChange(item.getItemStatusValue(), toStatus)) {
|
|
|
298 |
Window.alert(getAlertString(toStatus)[1]);
|
|
|
299 |
return -1;
|
|
|
300 |
}
|
|
|
301 |
return item.getId();
|
|
|
302 |
}
|
|
|
303 |
|
| 2427 |
ankur.sing |
304 |
/**
|
|
|
305 |
* @param toStatus
|
|
|
306 |
* @return messages to be show to the user if item status change validation fails.
|
|
|
307 |
* <br>-first message will be shown if no item is selected in the list
|
|
|
308 |
* <br>-second message is shown if validation for FromStatus to ToStatus fails.
|
|
|
309 |
*/
|
| 2126 |
ankur.sing |
310 |
private String[] getAlertString(int toStatus) {
|
|
|
311 |
String[] alertStr = {"", ""};
|
|
|
312 |
switch(toStatus) {
|
|
|
313 |
case Utils.PAUSED: {
|
|
|
314 |
alertStr[0] = "Please select an ACTIVE item to mark PAUSED";
|
|
|
315 |
alertStr[1] = "Cannot mark this item as PAUSED";
|
|
|
316 |
break;
|
|
|
317 |
}
|
|
|
318 |
case Utils.IN_PROCESS: {
|
|
|
319 |
alertStr[0] = "Please select a PHASED OUT item to mark IN PROCESS";
|
|
|
320 |
alertStr[1] = "Cannot mark this item as IN PROCESS";
|
|
|
321 |
break;
|
|
|
322 |
}
|
|
|
323 |
case Utils.ACTIVE: {
|
|
|
324 |
alertStr[0] = "Please select a PAUSED item to mark ACTIVE";
|
|
|
325 |
alertStr[1] = "Cannot mark this item as ACTIVE";
|
|
|
326 |
break;
|
|
|
327 |
}
|
|
|
328 |
case Utils.PHASED_OUT: {
|
|
|
329 |
alertStr[0] = "Please select an item to mark PHASED OUT";
|
|
|
330 |
alertStr[1] = "Cannot mark this item as PHASED OUT";
|
|
|
331 |
break;
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
return alertStr;
|
|
|
335 |
}
|
| 2105 |
ankur.sing |
336 |
}
|
| 2126 |
ankur.sing |
337 |
|