Subversion Repositories SmartDukaan

Rev

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