Skip to content

Commit

Permalink
Solution for lab #17
Browse files Browse the repository at this point in the history
  • Loading branch information
alcfeoh committed Feb 2, 2018
1 parent ce39f52 commit 3f1c1dd
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
14 changes: 1 addition & 13 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
<app-navigation></app-navigation>

<main role="main">
<app-carousel></app-carousel>

<div class="container">
<div class="row" >
<app-license-plate *ngFor="let plate of licensePlates | async" appHighlight
[plate]="plate" (onAddToCart)="addToCart($event)" buttonText="Add to cart" class="col-md-4">
</app-license-plate>
</div>
</div>
<router-outlet></router-outlet>
</main>

<footer class="container">
<p>&copy; License Plate Store 2017</p>
</footer>

<app-popup-window [isOpen]="showPopup" title="Item added to cart" (onClose)="showPopup = false" >
Thanks for shopping with us!
</app-popup-window>


15 changes: 0 additions & 15 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
import { Component } from '@angular/core';
import {LicensePlate} from './license-plate';
import {LicensePlateService} from './license-plate.service';
import {Observable} from 'rxjs';
import {CartService} from './cart.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {

licensePlates: Observable<LicensePlate[]>;
showPopup = false;

constructor(private service: LicensePlateService, private cartService: CartService) {
this.licensePlates = this.service.getList();
}

addToCart(plate: LicensePlate) {
this.cartService.addToCart(plate)
.subscribe(done => this.showPopup = true);
}
}
5 changes: 3 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { CartService } from './cart.service';
import {CartViewComponent} from './cart-view/cart-view.component';
import {CheckoutFormComponent} from './checkout-form/checkout-form.component';
import {CheckoutViewComponent} from './checkout-view/checkout-view.component';
import { StoreViewComponent } from './store-view/store-view.component';
//import { ReactiveFormsModule } from '@angular/forms';

@NgModule({
Expand All @@ -59,13 +60,13 @@ import {CheckoutViewComponent} from './checkout-view/checkout-view.component';
HighlightDirective,
CurrencyRendererPipe,
CurrencySwitcherComponent,
CartViewComponent, CheckoutFormComponent, CheckoutViewComponent
CartViewComponent, CheckoutFormComponent, CheckoutViewComponent, StoreViewComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
RouterModule , routing
RouterModule, routing
//,ReactiveFormsModule
],
providers: [AuthGuard, LoginService, PostsService, LicensePlateService, CurrencyService, CartService],
Expand Down
12 changes: 10 additions & 2 deletions src/app/app.routing.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import {HelloComponent} from "./hello/hello.component";
import {StoreViewComponent} from './store-view/store-view.component';
import {CartViewComponent} from './cart-view/cart-view.component';
import {CheckoutViewComponent} from './checkout-view/checkout-view.component';

const appRoutes: Routes = [
{
path: '', component: HelloComponent
path: '', component: StoreViewComponent
},
{
path: 'cart', component: CartViewComponent
},
{
path: 'checkout', component: CheckoutViewComponent
}
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
6 changes: 3 additions & 3 deletions src/app/navigation/navigation.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" routerLink="">Home <span class="sr-only">(current)</span></a>
<a class="nav-link" routerLink="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" >My cart <span class="sr-only"></span></a>
<a class="nav-link" routerLink="/cart">My cart <span class="sr-only"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" >Checkout <span class="sr-only"></span></a>
<a class="nav-link" routerLink="/checkout">Checkout <span class="sr-only"></span></a>
</li>

</ul>
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions src/app/store-view/store-view.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<app-carousel></app-carousel>

<div class="container">
<div class="row" >
<app-license-plate *ngFor="let plate of licensePlates | async" appHighlight
[plate]="plate" (onAddToCart)="addToCart($event)" buttonText="Add to cart" class="col-md-4">
</app-license-plate>
</div>
</div>

<app-popup-window [isOpen]="showPopup" title="Item added to cart" (onClose)="showPopup = false" >
Thanks for shopping with us!
</app-popup-window>
25 changes: 25 additions & 0 deletions src/app/store-view/store-view.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';
import {LicensePlate} from '../license-plate';
import {Observable} from 'rxjs/Observable';
import {LicensePlateService} from '../license-plate.service';
import {CartService} from '../cart.service';

@Component({
selector: 'app-store-view',
templateUrl: './store-view.component.html',
styleUrls: ['./store-view.component.css']
})
export class StoreViewComponent {

licensePlates: Observable<LicensePlate[]>;
showPopup = false;

constructor(private service: LicensePlateService, private cartService: CartService) {
this.licensePlates = this.service.getList();
}

addToCart(plate: LicensePlate) {
this.cartService.addToCart(plate)
.subscribe(done => this.showPopup = true);
}
}

0 comments on commit 3f1c1dd

Please sign in to comment.