diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/package.json b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/package.json index a0e89870..4698f430 100644 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/package.json +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/package.json @@ -19,13 +19,15 @@ "@angular/platform-browser": "~2.4.0", "@angular/platform-browser-dynamic": "~2.4.0", "@angular/router": "~3.4.0", + "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.20", + "angular-in-memory-web-api": "^0.2.4", "core-js": "^2.4.1", "rxjs": "5.0.1", "zone.js": "^0.7.4" }, "devDependencies": { + "@types/jasmine": "2.5.38", "@types/node": "^6.0.45", - "@types/jasmine": "^2.5.35", "angular2-template-loader": "^0.6.0", "awesome-typescript-loader": "^3.0.0-beta.18", "css-loader": "^0.26.1", diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app-routing.module.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app-routing.module.ts new file mode 100644 index 00000000..2dc7c625 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app-routing.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; + +import { HeroesComponent } from './components/heroes/heroes.component'; +import { DashboardComponent } from './components/dashboard/dashboard.component'; +import { HeroDetailComponent } from './components/hero-detail/hero-detail.component'; + +const routes: Routes = [ + { path: '', redirectTo: '/dashboard', pathMatch: 'full' }, + { path: 'dashboard', component: DashboardComponent }, + { path: 'detail/:id', component: HeroDetailComponent }, + { path: 'heroes', component: HeroesComponent } +]; +@NgModule({ + imports: [ RouterModule.forRoot(routes) ], + exports: [ RouterModule ] +}) +export class AppRoutingModule {} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.spec.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.spec.ts deleted file mode 100644 index 87beafad..00000000 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { AppComponent } from './app.component'; -describe('App', () => { - beforeEach(() => { - TestBed.configureTestingModule({ declarations: [AppComponent]}); - }); - it ('should work', () => { - let fixture = TestBed.createComponent(AppComponent); - expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); - }); -}); \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.ts index 750ee915..71ec2c3e 100644 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.ts +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.component.ts @@ -1,50 +1,34 @@ import { Component } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +import { HeroesComponent } from './components/heroes/heroes.component'; +import { DashboardComponent } from './components/dashboard/dashboard.component'; @Component({ - selector: 'tour-of-heroes', - templateUrl: './app.tour-of-heroes.html', - styleUrls: ['./app.tour-of-heroes.css'], + //moduleId: module.id, + selector: 'my-app', + template: ` +

{{title}}

+
+ +
+ + ` }) - export class AppComponent { - title = `Tour of Heroes`; - selectedHero: Hero; - heroes = HEROES; - badheroes = BADHEROES; - - onSelect(hero: Hero):void { - this.selectedHero = hero; - } + title = 'Tour of Heroes'; } -const HEROES: Hero[] = [ - { id: 11, name: 'Mr. Nice', img: 'https://upload.wikimedia.org/wikipedia/en/7/79/Mr._Nice.jpg' }, - { id: 12, name: 'Narco', img: 'https://s-media-cache-ak0.pinimg.com/236x/cb/1e/21/cb1e217af38d3c8e6658ff0322fca52b.jpg' }, - { id: 13, name: 'Bombasto', img: 'https://hydra-media.cursecdn.com/solsticearena.gamepedia.com/thumb/2/2e/Portrait_bombast.png/225px-Portrait_bombast.png?version=5684639074fe5ec7f58083d0b9e1e04e'}, - { id: 14, name: 'Celeritas', img: 'http://www.cardiacathletes.com/images/superheroes/superhero-3.png' }, - { id: 15, name: 'Magneta', img: 'http://vignette4.wikia.nocookie.net/marveldatabase/images/f/fd/MC2_Magneta.png/revision/latest?cb=20120409045056' }, - { id: 16, name: 'RubberMan', img: 'http://images.buycostumes.com/mgen/merchandiser/802980.jpg?zm=1600,1600,1,0,0' }, - { id: 17, name: 'Dynama', img: 'http://orig10.deviantart.net/ad33/f/2008/275/7/6/dynamo_via_hero_creator_by_gwhitmore.png' }, - { id: 18, name: 'Dr IQ', img: 'http://dresdencodak.com/images/costume/drstrange' }, - { id: 19, name: 'Magma', img: 'http://1.bp.blogspot.com/-3kcOLFqmjfg/VHavDweTvqI/AAAAAAAABJ0/TWUql7iB-1o/s1600/279.png' }, - { id: 20, name: 'Tornado', img: 'http://i283.photobucket.com/albums/kk286/skarth7/Renders/GreatTornado.png' } -]; - -const BADHEROES: Hero[] = [ - { id: 211, name: 'Ultron', img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/03/537bc76411307/standard_xlarge.jpg' }, - { id: 212, name: 'Loki', img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/03/537bc76411307/standard_xlarge.jpg' }, - { id: 213, name: 'Red Skull' , img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/03/526036550cd37/standard_xlarge.jpg'}, - { id: 214, name: 'Mystique', img: 'https://i.annihil.us/u/prod/marvel/i/mg/5/03/5390dc2225782/standard_xlarge.jpg' }, - { id: 215, name: 'Thanos', img: 'https://i.annihil.us/u/prod/marvel/i/mg/a/10/537bc68747ccf/standard_xlarge.jpg' }, - { id: 216, name: 'Ronan', img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/f0/5260363fc40f2/standard_xlarge.jpg' }, - { id: 217, name: 'Magneto', img: 'https://i.annihil.us/u/prod/marvel/i/mg/3/b0/5261a7e53f827/standard_xlarge.jpg' }, - { id: 218, name: 'Dr. Doom', img: 'https://i.annihil.us/u/prod/marvel/i/mg/3/60/53176bb096d17/standard_xlarge.jpg' }, - { id: 219, name: 'Green Goblin', img: 'https://i.annihil.us/u/prod/marvel/i/mg/f/40/538cf0c2acdd9/standard_xlarge.jpg' }, - { id: 220, name: 'Black Cat', img: 'https://i.annihil.us/u/prod/marvel/i/mg/e/03/526952357d91c/standard_xlarge.jpg' } -]; - -export class Hero { - id: number; - name: string; - img: string; -} \ No newline at end of file +RouterModule.forRoot([ + { + path: 'heroes', + component: HeroesComponent + }, + { + path: 'dashboard', + component: DashboardComponent + }, +]); \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.module.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.module.ts index 89a8972e..437507d8 100644 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.module.ts +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.module.ts @@ -1,15 +1,40 @@ -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { FormsModule } from '@angular/forms'; +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { FormsModule } from '@angular/forms'; +import { ReactiveFormsModule } from '@angular/forms'; +import { HttpModule } from '@angular/http'; +import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; +import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; -import { AppComponent } from './app.component'; +import { AppRoutingModule } from './app-routing.module'; +import { AppComponent } from './app.component'; +import { HeroesComponent } from './components/heroes/heroes.component'; +import { HeroDetailComponent } from './components/hero-detail/hero-detail.component'; +import { DashboardComponent } from './components/dashboard/dashboard.component'; +import { HeroSearchComponent } from './components/hero-search/hero-search.component'; + +import { HeroService } from './services/hero.service'; +import { InMemoryDataService } from './data/in-memory-data.service'; @NgModule({ imports: [ BrowserModule, - FormsModule + FormsModule, + ReactiveFormsModule, + HttpModule, + InMemoryWebApiModule.forRoot(InMemoryDataService), + AppRoutingModule, + NgbModule.forRoot() + ], + declarations: [ + AppComponent, + HeroesComponent, + HeroDetailComponent, + DashboardComponent, + HeroSearchComponent, ], - declarations: [ AppComponent ], + providers: [ HeroService ], bootstrap: [ AppComponent ] }) + export class AppModule { } diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.tour-of-heroes.html b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.tour-of-heroes.html deleted file mode 100644 index da5ed959..00000000 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.tour-of-heroes.html +++ /dev/null @@ -1,28 +0,0 @@ -

{{title}}

-
-

{{selectedHero.name}} details!

-
{{selectedHero.id}}
-
-
-
- -
-

My Heroes

- -
-
-

My Bad Heroes

- -
diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.css b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.css new file mode 100644 index 00000000..98491188 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.css @@ -0,0 +1,51 @@ +/* Master Styles */ +h1 { + color: #369; + font-family: Arial, Helvetica, sans-serif; + font-size: 250%; +} +h2, h3 { + color: #444; + font-family: Arial, Helvetica, sans-serif; + font-weight: lighter; +} +body { + margin: 2em; +} +body, input[text], button { + color: #888; + font-family: Cambria, Georgia; +} +/* . . . */ +/* everywhere else */ +* { + font-family: Arial, Helvetica, sans-serif; +} +h1 { + font-size: 1.2em; + color: #999; + margin-bottom: 0; +} +h2 { + font-size: 2em; + margin-top: 0; + padding-top: 0; +} +nav a { + padding: 5px 10px; + text-decoration: none; + margin-top: 10px; + display: inline-block; + background-color: #eee; + border-radius: 4px; +} +nav a:visited, a:link { + color: #607D8B; +} +nav a:hover { + color: #039be5; + background-color: #CFD8DC; +} +nav a.active { + color: #039be5; +} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.html b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.html new file mode 100644 index 00000000..47604bbc --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.html @@ -0,0 +1,18 @@ +
+

Top Heroes

+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.ts new file mode 100644 index 00000000..b71471aa --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/dashboard/dashboard.component.ts @@ -0,0 +1,22 @@ +import { Component, OnInit } from '@angular/core'; + +import { Hero } from '../../shared/hero'; +import { HeroService } from '../../services/hero.service'; + +@Component({ + //moduleId: module.id, + selector: 'my-dashboard', + templateUrl: './dashboard.component.html', + styleUrls: ['./dashboard.component.css'], +}) +export class DashboardComponent implements OnInit { + + heroes: Hero[] = []; + + constructor(private heroService: HeroService) { } + + ngOnInit(): void { + this.heroService.getHeroes() + .then(heroes => this.heroes = heroes.slice(1, 5)); + } +} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.component.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.component.ts new file mode 100644 index 00000000..bcaea932 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.component.ts @@ -0,0 +1,66 @@ +import 'rxjs/add/operator/switchMap'; +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Params } from '@angular/router'; +import { Location } from '@angular/common'; +import { FormControl, FormGroup, FormBuilder, Validators } from '@angular/forms'; + +import { Hero } from '../../shared/hero'; +import { HeroService } from '../../services/hero.service'; + +@Component({ + //moduleId: module.id, + selector: 'my-hero-detail', + templateUrl: './hero-detail.my-hero-detail.html', + styleUrls: ['./hero-detail.my-hero-detail.css'], +}) +export class HeroDetailComponent implements OnInit { + hero: Hero; + heroForm: FormGroup; + + constructor( + private heroService: HeroService, + private route: ActivatedRoute, + private location: Location, + private fb: FormBuilder, + ) { + + } + + createForm() { + this.heroForm = this.fb.group({ + id: ['', Validators.required], + name: ['', Validators.required], + img: '', + }) + } + + saveHero(){ + this.heroService.update(this.heroForm.value) + .then(() => this.goBack()); + } + + ngOnInit(): void { + + this.createForm(); + this.route.params + .switchMap((params: Params) => this.heroService.getHero(+params['id'])) + .subscribe(hero => { + this.hero = hero; + this.heroForm = this.fb.group({ + id: [this.hero.id, Validators.required], + name: [this.hero.name, Validators.required], + img: this.hero.img, + }) + }); + } + + save(): void { + console.log(this.hero); + this.heroService.update(this.hero) + .then(() => this.goBack()); + } + + goBack(): void { + this.location.back(); + } +} diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.my-hero-detail.css b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.my-hero-detail.css new file mode 100644 index 00000000..e69de29b diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.my-hero-detail.html b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.my-hero-detail.html new file mode 100644 index 00000000..753d5b62 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-detail/hero-detail.my-hero-detail.html @@ -0,0 +1,24 @@ +
+

{{hero.name}} details!

+
+
+
+ + +
+ +

Update using reactive Forms

+
+
+ +
+
+ +
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-search/hero-search.component.html b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-search/hero-search.component.html new file mode 100644 index 00000000..093caf64 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-search/hero-search.component.html @@ -0,0 +1,10 @@ +
+

Hero Search

+ +
+
+ {{hero.name}} +
+
+
\ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-search/hero-search.component.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-search/hero-search.component.ts new file mode 100644 index 00000000..6e0b50d4 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/hero-search/hero-search.component.ts @@ -0,0 +1,52 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; +import { Subject } from 'rxjs/Subject'; + +import 'rxjs/add/observable/of'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/debounceTime'; +import 'rxjs/add/operator/distinctUntilChanged'; + +import { HeroSearchService } from '../../services/hero-search.service'; +import { Hero } from '../../shared/hero'; + +@Component({ + selector: 'hero-search', + templateUrl: './hero-search.component.html', + providers: [HeroSearchService] +}) +export class HeroSearchComponent implements OnInit { + heroes: Observable; + private searchTerms = new Subject(); + + constructor( + private heroSearchService: HeroSearchService, + private router: Router) {} + + // Push a search term into the observable stream. + search(term: string): void { + this.searchTerms.next(term); + } + + ngOnInit(): void { + this.heroes = this.searchTerms + .debounceTime(300) // wait 300ms after each keystroke before considering the term + .distinctUntilChanged() // ignore if next search term is same as previous + .switchMap(term => term // switch to new observable each time the term changes + // return the http search observable + ? this.heroSearchService.search(term) + // or the observable of empty heroes if there was no search term + : Observable.of([])) + .catch(error => { + // TODO: add real error handling + console.log(error); + return Observable.of([]); + }); + } + + gotoDetail(hero: Hero): void { + let link = ['/detail', hero.id]; + this.router.navigate(link); + } +} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.component.spec.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.component.spec.ts new file mode 100644 index 00000000..299e3ded --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.component.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; +import { HeroesComponent } from './heroes.component'; + +describe('App', () => { + beforeEach(() => { + TestBed.configureTestingModule({declarations: [HeroesComponent]}); + }); + it ('should work', () => { + let fixture = TestBed.createComponent(HeroesComponent); + expect(fixture.componentInstance instanceof HeroesComponent).toBe(true, 'should create AppComponent'); + }); +}); \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.component.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.component.ts new file mode 100644 index 00000000..45ad776f --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.component.ts @@ -0,0 +1,64 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Hero } from '../../shared/hero'; +import { HeroService } from '../../services/hero.service'; + +@Component({ + selector: 'my-heroes', + templateUrl: './heroes.tour-of-heroes.html', + styleUrls: ['./heroes.tour-of-heroes.css'], + providers: [HeroService] +}) + +export class HeroesComponent implements OnInit { + heroes: Hero[]; + badheroes : Hero[]; + selectedHero: Hero; + + constructor( + private router: Router, + private heroService: HeroService) { } + + getHeroes(): void { + this.heroService.getHeroes().then(heroes => this.heroes = heroes); + } + + getBadHeroes(): void { + this.heroService.getBadHeroes().then(badheroes => this.badheroes = badheroes); + } + + ngOnInit(): void { + this.getHeroes(); + this.getBadHeroes(); + } + + onSelect(hero: Hero):void { + this.selectedHero = hero; + } + + add(name: string): void { + name = name.trim(); + if (!name) { return; } + this.heroService.create(name) + .then(hero => { + this.heroes.push(hero); + this.selectedHero = null; + }); + } + + delete(hero: Hero): void { + this.heroService + .delete(hero.id) + .then(() => { + this.heroes = this.heroes.filter(h => h !== hero); + if (this.selectedHero === hero) { this.selectedHero = null; } + }); + } + + gotoDetail(): void { + this.router.navigate(['/detail', this.selectedHero.id]); + } +} + + diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.tour-of-heroes.css b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.tour-of-heroes.css similarity index 74% rename from homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.tour-of-heroes.css rename to homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.tour-of-heroes.css index fcba55c3..676ae297 100644 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/app.tour-of-heroes.css +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.tour-of-heroes.css @@ -6,7 +6,7 @@ margin: 0 0 2em 0; list-style-type: none; padding: 0; - width: 15em; + width: 20em; } .heroes li { cursor: pointer; @@ -14,8 +14,6 @@ left: 0; background-color: #EEE; margin: .5em; - padding: .3em 0; - height: 1.6em; border-radius: 4px; } .heroes li.selected:hover { @@ -29,28 +27,17 @@ } .heroes .text { position: relative; - top: -3px; } .heroes .badge { display: inline-block; font-size: small; color: white; - padding: 0.8em 0.7em 0 0.7em; - background-color: #607D8B; - line-height: 1em; + line-height: inherit; + background-color: #0275d8; position: relative; - left: -1px; - top: -4px; - height: 1.8em; margin-right: .8em; - border-radius: 4px 0 0 4px; + border-radius: 50% ; } - -.col-xs-6 { - width: 50%; - float: left; -} - .heroe-image { width: 150px; height: 150px; @@ -59,4 +46,8 @@ } .heroe-image img { max-width: 100%; -} \ No newline at end of file +} +.col-xs-4 { + width: 33.3%; + float: left; +} diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.tour-of-heroes.html b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.tour-of-heroes.html new file mode 100644 index 00000000..223ba124 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/components/heroes/heroes.tour-of-heroes.html @@ -0,0 +1,44 @@ +
+
+ + +
+
+

Good Heroes

+
    +
  • + {{hero.id}} + {{hero.name}} + +
  • +
+
+
+
+

+ {{selectedHero.name | uppercase}} is my hero +

+
{{selectedHero.id}}
+
{{selectedHero.name}}
+
+ +
+

+
+ +
\ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/data/in-memory-data.service.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/data/in-memory-data.service.ts new file mode 100644 index 00000000..9128fea5 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/data/in-memory-data.service.ts @@ -0,0 +1,18 @@ +import { InMemoryDbService } from 'angular-in-memory-web-api'; +export class InMemoryDataService implements InMemoryDbService { + createDb() { + let heroes = [ + { id: 11, name: 'Mr. Nice', img: 'https://upload.wikimedia.org/wikipedia/en/7/79/Mr._Nice.jpg' }, + { id: 12, name: 'Narco', img: 'https://s-media-cache-ak0.pinimg.com/236x/cb/1e/21/cb1e217af38d3c8e6658ff0322fca52b.jpg' }, + { id: 13, name: 'Bombasto', img: 'https://hydra-media.cursecdn.com/solsticearena.gamepedia.com/thumb/2/2e/Portrait_bombast.png/225px-Portrait_bombast.png?version=5684639074fe5ec7f58083d0b9e1e04e'}, + { id: 14, name: 'Celeritas', img: 'http://www.cardiacathletes.com/images/superheroes/superhero-3.png' }, + { id: 15, name: 'Magneta', img: 'http://vignette4.wikia.nocookie.net/marveldatabase/images/f/fd/MC2_Magneta.png/revision/latest?cb=20120409045056' }, + { id: 16, name: 'RubberMan', img: 'http://images.buycostumes.com/mgen/merchandiser/802980.jpg?zm=1600,1600,1,0,0' }, + { id: 17, name: 'Dynama', img: 'http://orig10.deviantart.net/ad33/f/2008/275/7/6/dynamo_via_hero_creator_by_gwhitmore.png' }, + { id: 18, name: 'Dr IQ', img: 'http://dresdencodak.com/images/costume/drstrange' }, + { id: 19, name: 'Magma', img: 'http://1.bp.blogspot.com/-3kcOLFqmjfg/VHavDweTvqI/AAAAAAAABJ0/TWUql7iB-1o/s1600/279.png' }, + { id: 20, name: 'Tornado', img: 'http://i283.photobucket.com/albums/kk286/skarth7/Renders/GreatTornado.png' } + ]; + return {heroes}; + } +} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/data/mock-heroes.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/data/mock-heroes.ts new file mode 100644 index 00000000..df427d20 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/data/mock-heroes.ts @@ -0,0 +1,27 @@ +import { Hero } from '../shared/hero'; + +export const HEROES: Hero[] = [ + { id: 11, name: 'Mr. Nice', img: 'https://upload.wikimedia.org/wikipedia/en/7/79/Mr._Nice.jpg' }, + { id: 12, name: 'Narco', img: 'https://s-media-cache-ak0.pinimg.com/236x/cb/1e/21/cb1e217af38d3c8e6658ff0322fca52b.jpg' }, + { id: 13, name: 'Bombasto', img: 'https://hydra-media.cursecdn.com/solsticearena.gamepedia.com/thumb/2/2e/Portrait_bombast.png/225px-Portrait_bombast.png?version=5684639074fe5ec7f58083d0b9e1e04e'}, + { id: 14, name: 'Celeritas', img: 'http://www.cardiacathletes.com/images/superheroes/superhero-3.png' }, + { id: 15, name: 'Magneta', img: 'http://vignette4.wikia.nocookie.net/marveldatabase/images/f/fd/MC2_Magneta.png/revision/latest?cb=20120409045056' }, + { id: 16, name: 'RubberMan', img: 'http://images.buycostumes.com/mgen/merchandiser/802980.jpg?zm=1600,1600,1,0,0' }, + { id: 17, name: 'Dynama', img: 'http://orig10.deviantart.net/ad33/f/2008/275/7/6/dynamo_via_hero_creator_by_gwhitmore.png' }, + { id: 18, name: 'Dr IQ', img: 'http://dresdencodak.com/images/costume/drstrange' }, + { id: 19, name: 'Magma', img: 'http://1.bp.blogspot.com/-3kcOLFqmjfg/VHavDweTvqI/AAAAAAAABJ0/TWUql7iB-1o/s1600/279.png' }, + { id: 20, name: 'Tornado', img: 'http://i283.photobucket.com/albums/kk286/skarth7/Renders/GreatTornado.png' } +]; + +export const BADHEROES: Hero[] = [ + { id: 211, name: 'Ultron', img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/03/537bc76411307/standard_xlarge.jpg' }, + { id: 212, name: 'Loki', img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/03/537bc76411307/standard_xlarge.jpg' }, + { id: 213, name: 'Red Skull' , img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/03/526036550cd37/standard_xlarge.jpg'}, + { id: 214, name: 'Mystique', img: 'https://i.annihil.us/u/prod/marvel/i/mg/5/03/5390dc2225782/standard_xlarge.jpg' }, + { id: 215, name: 'Thanos', img: 'https://i.annihil.us/u/prod/marvel/i/mg/a/10/537bc68747ccf/standard_xlarge.jpg' }, + { id: 216, name: 'Ronan', img: 'https://i.annihil.us/u/prod/marvel/i/mg/2/f0/5260363fc40f2/standard_xlarge.jpg' }, + { id: 217, name: 'Magneto', img: 'https://i.annihil.us/u/prod/marvel/i/mg/3/b0/5261a7e53f827/standard_xlarge.jpg' }, + { id: 218, name: 'Dr. Doom', img: 'https://i.annihil.us/u/prod/marvel/i/mg/3/60/53176bb096d17/standard_xlarge.jpg' }, + { id: 219, name: 'Green Goblin', img: 'https://i.annihil.us/u/prod/marvel/i/mg/f/40/538cf0c2acdd9/standard_xlarge.jpg' }, + { id: 220, name: 'Black Cat', img: 'https://i.annihil.us/u/prod/marvel/i/mg/e/03/526952357d91c/standard_xlarge.jpg' } +]; diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/services/hero-search.service.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/services/hero-search.service.ts new file mode 100644 index 00000000..99ae66c4 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/services/hero-search.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; +import { Hero } from '../shared/hero'; + +@Injectable() + +export class HeroSearchService { + constructor(private http: Http) {} + search(term: string): Observable { + return this.http + .get(`app/heroes/?name=${term}`) + .map(response => response.json().data as Hero[]); + } +} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/services/hero.service.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/services/hero.service.ts new file mode 100644 index 00000000..b3a39ff3 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/services/hero.service.ts @@ -0,0 +1,67 @@ +import { Injectable } from '@angular/core'; +import { Headers, Http } from '@angular/http'; + +import 'rxjs/add/operator/toPromise'; + +import { Hero } from '../shared/hero'; +/*import { HEROES } from '../data/mock-heroes'; +import { BADHEROES } from '../data/mock-heroes';*/ + +@Injectable() +export class HeroService { + private headers = new Headers({'Content-Type': 'application/json'}); + private heroesUrl = 'api/heroes'; // URL to web api + + constructor(private http: Http) { } + + getHeroes(): Promise { + return this.http.get(this.heroesUrl) + .toPromise() + .then(response => response.json().data as Hero[]) + .catch(this.handleError); + } + + getBadHeroes(): Promise { + return this.http.get(this.heroesUrl) + .toPromise() + .then(response => response.json().data as Hero[]) + .catch(this.handleError); + } + + getHero(id: number): Promise { + const url = `${this.heroesUrl}/${id}`; + return this.http.get(url) + .toPromise() + .then(response => response.json().data as Hero) + .catch(this.handleError); + } + + delete(id: number): Promise { + const url = `${this.heroesUrl}/${id}`; + return this.http.delete(url, {headers: this.headers}) + .toPromise() + .then(() => null) + .catch(this.handleError); + } + + create(name: string): Promise { + return this.http + .post(this.heroesUrl, JSON.stringify({name: name}), {headers: this.headers}) + .toPromise() + .then(res => res.json().data) + .catch(this.handleError); + } + update(hero: Hero): Promise { + const url = `${this.heroesUrl}/${hero.id}`; + return this.http + .put(url, JSON.stringify(hero), {headers: this.headers}) + .toPromise() + .then(() => hero) + .catch(this.handleError); + } + + private handleError(error: any): Promise { + console.error('An error occurred', error); // for demo purposes only + return Promise.reject(error.message || error); + } +} diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/shared/hero.ts b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/shared/hero.ts new file mode 100644 index 00000000..a58b0c55 --- /dev/null +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/app/shared/hero.ts @@ -0,0 +1,5 @@ +export class Hero { + id: number; + name: string; + img: string; +} \ No newline at end of file diff --git a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/public/index.html b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/public/index.html index 2867e5fb..0a16c7a3 100644 --- a/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/public/index.html +++ b/homeworks/anton.luzhanovskyi_diss1dent/angular-test-project/src/public/index.html @@ -4,10 +4,19 @@ Angular Wbpack Tour-of-heroes by Dissident + - Loading AppComponent content here ... +
+ Loading AppComponent content here ... +
+ +