|
|
|
@ -4,10 +4,20 @@ import { Router, RouterOutlet, RouterLink, RouterLinkActive } from '@angular/rou |
|
|
|
import { MatToolbarModule } from '@angular/material/toolbar'; |
|
|
|
import { MatButtonModule } from '@angular/material/button'; |
|
|
|
import { MatTabsModule } from '@angular/material/tabs'; |
|
|
|
import { MatAutocompleteModule } from '@angular/material/autocomplete'; |
|
|
|
import { MatInputModule } from '@angular/material/input'; |
|
|
|
import { MatFormFieldModule } from '@angular/material/form-field'; |
|
|
|
import { AuthService } from './core/services/auth.service'; |
|
|
|
import { MatSidenavModule } from '@angular/material/sidenav'; |
|
|
|
import { MatListModule } from '@angular/material/list'; |
|
|
|
import { PokemonService } from './core/services/pokemon.service'; |
|
|
|
import { FormControl, ReactiveFormsModule } from '@angular/forms'; |
|
|
|
import { map, startWith } from 'rxjs/operators'; |
|
|
|
import { Observable } from 'rxjs'; |
|
|
|
import { Pokemon } from './core/models/pokemon.model'; |
|
|
|
import { PokemonSearchResult, SearchService } from './core/services/search.service'; |
|
|
|
import { PlanService } from './core/services/plan.service'; |
|
|
|
import { GamePlan } from './core/models/plan.model'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-root', |
|
|
|
@ -21,12 +31,39 @@ import { PokemonService } from './core/services/pokemon.service'; |
|
|
|
MatButtonModule, |
|
|
|
MatTabsModule, |
|
|
|
MatSidenavModule, |
|
|
|
MatListModule |
|
|
|
MatListModule, |
|
|
|
MatFormFieldModule, |
|
|
|
MatInputModule, |
|
|
|
MatAutocompleteModule, |
|
|
|
ReactiveFormsModule |
|
|
|
], |
|
|
|
template: ` |
|
|
|
<mat-toolbar color="primary" class="top-bar"> |
|
|
|
<div class="toolbar-left"> |
|
|
|
<span>OriginDex</span> |
|
|
|
|
|
|
|
<div class="search-container"> |
|
|
|
<mat-form-field appearance="fill" class="search-field"> |
|
|
|
<mat-label>Search Pokémon</mat-label> |
|
|
|
<input type="text" |
|
|
|
matInput |
|
|
|
[formControl]="searchControl" |
|
|
|
[matAutocomplete]="auto"> |
|
|
|
<mat-autocomplete #auto="matAutocomplete" |
|
|
|
(optionSelected)="onSearchSelect($event)" |
|
|
|
[displayWith]="displayFn"> |
|
|
|
<mat-option *ngFor="let result of filteredOptions | async" [value]="result"> |
|
|
|
{{ result.pokemon }} |
|
|
|
<span *ngIf="result.boxNumber !== undefined"> |
|
|
|
(Box {{ result.boxNumber + 1 }}) |
|
|
|
</span> |
|
|
|
<span *ngIf="result.game_id !== undefined"> |
|
|
|
({{ result.game_id }}) |
|
|
|
</span> |
|
|
|
</mat-option> |
|
|
|
</mat-autocomplete> |
|
|
|
</mat-form-field> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="image-container"> |
|
|
|
@ -104,7 +141,18 @@ import { PokemonService } from './core/services/pokemon.service'; |
|
|
|
transform: scale(1.1); /* Slightly enlarge the image on hover */ |
|
|
|
} |
|
|
|
|
|
|
|
.search-container { |
|
|
|
display: flex; |
|
|
|
justify-content: center; |
|
|
|
margin-left:20px; |
|
|
|
margin-top: 30px; |
|
|
|
} |
|
|
|
|
|
|
|
.search-field { |
|
|
|
width: 100%; |
|
|
|
max-width: 400px; |
|
|
|
min-width: 300px; |
|
|
|
} |
|
|
|
|
|
|
|
mat-toolbar { |
|
|
|
margin-bottom: 0; |
|
|
|
@ -141,21 +189,115 @@ import { PokemonService } from './core/services/pokemon.service'; |
|
|
|
}) |
|
|
|
export class AppComponent { |
|
|
|
hoveredRoute: string = ''; |
|
|
|
|
|
|
|
searchControl = new FormControl(''); |
|
|
|
filteredOptions: Observable<PokemonSearchResult[]>; |
|
|
|
|
|
|
|
pokemonGroups: (Pokemon | null)[][] = []; |
|
|
|
gamePlans: GamePlan[] = []; |
|
|
|
|
|
|
|
constructor( |
|
|
|
public auth: AuthService, |
|
|
|
public pokemonService: PokemonService, |
|
|
|
private planService: PlanService, |
|
|
|
private authService: AuthService, |
|
|
|
private router: Router |
|
|
|
private router: Router, |
|
|
|
private searchService: SearchService |
|
|
|
) { |
|
|
|
this.authService.isAuthenticated$.subscribe((isAuthenticated) => { |
|
|
|
if (isAuthenticated) { |
|
|
|
this.pokemonService.initializeCaughtPokemon(); |
|
|
|
console.log("Loading Plan") |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.filteredOptions = this.searchControl.valueChanges.pipe( |
|
|
|
startWith(''), |
|
|
|
map(value => this.filterPokemon(value)) |
|
|
|
); |
|
|
|
|
|
|
|
this.pokemonService.getPokemonBoxList().subscribe({ |
|
|
|
next: (groups) => { |
|
|
|
this.pokemonGroups = groups; |
|
|
|
}, |
|
|
|
error: (error) => { |
|
|
|
console.error('Error loading Pokemon:', error); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.planService.getPlan().subscribe( |
|
|
|
plan => { |
|
|
|
this.gamePlans = plan; |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
isRouteSelected(route: string): boolean { |
|
|
|
return this.router.url === route || this.hoveredRoute === route; |
|
|
|
} |
|
|
|
|
|
|
|
private filterPokemon(value: string | PokemonSearchResult | null): PokemonSearchResult[] { |
|
|
|
if (!value) return []; |
|
|
|
|
|
|
|
const searchTerm = typeof value === 'string' ? value.toLowerCase() : ''; |
|
|
|
if (searchTerm.length < 2) return []; // Only search with 2 or more characters
|
|
|
|
|
|
|
|
const results_map = new Map<string, PokemonSearchResult>(); |
|
|
|
|
|
|
|
if(this.isRouteSelected("/storage-carousel")){ |
|
|
|
this.pokemonGroups.forEach((group, boxIndex) => { |
|
|
|
group.forEach(pokemon => { |
|
|
|
if (pokemon && pokemon.Name.toLowerCase().includes(searchTerm)) { |
|
|
|
const uniqueKey = `${pokemon.Name}-${boxIndex}`; |
|
|
|
results_map.set(uniqueKey, { |
|
|
|
pokemon: pokemon.Name, |
|
|
|
boxNumber: boxIndex, |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
else if (this.isRouteSelected("/efficiency")) { |
|
|
|
this.gamePlans.forEach((gamePlan, planIndex) => { |
|
|
|
for (let family in gamePlan.pokemon) { |
|
|
|
if(!gamePlan.pokemon[family].evolve_to_augmented) { |
|
|
|
continue |
|
|
|
} |
|
|
|
for (let pkmn of gamePlan.pokemon[family].evolve_to_augmented) { |
|
|
|
if (pkmn.name.toLowerCase().includes(searchTerm)) { |
|
|
|
const uniqueKey = `${pkmn.name}-${gamePlan.game_name}`; |
|
|
|
results_map.set(uniqueKey, { |
|
|
|
pokemon: pkmn.name, |
|
|
|
game_id: gamePlan.game_name, |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if(!gamePlan.pokemon[family].breed_for_augmented) { |
|
|
|
continue |
|
|
|
} |
|
|
|
for (let pkmn of gamePlan.pokemon[family].breed_for_augmented) { |
|
|
|
if (pkmn.name.toLowerCase().includes(searchTerm)) { |
|
|
|
const uniqueKey = `${pkmn.name}-${gamePlan.game_name}`; |
|
|
|
results_map.set(uniqueKey, { |
|
|
|
pokemon: pkmn.name, |
|
|
|
game_id: gamePlan.game_name, |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const results: PokemonSearchResult[] = Array.from(results_map.values()); |
|
|
|
return results.slice(0, 10); // Limit to 10 results
|
|
|
|
} |
|
|
|
|
|
|
|
displayFn(result: PokemonSearchResult): string { |
|
|
|
return result?.pokemon || ''; |
|
|
|
} |
|
|
|
|
|
|
|
onSearchSelect(event: any) { |
|
|
|
const result: PokemonSearchResult = event.option.value; |
|
|
|
this.searchService.setSelectedItem(result); |
|
|
|
this.searchControl.setValue(''); |
|
|
|
} |
|
|
|
} |