This commit is contained in:
Le Deng
2017-03-10 12:20:55 -05:00
parent 1fd91886ba
commit 6bf9da5b77
7 changed files with 50 additions and 35 deletions

View File

@@ -151,8 +151,8 @@
<file leaf-file-name="ShoppingCartResource.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/ShoppingCartResource.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="563">
<caret line="104" column="60" lean-forward="false" selection-start-line="104" selection-start-column="60" selection-end-line="104" selection-end-column="60" />
<state relative-caret-position="593">
<caret line="104" column="44" lean-forward="false" selection-start-line="104" selection-start-column="44" selection-end-line="104" selection-end-column="44" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -1038,12 +1038,12 @@
<workItem from="1488378219247" duration="650000" />
<workItem from="1488461561430" duration="18419000" />
<workItem from="1488731165185" duration="30270000" />
<workItem from="1489159532831" duration="2499000" />
<workItem from="1489159532831" duration="3038000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="94781000" />
<option name="totallyTimeSpent" value="95320000" />
</component>
<component name="ToolWindowManager">
<frame x="72" y="23" width="1280" height="797" extended-state="0" />
@@ -1067,7 +1067,7 @@
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32907802" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32624114" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32624114" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Spring" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32907802" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32229403" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
@@ -1555,8 +1555,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/ShoppingCartResource.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="563">
<caret line="104" column="60" lean-forward="false" selection-start-line="104" selection-start-column="60" selection-end-line="104" selection-end-column="60" />
<state relative-caret-position="593">
<caret line="104" column="44" lean-forward="false" selection-start-line="104" selection-start-column="44" selection-end-line="104" selection-end-column="44" />
<folding>
<element signature="imports" expanded="true" />
</folding>

View File

