about summary refs log tree commit diff stats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/pokeviewer/pokemon_controller.rb67
1 files changed, 64 insertions, 3 deletions
diff --git a/app/controllers/pokeviewer/pokemon_controller.rb b/app/controllers/pokeviewer/pokemon_controller.rb index 17bd83d..f9f6c15 100644 --- a/app/controllers/pokeviewer/pokemon_controller.rb +++ b/app/controllers/pokeviewer/pokemon_controller.rb
@@ -3,12 +3,73 @@ require_dependency "pokeviewer/application_controller"
3module Pokeviewer 3module Pokeviewer
4 class PokemonController < ApplicationController 4 class PokemonController < ApplicationController
5 def index 5 def index
6 @trainers = Trainer.all 6 pokemon = Pokemon.joins(:revisions).
7 @unaccounted = Pokemon.where(trainer: nil) 7 order("trainer_id IS NULL DESC").
8 order(trainer_id: :asc).
9 order(box: :asc).
10 order(slot: :asc).
11 order("pokeviewer_revisions.sequential_id DESC").
12 group("pokeviewer_pokemon.uuid").
13 select(:box, :slot, :uuid, :trainer_id, :species_id).
14 select(:ot_gender, :ot_name, :unown_letter).
15 select("pokeviewer_revisions.nickname AS nickname").
16 chunk do |p|
17 if p.trainer_id.nil?
18 -1
19 else
20 p.trainer_id
21 end
22 end
23
24 if pokemon.peek.first == -1
25 @unaccounted = pokemon.next.second
26 else
27 @unaccounted = []
28 end
29
30 @trainers = Trainer.order(id: :asc).all.map do |trainer|
31 if trainer.id == pokemon.peek.first
32 party = []
33
34 boxes = (1..14).map do |i|
35 {
36 name: trainer.box_name(i),
37 pokemon: [nil] * 30
38 }
39 end
40
41 pokemon.next.second.chunk do |p|
42 if p.box.nil?
43 -1
44 else
45 p.box
46 end
47 end.each do |box, pokes|
48 if box == -1
49 party = pokes
50 else
51 boxes[box-1][:pokemon] = (0..29).map do |i|
52 if not pokes.empty? and (pokes.first.slot == i)
53 pokes.shift
54 else
55 nil
56 end
57 end
58 end
59 end
60
61 [trainer, party, boxes]
62 else
63 nil
64 end
65 end.compact
8 end 66 end
9 67
10 def show 68 def show
11 @pokemon = Pokemon.find_by_uuid! params[:id] 69 @pokemon = Pokemon.includes(
70 :trainer, :species, :location,
71 revisions: [:item, :move_1, :move_2, :move_3, :move_4]
72 ).find_by_uuid! params[:id]
12 end 73 end
13 end 74 end
14end 75end