Subversion Repositories SmartDukaan

Rev

Rev 3850 | Rev 6530 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3850 Rev 3872
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.client;
1
package in.shop2020.catalog.dashboard.client;
2
 
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
3
import in.shop2020.catalog.dashboard.shared.Item;
4
import in.shop2020.catalog.dashboard.shared.ItemStatus;
4
import in.shop2020.catalog.dashboard.shared.ItemStatus;
5
 
5
 
-
 
6
import java.util.ArrayList;
-
 
7
import java.util.Arrays;
6
import java.util.List;
8
import java.util.List;
7
 
9
 
8
import com.google.gwt.core.client.GWT;
10
import com.google.gwt.core.client.GWT;
9
import com.google.gwt.dom.client.Style.Unit;
11
import com.google.gwt.dom.client.Style.Unit;
10
import com.google.gwt.resources.client.CssResource;
12
import com.google.gwt.resources.client.CssResource;
Line 52... Line 54...
52
    
54
    
53
    private ItemDetails itemDetails;
55
    private ItemDetails itemDetails;
54
    
56
    
55
    private String currentTreeItemSelection = null;
57
    private String currentTreeItemSelection = null;
56
    
58
    
-
 
59
    private String searchText = "";
-
 
60
    
-
 
61
    private List<String> searchTerms = new ArrayList<String>();
-
 
62
    
57
    private TextColumn<Item> idColumn = new TextColumn<Item>() {
63
    private TextColumn<Item> idColumn = new TextColumn<Item>() {
58
        @Override
64
        @Override
59
        public String getValue(Item item) {
65
        public String getValue(Item item) {
60
            return item.getId() + "";
66
            return item.getId() + "";
61
        }
67
        }
Line 133... Line 139...
133
                loadBestSellers(start, limit);
139
                loadBestSellers(start, limit);
134
            else if(currentTreeItemSelection.equals(CatalogTree.LATEST_ARRIVALS))
140
            else if(currentTreeItemSelection.equals(CatalogTree.LATEST_ARRIVALS))
135
                loadLatestArrivals(start, limit);
141
                loadLatestArrivals(start, limit);
136
            else if(currentTreeItemSelection.equals(CatalogTree.RISKY_ITEMS))
142
            else if(currentTreeItemSelection.equals(CatalogTree.RISKY_ITEMS))
137
                loadAllRiskyItems(start, limit);
143
                loadAllRiskyItems(start, limit);
-
 
144
            else if(currentTreeItemSelection.equals(CatalogTree.SEARCH))
-
 
145
                loadSearchItems(start, limit);
138
        }
146
        }
139
    };
147
    };
140
    
148
    
141
    public ItemList() {
149
    public ItemList() {
142
        initWidget(uiBinder.createAndBindUi(this));
150
        initWidget(uiBinder.createAndBindUi(this));
Line 233... Line 241...
233
    public void loadBestDeals() {
241
    public void loadBestDeals() {
234
        currentTreeItemSelection = CatalogTree.BEST_DEALS;
242
        currentTreeItemSelection = CatalogTree.BEST_DEALS;
235
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
243
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
236
    }
244
    }
237
    
245
    
-
 
246
    public void loadBestSellers() {
-
 
247
        currentTreeItemSelection = CatalogTree.BEST_SELLERS;
-
 
248
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
-
 
249
    }
-
 
250
    
238
    public void loadLatestArrivals() {
251
    public void loadLatestArrivals() {
239
        currentTreeItemSelection = CatalogTree.LATEST_ARRIVALS;
252
        currentTreeItemSelection = CatalogTree.LATEST_ARRIVALS;
240
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
253
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
241
    }
254
    }
242
    
255
    
243
    public void loadBestSellers() {
256
    public void searchForItems(String searchText) {
244
        currentTreeItemSelection = CatalogTree.BEST_SELLERS;
257
        currentTreeItemSelection = CatalogTree.SEARCH;
-
 
258
        this.searchText = searchText.trim().replaceAll("\\s+", " ");
-
 
259
        searchTerms = Arrays.asList(this.searchText.split(" "));
245
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
260
        itemDescriptionTable.setVisibleRangeAndClearData(new Range(0, pager.getPageSize()), true);
246
    }
261
    }
247
    
262
    
248
    private void updateItemDescriptionTableRowCount(Integer count){
263
    private void updateItemDescriptionTableRowCount(Integer count){
249
        asyncDataProvider.updateRowCount(count, true);
264
        asyncDataProvider.updateRowCount(count, true);
Line 422... Line 437...
422
            public void onFailure(Throwable caught) {
437
            public void onFailure(Throwable caught) {
423
                caught.printStackTrace();
438
                caught.printStackTrace();
424
                Window.alert("Could not load RISKY items...");
439
                Window.alert("Could not load RISKY items...");
425
            }
440
            }
426
            public void onSuccess(List<Item> result) {
441
            public void onSuccess(List<Item> result) {
427
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
442
                updateAsyncItemDescriptionTable(start, result.subList(start, Math.min(start + limit, result.size())));
428
                updateItemDescriptionTableRowCount(result.size());
443
                updateItemDescriptionTableRowCount(result.size());
429
                currentTreeItemSelection = CatalogTree.RISKY_ITEMS;
444
                currentTreeItemSelection = CatalogTree.RISKY_ITEMS;
430
                currentlyShowing.setText(LEGEND + "Risky Items");
445
                currentlyShowing.setText(LEGEND + "Risky Items");
431
            }
446
            }
432
        });
447
        });
