| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
| 4506 |
phani.kuma |
3 |
import java.util.Map;
|
|
|
4 |
|
| 2359 |
ankur.sing |
5 |
import in.shop2020.catalog.dashboard.shared.Utils;
|
|
|
6 |
|
| 1961 |
ankur.sing |
7 |
import com.google.gwt.core.client.EntryPoint;
|
|
|
8 |
import com.google.gwt.core.client.GWT;
|
|
|
9 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
10 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
11 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
12 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
13 |
import com.google.gwt.uibinder.client.UiTemplate;
|
| 5128 |
amit.gupta |
14 |
import com.google.gwt.user.client.Window;
|
| 1961 |
ankur.sing |
15 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
16 |
import com.google.gwt.user.client.ui.DockLayoutPanel;
|
|
|
17 |
import com.google.gwt.user.client.ui.RootLayoutPanel;
|
|
|
18 |
|
| 2427 |
ankur.sing |
19 |
/**
|
|
|
20 |
* This is the entry point of dashboard application.
|
|
|
21 |
*
|
|
|
22 |
*/
|
| 1961 |
ankur.sing |
23 |
public class CatalogDashboard implements EntryPoint {
|
|
|
24 |
|
| 11671 |
vikram.rag |
25 |
@UiTemplate("CatalogDashboard.ui.xml")
|
|
|
26 |
interface CatalogBinder extends UiBinder<DockLayoutPanel, CatalogDashboard> {
|
|
|
27 |
}
|
| 1961 |
ankur.sing |
28 |
|
| 11671 |
vikram.rag |
29 |
private static final CatalogBinder binder = GWT.create(CatalogBinder.class);
|
|
|
30 |
private final LoginServiceAsync loginService = GWT.create(LoginService.class);
|
|
|
31 |
public String uname;
|
|
|
32 |
@UiField TopPanel topPanel; // logo, welcome message and sign out link
|
|
|
33 |
@UiField Shortcuts shortcuts; // anchors to filter item list based on status
|
|
|
34 |
//TODO @UiField Filters filters;
|
|
|
35 |
@UiField ItemList itemList; // list of items
|
|
|
36 |
@UiField ItemDetails itemDetails; // details of an item selected in the list
|
|
|
37 |
@UiField ItemActions itemActions; // action buttons to update, add item or change item status
|
| 1961 |
ankur.sing |
38 |
|
| 11671 |
vikram.rag |
39 |
RootLayoutPanel root;
|
|
|
40 |
LoginScreen login;
|
| 1961 |
ankur.sing |
41 |
|
| 11671 |
vikram.rag |
42 |
public void onModuleLoad() {
|
|
|
43 |
Map<Long, String> vendors = Utils.getAllVendors(); //do not delete this line it is done to prefetch the data
|
|
|
44 |
root = RootLayoutPanel.get();
|
|
|
45 |
root.getElement().setScrollLeft(10);
|
|
|
46 |
login = new LoginScreen();
|
|
|
47 |
//initMainDB("Testing");
|
|
|
48 |
root.add(login);
|
|
|
49 |
login.setLoginListener(new LoginScreen.LoginListener() {
|
|
|
50 |
@Override
|
|
|
51 |
public void onLoginPressed(String username, String password) {
|
|
|
52 |
authenticateUser(username, password);
|
|
|
53 |
}
|
|
|
54 |
});
|
|
|
55 |
}
|
| 1961 |
ankur.sing |
56 |
|
| 11671 |
vikram.rag |
57 |
/**
|
|
|
58 |
* Authenticates username and password and if successful, initialises
|
|
|
59 |
* main dashboard panel.
|
|
|
60 |
* @param username
|
|
|
61 |
* @param password
|
|
|
62 |
* @param role -- Utils.ROLE_STAGING (Login role for staging), another role
|
|
|
63 |
* is Utils.ROLE_PRODUCTION (for push to production username & password)
|
|
|
64 |
*/
|
|
|
65 |
private void authenticateUser(String username, String password) {
|
|
|
66 |
uname = username;
|
|
|
67 |
loginService.authenticateUser(username, password, new AsyncCallback<String>() {
|
|
|
68 |
@Override
|
|
|
69 |
public void onSuccess(String result) {
|
|
|
70 |
if (result != null) {
|
|
|
71 |
long role = Long.parseLong(result);
|
|
|
72 |
GWT.log(uname + " logged in catalog dashboard");
|
|
|
73 |
root.clear();
|
|
|
74 |
initMainDB(uname, role);
|
|
|
75 |
login.clearFields();
|
|
|
76 |
} else {
|
|
|
77 |
login.setErrorText("Invalid username/password");
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
@Override
|
|
|
81 |
public void onFailure(Throwable caught) {
|
|
|
82 |
caught.printStackTrace();
|
|
|
83 |
login.setErrorText("Error in authentication");
|
|
|
84 |
}
|
|
|
85 |
});
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
private void initMainDB(String username, long role) {
|
|
|
89 |
DockLayoutPanel dashboard = binder.createAndBindUi(this);
|
|
|
90 |
itemActions.setItemDetails(itemDetails);
|
|
|
91 |
itemList.setItemDetails(itemDetails);
|
|
|
92 |
itemDetails.setCatalogDashboardPanel(this);
|
|
|
93 |
topPanel.changeGreeting(username);
|
|
|
94 |
if(role == Utils.ROLE_READONLY){
|
|
|
95 |
itemActions.disableAllActions();
|
|
|
96 |
}
|
|
|
97 |
topPanel.getSignOutLink().addClickHandler(new ClickHandler() {
|
|
|
98 |
@Override
|
|
|
99 |
public void onClick(ClickEvent event) {
|
|
|
100 |
root.clear();
|
|
|
101 |
root.add(login);
|
|
|
102 |
}
|
|
|
103 |
});
|
|
|
104 |
root.clear();
|
|
|
105 |
root.add(dashboard);
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* listener for anchors to filter item list based on statuses and some other parameters.
|
|
|
109 |
* On click event, string of the anchor is passed as argument and the same listener is
|
|
|
110 |
* taking different actions based on the different string arguments.
|
|
|
111 |
*/
|
|
|
112 |
shortcuts.getCatalogTree().setTreeListener(new CatalogTree.TreeListener() {
|
|
|
113 |
@Override
|
|
|
114 |
public void onTreeItemClicked(String itemsType) {
|
|
|
115 |
if(CatalogTree.ALL_ITEMS.equals(itemsType)) {
|
|
|
116 |
itemList.loadAllItems();
|
|
|
117 |
} else if(CatalogTree.ALL_PHASED_OUT_ITEMS.equals(itemsType)) {
|
|
|
118 |
itemList.loadAllPhasedOutItems();
|
|
|
119 |
} else if(CatalogTree.ALL_PAUSED_ITEMS.equals(itemsType)) {
|
|
|
120 |
itemList.loadAllPausedItems();
|
|
|
121 |
} else if(CatalogTree.ALL_ACTIVE_ITEMS.equals(itemsType)) {
|
|
|
122 |
itemList.loadAllActiveItems();
|
|
|
123 |
} else if(CatalogTree.IN_PROCESS_ITEMS.equals(itemsType)) {
|
|
|
124 |
itemList.loadAllInProcessItems();
|
|
|
125 |
} else if(CatalogTree.CONTENT_COMPLETE_ITEMS.equals(itemsType)) {
|
|
|
126 |
itemList.loadAllContentCompleteItems();
|
|
|
127 |
} else if(CatalogTree.RISKY_ITEMS.equals(itemsType)) {
|
|
|
128 |
itemList.loadAllRiskyItems();
|
|
|
129 |
} else if(CatalogTree.BEST_DEALS.equals(itemsType)) {
|
|
|
130 |
itemList.loadBestDeals();
|
|
|
131 |
} else if(CatalogTree.BEST_SELLERS.equals(itemsType)) {
|
|
|
132 |
itemList.loadBestSellers();
|
|
|
133 |
} else if(CatalogTree.LATEST_ARRIVALS.equals(itemsType)) {
|
|
|
134 |
itemList.loadLatestArrivals();
|
|
|
135 |
} else if(CatalogTree.SEARCH.equals(itemsType)) {
|
|
|
136 |
//Open the search dialog box
|
|
|
137 |
SearchItemBox box = new SearchItemBox(itemList);
|
|
|
138 |
box.center();
|
|
|
139 |
} else if (CatalogTree.INACTIVE_ITEMS_WITH_INVENTORY.equals(itemsType)) {
|
|
|
140 |
String link = GWT.getHostPageBaseURL() + "inactivewithinventory/download";
|
|
|
141 |
Window.open(link, "_blank", "Inactive Items with Inventory");
|
|
|
142 |
}else if (CatalogTree.BREAKEVEN_ITEMS.equals(itemsType)){
|
|
|
143 |
String link1 = GWT.getHostPageBaseURL() + "belowbreakeven/download";
|
|
|
144 |
Window.open(link1, "_blank", "Item below break even price.");
|
|
|
145 |
}else if (CatalogTree.INVENTORY_OUTOFSYNC_ITEM_LIST.equals(itemsType)){
|
|
|
146 |
itemList.loadInventoryOutofSyncItems();
|
|
|
147 |
}
|
|
|
148 |
else if (CatalogTree.PRIVATE_DEALS.equals(itemsType)){
|
|
|
149 |
itemList.loadPrivateDealItems();
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
});
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
ItemList getItemListWidget() {
|
|
|
156 |
return this.itemList;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
ItemDetails getItemDetailsWidget() {
|
|
|
160 |
return this.itemDetails;
|
|
|
161 |
}
|
| 1961 |
ankur.sing |
162 |
}
|
| 2126 |
ankur.sing |
163 |
|