Skip to content

Commit 050581d

Browse files
committed
Records on the Character search page deep link to the profile pages for
their relevant Book records
1 parent 743bc80 commit 050581d

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ <h1>Character Search</h1>
2222
<tbody>
2323
<tr *ngFor="let char of characters">
2424
<td colspan="2">{{ char.characterName }}</td>
25-
<td>{{ char.booksAsString() }}</td>
25+
<td>
26+
<span [innerHTML]="char.booksWithLineBreaksAndAnchors()"></span>
27+
</td>
2628
</tr>
2729
</tbody>
2830
</table>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CharacterComponent {
3939
if(resultJson.success) {
4040
this.characters = [];
4141
result.json().result.forEach((character:ApiCharacter) => {
42-
this.characters.push(new Character(character.characterName, character.books));
42+
this.characters.push(new Character(character.characterName, character.books));
4343
});
4444
}
4545

@@ -53,5 +53,5 @@ export class CharacterComponent {
5353

5454
interface ApiCharacter {
5555
characterName: string;
56-
books: string[];
56+
books: { [key: number]: string };
5757
}

Angular2/ClientApp/app/models/Book.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Book extends BookBaseViewModel {
6666
for(let index = 0; index < this.series.length; index++) {
6767
let seriesRecord = this.series[index];
6868
returnString +=
69-
`<a href='/seriesProfile/${seriesRecord.seriesId}'>${seriesRecord.seriesName}</a>`;
69+
`<a href='/seriesProfile/${seriesRecord.seriesId}'>${seriesRecord.seriesName}</a></br>`;
7070
}
7171
return returnString;
7272
};
+32-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
export class Character {
2-
constructor(characterName: string, books: string[]) {
2+
constructor(characterName: string, books: { [key: number]: string }) {
33
this.characterName = characterName;
4-
this.books = books;
4+
5+
if (books) {
6+
this.books = [];
7+
for (let key in books) {
8+
let value = books[key];
9+
this.books.push(new BookIdNameViewModel(key, value));
10+
}
11+
}
512

613
this.registerFunctions();
714
}
815
characterName: string;
9-
books: string[];
10-
booksAsString: () => string;
16+
books: BookIdNameViewModel[];
17+
booksWithLineBreaksAndAnchors: () => string;
1118

1219
registerFunctions = () => {
13-
this.booksAsString = (): string =>{
14-
return this.books.length > 0
15-
? this.books.join(',')
16-
: '';
20+
this.booksWithLineBreaksAndAnchors = (): string =>{
21+
if (this.books.length == 0) {
22+
return '';
23+
}
24+
25+
let returnString = '';
26+
for(let index = 0; index < this.books.length; index++) {
27+
let bookRecord = this.books[index];
28+
returnString +=
29+
`<a href='/bookProfile/${bookRecord.bookId}'>${bookRecord.bookName}</a></br>`;
30+
}
31+
return returnString;
1732
}
1833
}
34+
}
35+
36+
export class BookIdNameViewModel {
37+
constructor(bookId: string, bookName: string) {
38+
this.bookId = bookId;
39+
this.bookName = bookName;
40+
}
41+
bookId: string;
42+
bookName: string;
1943
}

0 commit comments

Comments
 (0)