Skip to content

Commit 88485db

Browse files
brandonrobertsBrandon Roberts
authored andcommitted
Workshop application start
1 parent aaab779 commit 88485db

18 files changed

+6966
-61
lines changed

.angular-cli.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"styles": [
2222
"styles.css"
2323
],
24-
"scripts": [],
24+
"scripts": [
25+
],
2526
"environmentSource": "environments/environment.ts",
2627
"environments": {
2728
"dev": "environments/environment.ts",
@@ -52,6 +53,9 @@
5253
},
5354
"defaults": {
5455
"styleExt": "css",
55-
"component": {}
56+
"component": {
57+
"inlineStyle": true,
58+
"inlineTemplate": true
59+
}
5660
}
5761
}

package.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@
1212
},
1313
"private": true,
1414
"dependencies": {
15-
"@angular/common": ">=4.0.0-beta <5.0.0",
16-
"@angular/compiler": ">=4.0.0-beta <5.0.0",
17-
"@angular/core": ">=4.0.0-beta <5.0.0",
18-
"@angular/forms": ">=4.0.0-beta <5.0.0",
19-
"@angular/http": ">=4.0.0-beta <5.0.0",
20-
"@angular/platform-browser": ">=4.0.0-beta <5.0.0",
21-
"@angular/platform-browser-dynamic": ">=4.0.0-beta <5.0.0",
22-
"@angular/router": ">=4.0.0-beta <5.0.0",
15+
"@angular/common": "^4.0.0",
16+
"@angular/compiler": "^4.0.0",
17+
"@angular/core": "^4.0.0",
18+
"@angular/forms": "^4.0.0",
19+
"@angular/http": "^4.0.0",
20+
"@angular/material": "^2.0.0-beta.2",
21+
"@angular/platform-browser": "^4.0.0",
22+
"@angular/platform-browser-dynamic": "^4.0.0",
23+
"@angular/router": "^4.0.0",
24+
"@ngrx/core": "^1.2.0",
25+
"@ngrx/effects": "^2.0.2",
26+
"@ngrx/store": "^2.2.1",
2327
"core-js": "^2.4.1",
2428
"rxjs": "^5.1.0",
25-
"zone.js": "^0.7.6"
29+
"zone.js": "^0.8.4"
2630
},
2731
"devDependencies": {
28-
"@angular/cli": "1.0.0-rc.2",
29-
"@angular/compiler-cli": ">=4.0.0-beta <5.0.0",
32+
"@angular/cli": "1.0.0",
33+
"@angular/compiler-cli": "^4.0.0",
34+
"@ngrx/store-devtools": "^3.2.4",
3035
"@types/jasmine": "2.5.38",
3136
"@types/node": "~6.0.60",
3237
"codelyzer": "~2.0.0",
@@ -35,12 +40,10 @@
3540
"karma": "~1.4.1",
3641
"karma-chrome-launcher": "~2.0.0",
3742
"karma-cli": "~1.0.1",
43+
"karma-coverage-istanbul-reporter": "^0.2.0",
3844
"karma-jasmine": "~1.1.0",
3945
"karma-jasmine-html-reporter": "^0.2.2",
40-
"karma-coverage-istanbul-reporter": "^0.2.0",
41-
"protractor": "~5.1.0",
42-
"ts-node": "~2.0.0",
4346
"tslint": "~4.5.0",
44-
"typescript": "~2.1.0"
47+
"typescript": "~2.2.0"
4548
}
4649
}

src/app/app.component.css

Whitespace-only changes.

src/app/app.component.html

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

src/app/app.component.spec.ts

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

src/app/app.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-root',
5-
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.css']
5+
template: `
6+
<md-toolbar color="primary">
7+
NGRX Workshop
8+
</md-toolbar>
9+
10+
<router-outlet></router-outlet>
11+
`
712
})
813
export class AppComponent {
9-
title = 'app works!';
14+
1015
}

