Subversion Repositories SmartDukaan

Rev

Rev 5128 | Rev 6788 | 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) {
2359 ankur.sing 52
                authenticateUser(username, password, Utils.ROLE_STAGING);
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
     */
2359 ankur.sing 65
    private void authenticateUser(String username, String password, int role) {
4649 phani.kuma 66
        uname = username;
2359 ankur.sing 67
        loginService.authenticateUser(username, password, role, new AsyncCallback<String>() {
1961 ankur.sing 68
            @Override
2027 ankur.sing 69
            public void onSuccess(String result) {
70
                if (result != null) {
71
                    GWT.log(result + " logged in catalog dashboard");
1961 ankur.sing 72
                    root.clear();
73
                    initMainDB(uname);
74
                    login.clearFields();
2027 ankur.sing 75
                } else {
76
                    login.setErrorText("Invalid username/password");    
1961 ankur.sing 77
                }
78
            }
79
            @Override
80
            public void onFailure(Throwable caught) {
2489 ankur.sing 81
                caught.printStackTrace();
2027 ankur.sing 82
                login.setErrorText("Error in authentication");
1961 ankur.sing 83
            }
84
        });
85
    }
86
 
87
    private void initMainDB(String username) {
88
        DockLayoutPanel dashboard = binder.createAndBindUi(this);
2126 ankur.sing 89
        itemActions.setItemDetails(itemDetails);
90
        itemList.setItemDetails(itemDetails);
2489 ankur.sing 91
        itemDetails.setCatalogDashboardPanel(this);
1961 ankur.sing 92
        topPanel.changeGreeting(username);
93
 
94
        topPanel.getSignOutLink().addClickHandler(new ClickHandler() {
95
            @Override
96
            public void onClick(ClickEvent event) {
97
                root.clear();
98
                root.add(login);
99
            }
100
        });
101
        root.clear();
102
        root.add(dashboard);
1992 ankur.sing 103
 
2427 ankur.sing 104
        /**
105
         * listener for anchors to filter item list based on statuses and some other parameters.
106
         * On click event, string of the anchor is passed as argument and the same listener is
107
         * taking different actions based on the different string arguments.
108
         */
1992 ankur.sing 109
        shortcuts.getCatalogTree().setTreeListener(new CatalogTree.TreeListener() {
110
            @Override
2027 ankur.sing 111
            public void onTreeItemClicked(String itemsType) {
2119 ankur.sing 112
                if(CatalogTree.ALL_ITEMS.equals(itemsType)) {
2027 ankur.sing 113
                    itemList.loadAllItems();
2208 ankur.sing 114
                } else if(CatalogTree.ALL_PHASED_OUT_ITEMS.equals(itemsType)) { 
115
                    itemList.loadAllPhasedOutItems();
116
                } else if(CatalogTree.ALL_PAUSED_ITEMS.equals(itemsType)) { 
117
                    itemList.loadAllPausedItems();
2119 ankur.sing 118
                } else if(CatalogTree.ALL_ACTIVE_ITEMS.equals(itemsType)) { 
119
                    itemList.loadAllActiveItems();
2359 ankur.sing 120
                } else if(CatalogTree.IN_PROCESS_ITEMS.equals(itemsType)) { 
121
                    itemList.loadAllInProcessItems();
122
                } else if(CatalogTree.CONTENT_COMPLETE_ITEMS.equals(itemsType)) { 
123
                    itemList.loadAllContentCompleteItems();
124
                } else if(CatalogTree.RISKY_ITEMS.equals(itemsType)) { 
125
                    itemList.loadAllRiskyItems();
2119 ankur.sing 126
                } else if(CatalogTree.BEST_DEALS.equals(itemsType)) {
2027 ankur.sing 127
                    itemList.loadBestDeals();
2119 ankur.sing 128
                } else if(CatalogTree.BEST_SELLERS.equals(itemsType)) {
2027 ankur.sing 129
                    itemList.loadBestSellers();
2119 ankur.sing 130
                } else if(CatalogTree.LATEST_ARRIVALS.equals(itemsType)) {
2027 ankur.sing 131
                    itemList.loadLatestArrivals();
3872 chandransh 132
                } else if(CatalogTree.SEARCH.equals(itemsType)) {
133
                    //Open the search dialog box
134
                    SearchItemBox box = new SearchItemBox(itemList);
135
                    box.center();
5128 amit.gupta 136
                } else if (CatalogTree.INACTIVE_ITEMS_WITH_INVENTORY.equals(itemsType)) {
137
                	String link = GWT.getHostPageBaseURL() + "inactivewithinventory/download";
138
                    Window.open(link, "_blank", "Inactive Items with Inventory");
139
                }else if (CatalogTree.BREAKEVEN_ITEMS.equals(itemsType)){
140
                	String link1 = GWT.getHostPageBaseURL() + "belowbreakeven/download";
141
                	Window.open(link1, "_blank", "Item below break even price.");
6530 vikram.rag 142
                }else if (CatalogTree.INVENTORY_OUTOFSYNC_ITEM_LIST.equals(itemsType)){
143
                	itemList.loadInventoryOutofSyncItems();
144
                	}
1992 ankur.sing 145
            }
146
        });
1961 ankur.sing 147
    }
2489 ankur.sing 148
 
149
    ItemList getItemListWidget() {
150
        return this.itemList;
151
    }
152
 
153
    ItemDetails getItemDetailsWidget() {
154
        return this.itemDetails;
155
    }
1961 ankur.sing 156
}
2126 ankur.sing 157