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