@@ -91,7 +91,7 @@ public class ShoppingCartResource {
}
@RequestMapping("/updateCartItem")
public ResponseEntity updateShoppingCart(
public ResponseEntity updateCartItem(
@RequestBody HashMap<String, String> mapper
) {
String cartItemId = mapper.get("cartItemId");
@@ -102,7 +102,7 @@ public class ShoppingCartResource {
cartItemService.updateCartItem(cartItem);
return new ResponseEntity("Cart Updated Successfully!", HttpStatus.OK);
return new ResponseEntity("Cart Item Updated Successfully!", HttpStatus.OK);
}
}

View File

@@ -14,12 +14,16 @@
<div class="row">
<div class="col-xs-6 text-left">
<a md-raised-button class="mat-warn" routerLink="/bookList">Continue Shopping</a>
<!-- <a md-raised-button *ngIf="displayUpdateCart" class="mat-accent" (click)="onUpdateCart()">Update Cart</a> -->
</div>
<div class="col-xs-6 text-right">
<a md-raised-button class="mat-primary" routerLink="/checkout">Check Out</a>
</div>
</div>
<br/>
<div *ngIf="cartItemUpdated" class="alert alert-success">
Cart Item Updated Successfully!
</div>
<div *ngIf="notEnoughStock" class="alert alert-warning">
Oops, some of the products don't have enough stock. Please update product quantity.
</div>
@@ -36,32 +40,30 @@
</div>
<!--******* display products in cart ********-->
<div class="row" *ngFor="let cartItem of cartItemList">
<form (ngSubmit)="onSubmit()" method="post">
<hr/>
<div class="col-xs-2">
<a md-button (click)="onSelect(cartItem.book)"><img class="img-responsive shelf-book" src="{{serverPath}}/image/book/{{cartItem.book.id}}.png" style="width:70px;" /></a>
</div>
<div class="col-xs-6">
<a class="pointer" (click)="onSelect(cartItem.book)"><h4>
<hr/>
<div class="col-xs-2">
<a md-button (click)="onSelect(cartItem.book)"><img class="img-responsive shelf-book" src="{{serverPath}}/image/book/{{cartItem.book.id}}.png" style="width:70px;" /></a>
</div>
<div class="col-xs-6">
<a class="pointer" (click)="onSelect(cartItem.book)"><h4>
{{cartItem.book.title}}</h4></a>
<p *ngIf="cartItem.book.inStockNumber > 10" style="color: green;">In Stock</p>
<p *ngIf="cartItem.book.inStockNumber < 10 && cartItem.book.inStockNumber > 0" style="color: green;"> Only <span>{{cartItem.book.inStockNumber}}</span> In Stock
</p>
<p style="color: darkred;" *ngIf="cartItem.book.inStockNumber==0">Product Unavailable</p>
<a class="pointer" (click)="onRemoveCartItem(cartItem)">delete</a>
</div>
<div class="col-xs-2">
<h5 style="color: #db3208; font-size: large;">$<span [ngClass]="{'text-strike': cartItem.book.inStockNumber == 0 }"
<p *ngIf="cartItem.book.inStockNumber > 10" style="color: green;">In Stock</p>
<p *ngIf="cartItem.book.inStockNumber < 10 && cartItem.book.inStockNumber > 0" style="color: green;"> Only <span>{{cartItem.book.inStockNumber}}</span> In Stock
</p>
<p style="color: darkred;" *ngIf="cartItem.book.inStockNumber==0">Product Unavailable</p>
<a class="pointer" (click)="onRemoveCartItem(cartItem)">delete</a>
</div>
<div class="col-xs-2">
<h5 style="color: #db3208; font-size: large;">$<span [ngClass]="{'text-strike': cartItem.book.inStockNumber == 0 }"
>{{cartItem.book.ourPrice}}</span>
</h5>
</div>
<div class="col-xs-2">
<input hidden="hidden" name="id" [(ngModel)]="cartItem.id" />
<input id="cartItem.id" name="qty" [disabled]="cartItem.book.inStockNumber==0" class="form-control cartItemQty" [(ngModel)]="cartItem.qty" />
<button style="display:none;" id="'update-item-'cartItem.id" type="submit" class="btn btn-warning btn-xs">Update
</button>
</div>
</form>
</div>
<div class="col-xs-2">
<input hidden="hidden" name="id" [(ngModel)]="cartItem.id" />
<input id="cartItem.id" name="qty" [disabled]="cartItem.book.inStockNumber==0" class="form-control cartItemQty" [(ngModel)]="cartItem.qty" (ngModelChange)="cartItem.toUpdate=true" />
<a md-button *ngIf="cartItem.toUpdate" class="pointer mat-warn" (click)="onUpdateCartItem(cartItem)">Update</a>
</div>
</div>
<div class="row">
<hr/>

View File

@@ -17,6 +17,7 @@ export class ShoppingCartComponent implements OnInit {
private cartItemList: CartItem[] = [];
private cartItemNumber: number;
private shoppingCart: ShoppingCart = new ShoppingCart();
private cartItemUpdated:boolean;
constructor(private router:Router, private cartService: CartService) { }
@@ -37,6 +38,18 @@ export class ShoppingCartComponent implements OnInit {
);
}
onUpdateCartItem(cartItem:CartItem) {
this.cartService.updateCartItem(cartItem.id, cartItem.qty).subscribe(
res=>{
console.log(res.text());
this.cartItemUpdated=true;
},
error=>{
console.log(error.text());
}
);
}
getCartItemList(){
this.cartService.getCartItemList().subscribe(
res=>{

View File

@@ -10,5 +10,5 @@ export class CartItem {
public book: Book;
public shoppingCart: ShoppingCart;
public order: Order;
public toUpdate:boolean;
}

View File

@@ -37,8 +37,8 @@ export class CartService {
return this.http.get(url, {headers : tokenHeader});
}
updateShoppingCart(cartItemId:number, qty:number) {
let url = AppConst.serverPath+"/cart/removeItem";
updateCartItem(cartItemId:number, qty:number) {
let url = AppConst.serverPath+"/cart/updateCartItem";
let cartItemInfo = {
"cartItemId" : cartItemId,
"qty" : qty