Subversion Repositories SmartDukaan

Rev

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