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