Skip to content

Commit

Permalink
#115 added a cart icon on upper right corner, need to update the cart…
Browse files Browse the repository at this point in the history
… icon number on adding new items on cart
  • Loading branch information
tareq89 committed Aug 20, 2016
1 parent 809a237 commit 14bd49b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/cart/cart-icon/cart-icon.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
i {
color: white;
margin: 0;
}

.quantity-background {
border-radius: 50%;
background-color: red;
float: right;
margin-left: 5px;
width: 20px;
text-align: center;
}
6 changes: 6 additions & 0 deletions app/cart/cart-icon/cart-icon.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div (click)="update()">
<i class="fa fa-shopping-cart fa-lg" aria-hidden="true"></i>
<div class="quantity-background">
<strong>{{numberOfItems}}</strong>
</div>
</div>
35 changes: 35 additions & 0 deletions app/cart/cart-icon/cart-icon.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, OnInit } from '@angular/core';
import { OrderCart } from '../../shared/model/order-cart'

import { Observable } from 'rxjs';


@Component({
selector: 'cart-icon',
templateUrl: 'app/cart/cart-icon/cart-icon.component.html',
styleUrls: ['app/cart/cart-icon/cart-icon.component.css']
})


export class CartIconComponent implements OnInit{
numberOfItems: number = 0;

ngOnInit(){
this.update();
}

public update(){
if(OrderCart.getOrderCart().OrderCart.PackageList){
this.numberOfItems = 0;
OrderCart.getOrderCart().OrderCart.PackageList.forEach(item => {
this.numberOfItems += item.Quantity;
});

if(OrderCart.getOrderCart().Description){
this.numberOfItems += 1;
}
}
}


}
5 changes: 5 additions & 0 deletions app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<li *ngFor="let elm of navBarElementDict[State]">
<a class="pointer" (click)="elm.Event()">{{elm.Title}}</a>
</li>
<li>
<a class="pointer">
<cart-icon></cart-icon>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
Expand Down
3 changes: 2 additions & 1 deletion app/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CollapseDirective } from 'ng2-bootstrap/components/collapse/collapse.di

import { AppSettings } from '../shared/app.settings';
import { SignupComponent } from '../account/signup/signup.component';
import { CartIconComponent } from '../cart/cart-icon/cart-icon.component';
import { LoginComponent, LoginStatus } from '../account/login/login.component';
import { LoginService } from '../account/login/login.service';

Expand All @@ -19,7 +20,7 @@ interface NavbarElement {
@Component({
selector: 'navbar',
templateUrl: 'app/navbar/navbar.component.html',
directives: [ROUTER_DIRECTIVES, CollapseDirective, SignupComponent, LoginComponent],
directives: [ROUTER_DIRECTIVES, CollapseDirective, SignupComponent, LoginComponent, CartIconComponent],
providers: [LocalStorage],
styleUrls: ['app/navbar/navbar.component.css']
})
Expand Down
3 changes: 3 additions & 0 deletions app/vendor-menu/vendor-menu.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
position: relative;
z-index: 2;
}
.vendor-name-div p {
padding-bottom: 100px;
}
.vendor-item-list {
display: block;
width: 100%;
Expand Down
4 changes: 4 additions & 0 deletions app/vendor-menu/vendor-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { VendorDetailsService } from "./vendor-menu.service";
import { OrderModel, PackageListModel } from ".././shared/model/order-model";
import { OrderCart } from '.././shared/model/order-cart';


@Component({
selector: 'vendor-menu',
templateUrl: 'app/vendor-menu/vendor-menu.component.html',
Expand Down Expand Up @@ -61,6 +62,9 @@ export class VendorMenuComponent implements OnInit {
this.selectedItem.Item = item.item;
this.selectedItem.Price = item.price;
this.selectedItem.Quantity = 1;

console.log(OrderCart.getOrderCart().OrderCart.PackageList);

}

addMore(){
Expand Down

0 comments on commit 14bd49b

Please sign in to comment.