Commit 50a63b7f authored by prumde's avatar prumde

Updated


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@174439 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6083ffad
import { Component } from '@angular/core';
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
import { EcmCartService } from './ecm-view/ecm-cart/ecm-cart.service';
@Component({
selector: 'ecm-root',
......@@ -10,7 +11,7 @@ import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common'
export class AppComponent {
title = 'Proteus ECM';
location: Location;
constructor(location: Location) {
constructor(location: Location, public cartService: EcmCartService) {
this.location = location;
console.log( ' this.location.path(true)[' + this.location.path(true) + ']');
this.checkAppState();
......@@ -19,6 +20,8 @@ export class AppComponent {
this.setItem('jwtToken', this.get('jwtToken'), false );
this.setItem('appstate', this.get('app_stat'), true );
this.setItem('TOKEN_ID', this.get('TOKEN_ID'), true );
this.cartService.setCartItems();
}
get(name){
var retVal = 'undefined';
......
......@@ -6,7 +6,7 @@ import { HttpModule } from '@angular/http';
import { RouterModule, Routes } from '@angular/router';
//import { JwtHelper } from 'angular2-jwt'; //For Future
import {CATEGORY,SUBCATEGORY,ITEM,ECM_LOCATION,CART_COUNTER} from './ecm-store/ecm-store';
import {CATEGORY,SUBCATEGORY,ITEM,ECM_LOCATION, CART_ITEMS} from './ecm-store/ecm-store';
import {StoreModule} from '@ngrx/store';
import { MaterialModule } from '@angular/material';
......@@ -110,7 +110,7 @@ const appRoutes: Routes = [
HttpModule,
RouterModule.forRoot(appRoutes),
ReactiveFormsModule,
StoreModule.provideStore({CATEGORY,SUBCATEGORY,ITEM, location: ECM_LOCATION, counter: CART_COUNTER}),
StoreModule.provideStore({CATEGORY,SUBCATEGORY,ITEM, location: ECM_LOCATION, cart: CART_ITEMS}),
MaterialModule,
BrowserAnimationsModule
],
......
......@@ -9,7 +9,7 @@
<!-- Overlay End -->
<!-- SlidePanel Start -->
<div #rightSlidePanel class="rightSlidePanel" [ngClass]="{'width-300': ( sideOption=='CART_OPT' && cartItems == 0 ) }" >
<div #rightSlidePanel class="rightSlidePanel" [ngClass]="{'width-300': ( sideOption=='CART_OPT' && (cartItems | async)?.length == 0 ) }" >
<span (click)="hideSidePanel();" class="hide-button"></span>
<ecm-user-option *ngIf="sideOption=='USER_OPT'" (closePanel)="hideSidePanel(); createUserData();" (updateProfileImages) = "updateProfileImages();" ></ecm-user-option>
<div *ngIf="sideOption=='CART_OPT'" style="margin: 3rem;" >
......@@ -58,7 +58,7 @@
<ecm-search [compFadeState]="headerFadeState" [headerState]="'fixed'"></ecm-search>
<span [ngClass]="{'cart-span': sideOption=='CART_OPT'}" (click)="cartAction();" >
<button md-button class="square-button">
<span *ngIf="cartItems > 0" class="fixed-header-badge">{{ cartCounter | async }}</span>
<span *ngIf="(cartItems | async)?.length!=0" class="fixed-header-badge">{{(cartItems | async)?.length}}</span>
<img mdTooltip="Show Cart" [mdTooltipPosition]="'below'" class="fixed-header-cart img-cart-32" src="cart_32_32.svg"/>
<!-- <img *ngIf="cartItems == 0" class="fixed-header-cart img-cart-32 no-badge" /> -->
<!--<md-icon class="example-icon">shopping_cart</md-icon>-->
......@@ -86,7 +86,7 @@
</span>
<span [ngClass]="{'cart-span': sideOption=='CART_OPT'}" (click)="cartAction();" >
<button md-button class="square-button">
<span *ngIf="cartItems > 0" class="fixed-header-badge">{{ cartCounter | async }}</span>
<span *ngIf="cartCounter > 0" class="fixed-header-badge">{{ cartCounter }}</span>
<img mdTooltip="Show Cart" [mdTooltipPosition]="'below'" class="fixed-header-cart img-cart-32" src="cart_32_32.svg"/>
<!-- <img *ngIf="cartItems == 0" class="fixed-header-cart img-cart-32 no-badge" /> -->
<!--<md-icon class="example-icon">shopping_cart</md-icon>-->
......
import { Component, Input, Output, Inject, OnInit, OnDestroy, AfterViewChecked, ViewEncapsulation, HostListener, ElementRef, ViewChild, trigger, state, animate, transition, style } from '@angular/core';
import { Component, Input, Output, Inject, OnInit, OnDestroy, ViewEncapsulation, HostListener, ElementRef, ViewChild, trigger, state, animate, transition, style } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { ActivatedRoute, Router,ActivatedRouteSnapshot,RoutesRecognized } from '@angular/router';
import { MdDialog, MdDialogRef } from '@angular/material';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import { Item } from '../ecm-model/product-model';
import { EcmStoreModel } from '../ecm-store/ecm-store.model';
import { RESIZE_EVENT } from '../ecm-store/ecm-resize';
import { ScrollService } from '../scroll.service';
import { EcmCartService } from '../ecm-view/ecm-cart/ecm-cart.service';
import 'rxjs/add/operator/filter';
//declare var initSearch: any;
......@@ -78,7 +79,7 @@ declare var enableScroll: any;
]
})
export class ECMHeaderComponent implements OnInit, OnDestroy, AfterViewChecked {
export class ECMHeaderComponent implements OnInit, OnDestroy {
@ViewChild( 'rightSlidePanel' ) rightSlidePanel: ElementRef;
@ViewChild( 'overlayPanel' ) overlayPanel: ElementRef;
......@@ -92,11 +93,11 @@ export class ECMHeaderComponent implements OnInit, OnDestroy, AfterViewChecked {
selectedOption: string;
userData: any;
sideOption: any;
cartItems = 0;
cartCounter : Observable<number>;
cartItems: Observable<Item>;
cartCounter: number;
profileImageLink : string;
clientWidth: any;
constructor( @Inject( DOCUMENT ) private document: Document, private route: ActivatedRoute, private router: Router, private scroll_service: ScrollService, private store: Store<EcmStoreModel>, public dialog: MdDialog) { }
constructor( @Inject( DOCUMENT ) private document: Document, private route: ActivatedRoute, private router: Router, private scroll_service: ScrollService, private store: Store<EcmStoreModel>, public dialog: MdDialog, public cartService: EcmCartService) { }
ngOnInit() {
console.log( 'ECMHeaderComponent onInit' );
......@@ -105,6 +106,8 @@ export class ECMHeaderComponent implements OnInit, OnDestroy, AfterViewChecked {
RESIZE_EVENT.subscribe(data => {
this.clientWidth = data;
});
this.cartItems = this.store.select('cart');
}
ngOnDestroy() {
......@@ -173,16 +176,7 @@ export class ECMHeaderComponent implements OnInit, OnDestroy, AfterViewChecked {
//Removed Collapsible Search
//initSearch();
}
ngAfterViewChecked() {
this.cartCounter = this.store.select('counter');
this.cartCounter.subscribe( count => {
this.cartItems = count;
//console.log('>>>count ::' + count);
});
//console.log('this.cartItems ::' + this.cartItems);
}
userAction() {
if( this.userData ){
this.showSidePanel('USER_OPT');
......
......@@ -4,7 +4,7 @@
*/
export class Item {
public itemCode: string = '';
public descr: string = '';
public item_descr: string = '';
public shDescr: string = '';
public costRate: string;
public rating: number;
......@@ -13,5 +13,19 @@ export class Item {
public scat_descr: string = '';
public cat_sh_descr: string = '';
public cat_descr: string = '';
public length: number;
public width: number;
public height: number;
public gross_weight: number;
public product_code: string = "";
public price_list: string = "";
public item_type: string = "";
public phyAttribId1: string = "";
public phyAttribId2: string = "";
public phyAttribId3: string = "";
public phyAttribId4: string = "";
public phyAttribId5: string = "";
public phyAttribId6: string = "";
public descr: string = "";
}
......@@ -4,7 +4,7 @@ import { MdSnackBar } from '@angular/material';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../ecm-store/ecm-store.model';
import { INCREMENT, DECREMENT, RESET } from '../ecm-store/ecm-store';
import { UPDATE_QUANTITY, ADD_TO_CART, REMOVE } from '../ecm-store/ecm-store';
import { EcmProductDetailService } from './ecm-product-detail.service';
import { ScrollService } from '../scroll.service';
......@@ -18,6 +18,7 @@ import { EcmHandicraftComponent } from './ecm-template/ecm-handicraft.component'
import { EcmProductReviewComponent } from './ecm-product-review.component';
import { EcmRelatedItemsComponent } from '../ecm-view/ecm-related-items/ecm-related-items.component';
import { ECMCart } from '../ecm-model/cart-model';
import { Item } from '../ecm-model/product-model';
import { ECMHeaderComponent } from '../ecm-header/ecm-header.component';
export const ECM_TEMPLATES: any = {
......@@ -44,7 +45,7 @@ export class EcmProductDetailsComponent implements OnInit {
scatCode;
noOfReviews;
constructor(private route: ActivatedRoute, private router:Router, public subcategoryService: EcmProductDetailService, public snackBar: MdSnackBar, private store: Store<EcmStoreModel>) { }
constructor(private route: ActivatedRoute, private router:Router, public productDetailService: EcmProductDetailService, public snackBar: MdSnackBar, private store: Store<EcmStoreModel>) { }
ngOnInit() {
this.route.params.subscribe( params => {
......@@ -58,7 +59,7 @@ export class EcmProductDetailsComponent implements OnInit {
}
getItemDetail( itemCode: string ) {
this.subcategoryService.getItemDetail( itemCode ).subscribe(
this.productDetailService.getItemDetail( itemCode ).subscribe(
itemDetail => {
if( itemDetail ) console.log( 'comp itemCode[' + itemCode + '] itemDetail[' + itemDetail + '] \n this.itemDetail[' + JSON.stringify( itemDetail ) + ']' );
......@@ -102,7 +103,7 @@ export class EcmProductDetailsComponent implements OnInit {
console.log( 'doActivity > > ' , activity, data );
if( activity == 'ADD_CART' ) {
if( data.isAddToCart ) { //GO TO CART
this.router.navigate(['/checkout']);
this.router.navigate(['/cart']);
}
else { //ADD TO CART
this.addToCart(data.itemCode);
......@@ -128,13 +129,24 @@ export class EcmProductDetailsComponent implements OnInit {
}
addToCart(data:any) {
let cartData = new ECMCart;
let cartData = new Item;
cartData.itemCode = data;
cartData.quantity = 1;
cartData.itemCost = this.itemDetail.itemHeader.itemCostRate;
cartData.itemQuantity = 1;
cartData.costRate = this.itemDetail.itemHeader.itemCostRate;
cartData.descr = this.itemDetail.itemHeader.itemDescr;
cartData.shDescr = this.itemDetail.itemHeader.itemShDescr;
this.store.dispatch({ type: INCREMENT, payload: cartData });
this.subcategoryService.addToCart(cartData);
this.store.dispatch({ type: ADD_TO_CART, payload: cartData });
this.productDetailService.addToCart(cartData);
let cartItems;
this.store.select('cart').forEach(
value => {
cartItems=value;
console.log('Cart Items----');
console.log(value);
}
);
}
addToWishlist() {
......
......@@ -303,7 +303,7 @@ hr {
}
.selected {
box-shadow: inset 0 0 1px 1px mediumvioletred;
box-shadow: 0 0 1px 1px mediumvioletred;
cursor: auto;
}
......@@ -393,12 +393,14 @@ hr {
.item-shdescr {
display: block;
color: mediumvioletred;
font-size: 14px;
font-weight: bold;
padding-bottom: 8px;
padding-top: 28px;
cursor: pointer;
}
.subcat-link {
color: mediumvioletred;
}
.item-descount-rate {
......
......@@ -17,7 +17,11 @@
<i _ngcontent-c30="" class="material-icons share-icon">&#xE80D;</i>
<span _ngcontent-c30="" class="share">Share</span>
</div>
<a [routerLink]="['/products', itemDetail.itemSubCategory.scatCode]" class="item-shdescr"> {{itemDetail.itemSubCategory.shDescr}} </a>
<span class="item-shdescr">
<a [routerLink]="['/products', itemDetail.itemSubCategory.scatCode]" class="subcat-link">
{{itemDetail.itemSubCategory.shDescr}}
</a>
</span>
<span class="item-descr"> {{itemDetail.itemHeader.itemDescr}} </span>
......
......@@ -78,6 +78,7 @@
background-position: 15px 10px;
background-size: 24px 24px;
font-size: 10pt;
color: black;
}
.search-which {
margin: 0;
......
......@@ -56,7 +56,7 @@ export class ECMSearchComponent implements OnInit {
console.log("Selected Value[" +val+ "]");
let trimmedVal = val.trim().replace(/<\/?[^>]+(>|$)/g, "");
if(trimmedVal)
if(trimmedVal.length > 2)
{
this.search_service.getSuggestions(trimmedVal).subscribe(data => {
this.filteredOptions = data;
......
......@@ -4,11 +4,11 @@ import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../ecm-store/ecm-store.model';
import { RESET } from '../ecm-store/ecm-store';
import { ECMSigninService } from './ecm-signin.service';
import { EcmCartService } from '../ecm-view/ecm-cart/ecm-cart.service';
declare var encPwd: any;
......@@ -30,7 +30,7 @@ export class EcmSigninComponent implements OnInit {
loginErrorMsg: string;
@Output() closePanel = new EventEmitter();
constructor(public signinService: ECMSigninService, private store: Store<EcmStoreModel>) { }
constructor(public signinService: ECMSigninService, private store: Store<EcmStoreModel>, public cartService: EcmCartService) { }
ngOnInit() {
}
......@@ -77,14 +77,17 @@ export class EcmSigninComponent implements OnInit {
this.userData.jti = this._username;
this.store.dispatch({ type: RESET });
//Fetch User Data and Store in cache
this.signinService.fetchUserData().subscribe(
response => {
console.log('response[' + response + ']');
if(response)
this.cartService.setCartItems();
});
console.log( 'comp Object.keys(this.userData) [' + Object.keys(this.userData) + ']' );
localStorage.setItem('userInfo', JSON.stringify( this.userData ) );
localStorage.setItem('userInfo', JSON.stringify( this.userData ) );
}
this.closePanel.emit();
}
......
......@@ -8,4 +8,5 @@ export class EcmStoreModel {
ITEM: Item;
ECM_LOCATION: EcmLocation;
CART_COUNTER: number;
CART_ITEMS: Item;
};
import { ActionReducer, Action } from '@ngrx/store';
import { ECMCart } from '../ecm-model/cart-model';
import { Item } from '../ecm-model/product-model';
export function CATEGORY (state: any = null, {type, payload}) {
switch (type) {
......@@ -40,6 +41,41 @@ export function ITEM (state: any = null, {type, payload}) {
}
};
export const ADD_TO_CART = 'ADD_TO_CART';
export const UPDATE_QUANTITY = 'UPDATE_QUANTITY';
export const REMOVE = 'REMOVE';
export const RESET = 'RESET';
export function CART_ITEMS (state:any = [], action: Action) {
switch (action.type) {
case ADD_TO_CART:
const item:Item = action.payload;
return [ ...state, item ];
case UPDATE_QUANTITY:
return state.map((item, index) => {
return index === action.payload.index
? Object.assign({}, item, { value: action.payload.newValue })
: item;
});
case REMOVE:
console.log('Delete--');
console.log(JSON.stringify(action.payload));
return state.filter(item => {
return item.itemCode !== action.payload.itemCode;
});
case RESET:
console.log('RESET----');
return state=[];
default:
return state;
}
};
export function ECM_LOCATION (state: any = null, {type, payload}) {
switch (type) {
case 'ECMLOCATION':
......@@ -52,85 +88,3 @@ export function ECM_LOCATION (state: any = null, {type, payload}) {
return state;
}
};
export const INCREMENT = 'INCREMENT';
export const DECREMENT = 'DECREMENT';
export const RESET = 'RESET';
export const REMOVE = 'REMOVE';
const cartInitState = {
cartItems : []
}
export function CART_COUNTER(state: any = cartInitState, action: Action) {
console.log('payload >>' + action.payload);
console.log('cartCount >> ' + cartInitState.cartItems.length);
console.log('cartItems >> ' + cartInitState.cartItems);
let payloadExist = false;
let payloadIdx = -1;
if(action.payload)
cartInitState.cartItems.forEach(check);
function check(item, index)
{
if(item.itemCode == action.payload.itemCode)
{
payloadExist = true;
payloadIdx = index;
}
}
//let payloadIdx = cartInitState.cartItems.indexOf(action.payload);
//let payloadExist = ( payloadIdx > -1 ) ? true : false;
console.log('indexOf payload >>' + payloadExist + 'payloadIdx:' +payloadIdx);
switch (action.type) {
case INCREMENT:
if( ! payloadExist )
{
//cartInitState.cartItems.pop()
cartInitState.cartItems.push(action.payload);
console.log('cartItems after Push>> ' + cartInitState.cartItems);
}
else if(payloadExist)
{
cartInitState.cartItems[payloadIdx].quantity++;
console.log('Quantity = '+ cartInitState.cartItems[payloadIdx].quantity);
}
return cartInitState.cartItems.length;
case DECREMENT:
if( payloadExist )
{
cartInitState.cartItems[payloadIdx].quantity--;
console.log('Quantity = '+ cartInitState.cartItems[payloadIdx].quantity);
//let removed = cartInitState.cartItems.splice(payloadIdx)
//console.log('cartItems after splice >>' + removed + '>> ' + cartInitState.cartItems);
}
return cartInitState.cartItems.length;
case REMOVE:
if( payloadExist )
{
let i ;
for( i = cartInitState.cartItems.length - 1; i >= 0; i--)
{
if( cartInitState.cartItems[i].itemCode == action.payload.itemCode)
{
cartInitState.cartItems.splice(i,1);
}
}
}
return cartInitState.cartItems.length;
case RESET:
return 0;
default:
return cartInitState.cartItems.length;
}
};
import { Component, OnInit, Input, Output, EventEmitter, ViewEncapsulation } from '@angular/core';
import { ECMSigninService } from '../ecm-signin/ecm-signin.service';
import { EcmCartService } from '../ecm-view/ecm-cart/ecm-cart.service';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../ecm-store/ecm-store.model';
import { RESET } from '../ecm-store/ecm-store';
declare var getContentPlugin: any;
......@@ -20,7 +25,7 @@ export class EcmUserOptionComponent implements OnInit {
userData: any;
//profileImageLink : string;
constructor( public signinService: ECMSigninService ) { }
constructor( public signinService: ECMSigninService, private store: Store<EcmStoreModel>, public cartService: EcmCartService ) { }
ngOnInit() {
var userInfo = localStorage.getItem( 'userInfo' );
......@@ -77,13 +82,18 @@ export class EcmUserOptionComponent implements OnInit {
logout() {
localStorage.removeItem( 'userInfo' );
this.store.dispatch({ type: RESET });
this.signinService.sendLogout( this.userData.jti, this.userData.TOKEN_ID ).subscribe(
result => {
console.log( 'comp result.results.indexOf [' + result.Response.results.indexOf( '{' ) + ']' );
if ( result.Response.status == 'success' ) {
console.log( 'Logging Out' );
this.userData = null;
localStorage.removeItem( 'userInfo' );
this.store.dispatch({ type: RESET });
this.cartService.setCartItems();
}
else if ( result.Response.status == 'error' ) {
this.userData = null;
......@@ -94,6 +104,8 @@ export class EcmUserOptionComponent implements OnInit {
console.log( 'comp errorMessage[' + errorMessage + ']' );
}
);
this.cartService.setCartItems();
}
}
......@@ -2,7 +2,7 @@
<div *ngIf="isMiniCart then miniCart; else fullCart;"></div>
<ng-template #miniCart>
<div *ngIf="cartCount == 0" style="text-align: center;">
<div *ngIf="(cartItems | async)?.length == 0" style="text-align: center;">
<img class="empty-cart-img" src="/ecm/assets/images/svg/Empty Cart.svg">
<span class="empty-cart-title">Empty Cart</span> <span
class="border-line"></span> <span class="empty-cart-msg">Looks
......@@ -35,16 +35,16 @@
<i class="material-icons" style="position: relative; left: 8px;">trending_flat</i>
</button>
</div> -->
<div class="scrollMe" #scrollMe *ngIf="cartCount > 0">
<div class="scrollMe" #scrollMe *ngIf="(cartItems | async)?.length > 0">
<div class="cartItemsDetail"
*ngFor="let item of cartItemsDetail">
*ngFor="let item of cartItems | async">
<table style="width: 100%;">
<tr>
<td class="itemImage"><ecm-image [refId]='item.itemCode'
[refSer]="'M-ITEM'" [object]="'ITEM'" [isSingleImage]="true"
[isThumbnail]="true"></ecm-image></td>
<td class="itemdescription" (click)="closePanel.emit(viewItem(item.itemCode))">
<span class="item-descr-span">{{item.descr}}</span>
<span class="item-descr-span">{{item.shDescr}}</span>
</td>
<td style="padding: 10px;">Rs. {{item.costRate}}</td>
<td (click)="confirmDialog(item)" style="cursor: pointer;"><span
......@@ -53,7 +53,7 @@
</table>
</div>
</div>
<div *ngIf="cartCount > displayItem" (click)="showTotalCartItems()">
<div *ngIf="(cartItems | async)?.length > displayItem" (click)="showTotalCartItems()">
<a md-button class="edit-cart-button" [routerLink]="['/cart']"
(click)="closePanel.emit();">Edit Cart</a>
</div>
......@@ -63,7 +63,7 @@
<!-- ---------================ detailCart start==============================---------------------------- -->
<ng-template #fullCart>
<div *ngIf="cartCount == 0">
<div *ngIf="(cartItems | async)?.length == 0">
<ecm-header [isFixedHeader]=false> </ecm-header>
<ecm-breadcrumbs [pageName]="'CART'"></ecm-breadcrumbs>
<div class="row">
......@@ -78,16 +78,16 @@
<ecm-footer></ecm-footer>
</div>
</div>
<div *ngIf="cartCount > 0 && cartItemsDetail">
<div *ngIf="(cartItems | async)?.length > 0">
<ecm-header [isFixedHeader]=false> </ecm-header>
<ecm-breadcrumbs [pageName]="'CART'"></ecm-breadcrumbs>
<div class="row details-of-Cart">
<md-card class="medium-8 columns cartItemsDetails">
<div class="ecmdetailsItems">
<div class="ecm-headings">
<span class="my-cart-title">({{cartCount}}) My Cart</span>
<span class="my-cart-title">( {{(cartItems | async)?.length}} ) My Cart</span>
</div>
<div class="listItems" *ngFor="let item of cartItemsDetail">
<div class="listItems" *ngFor="let item of cartItems | async">
<div class="item-image">
<ecm-image [refId]='item.itemCode' [refSer]="'M-ITEM'"
......@@ -199,7 +199,7 @@
</div>
<div class="totalProductsInfo">
<div class="priceItems">
<span style="font-size: 15px;">Price ( {{cartCount}} Items )</span>
<span style="font-size: 15px;">Price ( {{(cartItems | async)?.length}} Items )</span>
<span class="price-info">Rs. {{totalPrice}}</span>
</div>
<br>
......
......@@ -4,12 +4,12 @@ import { MdSnackBar } from '@angular/material';
import { MdDialog, MdDialogRef } from '@angular/material';
import { ItemDetail } from '../../ecm-model/product-detail-model';
import { EcmCategoryComponent } from '../ecm-category/ecm-category.component';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../../ecm-store/ecm-store.model';
import { INCREMENT, DECREMENT, REMOVE, RESET } from '../../ecm-store/ecm-store';
import { UPDATE_QUANTITY, REMOVE } from '../../ecm-store/ecm-store';
import { Item } from '../../ecm-model/product-model';
import { EcmCartService } from './ecm-cart.service';
......@@ -30,17 +30,17 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
catCode;
displayItem = 3;
totalPrice: number = 0;
cartItems : Observable<Item[]>;
disableScrollDown = false
@Input() isMiniCart: boolean = false;
@Output() closePanel = new EventEmitter();
@Output() doActivity = new EventEmitter();
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
constructor( private route: ActivatedRoute, public dialog: MdDialog, private router: Router,public subcategoryService: EcmProductDetailService, public cartService: EcmCartService, public snackBar: MdSnackBar, private http: Http, private store: Store<EcmStoreModel> ) { }
constructor( private route: ActivatedRoute, public dialog: MdDialog, private router: Router,public productDetailService: EcmProductDetailService, public cartService: EcmCartService, public snackBar: MdSnackBar, private http: Http, private store: Store<EcmStoreModel> ) { }
ngOnInit() {
this.getCartItem();
......@@ -52,96 +52,66 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
}
getCartItem() {
this.cartService.getCartItems().subscribe(
cartItemsDetail => {
this.cartItemsDetail = cartItemsDetail;
if( this.cartItemsDetail && this.cartItemsDetail.length)
{
this.cartCount = this.cartItemsDetail.length ;
console.log( 'comp cartItemsDetail[' + this.cartItemsDetail + '] \n this.cartItemsDetail[' + this.cartItemsDetail.length + ']' );
if ( this.cartItemsDetail ) {
this.getTotalPrice();
console.log( "the total Price is" + this.totalPrice );
this.cartItems = this.store.select('cart');
this.cartItems.subscribe( cartItems => {
this.totalPrice = 0;
cartItems.forEach(
item => {
this.totalPrice = this.totalPrice + (parseFloat( item.costRate ) * item.itemQuantity);
}
}
else
{
this.cartCount = 0;
}
},
error => {
this.cartCount = 0;
let errorMessage = <any>error;
console.log( 'comp errorMessage[' + errorMessage + ']' );
});
);
});
}
userActionUrl = '/ecm/service/feeds/cart';
deleteCartItem( itemCode ) {
deleteCartItem( item ) {
console.log( "deleteCartItem Called" );
this.http.delete( this.userActionUrl + '/' + itemCode, {})
this.store.dispatch({ type: REMOVE, payload: item });
this.http.delete( this.userActionUrl + '/' + item.itemCode, {})
.subscribe( data => {
console.log( "deleted item in Cart" );
}, error => {
console.log( error.json() );
});
this.getCartItem();
this.decreasePrice();
let cartData = new ECMCart;
cartData.itemCode = itemCode;
this.store.dispatch({ type: REMOVE, payload: cartData });
this.openSnackBar('Item Removed from your Cart' );
}
showTotalCartItems() {
this.getTotalPrice();
this.router.navigate( ['/cart'] );
}
getTotalPrice() {
this.cartItemsDetail.forEach(( item, i ) => {
item.itemQuantity = 1;
this.totalPrice = this.totalPrice + parseFloat( item.costRate ) ;
// this.totalPrice = this.totalPrice + item.totalAmount ;
});
}
decreasePrice() {
this.cartItemsDetail.forEach(( item, i ) => {
this.totalPrice = this.totalPrice - parseFloat( item.costRate );
});
}
increment(item : Item) {
item.itemQuantity++;
this.addToCart(item);
}
addToCart(data : Item) {
let cartData = new ECMCart;
let cartData = new Item;
cartData.itemCode = data.itemCode;
cartData.quantity = data.itemQuantity;
cartData.itemCost = parseFloat( data.costRate );
// cartData.totalAmount = (cartData.quantity)* (cartData.itemCost);
cartData.itemQuantity = data.itemQuantity;
cartData.costRate = data.costRate;
this.store.dispatch({ type: INCREMENT, payload: cartData });
this.subcategoryService.addToCart(cartData);
this.store.dispatch({ type: 'UPDATE_QUANTITY', payload: cartData });
this.productDetailService.addToCart(cartData);
this.openSnackBar( data.shDescr + ' Added to your Cart ' );
}
decrement(data : Item) {
data.itemQuantity--;
let cartData = new ECMCart;
let cartData = new Item;
cartData.itemCode = data.itemCode;
this.store.dispatch({ type: DECREMENT, payload: cartData });
this.store.dispatch({ type: 'UPDATE_QUANTITY', payload: cartData });
this.openSnackBar( data.shDescr + ' Removed from your Cart' );
}
checkQantity(item)
{
checkQantity(item) {
if (item.itemQuantity == 1)
return true;
else
......@@ -152,7 +122,6 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
this.openSnackBar('Item Added to your Wishlist' );
}
openSnackBar( message: string ) {
this.snackBar.open( message, '', {
duration: 2000,
......@@ -173,7 +142,7 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
dialogRef.afterClosed().subscribe( result => {
if( result == 'true')
{
this.deleteCartItem(item.itemCode);
this.deleteCartItem(item);
}
});
}
......@@ -189,7 +158,6 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
}
@Component( {
selector: 'ecm-confirm-dialog',
templateUrl: 'ecm-confirm-dialog.html',
......
......@@ -4,17 +4,46 @@ import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Item } from '../../ecm-model/product-model';
import { Store } from '@ngrx/store';
import { ADD_TO_CART } from '../../ecm-store/ecm-store';
import { EcmStoreModel } from '../../ecm-store/ecm-store.model';
@Injectable()
export class EcmCartService {
private userActionUrl = '/ecm/service/feeds/cart';
public itemCode;
cartItems: Item[];
constructor(private http: Http) { }
constructor(private http: Http, private store: Store<EcmStoreModel>) { }
getCartItems() {
let cartItems;
this.store.select('cart').forEach(
value => {
cartItems=value;
}
);
return cartItems;
}
setCartItems(){
this.fetchCartItems().subscribe(
data => {
this.cartItems = data;
if ( data && data != null ) {
this.cartItems.forEach( item => {
this.store.dispatch({ type: ADD_TO_CART, payload: item });
})
}
});
}
getCartItems(): Observable<Item[]> {
fetchCartItems(): Observable<Item[]> {
let headers = new Headers( { 'Content-Type': 'application/json' });
let options = new RequestOptions( { headers: headers });
......
......@@ -162,14 +162,14 @@
</div>
<div *ngIf="cartItemsDetail" class="medium-5 columns">
<div *ngIf="(cartItems | async)?.length > 0" class="medium-5 columns">
<md-card>
<div class="orderSummary">
<table>
<tr>
<th class="order-summary-title">Order Summary</th>
</tr>
<tr *ngFor="let item of cartItemsDetail">
<tr *ngFor="let item of cartItems | async">
<td class="item-name">{{item.shDescr}}</td>
<td class="item-cost">Rs. {{item.costRate}}</td>
</tr>
......
......@@ -2,6 +2,9 @@ import { Component, OnInit, ViewChild, ElementRef, Input, Output, EventEmitter }
import { FormBuilder, Validators,NgForm } from '@angular/forms';
import { EcmCartService } from '../ecm-cart/ecm-cart.service';
import { Item } from '../../ecm-model/product-model';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../../ecm-store/ecm-store.model';
@Component( {
selector: 'ecm-checkout',
......@@ -19,8 +22,9 @@ export class EcmCheckoutComponent implements OnInit {
countries;
months;
years;
constructor(private formBuilder: FormBuilder, public cartService: EcmCartService) {
cartItems: Observable<Item[]>;
constructor(private formBuilder: FormBuilder, public cartService: EcmCartService, private store: Store<EcmStoreModel>) {
this.countries = [
{ viewValue: 'India' },
{ viewValue: 'UAE' },
......@@ -61,25 +65,15 @@ export class EcmCheckoutComponent implements OnInit {
}
getCartItems() {
this.cartService.getCartItems().subscribe(
cartItemsDetail => {
this.cartItemsDetail = cartItemsDetail;
console.log( 'comp cartItemsDetail[' + JSON.stringify( cartItemsDetail ) + '] \n this.cartItemsDetail[' + this.cartItemsDetail.length + ']' );
if ( this.cartItemsDetail ) {
this.getTotalPrice();
console.log( "the total Price is" + this.totalPrice );
}
},
error => {
let errorMessage = <any>error;
console.log( 'comp errorMessage[' + errorMessage + ']' );
});
}
getTotalPrice() {
this.cartItemsDetail.forEach(( item, i ) => {
this.totalPrice = this.totalPrice + parseFloat( item.costRate );
console.log('Total Price Is'+item.costRate);
this.cartItems = this.store.select('cart');
this.cartItems.subscribe( cartItems => {
this.totalPrice = 0;
cartItems.forEach(
item => {
this.totalPrice = this.totalPrice + (parseFloat( item.costRate ) * item.itemQuantity);
}
);
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment