-
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.
- Loading branch information
1 parent
4696b91
commit c31310e
Showing
7 changed files
with
144 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { Cart } from "./cart.model"; | ||
|
||
@Injectable() | ||
export class Order { | ||
|
||
public id: number; | ||
public name: string; | ||
public address: string; | ||
public city: string; | ||
public state: string; | ||
public zip: string; | ||
public country: string; | ||
public shipped: boolean = false; | ||
|
||
constructor(public cart: Cart) {} | ||
|
||
clear() { | ||
this.id = null; | ||
this.name = this.address = this.city = null; | ||
this.state = this.zip = this.country = null; | ||
this.shipped = false; | ||
this.cart.clear(); | ||
} | ||
|
||
} |
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,20 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { Observable } from "rxjs"; | ||
import { Order } from "./order.model"; | ||
import { StaticDataSource } from "./static.datasource"; | ||
|
||
@Injectable() | ||
export class OrderRepository { | ||
|
||
private orders: Order[] = []; | ||
|
||
constructor(private dataSource: StaticDataSource) {} | ||
|
||
getOrders(): Order[] { | ||
return this.orders; | ||
} | ||
|
||
saveOrder(order: Order): Observable<Order> { | ||
return this.dataSource.saveOrder(order); | ||
} | ||
} |
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,2 @@ | ||
input.ng-dirty.ng-invalid { border: 2px solid #ff0000 } | ||
input.ng-dirty.ng-valid { border:2px solid #6bc502 } |
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,63 @@ | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col bg-dark text-white"> | ||
<a class="navbar-brand">SPORTS STORE</a> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div *ngIf="orderSent" class="m-2 text-center"> | ||
<h2>Thanks!</h2> | ||
<p>Thanks for placing your order.</p> | ||
<p>We'll ship your goods as soon as possible.</p> | ||
<button class="btn btn-primary" routerLink="/store">Return to Store</button> | ||
</div> | ||
|
||
<form *ngIf="!orderSent" #form="ngForm" novalidate (ngSubmit)="submitOrder(form)" class="m-2"> | ||
<div class="form-group"> | ||
<label>Name</label> | ||
<input class="form-control" #name="ngModel" name="name" [(ngModel)]="order.name" required/> | ||
<span *ngIf="submitted && name.invalid" class="text-danger"> | ||
Please enter your name | ||
</span> | ||
</div> | ||
<div class="form-group"> | ||
<label>Address</label> | ||
<input class="form-control" #address="ngModel" name="address" [(ngModel)]="order.address" required/> | ||
<span *ngIf="submitted && address.invalid" class="text-danger"> | ||
Please enter your address | ||
</span> | ||
</div> | ||
<div class="form-group"> | ||
<label>City</label> | ||
<input class="form-control" #city="ngModel" name="city" [(ngModel)]="order.city" required/> | ||
<span *ngIf="submitted && city.invalid" class="text-danger"> | ||
Please enter your city | ||
</span> | ||
</div> | ||
<div class="form-group"> | ||
<label>State</label> | ||
<input class="form-control" #state="ngModel" name="state" [(ngModel)]="order.state" required/> | ||
<span *ngIf="submitted && state.invalid" class="text-danger"> | ||
Please enter your state | ||
</span> | ||
</div> | ||
<div class="form-group"> | ||
<label>Zip/Postal</label> | ||
<input class="form-control" #zip="ngModel" name="zip" [(ngModel)]="order.zip" required/> | ||
<span *ngIf="submitted && zip.invalid" class="text-danger"> | ||
Please enter your zip/postal code | ||
</span> | ||
</div> | ||
<div class="form-group"> | ||
<label>Country</label> | ||
<input class="form-control" #country="ngModel" name="country" [(ngModel)]="order.country" required/> | ||
<span *ngIf="submitted && country.invalid" class="text-danger"> | ||
Please enter your country | ||
</span> | ||
</div> | ||
<div class="text-center"> | ||
<button class="btn btn-secondary m-1" routerLink="/cart">Back</button> | ||
<button class="btn btn-primary m-1" type="submit">Complete Order</button> | ||
</div> | ||
</form> |
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,7 +1,29 @@ | ||
import { Component } from "@angular/core"; | ||
import { NgForm } from "@angular/forms"; | ||
import { OrderRepository } from "../model/order.repository"; | ||
import { Order } from "../model/order.model"; | ||
|
||
@Component({ | ||
template:`<div><h3 class="bg-info p-1 text-white">Checkout Component</h3></div>` | ||
templateUrl:"checkout.component.html", | ||
styleUrls: ["checkout.component.css"] | ||
}) | ||
|
||
export class CheckoutComponent {} | ||
export class CheckoutComponent { | ||
|
||
orderSent: boolean = false; | ||
submitted: boolean = false; | ||
|
||
constructor(public repository: OrderRepository, public order: Order) {} | ||
|
||
submitOrder(form: NgForm) { | ||
this.submitted = true; | ||
if (form.valid) { | ||
this.repository.saveOrder(this.order).subscribe(order => { | ||
this.order.clear(); | ||
this.orderSent = true; | ||
this.submitted = false; | ||
}); | ||
} | ||
} | ||
|
||
} |