Subversion Repositories SmartDukaan

Rev

Rev 6530 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
25
    @UiTemplate("CatalogDashboard.ui.xml")
26
    interface CatalogBinder extends UiBinder<DockLayoutPanel, CatalogDashboard> {
27
    }
2066 ankur.sing 28
 
1961 ankur.sing 29
    private static final CatalogBinder binder = GWT.create(CatalogBinder.class);
30
    private final LoginServiceAsync loginService = GWT.create(LoginService.class);
4649 phani.kuma 31
    public String uname;
2427 ankur.sing 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
 
39
    RootLayoutPanel root;
40
    LoginScreen login;
41
 
42
    public void onModuleLoad() {
4506 phani.kuma 43
    	Map<Long, String> vendors = Utils.getAllVendors();	//do not delete this line it is done to prefetch the data
1961 ankur.sing 44
        root = RootLayoutPanel.get();
2027 ankur.sing 45
        root.getElement().setScrollLeft(10);
1961 ankur.sing 46
        login = new LoginScreen();
2119 ankur.sing 47
        //initMainDB("Testing");
48
        root.add(login);
1961 ankur.sing 49
        login.setLoginListener(new LoginScreen.LoginListener() {
50
            @Override
51
            public void onLoginPressed(String username, String password) {
6788 rajveer 52
                authenticateUser(username, password);
1961 ankur.sing 53
            }
2119 ankur.sing 54
        });
1961 ankur.sing 55
    }
56
 
2427 ankur.sing 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
     */
6788 rajveer 65
    private void authenticateUser(String username, String password) {
4649 phani.kuma 66
        uname = username;
6788 rajveer 67
        loginService.authenticateUser(username, password, new AsyncCallback<String>() {
1961 ankur.sing 68
            @Override
2027 ankur.sing 69
            public void onSuccess(String result) {
70
                if (result != null) {
6788 rajveer 71
                	long role = Long.parseLong(result);
72
                    GWT.log(uname + " logged in catalog dashboard");
1961 ankur.sing 73
                    root.clear();
6788 rajveer 74
                    initMainDB(uname, role);
1961 ankur.sing 75
                    login.clearFields();
2027 ankur.sing 76
                } else {
77
                    login.setErrorText("Invalid username/password");    
1961 ankur.sing 78
                }
79
            }
80
            @Override
81
            public void onFailure(Throwable caught) {
2489 ankur.sing 82
                caught.printStackTrace();
2027 ankur.sing 83
                login.setErrorText("Error in authentication");
1961 ankur.sing 84
            }
85
        });
86
    }
87
 
6788 rajveer 88
    private void initMainDB(String username, long role) {
1961 ankur.sing 89
        DockLayoutPanel dashboard = binder.createAndBindUi(this);
2126 ankur.sing 90
        itemActions.setItemDetails(itemDetails);
91
        itemList.setItemDetails(itemDetails);
2489 ankur.sing 92
        itemDetails.setCatalogDashboardPanel(this);
1961 ankur.sing 93
        topPanel.changeGreeting(username);
6788 rajveer 94
        if(role == Utils.ROLE_READONLY){
95
        	itemActions.disableAllActions();
96
        }
1961 ankur.sing 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);
1992 ankur.sing 106
 
2427 ankur.sing 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
         */
1992 ankur.sing 112
        shortcuts.getCatalogTree().setTreeListener(new CatalogTree.TreeListener() {
113
            @Override
2027 ankur.sing 114
            public void onTreeItemClicked(String itemsType) {
2119 ankur.sing 115
                if(CatalogTree.ALL_ITEMS.equals(itemsType)) {
2027 ankur.sing 116
                    itemList.loadAllItems();
2208 ankur.sing 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();
2119 ankur.sing 121
                } else if(CatalogTree.ALL_ACTIVE_ITEMS.equals(itemsType)) { 
122
                    itemList.loadAllActiveItems();
2359 ankur.sing 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();
2119 ankur.sing 129
                } else if(CatalogTree.BEST_DEALS.equals(itemsType)) {
2027 ankur.sing 130
                    itemList.loadBestDeals();
2119 ankur.sing 131
                } else if(CatalogTree.BEST_SELLERS.equals(itemsType)) {
2027 ankur.sing 132
                    itemList.loadBestSellers();
2119 ankur.sing 133
                } else if(CatalogTree.LATEST_ARRIVALS.equals(itemsType)) {
2027 ankur.sing 134
                    itemList.loadLatestArrivals();
3872 chandransh 135
                } else if(CatalogTree.SEARCH.equals(itemsType)) {
136
                    //Open the search dialog box
137
                    SearchItemBox box = new SearchItemBox(itemList);
138
                    box.center();
5128 amit.gupta 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.");
6530 vikram.rag 145
                }else if (CatalogTree.INVENTORY_OUTOFSYNC_ITEM_LIST.equals(itemsType)){
146
                	itemList.loadInventoryOutofSyncItems();
147
                	}
1992 ankur.sing 148
            }
149
        });
1961 ankur.sing 150
    }
2489 ankur.sing 151
 
152
    ItemList getItemListWidget() {
153
        return this.itemList;
154
    }
155
 
156
    ItemDetails getItemDetailsWidget() {
157
        return this.itemDetails;
158
    }
1961 ankur.sing 159
}
2126 ankur.sing 160