433
    }
448
    }
434
 
449
 
435
    private void loadLatestArrivals(final int start, final int limit) {
450
    private void loadBestDeals(final int start, final int limit) {
436
        catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
451
        catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
437
            public void onFailure(Throwable caught) {
452
            public void onFailure(Throwable caught) {
438
                caught.printStackTrace();
453
                caught.printStackTrace();
439
                Window.alert("Could not load latest arrivals.");
454
                Window.alert("Could not load best deals.");
440
            }
455
            }
441
            public void onSuccess(List<Item> result) {
456
            public void onSuccess(List<Item> result) {
442
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
457
                updateAsyncItemDescriptionTable(start, result.subList(start, Math.min(start + limit, result.size())));
443
                updateItemDescriptionTableRowCount(result.size());
458
                updateItemDescriptionTableRowCount(result.size());
444
                currentlyShowing.setText(LEGEND + "Latest Arrivals");
459
                currentlyShowing.setText(LEGEND + "Best Deals");
445
            }
460
            }
446
        });
461
        });
447
        
-
 
448
    }
462
    }
449
 
463
 
450
    private void loadBestSellers(final int start, final int limit) {
464
    private void loadBestSellers(final int start, final int limit) {
451
        catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
465
        catalogService.getBestSellers(new AsyncCallback<List<Item>>() {
452
            public void onFailure(Throwable caught) {
466
            public void onFailure(Throwable caught) {
453
                caught.printStackTrace();
467
                caught.printStackTrace();
454
                Window.alert("Could not load best sellers.");
468
                Window.alert("Could not load best sellers.");
455
            }
469
            }
456
            public void onSuccess(List<Item> result) {
470
            public void onSuccess(List<Item> result) {
457
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
471
                updateAsyncItemDescriptionTable(start, result.subList(start, Math.min(start + limit, result.size())));
458
                updateItemDescriptionTableRowCount(result.size());
472
                updateItemDescriptionTableRowCount(result.size());
459
                currentlyShowing.setText(LEGEND + "Best Sellers");
473
                currentlyShowing.setText(LEGEND + "Best Sellers");
460
            }
474
            }
461
        });
475
        });
462
    }
476
    }
463
 
477
 
464
    private void loadBestDeals(final int start, final int limit) {
478
    private void loadLatestArrivals(final int start, final int limit) {
465
        catalogService.getBestDeals(new AsyncCallback<List<Item>>() {
479
        catalogService.getLatestArrivals(new AsyncCallback<List<Item>>() {
466
            public void onFailure(Throwable caught) {
480
            public void onFailure(Throwable caught) {
467
                caught.printStackTrace();
481
                caught.printStackTrace();
468
                Window.alert("Could not load best deals.");
482
                Window.alert("Could not load latest arrivals.");
469
            }
483
            }
470
            public void onSuccess(List<Item> result) {
484
            public void onSuccess(List<Item> result) {
471
                updateAsyncItemDescriptionTable(0, result.subList(start, Math.min(start + limit, result.size())));
485
                updateAsyncItemDescriptionTable(start, result.subList(start, Math.min(start + limit, result.size())));
472
                updateItemDescriptionTableRowCount(result.size());
486
                updateItemDescriptionTableRowCount(result.size());
473
                currentlyShowing.setText(LEGEND + "Best Deals");
487
                currentlyShowing.setText(LEGEND + "Latest Arrivals");
474
            }
488
            }
475
        });
489
        });
-
 
490
        
476
    }
491
    }
477
 
492
 
-
 
493
    private void loadSearchItems(final int start, final int limit) {
-
 
494
        catalogService.searchItems(start, limit, searchTerms, new AsyncCallback<List<Item>>() {
-
 
495
            public void onFailure(Throwable caught) {
-
 
496
                caught.printStackTrace();
-
 
497
                Window.alert("Could not load the search results.");
-
 
498
            }
-
 
499
            public void onSuccess(List<Item> result) {
-
 
500
                updateAsyncItemDescriptionTable(start, result);
-
 
501
                currentlyShowing.setText(LEGEND + "Search results for " + searchText);
-
 
502
            }
-
 
503
        });
-
 
504
        
-
 
505
        
-
 
506
        catalogService.getSearchResultCount(searchTerms, new AsyncCallback<Integer>() {
-
 
507
 
-
 
508
            @Override
-
 
509
            public void onFailure(Throwable caught) {
-
 
510
                caught.printStackTrace();
-
 
511
                Window.alert("Could not get the count of items...");
-
 
512
            }
-
 
513
 
-
 
514
            @Override
-
 
515
            public void onSuccess(Integer count) {
-
 
516
                updateItemDescriptionTableRowCount(count);
-
 
517
            }
-
 
518
        });
-
 
519
    }
-
 
520
    
478
    public void setItemDetails(ItemDetails itemDetails) {
521
    public void setItemDetails(ItemDetails itemDetails) {
479
        this.itemDetails = itemDetails;
522
        this.itemDetails = itemDetails;
480
    }
523
    }
481
    
524
    
482
    /**
525
    /**