From 5ade37d852bd1e96f9451ab98619359a5a048cee Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 29 Jan 2018 21:13:35 -0500 Subject: Added Pokédex viewing page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently a work in progress. The queries used to display the Pokémon for each species are very inefficient. The text at the top of the page is also very specific to the author. --- app/helpers/pokeviewer/pokedex_helper.rb | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/helpers/pokeviewer/pokedex_helper.rb (limited to 'app/helpers') diff --git a/app/helpers/pokeviewer/pokedex_helper.rb b/app/helpers/pokeviewer/pokedex_helper.rb new file mode 100644 index 0000000..fe3e575 --- /dev/null +++ b/app/helpers/pokeviewer/pokedex_helper.rb @@ -0,0 +1,51 @@ +module Pokeviewer + module PokedexHelper + + def pokedex_table(all_species, trainers) + final_result = "".html_safe + + all_species.each do |species| + noted_trainers = species.pokedex_entries.to_a + + if noted_trainers.empty? + poke_name = "???" + poke_image = image_tag "pokeviewer/icons/0.png" + else + poke_name = species.name + poke_image = image_tag "pokeviewer/icons/#{species.id}.png" + end + + result = "".html_safe + + result << tag.th("\##{species.id}") + result << tag.th(poke_name) + result << tag.th(poke_image) + + trainers.each do |trainer| + if !noted_trainers.empty? and noted_trainers.first.trainer_id == trainer.id + nt = noted_trainers.shift + + if nt.caught + result << tag.td(trainer.display_number, + class: ["pkvd-caught", trainer.game]) + else + result << tag.td(trainer.display_number, + class: ["pkvd-seen", trainer.game]) + end + else + result << tag.td(trainer.display_number, class: "pkvd-unseen") + end + end + + result << tag.td( + species.current_revisions.map { + |p| link_to p.nickname, p.pokemon }.join(", ").html_safe) + + final_result << tag.tr(result) + end + + tag.table(final_result, class: "pkvd-table") + end + + end +end -- cgit 1.4.1