Skip to content

Commit 59f0d62

Browse files
committed
Added series search
1 parent ca0658b commit 59f0d62

File tree

10 files changed

+413
-139
lines changed

10 files changed

+413
-139
lines changed

Angular2/ClientApp/app/app.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AppComponent } from './components/app/app.component'
55
import { NavMenuComponent } from './components/navmenu/navmenu.component';
66
import { BooksComponent } from './components/books/books.component';
77
import { CharacterComponent } from './components/characters/characters.component';
8+
import { SeriesComponent } from './components/series/series.component';
89
import { AboutComponent } from './components/about/about.component';
910

1011
@NgModule({
@@ -14,6 +15,7 @@ import { AboutComponent } from './components/about/about.component';
1415
NavMenuComponent,
1516
CharacterComponent,
1617
BooksComponent,
18+
SeriesComponent,
1719
AboutComponent
1820
],
1921
imports: [
@@ -22,6 +24,7 @@ import { AboutComponent } from './components/about/about.component';
2224
{ path: '', redirectTo: 'books', pathMatch: 'full' },
2325
{ path: 'books', component: BooksComponent },
2426
{ path: 'characters', component: CharacterComponent },
27+
{ path: 'series', component: SeriesComponent },
2528
{ path: 'about', component: AboutComponent },
2629
{ path: '**', redirectTo: 'about' }
2730
])

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class='main-nav'>
1+
<div class='main-nav'>
22
<div class='navbar navbar-inverse'>
33
<div class='navbar-header'>
44
<button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse'>
@@ -22,6 +22,11 @@
2222
<span class='glyphicon glyphicon-user'></span> Characters
2323
</a>
2424
</li>
25+
<li [routerLinkActive]="['link-active']">
26+
<a [routerLink]="['/series']">
27+
<span class='glyphicon glyphicon-tags'></span> Series
28+
</a>
29+
</li>
2530
</ul>
2631
</div>
2732
</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<h1>Series Search</h1>
2+
<div class="row">
3+
<div class="col-xs-12">
4+
<input [value]="searchString" (input)="searchString = $event.target.value" />
5+
<button (click)="getDwSeries()">Search</button>
6+
</div>
7+
</div>
8+
<div class="loader" *ngIf="!success">
9+
<p>Could not find any results</p>
10+
</div>
11+
<div class="table-responsive" *ngIf="success">
12+
<table class='table' *ngIf="series">
13+
<thead>
14+
<tr>
15+
<th colspan="2">Name</th>
16+
<th>Books</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr *ngFor="let ser of series">
21+
<td colspan="2">{{ ser.seriesName }}</td>
22+
<td>{{ ser.booksAsString() }}</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
</div>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component } from '@angular/core';
2+
import { Http } from '@angular/http';
3+
import { ResultJson } from "../../models/ResultJson";
4+
import { Series } from "../../models/Series";
5+
6+
@Component({
7+
selector: 'series',
8+
templateUrl: './series.component.html'
9+
})
10+
export class SeriesComponent {
11+
constructor(http: Http) {
12+
this.http = http;
13+
14+
this.success = true;
15+
this.loading = false;
16+
this.baseApiUrl = 'http://dwcheckapi.azurewebsites.net/series/search?searchString';
17+
this.registerFunctions();
18+
}
19+
// private vars
20+
private http: Http;
21+
22+
// public bound vars
23+
success: boolean;
24+
loading: boolean;
25+
baseApiUrl: string;
26+
searchString = '';
27+
series: ISeries[];
28+
29+
// public functions
30+
getDwSeries: () => void;
31+
32+
private registerFunctions() {
33+
this.getDwSeries = () => {
34+
this.success = false;
35+
var route = `${this.baseApiUrl}${this.searchString}`;
36+
this.http.get(route).subscribe((result) => {
37+
var resultJson = result.json() as IResultJson;
38+
if(resultJson.success) {
39+
this.success = true;
40+
this.series = new Array<ISeries>();
41+
result.json().result.forEach(element => {
42+
this.series.push(new Series(element.seriesName, element.bookNames));
43+
});
44+
}
45+
});
46+
}
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface ISeries {
2+
seriesName: string;
3+
books: string[];
4+
5+
booksAsString:() => string;
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class Series implements ISeries {
2+
constructor(seriesName: string, books: string[]){
3+
this.seriesName = seriesName;
4+
this.books = books;
5+
6+
this.booksAsString = (): string =>{
7+
return books.map(b => b).join(', ');
8+
}
9+
}
10+
seriesName: string;
11+
books: string[];
12+
booksAsString: () => string;
13+
}

0 commit comments

Comments
 (0)