Commit eca66088 authored by prumde's avatar prumde

Updated


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@174455 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 90154d9b
......@@ -7,7 +7,7 @@ import {AppState} from '../ecm-store/reducers';
import { ECMCard } from '../ecm-model/card-model';
import { Category } from '../ecm-model/category-model';
import { SubCategory } from '../ecm-model/subcategory-model';
import { Item } from '../ecm-model/product-model';
import { ItemDetail } from '../ecm-model/product-detail-model';
import { Reviews } from '../ecm-model/product-review.model';
import { EcmProductReviewService } from '../ecm-product-details/ecm-product-review.service';
......@@ -22,7 +22,7 @@ export class ECMCardComponent implements OnInit {
@Input() card: ECMCard;
@Input() category: Category;
@Input() subcategory: SubCategory;
@Input() itemData: Item;
@Input() itemData: ItemDetail;
@Input() extraParam: any;
@Input() reviewsData: Reviews;
......
......@@ -4,8 +4,8 @@ import { MdSnackBar } from '@angular/material';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import {AppState} from '../ecm-store/reducers';
import {CartActions} from '../ecm-store/actions';
import { AppState } from '../ecm-store/reducers';
import { CartActions } from '../ecm-store/actions';
import { EcmProductDetailService } from './ecm-product-detail.service';
import { ScrollService } from '../scroll.service';
......@@ -23,7 +23,7 @@ import { ECMCart } from '../ecm-model/cart-model';
import { Item } from '../ecm-model/product-model';
import { ECMHeaderComponent } from '../ecm-header/ecm-header.component';
import { Reviews } from '../ecm-model/product-review.model';
import {MdDialog, MdDialogRef, MdDialogConfig, MD_DIALOG_DATA} from '@angular/material';
import { MdDialog, MdDialogRef, MdDialogConfig, MD_DIALOG_DATA } from '@angular/material';
import { ECMWriteReviewDialog } from './ecm-product-review.component';
export const ECM_TEMPLATES: any = {
......@@ -46,7 +46,7 @@ export class EcmProductDetailsComponent implements OnInit {
itemCode: string;
ecmTemplate: EcmTemplateItem;
itemDetail: ItemDetail;
itemDetail;
scatCode;
noOfReviews;
userReview: Reviews;
......@@ -67,6 +67,31 @@ export class EcmProductDetailsComponent implements OnInit {
}
getItemDetail( itemCode: string ) {
this.store.select('item')
.subscribe( itemDetail => {
this.itemDetail = itemDetail
if ( this.itemDetail ) {
this.storeCatSubcat();
let ecmTemplateName = this.itemDetail.itemCategory.ecmTemplate;
console.log( "getItemDetail ecmTemplateName: " + ecmTemplateName )
this.ecmTemplate = ECM_TEMPLATES[ecmTemplateName];
this.scatCode = this.itemDetail.itemSubCategory.scatCode;
this.noOfReviews = this.itemDetail.itemRatings.NO_OF_REVIEWS;
console.log( "Changed scatCode.." + this.scatCode );
if ( this.ecmTemplate ) {
this.ecmTemplate.setItemDetail( this.itemDetail );
}
else {
alert( "Sorry, the " + ecmTemplateName + " is not in the system yet!" );
}
}
});
/*
this.productDetailService.getItemDetail( itemCode ).subscribe(
itemDetail => {
if( itemDetail ) console.log( 'comp itemCode[' + itemCode + '] itemDetail[' + itemDetail + '] \n this.itemDetail[' + JSON.stringify( itemDetail ) + ']' );
......@@ -95,6 +120,7 @@ export class EcmProductDetailsComponent implements OnInit {
console.log( 'comp ecmTemplate[' + this.ecmTemplate + ']' );
},
);
*/
}
scrollToReviews() {
......
......@@ -19,7 +19,7 @@ export class CategoryEffects {
.map(categories => this.catgoryActions.loadCategoriesSuccess(categories));
@Effect() getCategory$ = this.update$
.ofType(CategoryActions.GET_CATEGORY)
.switchMap(catCode => this.svc.getCategory(catCode.payload))
.map(category => this.catgoryActions.getCategorySuccess(category));
.ofType(CategoryActions.GET_CATEGORY)
.switchMap(catCode => this.svc.getCategory(catCode.payload))
.map(category => this.catgoryActions.getCategorySuccess(category));
}
......@@ -19,8 +19,7 @@ export class SubCategoryEffects {
.map(subcategories => this.subCategoryActions.loadSubCategoriesSuccess(subcategories));
@Effect() getSubCategory$ = this.update$
.ofType(SubCategoryActions.GET_SUBCATEGORY)
.switchMap(scatCode => this.svc.getSubCategory(scatCode.payload))
.map(subcategory => this.subCategoryActions.getSubCategorySuccess(subcategory));
.ofType(SubCategoryActions.GET_SUBCATEGORY)
.switchMap(scatCode => this.svc.getSubCategory(scatCode.payload))
.map(subcategory => this.subCategoryActions.getSubCategorySuccess(subcategory));
}
\ No newline at end of file
import {Action} from '@ngrx/store';
import {Observable} from 'rxjs/Observable';
import {Item} from '../../ecm-model/product-model';
import { ItemDetail } from '../../ecm-model/product-detail-model';
import {ItemActions} from '../actions';
import * as _ from 'lodash';
export type ItemListState = Item[];
export type ItemListState = ItemDetail[];
const initialState: ItemListState = [];
......
......@@ -39,7 +39,7 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
@ViewChild('scrollMe') private myScrollContainer: ElementRef;
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<AppState>, private cartActions: CartActions) { }
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<AppState>, private cartAction: CartActions) { }
ngOnInit() {
this.getCartItem();
......@@ -78,7 +78,7 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
console.log( error.json() );
});
*/
this.store.dispatch(this.cartActions.deleteCartItem(item));
this.store.dispatch(this.cartAction.deleteCartItem(item));
this.getCartItem();
this.openSnackBar('Item Removed from your Cart' );
......@@ -98,7 +98,7 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
//cartData.costRate = item.itemHeader.itemDiscountedRate;
//this.store.dispatch({ type: 'UPDATE_QUANTITY', payload: cartData });
this.store.dispatch(this.cartActions.updateCart(cartData));
this.store.dispatch(this.cartAction.updateCart(cartData));
this.openSnackBar( 'Quantity increased of ' + item.itemHeader.itemShDescr );
//this.productDetailService.addToCart(cartData);
}
......@@ -111,7 +111,7 @@ export class EcmCartComponent implements OnInit, AfterViewChecked {
// cartData.costRate = item.itemHeader.itemDiscountedRate;
//this.store.dispatch({ type: 'UPDATE_QUANTITY', payload: cartData });
this.store.dispatch(this.cartActions.updateCart(cartData));
this.store.dispatch(this.cartAction.updateCart(cartData));
this.openSnackBar( 'Quantity decreased of ' + item.itemHeader.itemShDescr );
//this.productDetailService.addToCart(cartData);
}
......
......@@ -66,7 +66,7 @@
</span>
</div>
<!--<ecm-item-caption [itemData]="_item"></ecm-item-caption> -->
<ecm-card [itemData]="_item" [extraParam]="extra_param"></ecm-card>
<ecm-card (storeData)="storeItem(_item)" [itemData]="_item" [extraParam]="extra_param"></ecm-card>
</div>
</div>
</div>
......
......@@ -4,7 +4,7 @@ import { Observable } from 'rxjs/Observable';
import { AppState } from '../../ecm-store/reducers';
import { Store } from '@ngrx/store';
import { ItemActions } from '../../ecm-store/actions';
import { ItemActions, CartActions } from '../../ecm-store/actions';
import { Category } from '../../ecm-model/category-model';
import { SubCategory } from '../../ecm-model/subcategory-model';
......@@ -36,7 +36,7 @@ export class EcmProductComponent implements OnInit {
}
Items = 0;
private items: Observable<Item[]>;
private items: Observable<ItemDetail[]>;
private extra_param= { "catCode":'', "catShDesc":'',scatDesc:'' };
private category : Category;
......@@ -46,7 +46,7 @@ export class EcmProductComponent implements OnInit {
attribCode;
constructor(private route: ActivatedRoute, private router:Router,public subcategoryService: EcmProductService,public productDetailService: EcmProductDetailService, private scroll_service: ScrollService, private store: Store<AppState>, private itemAction: ItemActions) { }
constructor(private route: ActivatedRoute, private router:Router,public subcategoryService: EcmProductService,public productDetailService: EcmProductDetailService, private scroll_service: ScrollService, private store: Store<AppState>, private itemAction: ItemActions, private cartAction: CartActions) { }
ngOnInit() {
window.scrollTo(0,0);
this.route.params.subscribe( params => {
......@@ -78,12 +78,12 @@ export class EcmProductComponent implements OnInit {
*/
}
storeCategory(selectedItem){
storeItem(selectedItem){
console.log(selectedItem);
//this.store.dispatch({type: 'CLEAR_SUB_CATEGORY', payload: selectedSubCategory});
//this.store.dispatch({type: 'SUB_CATEGORY', payload: selectedSubCategory});
this.store.dispatch( this.itemAction.getItem( selectedItem.itemCode ) );
this.store.dispatch( this.itemAction.getItemSuccess(selectedItem) );
}
fetchStore( viewType: string){
......@@ -106,25 +106,16 @@ export class EcmProductComponent implements OnInit {
}
}
addToCart(items) {
addToCart(item) {
let cartData = new Item;
cartData.itemCode = items.itemCode;
cartData.itemCode = item.itemCode;
cartData.itemQuantity = 1;
cartData.costRate = items.costRate;
cartData.descr = items.itemDescr;
cartData.shDescr = items.shDescr;
if(this.attribCode == "COLOR"){
cartData.phyAttribId3 = this.attribVal;
}
else if(this.attribCode == "SIZE"){
cartData.phyAttribId1 = this.attribVal;
}
//this.store.dispatch({ type: ADD_TO_CART, payload: cartData });
this.store.dispatch(this.cartAction.addToCartSuccess(item));
this.productDetailService.addToCart(cartData);
//Check Store data
this.store.select('cart').forEach(
this.store.select('cartItems').forEach(
value => {
console.log('Cart Items----');
console.log(value);
......
......@@ -5,7 +5,7 @@ import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Store } from '@ngrx/store';
import { Item } from '../../ecm-model/product-model';
import { ItemDetail } from '../../ecm-model/product-detail-model';
@Injectable()
export class EcmProductService {
......@@ -14,22 +14,71 @@ export class EcmProductService {
constructor (private http: Http,) {}
getItems (scatCode : string): Observable<Item[]> {
getItems (scatCode : string): Observable<ItemDetail[]> {
let itemsUrl = this.SERVICE_URL + scatCode ;
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.get(itemsUrl, options)
.map(this.extractData)
.map( (res) => this.extractData(res) )
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
console.log('extractData[' + JSON.stringify(body) + ']');
return body || { };
}
let respJson = res.json();
console.log('extracData',respJson);
if(respJson != null)
{
for( let key of Object.keys( respJson ) )
{
console.log( "getItemDetail itemDetail ==> key: " + key )
let data = respJson[key];
try
{
respJson[key] = JSON.parse( data );
console.log( "getItemDetail itemDetail try : " + respJson[key] );
}
catch(e)
{
console.log( "getItemDetail itemDetail ==> key: " ,data, typeof data === 'object')
if(typeof data === 'object')
respJson[key] = this.formatObject(data);
else
respJson[key] = data;
console.log( "getItemDetail itemDetail catch : " + respJson[key] );
}
}
console.log('extractData[' + JSON.stringify(respJson) + ']');
}
return respJson || { };
}
formatObject(respJson: any) {
console.log('formatObject',respJson);
if(respJson != null)
{
for( let key of Object.keys( respJson ) )
{
console.log( "formatObject itemDetail ==> key: " + key )
let data = respJson[key];
try
{
respJson[key] = JSON.parse( data );
console.log( "formatObject itemDetail try : " + respJson[key] );
}
catch(e)
{
respJson[key] = data;
console.log( "formatObject itemDetail catch : " + respJson[key] );
}
}
console.log('formatObject[' + JSON.stringify(respJson) + ']');
}
return respJson || { };
}
private handleError (error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
......
......@@ -25,7 +25,7 @@
<span *ngIf="category" class="ecm-section-info-subhead">{{category?.descr}}</span>
</div>
<div class="small-12 medium-6 large-4 column end " *ngFor="let _subcategory of subcategories | async">
<ecm-card (storeData)="storeCategory(_subcategory)" [subcategory]="_subcategory"></ecm-card>
<ecm-card (storeData)="storeSubCategory(_subcategory)" [subcategory]="_subcategory"></ecm-card>
</div>
</div>
</section>
......
......@@ -79,7 +79,7 @@ export class EcmSubCategoryComponent implements OnInit {
*/
}
storeCategory( selectedSubCategory ) {
storeSubCategory( selectedSubCategory ) {
//this.store.dispatch({type: 'CLEAR_SUB_CATEGORY', payload: selectedSubCategory});
//this.store.dispatch({type: 'SUB_CATEGORY', payload: selectedSubCategory});
......
......@@ -12,7 +12,7 @@ export class EcmSubCategoryService {
private SERVICE_URL = '/ecm/service/category'; // URL to web service
constructor (private http: Http,) {}
constructor (private http: Http) {}
getSubCategories( catCode: string ): Observable<SubCategory[]> {
......
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