Skip to content

Commit

Permalink
Started adding in Monster information
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek McDaniel committed Mar 5, 2019
1 parent f613099 commit 2209441
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppComponent } from './app.component';
import { SpellsComponent } from './components/spells/spells.component';
import { ClassesComponent } from './components/classes/classes.component';
import { SpellComponent } from './components/spell/spell.component';
import { MonsterComponent } from './components/monster/monster.component';

const routes: Routes = [
{
Expand All @@ -16,6 +17,10 @@ const routes: Routes = [
path: 'monsters',
component: MonstersComponent,
},
{
path: 'monster/:id',
component: MonsterComponent,
},
{
path: 'spells',
component: SpellsComponent,
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { ClassesComponent } from './components/classes/classes.component';
import {ClassesService} from './services/classes.service';
import { SpellComponent } from './components/spell/spell.component';
import { MonsterComponent } from './components/monster/monster.component';

@NgModule({
declarations: [
Expand All @@ -21,6 +22,7 @@ import { SpellComponent } from './components/spell/spell.component';
SpellsComponent,
ClassesComponent,
SpellComponent,
MonsterComponent,
],
imports: [
BrowserModule,
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions src/app/components/monster/monster.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="container">

<div class="col-md-12" *ngIf="monster">
<h2>{{ monster.name }}</h2>
<p>{{ monster.desc }}</p>

<div class="row">

<div class="col-md-4">

</div>

<div class="col-md-4">

</div>

<div class="col-md-4">

</div>
</div>

</div>

</div>
25 changes: 25 additions & 0 deletions src/app/components/monster/monster.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { MonsterComponent } from './monster.component';

describe('MonsterComponent', () => {
let component: MonsterComponent;
let fixture: ComponentFixture<MonsterComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MonsterComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MonsterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
37 changes: 37 additions & 0 deletions src/app/components/monster/monster.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Monster } from '../../domain/monsters';
import { MonstersService } from '../../services/monsters.service';

@Component({
selector: 'app-monster',
templateUrl: './monster.component.html',
styleUrls: ['./monster.component.css']
})
export class MonsterComponent implements OnInit {
public monster: Monster
private id: any;

constructor(
private monsterService: MonstersService,
private router: Router,
private activatedRoute: ActivatedRoute
) {

this.activatedRoute.params
.subscribe(params => {
if (params.id) {
this.id = params.id;
} else {
// redirect back to monsters
}
});


}

ngOnInit() {
this.monsterService.getMonster(this.id).subscribe(monster => { this.monster = monster; });
}

}
1 change: 1 addition & 0 deletions src/app/components/spell/spell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SpellComponent implements OnInit {
private router: Router,
private activatedRoute: ActivatedRoute
) {

this.activatedRoute.params
.subscribe(params => {
if (params.id) {
Expand Down
6 changes: 6 additions & 0 deletions src/app/services/monsters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ export class MonstersService implements OnDestroy {
return this.http.get<Monsters>(url, this.options);
}

public getMonster(id: number) {
const url = this.baseUrl + this.apiEndpoint + '/' + id;

return this.http.get<Monster>(url, this.options);
}

}

0 comments on commit 2209441

Please sign in to comment.