src/app/app.module.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3-
import { FormsModule } from '@angular/forms';
3+
import { ReactiveFormsModule } from '@angular/forms';
44
import { HttpModule } from '@angular/http';
5+
import { RouterModule } from '@angular/router';
6+
import { MaterialModule } from '@angular/material';
57

68
import { AppComponent } from './app.component';
9+
import { SearchComponent } from './search.component';
10+
11+
import { GoogleBooksService } from './google-books.service';
12+
import { BookSearchComponent } from './book-search.component';
13+
import { SearchResultsComponent } from './search-results.component';
714

815
@NgModule({
916
declarations: [
10-
AppComponent
17+
AppComponent,
18+
SearchComponent,
19+
BookSearchComponent,
20+
SearchResultsComponent
1121
],
1222
imports: [
1323
BrowserModule,
14-
FormsModule,
15-
HttpModule
24+
ReactiveFormsModule,
25+
HttpModule,
26+
MaterialModule,
27+
RouterModule.forRoot([
28+
{ path: '', component: SearchComponent }
29+
])
1630
],
17-
providers: [],
31+
providers: [GoogleBooksService],
1832
bootstrap: [AppComponent]
1933
})
2034
export class AppModule { }

src/app/book-model.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface Book {
2+
id: string;
3+
volumeInfo: {
4+
title: string;
5+
subtitle: string;
6+
authors: string[];
7+
publisher: string;
8+
publishDate: string;
9+
description: string;
10+
averageRating: number;
11+
ratingsCount: number;
12+
imageLinks: {
13+
thumbnail: string;
14+
smallThumbnail: string;
15+
};
16+
};
17+
}

src/app/book-search.component.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'rxjs/add/operator/debounceTime';
2+
import 'rxjs/add/operator/filter';
3+
import { Component, Output, Input, EventEmitter } from '@angular/core';
4+
import { FormControl } from '@angular/forms';
5+
6+
@Component({
7+
selector: 'app-book-search',
8+
template: `
9+
<md-card>
10+
<md-card-title>Find a Book</md-card-title>
11+
<md-card-content>
12+
<md-input-container>
13+
<input mdInput placeholder="Search for a book" [formControl]="searchTerms">
14+
</md-input-container>
15+
</md-card-content>
16+
</md-card>
17+
`,
18+
styles: [`
19+
md-card-title,
20+
md-card-content {
21+
display: flex;
22+
justify-content: center;
23+
}
24+
input {
25+
width: 300px;
26+
}
27+
`]
28+
})
29+
export class BookSearchComponent {
30+
searchTerms: FormControl = new FormControl();
31+
32+
@Input() set value(val: string) {
33+
this.searchTerms.setValue(val, { onlySelf: true, emitEvent: false });
34+
}
35+
36+
@Output() search = new EventEmitter<string>();
37+
38+
ngOnInit() {
39+
this.searchTerms
40+
.valueChanges
41+
.debounceTime(500)
42+
.filter(terms => terms != '' && terms !== this.value)
43+
.subscribe(this.search);
44+
}
45+
}

src/app/google-books.service.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'rxjs/add/operator/map';
2+
import { Injectable } from '@angular/core';
3+
import { Http } from '@angular/http';
4+
import { Observable } from 'rxjs/Observable';
5+
import { Book } from './book-model';
6+
7+
@Injectable()
8+
export class GoogleBooksService {
9+
private API_PATH = 'https://www.googleapis.com/books/v1/volumes';
10+
11+
constructor(private http: Http) {}
12+
13+
searchBooks(queryTitle: string): Observable<Book[]> {
14+
return this.http.get(`${this.API_PATH}?q=${queryTitle}`)
15+
.catch(() => {
16+
if (queryTitle === 'RxJS') {
17+
return this.http.get('/assets/rxjs.json');
18+
} else if (queryTitle === 'Star Wars Bloodline') {
19+
return this.http.get('/assets/starwars.json');
20+
} else {
21+
return this.http.get('/assets/empty.json');
22+
}
23+
})
24+
.map(res => res.json().items || []);
25+
}
26+
}

0 commit comments

Comments
 (0)