Changeset 380

Show
Ignore:
Timestamp:
11/14/07 00:22:10 (2 years ago)
Author:
eevee
Message:

Replaced the table with links to the search when the table would have > 50 rows. Displayed 'other' moves. Bit of cleanup. (#81)

Location:
veekun/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee/Controller/Dex.pm

    r379 r380  
    1616# TODO: move this somewhere shared 
    1717my $MAX_WILDCARD_RESULTS = 10;  # maximum wildcard matches per category 
     18my $MAX_LEARNERS = 50;  # maximum learners per method on a move page 
    1819 
    1920=head1 NAME 
     
    982983        my $method = 'other'; 
    983984        $method = $pm->method if $valid_methods{ $pm->method }; 
    984         for my $ver (split /,/, $pm->version) { 
     985        my @versions; 
     986 
     987        if ($method eq 'other') { 
     988            # XXX: this will break if there are more other moves than the max 
     989            @versions = ('all'); 
     990        } else { 
     991            @versions = split /,/, $pm->version; 
     992        } 
     993 
     994        for my $ver (@versions) { 
    985995            $pokemon_hash{$method}{$pm->pokeid}{pokemon} ||= $pm->pokemon; 
    986996            $pokemon_hash{$method}{$pm->pokeid}{$ver} = $pm->level || 1; 
     
    9911001    my %learners;  # method => [ version => level, pokemon => pokemon ] 
    9921002    for my $method (keys %pokemon_hash) { 
    993         @{ $learners{$method} } = sort { $a->{pokemon}->name cmp $b->{pokemon}->name } values %{ $pokemon_hash{$method} }; 
     1003        my @sorted_learners = sort { 
     1004            $a->{pokemon}->name cmp $b->{pokemon}->name 
     1005        } values %{ $pokemon_hash{$method} }; 
     1006         
     1007        if (@sorted_learners > $MAX_LEARNERS) { 
     1008            $learners{$method} = {}; 
     1009            for my $learner_hash (@sorted_learners) { 
     1010                for my $version (keys %$learner_hash) { 
     1011                    $learners{$method}{$version}++; 
     1012                } 
     1013            } 
     1014        } else { 
     1015            $learners{$method} = \@sorted_learners; 
     1016        } 
    9941017    } 
    9951018 
  • veekun/trunk/templates/dex/page/move.tt

    r379 r380  
    178178<!-- ####################################################################### --> 
    179179 
     180<h1>Pok&eacute;mon</h1> 
     181<p> <a href="[% c.uri_for('pokemon/search', { move => this.name }) %]"><img src="/images/see-also.png" alt="See also:"/> All [% pokemon_count %] in the Pok&eacute;mon search</a> </p> 
     182 
    180183[% learn_versions = ['rb','y','gs','c','rusa','frlg','dp'] %] 
    181184 
    182185[% IF learners.level %] 
    183186<h2>By leveling up</h2> 
     187<p class="total">[% learners.level.size %] Pok&eacute;mon</p> 
    184188<table cellspacing="0" class="dex-table dex-pokemon"> 
    185189<tr class="heading"> 
     
    211215[%     END %] 
    212216</table> 
    213 <div class="total">Level-up Pok&eacute;mon: [% learners.level.size %]</div> 
    214217[% END %] 
    215218 
     
    219222[% tutor_versions = ['c','e','frlg','dp'] %] 
    220223[% machine_versions = ['rby','gsc','rsfl','dp'] %] 
     224[% other_versions = [] %] 
    221225[% versions_map = { 'rby' => 'y', 'gsc' => 'c', 'rsfl' => 'rusa' } %] 
    222226 
    223 <h1>Pok&eacute;mon</h1> 
    224 <p> <a href="[% c.uri_for('pokemon/search', { move => this.name }) %]"><img src="/images/see-also.png" alt="See also:"/> This move in the Pok&eacute;mon search</a> </p> 
    225  
    226227[%# TODO: yellow/crystal-only TMs %] 
    227228 
    228 [% FOREACH method IN ['machine', 'egg', 'tutor'] %] 
     229[% FOREACH method IN ['machine', 'egg', 'tutor', 'other'] %] 
    229230[%     NEXT IF NOT learners.exists(method) %] 
    230231[%     list = learners.$method %] 
     232[%     tmp = method _ '_versions'; our_versions = $tmp %] 
    231233<h2>[% method | ucfirst %]</h2> 
     234[%     IF list.exists('pokemon')  # this is a too-big hash %] 
     235<p> Too many to list! </p> 
     236<ul> 
     237[%         FOR version IN our_versions %] 
     238[%             specific_version = versions_map.exists(version) ? versions_map.$version : version %] 
     239    <li> <a href="[% c.uri_for('pokemon/search', { move => this.name, move_method => method, move_version => specific_version }) %]">[% Icons.$version +%] [%+ list.$specific_version %]</a> </li> 
     240[%         END %] 
     241    <li> <a href="[% c.uri_for('pokemon/search', { move => this.name, move_method => method }) %]">Total: [% list.$specific_version %]</a> </li> 
     242</ul> 
     243[%         NEXT %] 
     244[%     END %] 
     245<p class="total">[% list.size %] Pok&eacute;mon</p> 
    232246<table cellspacing="0" class="dex-table dex-pokemon"> 
    233247<tr class="heading"> 
    234 [%     tmp = method _ '_versions'; our_versions = $tmp %] 
    235248[%     FOREACH version IN our_versions %] 
    236249    <th class="level">[% Icons.$version %]</th> 
     
    261274[%     END %] 
    262275</table> 
    263 <div class="total">[% list.size %] Pok&eacute;mon</div> 
    264 [% END %] 
    265  
    266 <hr/> 
    267 <div class="total">Total Pok&eacute;mon: [% pokemon_count %]</div> 
     276[% END %] 
    268277 
    269278<!-- ####################################################################### -->