Skip to content

Commit 7c04274

Browse files
author
Carlos Cañizares Estévez
committed
service in spa to retrieve data from catalog api, project structure simplified
1 parent e11bbc2 commit 7c04274

16 files changed

Lines changed: 90 additions & 319 deletions
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Title } from '@angular/platform-browser';
22
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
33
import { RouterModule } from '@angular/router';
4-
import { TranslateService } from 'ng2-translate/ng2-translate';
54

65
import { DataService } from './shared/services/data.service';
76

@@ -18,20 +17,15 @@ import { DataService } from './shared/services/data.service';
1817
export class AppComponent implements OnInit {
1918

2019

21-
constructor(private translate: TranslateService, private titleService: Title) {
22-
// this language will be used as a fallback when a translation isn't found in the current language
23-
translate.setDefaultLang('en');
20+
constructor(private titleService: Title) {
2421

25-
// the lang to use, if the lang isn't available, it will use the current loader to get them
26-
translate.use('en');
2722
}
2823

2924
ngOnInit() {
30-
this.translate.get('title')
31-
.subscribe(title => this.setTitle(title));
25+
3226
}
3327

3428
public setTitle(newTitle: string) {
35-
this.titleService.setTitle(newTitle);
29+
this.titleService.setTitle('eShopOnContainers');
3630
}
3731
}
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { CatalogService } from './catalog.service';
3+
import { Catalog } from '../shared/models/catalog.model';
4+
import { CatalogItem } from '../shared/models/catalogItem.model';
25

36
@Component({
4-
selector: 'appc-catalog',
5-
styleUrls: ['./catalog.component.scss'],
6-
templateUrl: './catalog.component.html'
7+
selector: 'appc-catalog',
8+
styleUrls: ['./catalog.component.scss'],
9+
templateUrl: './catalog.component.html'
710
})
811
export class CatalogComponent implements OnInit {
9-
constructor() { }
12+
private brands: any[];
13+
private types: any[];
14+
private items: CatalogItem[];
15+
private filteredItems: any[];
16+
private catalog: Catalog;
1017

11-
ngOnInit() {
12-
console.log('catalog component loaded');
13-
}
18+
constructor(private service: CatalogService) { }
1419

20+
ngOnInit() {
21+
console.log('catalog component loaded');
22+
this.service.getCatalog().subscribe((catalog: Catalog) => {
23+
this.catalog = catalog;
24+
this.items = catalog.data;
25+
console.log(this.items.length + ' catalog items retrieved from api');
26+
});
27+
}
1528
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { NgModule } from '@angular/core';
1+
import { NgModule } from '@angular/core';
22

3-
import { CatalogComponent } from './catalog.component';
4-
import { routing } from './catalog.routes';
3+
import { CatalogComponent } from './catalog.component';
4+
import { routing } from './catalog.routes';
5+
import { CatalogService } from './catalog.service';
56

67

78
@NgModule({
89
imports: [routing],
9-
declarations: [CatalogComponent]
10+
declarations: [CatalogComponent],
11+
providers: [CatalogService]
1012
})
1113
export class CatalogModule { }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Injectable } from '@angular/core';
2+
3+
import { DataService } from '../shared/services/data.service';
4+
5+
@Injectable()
6+
export class CatalogService {
7+
private catalogUrl: string = 'http://eshopcontainers:5101/api/v1/catalog/items';
8+
9+
constructor(private service: DataService) {
10+
}
11+
12+
getCatalog(){
13+
return this.service.get(this.catalogUrl);
14+
}
15+
}

src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/layout/footer.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="container">
33
<hr>
44
<p class="text-muted">
5-
&copy; 2015-2016 {{'title' | translate}} Company
5+
&copy; 2015-2016 {{'title'}} Company
66
</p>
77
</div>
88
</footer>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {CatalogItem} from './catalogItem.model';
2+
3+
export class Catalog {
4+
constructor(public pageIndex: number, public data: CatalogItem[], public pageSize: number, public count: number) {
5+
}
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class CatalogItem {
2+
constructor(public Id: string, public Name: string, public Description: string, public Price: number, public PictureUri: string, public CatalogBrandId: number, public CatalogBrand: string, public CatalogTypeId: number, public CatalogType: string) { }
3+
}

src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/models/user.model.spec.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/services/api-gateway.service.ts

Lines changed: 0 additions & 207 deletions
This file was deleted.

src/Web/WebSPA/eShopOnContainers.WebSPA/Client/modules/shared/services/api-translation-loader.service.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)