Skip to content

Commit 400abf7

Browse files
committed
Moved bookName and bookOrdinal fields to base view model
1 parent e3ff85e commit 400abf7

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
<div *ngIf="!loading && success && hasBooks">
66
<div class="row" *ngFor="let book of books">
7-
<div class="col-xs-12">
8-
<h1>{{ book.bookName }}</h1>
9-
</div>
10-
117
<div class="row">
128
<div class="col-xs-3">
139
<img src="{{ book.imageTag() }}" class="img-responsive"/>
1410
</div>
1511
<div class="col-xs-9">
12+
<h2>
13+
<a [routerLink]="['/bookProfile', book.bookOrdinal]">{{ book.bookName }}</a>
14+
</h2>
1615
<p>{{ book.bookDescription }}</p>
1716
</div>
1817
</div>

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

+19-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ActivatedRoute } from "@angular/router";
33
import { Http } from '@angular/http';
44
import { ResultJson } from "../../models/ResultJson";
55
import { BookBaseViewModel } from "../../models/Book";
6-
import {ImageViewModel} from "../../models/Image";
6+
import { ImageViewModel } from "../../models/Image";
77

88
@Component({
99
selector: 'seriesProfile',
@@ -21,7 +21,6 @@ export class SeriesProfileComponent implements OnInit, OnDestroy {
2121
hasBooks = false;
2222
books: BookBaseViewModel[];
2323

24-
2524
private subscription: any;
2625

2726
ngOnInit() {
@@ -36,10 +35,9 @@ export class SeriesProfileComponent implements OnInit, OnDestroy {
3635
this.books = [];
3736
result.json().result.forEach((serverBook: ApiBookBaseViewModel) => {
3837
let newData = new BookBaseViewModel(serverBook.bookId,
39-
serverBook.bookDescription);
40-
newData.coverData = new ImageViewModel(
41-
serverBook.bookCoverImage, serverBook.bookImageIsBase64String
42-
);
38+
serverBook.bookDescription, serverBook.bookName,
39+
serverBook.bookOrdinal);
40+
this.getBookImageData(newData);
4341
this.books.push(newData);
4442
});
4543
}
@@ -51,15 +49,29 @@ export class SeriesProfileComponent implements OnInit, OnDestroy {
5149
});
5250
}
5351

54-
5552
ngOnDestroy() {
5653
this.subscription.unsubscribe();
5754
}
55+
56+
private getBookImageData = (book: BookBaseViewModel) => {
57+
let route = `http://dwcheckapi.azurewebsites.net/Books/GetBookCover/${book.bookId}`;
58+
this.http.get(route).subscribe((result) => {
59+
let resultJson = result.json() as ResultJson;
60+
if (resultJson.success) {
61+
let serverData = result.json().result;
62+
book.coverData = new ImageViewModel(
63+
serverData.bookCoverImage, serverData.bookImageIsBase64String
64+
);
65+
}
66+
});
67+
}
5868

5969
}
6070

6171
interface ApiBookBaseViewModel {
6272
bookId: number;
73+
bookOrdinal: number;
74+
bookName: string;
6375
bookCoverImage: string;
6476
bookImageIsBase64String: boolean;
6577
bookDescription: string;

Angular2/ClientApp/app/models/Book.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { ImageViewModel } from "./Image";
22

33
export class BookBaseViewModel {
4-
constructor(bookId: number, bookDescription: string) {
4+
constructor(bookId: number, bookDescription: string, bookName: string, bookOrdinal: number) {
55
this.bookId = bookId;
66
this.bookDescription = bookDescription;
7+
this.bookName = bookName;
8+
this.bookOrdinal = bookOrdinal;
79
}
810

911
bookId: number;
1012
bookDescription: string;
13+
bookOrdinal: number;
14+
bookName: string;
1115
coverData: ImageViewModel;
1216

1317
imageTag = (): string => {
@@ -23,11 +27,8 @@ export class Book extends BookBaseViewModel {
2327
constructor(bookId: number, bookOrdinal: number, bookName: string, bookIsbn10: string,
2428
bookIsbn13: string, bookDescription: string, characters: string[],
2529
series: string[]) {
30+
super(bookId, bookDescription, bookName, bookOrdinal);
2631

27-
super(bookId, bookDescription);
28-
29-
this.bookOrdinal = bookOrdinal;
30-
this.bookName = bookName;
3132
this.bookIsbn10 = bookIsbn10;
3233
this.bookIsbn13 = bookIsbn13;
3334
this.characters = characters;

0 commit comments

Comments
 (0)