diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ddc36c1..31eab85 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -2,9 +2,16 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {RouterModule, Routes} from '@angular/router'; import {TierComponent} from './content/tier/tier.component'; +import {ChampionshipComponent} from './championship/championship.component'; const routes: Routes = [ - {path: 'championship/:idchampionship/tier/:idtier', component: TierComponent}, + { + path: 'championship/:idchampionship', + component: ChampionshipComponent, + children: [ + {path: 'tier/:idtier', component: TierComponent}, + ] + }, ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 18e382e..aa9e8b2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,34 +4,13 @@ import {NgModule} from '@angular/core'; import {AppComponent} from './app.component'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {MatButtonModule, MatCardModule, MatCheckboxModule} from '@angular/material'; -import {RouterModule, Routes} from '@angular/router'; import {TopmenuComponent} from './topmenu/topmenu.component'; import {ReclamespinnerComponent} from './reclamespinner/reclamespinner.component'; import {PouleComponent} from './content/poule/poule.component'; import {TierComponent} from './content/tier/tier.component'; import {HttpClientModule} from '@angular/common/http'; import {AppRoutingModule} from './app-routing.module'; - -const appRoutes: Routes = [ - {path : '', pathMatch: 'full', component: AppComponent}, - { - path: 'championship/:idchampionship', - children: [ - {path: 'tier/:idtier', component: TierComponent} - ] - }, - // { path: 'hero/:id', component: HeroDetailComponent }, - // { - // path: 'heroes', - // component: HeroListComponent, - // data: { title: 'Heroes List' } - // }, - // { path: '', - // redirectTo: '/heroes', - // pathMatch: 'full' - // }, - // { path: '**', component: PageNotFoundComponent } -]; +import { ChampionshipComponent } from './championship/championship.component'; @NgModule({ declarations: [ @@ -39,7 +18,8 @@ const appRoutes: Routes = [ TopmenuComponent, ReclamespinnerComponent, PouleComponent, - TierComponent + TierComponent, + ChampionshipComponent ], imports: [ BrowserModule, diff --git a/src/app/championship.service.ts b/src/app/championship.service.ts index a07ea69..5779816 100644 --- a/src/app/championship.service.ts +++ b/src/app/championship.service.ts @@ -17,19 +17,29 @@ export class ChampionshipService implements OnInit { protected baseUrl = 'http://localhost:8080/'; private championships: any[] = []; + // these are the tiers (from 1 ... x, as defined in database) + private tiers = new BehaviorSubject([]); /** * What's the current championship? Could be null if not loaded yet. */ private idChampionship = new BehaviorSubject(null); - constructor(private http: HttpClient, private route: ActivatedRoute) { // load the champs from the DB this.loadChampionships(); + // whenever the currently set championsip changes, also update tiers + this.idChampionship.subscribe(id => { + console.log('idchamp'); + console.log(id); + if(id) { + this.loadTiers(id); + } + }); + } private loadChampionships() { @@ -40,6 +50,18 @@ export class ChampionshipService implements OnInit { }); } + loadTiers(idChampionship: number) { + this.http.get(`${this.baseUrl}championship/${idChampionship}/tiers`, this.httpOptions).subscribe(val => { + console.log('loaded tiers for championship'); + console.log(val); + this.tiers.next(val.map(v => v.tier)); + }); + } + + getTiers(): BehaviorSubject { + return this.tiers; + } + /** * Set the currently visible championship. * @param idChampionship @@ -53,9 +75,7 @@ export class ChampionshipService implements OnInit { } getCurrentChampionship() { - console.log(this.championships); const theOne = this.championships.filter(val => val.idchampionship === this.idChampionship.value); - console.log(theOne); if (theOne && theOne.length > 0) { return theOne[0]; } else { diff --git a/src/app/content/tier/tier.component.ts b/src/app/content/tier/tier.component.ts index e2dbf81..b1e2e0e 100644 --- a/src/app/content/tier/tier.component.ts +++ b/src/app/content/tier/tier.component.ts @@ -11,14 +11,8 @@ export class TierComponent implements OnInit { constructor(private route: ActivatedRoute, private championshipService: ChampionshipService) { - // mark the championservice to set the right championship - route.paramMap.subscribe(val => { - console.log(val); - this.championshipService.setChampionship(+val.get('idchampionship')); - }); } - ngOnInit() { } diff --git a/src/app/topmenu/topmenu.component.html b/src/app/topmenu/topmenu.component.html index c779440..ac91631 100644 --- a/src/app/topmenu/topmenu.component.html +++ b/src/app/topmenu/topmenu.component.html @@ -1,9 +1,6 @@
- - - - + Link
diff --git a/src/app/topmenu/topmenu.component.ts b/src/app/topmenu/topmenu.component.ts index 89b34b0..b3cefc9 100644 --- a/src/app/topmenu/topmenu.component.ts +++ b/src/app/topmenu/topmenu.component.ts @@ -10,6 +10,7 @@ import {ActivatedRoute, Router} from '@angular/router'; export class TopmenuComponent implements OnInit { private idChampionship: number; + protected tiers: number[] = []; constructor(private championshipService: ChampionshipService, private route: ActivatedRoute, @@ -17,6 +18,9 @@ export class TopmenuComponent implements OnInit { } ngOnInit() { + this.championshipService.getTiers().subscribe(tiers => { + this.tiers = tiers; + }); } currentChampionship(): string {