-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Popovkov57/development
Development
- Loading branch information
Showing
10 changed files
with
151 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { StoreModule } from './store/store.module'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { StoreModule } from './store/store.module'; | ||
import { StoreComponent } from './store/store.component'; | ||
import { CheckoutComponent } from './store/checkout.component'; | ||
import { CartDetailComponent } from './store/cartDetail.component'; | ||
import { RouterModule } from '@angular/router'; | ||
import { StoreFirstGuard } from './storeFirst.guard'; | ||
|
||
@NgModule({ | ||
imports: [BrowserModule, StoreModule, | ||
RouterModule.forRoot([ | ||
{ | ||
path: "store", component: StoreComponent, | ||
canActivate: [StoreFirstGuard] | ||
}, | ||
{ | ||
path: "cart", component: CartDetailComponent, | ||
canActivate: [StoreFirstGuard] | ||
}, | ||
{ | ||
path: "checkout", component: CheckoutComponent, | ||
canActivate: [StoreFirstGuard] | ||
}, | ||
{ path: "**", redirectTo: "/store" } | ||
])], | ||
providers: [StoreFirstGuard], | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, StoreModule | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col bg-dark text-white"> | ||
<a class="navbar-brand">SPORTS STORE</a> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col mt-2"> | ||
<h2 class="text-center">Your Cart</h2> | ||
<table class="table table-bordered table-striped p-2"> | ||
<thead> | ||
<tr> | ||
<th>Quantity</th> | ||
<th>Product</th> | ||
<th class="text-right">Price</th> | ||
<th class="text-right">Subtotal</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngIf="cart.lines.length == 0"> | ||
<td colspan="4" class="text-center"> | ||
Your cart is empty | ||
</td> | ||
</tr> | ||
<tr *ngFor="let line of cart.lines"> | ||
<td> | ||
<input type="number" | ||
class="form-control-sm" | ||
style="width: 5em;" | ||
[value]="line.quantity" | ||
(change)="cart.updateQuantity(line.product, $event.target.value)"/> | ||
</td> | ||
<td>{{ line.product.name }}</td> | ||
<td class="text-right"> | ||
{{ line.product.price | currency:"USD":true:"2.2-2" }} | ||
</td> | ||
<td class="text-right"> | ||
{{ line.lineTotal | currency:"USD":true:"2.2-2" }} | ||
</td> | ||
<td class="text-center"> | ||
<button class="btn btn-sm btn-danger" (click)="cart.removeLine(line.product.id)"> | ||
Remove | ||
</button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td colspan="3" class="text-right">Total:</td> | ||
<td class="text-right"> | ||
{{ cart.cartPrice | currency:"USD":true:"2.2-2" }} | ||
</td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col"> | ||
<div class="text-center"> | ||
<button class="btn btn-primary m-1" routerLink="/store"> | ||
Continue Shopping | ||
</button> | ||
<button class="btn btn-secondary m-1" routerLink="/checkout" [disabled]="cart.lines.length == 0"> | ||
Checkout | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component } from "@angular/core"; | ||
import { Cart } from "../model/cart.model"; | ||
|
||
@Component({ | ||
templateUrl: "cartDetail.component.html" | ||
}) | ||
|
||
export class CartDetailComponent { | ||
|
||
constructor(public cart: Cart) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Component } from "@angular/core"; | ||
|
||
@Component({ | ||
template:`<div><h3 class="bg-info p-1 text-white">Checkout Component</h3></div>` | ||
}) | ||
|
||
export class CheckoutComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { ActivatedRouteSnapshot, RouterStateSnapshot, Router } from "@angular/router"; | ||
import { StoreComponent } from "./store/store.component"; | ||
|
||
@Injectable() | ||
export class StoreFirstGuard { | ||
private firstNavigation = true; | ||
|
||
constructor(private router: Router) {} | ||
|
||
canActivate(route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): boolean { | ||
if (this.firstNavigation) { | ||
this.firstNavigation = false; | ||
if (route.component != StoreComponent) { | ||
this.router.navigateByUrl("/"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |