about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-09-24 19:15:55 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-09-24 19:15:55 -0400
commit687299b33934d25017a226ba6b979e44f0b1f441 (patch)
treeb013bbc0384ac691fcb359a78e7e0234c3eb34f5 /app
parent2721f3768ebd4d279caa967bee210249d93f92cb (diff)
downloadpokeviewer-687299b33934d25017a226ba6b979e44f0b1f441.tar.gz
pokeviewer-687299b33934d25017a226ba6b979e44f0b1f441.tar.bz2
pokeviewer-687299b33934d25017a226ba6b979e44f0b1f441.zip
Added box names
Diffstat (limited to 'app')
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb6
-rw-r--r--app/models/pokeviewer/box.rb29
-rw-r--r--app/models/pokeviewer/trainer.rb20
-rw-r--r--app/views/pokeviewer/pokemon/index.html.haml6
4 files changed, 39 insertions, 22 deletions
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index 404716a..3409a5f 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb
@@ -22,6 +22,12 @@ module Pokeviewer
22 end 22 end
23 end 23 end
24 24
25 args["boxes"].each_with_index do |box_name,index|
26 box = Box.find_or_initialize_by(trainer: game, number: index)
27 box.name = box_name
28 box.save!
29 end
30
25 game.pokemon.clear 31 game.pokemon.clear
26 32
27 args["pokemon"].each do |param| 33 args["pokemon"].each do |param|
diff --git a/app/models/pokeviewer/box.rb b/app/models/pokeviewer/box.rb new file mode 100644 index 0000000..090175e --- /dev/null +++ b/app/models/pokeviewer/box.rb
@@ -0,0 +1,29 @@
1module Pokeviewer
2 class Box < ApplicationRecord
3 belongs_to :trainer
4
5 validates :name, presence: true
6
7 validates :number, presence: true,
8 numericality: {
9 greater_than_or_equal_to: 0,
10 less_than: 14,
11 only_integer: true },
12 uniqueness: { scope: :trainer_id }
13
14 def contents
15 pokes = trainer.pokemon.where(box: number).order("slot ASC").to_a
16
17 result = []
18 (0..29).each do |i|
19 if pokes.empty? or (pokes.first.slot == i)
20 result << pokes.shift
21 else
22 result << nil
23 end
24 end
25
26 result
27 end
28 end
29end
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index d3a5b91..f890d61 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb
@@ -3,6 +3,7 @@ module Pokeviewer
3 extend Enumerize 3 extend Enumerize
4 4
5 has_many :pokemon, dependent: :nullify 5 has_many :pokemon, dependent: :nullify
6 has_many :boxes, -> { order("number ASC") }, dependent: :destroy
6 7
7 validates :number, presence: true, 8 validates :number, presence: true,
8 numericality: { greater_than_or_equal_to: 0, only_integer: true } 9 numericality: { greater_than_or_equal_to: 0, only_integer: true }
@@ -22,24 +23,5 @@ module Pokeviewer
22 def party 23 def party
23 pokemon.where(box: nil).order("slot ASC") 24 pokemon.where(box: nil).order("slot ASC")
24 end 25 end
25
26 def boxes
27 (0..13).map { |i| box(i) }
28 end
29
30 def box(number)
31 pokes = pokemon.where(box: number).order("slot ASC").to_a
32
33 result = []
34 (0..29).each do |i|
35 if pokes.empty? or (pokes.first.slot == i)
36 result << pokes.shift
37 else
38 result << nil
39 end
40 end
41
42 result
43 end
44 end 26 end
45end 27end
diff --git a/app/views/pokeviewer/pokemon/index.html.haml b/app/views/pokeviewer/pokemon/index.html.haml index 69b6a68..e536080 100644 --- a/app/views/pokeviewer/pokemon/index.html.haml +++ b/app/views/pokeviewer/pokemon/index.html.haml
@@ -10,11 +10,11 @@
10 %li 10 %li
11 %span.party-icon= image_tag p.icon_path 11 %span.party-icon= image_tag p.icon_path
12 %span.party-name= link_to p.revisions.last.nickname, p 12 %span.party-name= link_to p.revisions.last.nickname, p
13 - trainer.boxes.each_with_index do |box,bid| 13 - trainer.boxes.each do |box|
14 .pc-box 14 .pc-box
15 %h3= "Box #{bid+1}" 15 %h3= box.name
16 %table.pc-contents 16 %table.pc-contents
17 - box.each_slice(6) do |row| 17 - box.contents.each_slice(6) do |row|
18 %tr 18 %tr
19 - row.each do |p| 19 - row.each do |p|
20 %td.pc-pokemon 20 %td.pc-pokemon