| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.client.inbox;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderDetailsEvent;
|
| 4133 |
chandransh |
4 |
import in.shop2020.hotspot.dashbaord.client.event.LoadOrderListEvent;
|
| 4398 |
rajveer |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderAlert;
|
| 167 |
ashish |
6 |
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
|
| 4133 |
chandransh |
7 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
|
| 167 |
ashish |
8 |
|
|
|
9 |
import java.util.Date;
|
|
|
10 |
import java.util.List;
|
|
|
11 |
|
|
|
12 |
import org.enunes.gwt.mvp.client.EventBus;
|
|
|
13 |
|
| 4361 |
rajveer |
14 |
import com.google.gwt.cell.client.CheckboxCell;
|
| 167 |
ashish |
15 |
import com.google.gwt.core.client.GWT;
|
| 4124 |
chandransh |
16 |
import com.google.gwt.dom.client.Style.Unit;
|
| 167 |
ashish |
17 |
import com.google.gwt.resources.client.CssResource;
|
|
|
18 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
19 |
import com.google.gwt.uibinder.client.UiField;
|
| 4361 |
rajveer |
20 |
import com.google.gwt.user.cellview.client.Column;
|
| 4124 |
chandransh |
21 |
import com.google.gwt.user.cellview.client.DataGrid;
|
|
|
22 |
import com.google.gwt.user.cellview.client.RowStyles;
|
|
|
23 |
import com.google.gwt.user.cellview.client.SimplePager;
|
|
|
24 |
import com.google.gwt.user.cellview.client.TextColumn;
|
| 167 |
ashish |
25 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
26 |
import com.google.gwt.user.client.ui.Widget;
|
| 4124 |
chandransh |
27 |
import com.google.gwt.view.client.AsyncDataProvider;
|
|
|
28 |
import com.google.gwt.view.client.HasData;
|
|
|
29 |
import com.google.gwt.view.client.Range;
|
|
|
30 |
import com.google.gwt.view.client.SelectionChangeEvent;
|
|
|
31 |
import com.google.gwt.view.client.SingleSelectionModel;
|
| 167 |
ashish |
32 |
|
| 4125 |
chandransh |
33 |
public class OrderList extends ResizeComposite {
|
| 167 |
ashish |
34 |
|
| 4125 |
chandransh |
35 |
interface OrderListUiBinder extends UiBinder<Widget, OrderList>{}
|
| 167 |
ashish |
36 |
|
| 4125 |
chandransh |
37 |
interface SelectionStyle extends CssResource {
|
| 167 |
ashish |
38 |
String selectedRow();
|
| 4004 |
chandransh |
39 |
String fatalRow();
|
|
|
40 |
String criticalRow();
|
| 8717 |
amar.kumar |
41 |
String badInventory();
|
| 19004 |
manish.sha |
42 |
String todayShippingInStockRow();
|
|
|
43 |
String todayShippingNotInStockRow();
|
|
|
44 |
String laterShippingRow();
|
| 167 |
ashish |
45 |
}
|
|
|
46 |
//add gin here
|
| 584 |
chandransh |
47 |
private static final OrderListUiBinder binder = GWT.create(OrderListUiBinder.class);
|
| 167 |
ashish |
48 |
|
| 4124 |
chandransh |
49 |
@UiField DataGrid<Order> table;
|
|
|
50 |
// Create paging controls.
|
|
|
51 |
@UiField SimplePager pager = new SimplePager();
|
| 167 |
ashish |
52 |
@UiField SelectionStyle selectionStyle;
|
|
|
53 |
|
| 4361 |
rajveer |
54 |
|
|
|
55 |
Column<Order, Boolean> checkboxColumn = new Column<Order, Boolean>(new CheckboxCell(true, false)) {
|
|
|
56 |
@Override
|
|
|
57 |
public Boolean getValue(Order order) {
|
|
|
58 |
return table.getSelectionModel().isSelected(order);
|
|
|
59 |
}
|
|
|
60 |
};
|
|
|
61 |
|
| 19004 |
manish.sha |
62 |
private TextColumn<Order> transactionIdColumn = new TextColumn<Order>() {
|
|
|
63 |
@Override
|
|
|
64 |
public String getValue(Order order) {
|
|
|
65 |
return "" + order.getTransactionId();
|
|
|
66 |
}
|
|
|
67 |
};
|
| 4361 |
rajveer |
68 |
|
| 4666 |
rajveer |
69 |
private TextColumn<Order> promisedShippingDateColumn = new TextColumn<Order>() {
|
|
|
70 |
@Override
|
| 4124 |
chandransh |
71 |
public String getValue(Order order) {
|
| 4671 |
rajveer |
72 |
return getDisplayableDate(new Date(order.getPromisedShippingTime()))+"";
|
| 4124 |
chandransh |
73 |
}
|
|
|
74 |
};
|
|
|
75 |
|
|
|
76 |
private TextColumn<Order> paymentModeColumn = new TextColumn<Order>() {
|
|
|
77 |
@Override
|
|
|
78 |
public String getValue(Order order) {
|
|
|
79 |
return order.isCod() ? "COD" : "Prepaid";
|
|
|
80 |
}
|
|
|
81 |
};
|
|
|
82 |
|
| 7422 |
rajveer |
83 |
private TextColumn<Order> orderFromColumn = new TextColumn<Order>() {
|
|
|
84 |
@Override
|
|
|
85 |
public String getValue(Order order) {
|
|
|
86 |
return order.getSource();
|
|
|
87 |
}
|
|
|
88 |
};
|
|
|
89 |
|
| 4124 |
chandransh |
90 |
private TextColumn<Order> idColumn = new TextColumn<Order>() {
|
|
|
91 |
@Override
|
|
|
92 |
public String getValue(Order order) {
|
|
|
93 |
return "" + order.getOrderId();
|
|
|
94 |
}
|
|
|
95 |
};
|
|
|
96 |
|
|
|
97 |
private TextColumn<Order> productDescriptionColumn = new TextColumn<Order>() {
|
|
|
98 |
@Override
|
|
|
99 |
public String getValue(Order order) {
|
|
|
100 |
StringBuilder productDescription = new StringBuilder(order.getProductGroup());
|
|
|
101 |
if(order.getBrand()!=null)
|
|
|
102 |
productDescription.append(" " + order.getBrand());
|
|
|
103 |
if(order.getModelNumber()!=null)
|
|
|
104 |
productDescription.append(" " + order.getModelNumber());
|
|
|
105 |
if(order.getModelName()!=null)
|
|
|
106 |
productDescription.append(" " + order.getModelName());
|
|
|
107 |
if(order.getColor()!=null)
|
| 4175 |
rajveer |
108 |
productDescription.append(" " + order.getColor());
|
|
|
109 |
if(order.getDealText()!=null)
|
|
|
110 |
productDescription.append(" (" + order.getDealText() + ")");
|
| 5387 |
rajveer |
111 |
if(order.getQuantity() > 1)
|
|
|
112 |
productDescription.append(" (" + order.getQuantity() + ")");
|
| 4124 |
chandransh |
113 |
return productDescription.toString();
|
|
|
114 |
}
|
|
|
115 |
};
|
|
|
116 |
|
|
|
117 |
private TextColumn<Order> creationDateColumn = new TextColumn<Order>() {
|
|
|
118 |
@Override
|
|
|
119 |
public String getValue(Order order) {
|
|
|
120 |
return getDisplayableDate(new Date(order.getCreatedOn()))+"";
|
|
|
121 |
}
|
|
|
122 |
};
|
|
|
123 |
|
| 7422 |
rajveer |
124 |
// private TextColumn<Order> promisedDeliveryDateColumn = new TextColumn<Order>() {
|
|
|
125 |
// @Override
|
|
|
126 |
// public String getValue(Order order) {
|
|
|
127 |
// return getDisplayableDate(new Date(order.getPromisedDeliveryTime()))+"";
|
|
|
128 |
// }
|
|
|
129 |
// };
|
|
|
130 |
//
|
|
|
131 |
// private TextColumn<Order> expectedDeliveryDateColumn = new TextColumn<Order>() {
|
|
|
132 |
// @Override
|
|
|
133 |
// public String getValue(Order order) {
|
|
|
134 |
// return getDisplayableDate(new Date(order.getExpectedDeliveryTime()))+"";
|
|
|
135 |
// }
|
|
|
136 |
// };
|
| 4124 |
chandransh |
137 |
|
|
|
138 |
private TextColumn<Order> statusMessageColumn = new TextColumn<Order>() {
|
|
|
139 |
@Override
|
|
|
140 |
public String getValue(Order order) {
|
|
|
141 |
return order.getStatusMessage();
|
|
|
142 |
}
|
|
|
143 |
};
|
|
|
144 |
|
|
|
145 |
AsyncDataProvider<Order> asyncDataProvider = new AsyncDataProvider<Order>() {
|
|
|
146 |
|
|
|
147 |
@Override
|
|
|
148 |
protected void onRangeChanged(HasData<Order> display) {
|
|
|
149 |
Range range = display.getVisibleRange();
|
| 4133 |
chandransh |
150 |
int newStart = range.getStart();
|
|
|
151 |
// This is to prevent the recursive firing of onRangeChanged events.
|
|
|
152 |
// Every time fresh data is pushed into the DataProvider, this
|
|
|
153 |
// method is called. This, in turn, fires an event to refresh the
|
|
|
154 |
// data. If the start of the new range is same as that of the
|
|
|
155 |
// currently loaded data, there is no point in proceeding further.
|
|
|
156 |
GWT.log(this + "Current start: " + start + ", New start:" + newStart);
|
|
|
157 |
if(newStart == start)
|
|
|
158 |
return;
|
| 4124 |
chandransh |
159 |
int limit = range.getLength();
|
| 4133 |
chandransh |
160 |
|
|
|
161 |
eventbus.fireEvent(new LoadOrderListEvent(orderType, newStart, limit));
|
| 4124 |
chandransh |
162 |
}
|
|
|
163 |
|
|
|
164 |
};
|
|
|
165 |
|
| 167 |
ashish |
166 |
private final EventBus eventbus;
|
| 4133 |
chandransh |
167 |
private final OrderType orderType;
|
| 167 |
ashish |
168 |
private final List<Order> orders;
|
| 4133 |
chandransh |
169 |
private int count;
|
|
|
170 |
private final int start;
|
| 167 |
ashish |
171 |
|
| 4133 |
chandransh |
172 |
public OrderList(EventBus eventbus, OrderType orderType, List<Order> orders, int start, int count){
|
| 167 |
ashish |
173 |
this.orders = orders;
|
| 4124 |
chandransh |
174 |
this.eventbus = eventbus;
|
| 4133 |
chandransh |
175 |
this.orderType = orderType;
|
|
|
176 |
this.start = start;
|
|
|
177 |
this.count = count;
|
| 167 |
ashish |
178 |
initWidget(binder.createAndBindUi(this));
|
|
|
179 |
initTable();
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
private void initTable(){
|
| 4124 |
chandransh |
183 |
|
|
|
184 |
//Add custom styles to show in case we want to alert the user
|
|
|
185 |
table.setRowStyles(new RowStyles<Order>(){
|
| 167 |
ashish |
186 |
|
| 4124 |
chandransh |
187 |
@Override
|
|
|
188 |
public String getStyleNames(Order order, int rowIndex) {
|
| 4133 |
chandransh |
189 |
if(order==null)
|
|
|
190 |
return "";
|
| 4398 |
rajveer |
191 |
OrderAlert alert = order.getAlert();
|
| 4124 |
chandransh |
192 |
String style = "";
|
|
|
193 |
switch(alert){
|
|
|
194 |
case DELIVERY_TIME_EXCEEDED:
|
|
|
195 |
case SHIPPING_TIME_EXCEEDED:
|
|
|
196 |
case VERIFICATION_DELAYED_TOO_MUCH:
|
|
|
197 |
case ACCEPTANCE_DELAYED_TOO_MUCH:
|
|
|
198 |
case ORDER_NOT_CONNECTED_FOR_TOO_LONG:
|
|
|
199 |
style = selectionStyle.fatalRow();
|
|
|
200 |
break;
|
|
|
201 |
case ACCEPTANCE_DELAYED:
|
|
|
202 |
case VERIFICATION_DELAYED:
|
|
|
203 |
case ORDER_NOT_CONNECTED:
|
|
|
204 |
style = selectionStyle.criticalRow();
|
|
|
205 |
break;
|
| 19004 |
manish.sha |
206 |
case TODAY_SHIPPING_IN_STOCK:
|
|
|
207 |
style = selectionStyle.todayShippingInStockRow();
|
|
|
208 |
break;
|
|
|
209 |
case TODAY_SHIPPING_NOT_IN_STOCK:
|
|
|
210 |
style = selectionStyle.todayShippingNotInStockRow();
|
|
|
211 |
break;
|
| 19166 |
manish.sha |
212 |
case LATER_SHIPPING_IN_STOCK:
|
| 19004 |
manish.sha |
213 |
style = selectionStyle.laterShippingRow();
|
|
|
214 |
break;
|
| 4124 |
chandransh |
215 |
case WARNING:
|
|
|
216 |
case NONE:
|
|
|
217 |
}
|
| 8717 |
amar.kumar |
218 |
if(order.getProductCondition()==1) {
|
|
|
219 |
style = selectionStyle.badInventory();
|
|
|
220 |
}
|
| 4124 |
chandransh |
221 |
return style;
|
|
|
222 |
}
|
|
|
223 |
});
|
|
|
224 |
|
| 4361 |
rajveer |
225 |
|
|
|
226 |
|
|
|
227 |
// Add the columns.
|
|
|
228 |
table.addColumn(checkboxColumn,"");
|
| 4666 |
rajveer |
229 |
table.addColumn(promisedShippingDateColumn, "Promised Shipping");
|
| 19057 |
manish.sha |
230 |
table.addColumn(transactionIdColumn, "Txn Id");
|
| 4124 |
chandransh |
231 |
table.addColumn(paymentModeColumn, "Type");
|
| 19059 |
manish.sha |
232 |
table.addColumn(orderFromColumn, "Source");
|
| 4124 |
chandransh |
233 |
table.addColumn(idColumn, "Order Id");
|
|
|
234 |
table.addColumn(productDescriptionColumn, "Product Description");
|
|
|
235 |
table.addColumn(creationDateColumn, "Creation Date");
|
| 7422 |
rajveer |
236 |
// table.addColumn(promisedDeliveryDateColumn, "Promised Delivery");
|
|
|
237 |
// table.addColumn(expectedDeliveryDateColumn, "Expected Delivery");
|
| 4124 |
chandransh |
238 |
table.addColumn(statusMessageColumn, "Current Status");
|
| 167 |
ashish |
239 |
|
| 4124 |
chandransh |
240 |
//Set the widths
|
|
|
241 |
table.setWidth("100%");
|
| 19060 |
manish.sha |
242 |
table.setColumnWidth(checkboxColumn, 30, Unit.PX);
|
| 19004 |
manish.sha |
243 |
table.setColumnWidth(promisedShippingDateColumn, 120.0, Unit.PX);
|
|
|
244 |
table.setColumnWidth(transactionIdColumn, 70.0, Unit.PX);
|
|
|
245 |
table.setColumnWidth(paymentModeColumn, 50.0, Unit.PX);
|
| 4125 |
chandransh |
246 |
table.setColumnWidth(idColumn, 70.0, Unit.PX);
|
| 7422 |
rajveer |
247 |
table.setColumnWidth(orderFromColumn, 70.0, Unit.PX);
|
| 4670 |
rajveer |
248 |
table.setColumnWidth(productDescriptionColumn, 230.0, Unit.PX);
|
| 19004 |
manish.sha |
249 |
table.setColumnWidth(creationDateColumn, 120.0, Unit.PX);
|
| 7422 |
rajveer |
250 |
// table.setColumnWidth(promisedDeliveryDateColumn, 140.0, Unit.PX);
|
|
|
251 |
// table.setColumnWidth(expectedDeliveryDateColumn, 140.0, Unit.PX);
|
| 19057 |
manish.sha |
252 |
table.setColumnWidth(statusMessageColumn, 160.0, Unit.PX);
|
| 4124 |
chandransh |
253 |
|
| 4133 |
chandransh |
254 |
table.setRowCount(count, true);
|
|
|
255 |
table.setVisibleRange(start, orders.size());
|
|
|
256 |
|
| 4124 |
chandransh |
257 |
// Connect the table to the data provider.
|
|
|
258 |
asyncDataProvider.addDataDisplay(table);
|
| 4133 |
chandransh |
259 |
|
| 4124 |
chandransh |
260 |
//Add paging support
|
|
|
261 |
pager.setDisplay(table);
|
|
|
262 |
|
|
|
263 |
// Initialize the data
|
| 4133 |
chandransh |
264 |
asyncDataProvider.updateRowCount(count, true);
|
|
|
265 |
asyncDataProvider.updateRowData(start, orders);
|
| 4124 |
chandransh |
266 |
|
|
|
267 |
// Add a selection model to handle item selection.
|
|
|
268 |
final SingleSelectionModel<Order> selectionModel = new SingleSelectionModel<Order>();
|
|
|
269 |
table.setSelectionModel(selectionModel);
|
|
|
270 |
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
|
|
271 |
|
|
|
272 |
@Override
|
|
|
273 |
public void onSelectionChange(SelectionChangeEvent event) {
|
|
|
274 |
Order selectedOrder = selectionModel.getSelectedObject();
|
|
|
275 |
eventbus.fireEvent(new LoadOrderDetailsEvent(selectedOrder));
|
| 4004 |
chandransh |
276 |
}
|
| 4124 |
chandransh |
277 |
});
|
|
|
278 |
|
|
|
279 |
}
|
| 167 |
ashish |
280 |
|
| 306 |
ashish |
281 |
private String getDisplayableDate(Date date){
|
|
|
282 |
String dateString = date.toString();
|
|
|
283 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
284 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
285 |
return dateString;
|
|
|
286 |
}
|
| 167 |
ashish |
287 |
}
|