Commit 9d45541a authored by prumde's avatar prumde

Changes for Subcategory and Category


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@174067 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 60f3eaba
...@@ -25,6 +25,13 @@ export class SubCategory { ...@@ -25,6 +25,13 @@ export class SubCategory {
console.log('comp this.resourceUrl[' + this.resourceUrl + ']'); console.log('comp this.resourceUrl[' + this.resourceUrl + ']');
} }
} }
export class Item {
public itemCode: string = '';
public descr: string = '';
public shDescr: string = '';
}
export const MockTrendings: Category[] = [ export const MockTrendings: Category[] = [
new Category('food', 'Kabab Special', 'Authentic Home Made recipe','',''), new Category('food', 'Kabab Special', 'Authentic Home Made recipe','',''),
new Category('tour', 'Into the blue', 'Scuba diving in deep blue ocean','',''), new Category('tour', 'Into the blue', 'Scuba diving in deep blue ocean','',''),
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
padding: 0; padding: 0;
margin: 0; margin: 0;
padding-top: 100px; padding-top: 100px;
padding-top: 50px;
background-color: #FFF; background-color: #FFF;
} }
.ecm-section-info { .ecm-section-info {
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<section class="categories-section"> <section class="categories-section">
<div class="row row-category"> <div class="row row-category">
<div class="ecm-section-info"> <div class="ecm-section-info">
<span class="ecm-section-info-title">Categories</span> <span class="ecm-section-info-subhead">Explore top AuthenticRegional Foods, Outings, Celebrations around {{selectedPlace}}</span> <span class="ecm-section-info-title">Categories</span>
<span class="ecm-section-info-subhead">Explore top Authentic Regional Foods, Outings, Celebrations around {{selectedPlace}}</span>
</div> </div>
<div class="small-12 medium-6 large-4 column end "*ngFor="let _category of categories"> <div class="small-12 medium-6 large-4 column end "*ngFor="let _category of categories">
<ecm-card [category]="_category"></ecm-card> <ecm-card [category]="_category"></ecm-card>
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ECMCategoryService } from './ecm-category.service'; import { ECMCategoryService } from './ecm-category.service';
import { ECMCard } from '../ecm-card/card-model'; import { ECMCard } from '../ecm-card/card-model';
import { Category, SubCategory } from '../ecm-category/category-model'; import { Category, SubCategory } from './category-model';
@Component({ @Component({
selector: 'ecm-category', selector: 'ecm-category',
templateUrl: './ecm-category.component.html', templateUrl: './ecm-category.component.html',
...@@ -12,58 +12,22 @@ export class ECMCategoryComponent implements OnInit { ...@@ -12,58 +12,22 @@ export class ECMCategoryComponent implements OnInit {
errorMessage: string; errorMessage: string;
selectedPlace = 'Mumbai'; selectedPlace = 'Mumbai';
categories: Category[]; categories: Category[];
// cat_cards: ECMCard[];
constructor(public categoryService: ECMCategoryService) { } constructor(public categoryService: ECMCategoryService) { }
ngOnInit() { ngOnInit() {
this.getCategories(); this.getCategories();
} }
/*
getCategories(): void {
this.categoryService.getCategories().then( categories => {
this.categories = categories;
this.cat_cards = [];
for ( let i = 0; i < this.categories.length ; ++i ) {
let img = 'assets/images/' + this.categories[i].type + '.png';
let info_img = 'assets/images/' + this.categories[i].type + '_icon.png';
let info_title = this.categories[i].title;
let info_subhead = this.categories[i].descr;
this.cat_cards.push( new ECMCard( img, info_img, info_title, info_subhead, false ) );
}
}
);
}
*/
getCategories() { getCategories() {
this.categoryService.getCategories().subscribe( this.categoryService.getCategories().subscribe(
categories => { categories => {
this.categories = categories; this.categories = categories;
console.log('comp categories[' + JSON.stringify( categories ) + '] \n this.categories[' + JSON.stringify( this.categories ) + ']'); console.log('comp categories[' + JSON.stringify( categories ) + '] \n this.categories[' + JSON.stringify( this.categories ) + ']');
/*
this.cat_cards = [];
for ( let i = 0; i < this.categories.length ; ++i ) {
let img = 'assets/images/category/' + this.categories[i].catCode + '.png';
let info_img = 'assets/images/category/' + this.categories[i].catCode + '_icon.png';
let info_title = this.categories[i].catDescr;
let info_subhead = this.categories[i].catShortDescr;
this.cat_cards.push( new ECMCard( img, info_img, info_title, info_subhead, false ) );
}
*/
}, },
error => { error => {
this.errorMessage = <any>error; this.errorMessage = <any>error;
console.log('comp errorMessage[' + this.errorMessage + ']'); console.log('comp errorMessage[' + this.errorMessage + ']');
}); });
} }
/*
addCategory (name: string) {
if (!name) { return; }
this.categoryService.addCategory(name)
.subscribe(
hero => this.categories.push(category),
error => this.errorMessage = <any>error);
}
*/
} }
...@@ -4,53 +4,72 @@ import { Observable } from 'rxjs/Observable'; ...@@ -4,53 +4,72 @@ import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import { Category, SubCategory } from '../ecm-category/category-model'; import { Category, SubCategory, Item } from '../ecm-category/category-model';
@Injectable() @Injectable()
export class ECMCategoryService { export class ECMCategoryService {
private categoriesUrl = '/ecm/service/category'; // URL to web service private categoryUrl = '/ecm/service/category'; // URL to web service
private subCategoriesUrl = '/ecm/service/category'; // URL to web service
constructor (private http: Http) {} constructor (private http: Http) {}
/* getCategories(): Observable<Category[]> {
getCategories(): Promise<Category[]> { let headers = new Headers( { 'Content-Type': 'application/json' });
return Promise.resolve(MockCategories); let options = new RequestOptions( { headers: headers });
return this.http.get( this.categoryUrl, options )
.map( this.extractData )
.catch( this.handleError );
} }
getCategoriesSlowly(): Promise<Category[]> { getSubCategories( catCode: string ): Observable<SubCategory[]> {
return new Promise(resolve => {
// Simulate server latency with 2 second delay let subCategoriesUrl = this.categoryUrl + '/' + catCode + '/list';
setTimeout(() => resolve(this.getCategories()), 2000); let headers = new Headers( { 'Content-Type': 'application/json' });
}); let options = new RequestOptions( { headers: headers });
return this.http.get( subCategoriesUrl, options )
.map( this.extractData )
.catch( this.handleError );
} }
constructor() { }
*/
getCategories (): Observable<Category[]> { getCategory (catCode : string): Observable<Category> {
let categoryUrl = this.categoryUrl + '/' + catCode;
let headers = new Headers({ 'Content-Type': 'application/json' }); let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers }); let options = new RequestOptions({ headers: headers });
return this.http.get(this.categoriesUrl, options) return this.http.get(categoryUrl, options)
.map(this.extractData) .map(this.extractData)
.catch(this.handleError); .catch(this.handleError);
} }
getSubCategories (scatCode : string): Observable<SubCategory[]> { getSubCategory (scatCode : string): Observable<SubCategory> {
this.subCategoriesUrl = this.subCategoriesUrl + '/' + scatCode + '/list'; let subCategoryUrl = this.categoryUrl + '/list/' + scatCode;
let headers = new Headers({ 'Content-Type': 'application/json' }); let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers }); let options = new RequestOptions({ headers: headers });
return this.http.get(this.subCategoriesUrl, options) return this.http.get(subCategoryUrl, options)
.map(this.extractData) .map(this.extractData)
.catch(this.handleError); .catch(this.handleError);
} }
getItems (scatCode : string): Observable<Item[]> {
let itemsUrl = this.categoryUrl + '/itemlist/' + scatCode ;
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.get(itemsUrl, options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) { private extractData(res: Response) {
let body = res.json(); let body = res.json();
console.log('comp categories[' + JSON.stringify(body) + ']'); console.log('extractData[' + JSON.stringify(body) + ']');
return body || { }; return body || { };
} }
...@@ -68,15 +87,4 @@ export class ECMCategoryService { ...@@ -68,15 +87,4 @@ export class ECMCategoryService {
return Observable.throw(errMsg); return Observable.throw(errMsg);
} }
/*
addCategory (name: string): Observable<Hero> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.categoriesUrl, { name }, options)
.map(this.extractData)
.catch(this.handleError);
}
*/
} }
.subcategories-section {
padding: 0;
margin: 0;
padding-top: 100px;
padding-top: 50px;
background-color: #FFF;
}
.ecm-section-info {
padding: 10px;
}
.ecm-section-info-title {
font-size: 26px;
color: #444;
display: block;
}
.ecm-section-info-subhead {
font-size: 16px;
color: #888;
display: block;
}
.end {
padding-top: 15px;
padding-bottom: 50px;
}
.row.row-subcategory {
max-width: 72rem;
}
<div *ngIf="subcategories">
<section class="subcategories-section">
<div class="row row-subcategory">
<div class="ecm-section-info">
<span class="ecm-section-info-title">{{category.shDescr}}</span>
<span class="ecm-section-info-subhead">{{category.descr}}</span>
</div>
<div class="small-12 medium-6 large-4 column end "*ngFor="let _subcategory of subcategories">
<ecm-card [subcategory]="_subcategory"></ecm-card>
</div>
</div>
</section>
</div>
<div *ngIf="items">
<section class="subcategories-section">
<div class="row row-subcategory">
<div class="ecm-section-info">
<span class="ecm-section-info-title">{{subcategory.shDescr}}</span>
<span class="ecm-section-info-subhead">{{subcategory.descr}}</span>
</div>
<div class="small-12 medium-6 large-4 column end "*ngFor="let _item of items">
<ecm-item-caption [itemData]="_item"></ecm-item-caption>
</div>
</div>
</section>
</div>
import { Component, OnInit } from '@angular/core';
import { Item, SubCategory, Category } from './category-model';
import { ECMCategoryService } from './ecm-category.service';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'ecm-sub-category',
templateUrl: './ecm-sub-category.component.html',
styleUrls: ['./ecm-sub-category.component.css'],
providers: [ECMCategoryService]
})
export class EcmSubCategoryComponent implements OnInit {
private subcategories: SubCategory[];
private items: Item[];
private category : Category;
private subcategory : SubCategory;
constructor(private route: ActivatedRoute, private router:Router,public subcategoryService: ECMCategoryService) { }
ngOnInit() {
this.route.params.subscribe( params => {
//let id: number = +params['id']; // (+) converts string 'id' to a number
// In a real app: dispatch action to load the details here.
let viewType = params['type'];
let viewKey = params['key'];
console.log( 'ngOnInit viewType[' + viewType + ']viewKey[' + viewKey + ']' );
this.openView(viewType, viewKey);
});
}
openView(viewType:string, viewKey:string){
if( viewType == 'SUB_CATEGORY')
{
this.getCategory( viewKey );
}
else if( viewType == 'ITEMS')
{
this.getSubCategory( viewKey );
}
}
getCategory( catCode: string ) {
this.subcategoryService.getCategory( catCode ).subscribe(
category => {
this.category = category;
console.log( 'comp catCode[' + catCode + '] \n this.category[' + JSON.stringify( this.category ) + ']' );
this.getSubCategories( catCode );
},
);
}
getSubCategory( scatCode: string ) {
this.subcategoryService.getSubCategory( scatCode ).subscribe(
subcategory => {
this.subcategory = subcategory;
console.log( 'comp scatCode[' + scatCode + '] \n this.subcategory[' + JSON.stringify( this.subcategory ) + ']' );
this.getItems( scatCode );
},
);
}
getSubCategories( catCode: string ) {
this.subcategoryService.getSubCategories( catCode ).subscribe(
subcategories => {
this.subcategories = subcategories;
this.items = null;
console.log( 'comp catCode[' + catCode + '] \n this.subcategories[' + JSON.stringify( this.subcategories ) + ']' );
},
);
}
getItems( scatCode: string ) {
this.subcategoryService.getItems( scatCode ).subscribe(
items => {
this.items = items;
this.subcategories = null;
console.log( 'comp scatCode[' + scatCode + '] \n this.items[' + JSON.stringify( this.items ) + ']' );
},
);
}
}
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