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