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