Skip to content

Commit 9dc1183

Browse files
authored
Merge pull request #12 from GaProgMan/net-core-2-0
Fixes #3 - Added Series Profile page
2 parents b7f99c7 + 0d0c8a2 commit 9dc1183

File tree

10 files changed

+1135
-844
lines changed

10 files changed

+1135
-844
lines changed

Angular2/ClientApp/app/app.module.shared.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BooksComponent } from './components/books/books.component';
1111
import { CharacterComponent} from "./components/characters/characters.component";
1212
import { SeriesComponent } from "./components/series/series.component";
1313
import { BookProfileComponent } from "./components/bookProfile/bookProfile.component";
14+
import { SeriesProfileComponent} from "./components/seriesProfile/seriesProfile.component";
1415

1516
@NgModule({
1617
declarations: [
@@ -20,7 +21,8 @@ import { BookProfileComponent } from "./components/bookProfile/bookProfile.compo
2021
BooksComponent,
2122
CharacterComponent,
2223
SeriesComponent,
23-
BookProfileComponent
24+
BookProfileComponent,
25+
SeriesProfileComponent
2426
],
2527
imports: [
2628
CommonModule,
@@ -33,6 +35,7 @@ import { BookProfileComponent } from "./components/bookProfile/bookProfile.compo
3335
{ path: 'characters', component: CharacterComponent },
3436
{ path: 'series', component: SeriesComponent },
3537
{ path: 'bookProfile/:id' , component: BookProfileComponent },
38+
{ path: 'seriesProfile/:id', component: SeriesProfileComponent },
3639
{ path: '**', redirectTo: 'about' }
3740
])
3841
]

Angular2/ClientApp/app/components/series/series.component.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ <h1>Series Search</h1>
2020
</thead>
2121
<tbody>
2222
<tr *ngFor="let ser of series">
23-
<td colspan="2">{{ ser.seriesName }}</td>
23+
<td colspan="2">
24+
<a [routerLink]="['/seriesProfile', ser.seriesId]">
25+
{{ ser.seriesName }}
26+
</a>
27+
</td>
2428
<td>{{ ser.booksAsString() }}</td>
2529
</tr>
2630
</tbody>

Angular2/ClientApp/app/components/series/series.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class SeriesComponent {
3838
if(resultJson.success) {
3939
this.series = [];
4040
result.json().result.forEach((series:ApiSeries) => {
41-
this.series.push(new Series(series.seriesName, series.bookNames));
41+
this.series.push(new Series(series.seriesId, series.seriesName, series.bookNames));
4242
});
4343
}
4444
this.success = resultJson.success;
@@ -48,7 +48,8 @@ export class SeriesComponent {
4848
}
4949
}
5050

51-
interface ApiSeries{
51+
interface ApiSeries {
52+
seriesId: number;
5253
seriesName: string;
5354
bookNames: string[];
5455
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="loader" *ngIf="loading">
2+
<p>Searching, please wait</p>
3+
</div>
4+
5+
<div *ngIf="!loading && success && books">
6+
<div class="row" *ngFor="let book of books">
7+
<div class="col-xs-12">
8+
<h1>{{ book.bookName }}</h1>
9+
</div>
10+
11+
<div class="row">
12+
<div class="col-xs-3">
13+
<img src="{{book.bookCoverImageUrl}}" class="img-responsive"/>
14+
</div>
15+
<div class="col-xs-9">
16+
<p>{{ book.bookDescription }}</p>
17+
</div>
18+
</div>
19+
<hr />
20+
</div>
21+
22+
<hr />
23+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
2+
import { ActivatedRoute } from "@angular/router";
3+
import { Http } from '@angular/http';
4+
import { ResultJson } from "../../models/ResultJson";
5+
import { BookBaseViewModel } from "../../models/Book";
6+
7+
@Component({
8+
selector: 'seriesProfile',
9+
templateUrl: './seriesProfile.component.html'
10+
})
11+
12+
export class SeriesProfileComponent implements OnInit, OnDestroy {
13+
constructor(private route: ActivatedRoute, public http: Http) {
14+
}
15+
16+
loading = false;
17+
success = true;
18+
baseApiUrl = 'http://dwcheckapi.azurewebsites.net/Books/Series';
19+
seriesId: number;
20+
books: BookBaseViewModel[];
21+
22+
23+
private subscription: any;
24+
25+
ngOnInit() {
26+
this.subscription = this.route.params.subscribe(params => {
27+
this.seriesId = +params['id']; // the + here converts a string to a number
28+
29+
var route = `${this.baseApiUrl}/${this.seriesId}`;
30+
31+
this.http.get(route).subscribe((result) => {
32+
var resultJson = result.json() as ResultJson;
33+
debugger;
34+
if (resultJson.success) {
35+
this.books = [];
36+
result.json().result.forEach((serverBook: ApiBookBaseViewModel) => {
37+
this.books.push(new BookBaseViewModel(serverBook.bookDescription, serverBook.bookCoverImageUrl));
38+
});
39+
}
40+
this.success = resultJson.success;
41+
this.loading = false;
42+
});
43+
});
44+
}
45+
46+
47+
ngOnDestroy() {
48+
this.subscription.unsubscribe();
49+
}
50+
}
51+
52+
interface ApiBookBaseViewModel {
53+
bookCoverImageUrl: string;
54+
bookDescription: string;
55+
}

Angular2/ClientApp/app/models/Book.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
export class Book {
1+
export class BookBaseViewModel {
2+
constructor(bookDescription: string, bookCoverImageUrl: string){
3+
this.bookDescription = bookDescription;
4+
this.bookCoverImageUrl = bookCoverImageUrl;
5+
}
6+
7+
bookDescription: string;
8+
bookCoverImageUrl: string;
9+
}
10+
11+
export class Book extends BookBaseViewModel {
212
constructor(bookOrdinal: number, bookName: string, bookIsbn10: string,
313
bookIsbn13: string, bookDescription: string, bookCoverImageUrl: string,
4-
characters: string[], series: string[]){
14+
characters: string[], series: string[]) {
15+
super(bookDescription, bookCoverImageUrl);
16+
517
this.bookOrdinal = bookOrdinal;
618
this.bookName = bookName;
719
this.bookIsbn10 = bookIsbn10;
820
this.bookIsbn13 = bookIsbn13;
9-
this.bookDescription = bookDescription;
10-
this.bookCoverImageUrl = bookCoverImageUrl;
1121
this.characters = characters;
1222
this.series = series;
1323

Angular2/ClientApp/app/models/Series.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
export class Series {
2-
constructor(seriesName: string, books: string[]){
2+
constructor(seriesId: number, seriesName: string, books: string[]) {
3+
this.seriesId = seriesId;
34
this.seriesName = seriesName;
45
this.books = books;
56

67
this.registerFunctions();
78
}
9+
seriesId: number;
810
seriesName: string;
911
books: string[];
1012
booksAsString: () => string;

0 commit comments

Comments
 (0)