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