about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/pokeviewer/pokemon_controller.rb7
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb2
-rw-r--r--app/models/pokeviewer/pokemon.rb5
-rw-r--r--app/models/pokeviewer/trainer.rb4
4 files changed, 7 insertions, 11 deletions
diff --git a/app/controllers/pokeviewer/pokemon_controller.rb b/app/controllers/pokeviewer/pokemon_controller.rb index 7a1b9f9..86b0ea6 100644 --- a/app/controllers/pokeviewer/pokemon_controller.rb +++ b/app/controllers/pokeviewer/pokemon_controller.rb
@@ -3,14 +3,13 @@ require_dependency "pokeviewer/application_controller"
3module Pokeviewer 3module Pokeviewer
4 class PokemonController < ApplicationController 4 class PokemonController < ApplicationController
5 def index 5 def index
6 pokemon = Pokemon.joins(:revisions). 6 pokemon = Pokemon.joins(:current).
7 order("trainer_id IS NULL DESC"). 7 order("trainer_id IS NULL DESC").
8 order(trainer_id: :asc). 8 order(trainer_id: :asc).
9 order(box: :asc). 9 order(box: :asc).
10 order(slot: :asc). 10 order(slot: :asc).
11 order("pokeviewer_revisions.sequential_id DESC").
12 group("pokeviewer_pokemon.uuid"). 11 group("pokeviewer_pokemon.uuid").
13 includes(:revisions). 12 includes(:current).
14 chunk do |p| 13 chunk do |p|
15 if p.trainer_id.nil? 14 if p.trainer_id.nil?
16 -1 15 -1
@@ -70,7 +69,7 @@ module Pokeviewer
70 def show 69 def show
71 @pokemon = Pokemon.includes( 70 @pokemon = Pokemon.includes(
72 :trainer, :location, 71 :trainer, :location,
73 revisions: [:species, :item, :move_1, :move_2, :move_3, :move_4] 72 current: [:species, :item, :move_1, :move_2, :move_3, :move_4]
74 ).find_by_uuid! params[:id] 73 ).find_by_uuid! params[:id]
75 end 74 end
76 end 75 end
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index d1968af..b0999ef 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb
@@ -169,7 +169,7 @@ module Pokeviewer
169 rev.earth_ribbon = param.fetch "earthRibbon", false 169 rev.earth_ribbon = param.fetch "earthRibbon", false
170 rev.world_ribbon = param.fetch "worldRibbon", false 170 rev.world_ribbon = param.fetch "worldRibbon", false
171 171
172 if pk.revisions.empty? or rev.diff?(pk.revisions.last) 172 if pk.revisions.empty? or rev.diff?(pk.current)
173 rev.save! 173 rev.save!
174 end 174 end
175 end 175 end
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index db3da5a..012abab 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb
@@ -4,6 +4,7 @@ module Pokeviewer
4 extend ActiveModel::Naming 4 extend ActiveModel::Naming
5 5
6 has_many :revisions, -> { order "sequential_id ASC" }, dependent: :destroy 6 has_many :revisions, -> { order "sequential_id ASC" }, dependent: :destroy
7 has_one :current, -> { order "sequential_id DESC" }, class_name: "Revision"
7 8
8 belongs_to :trainer, optional: true 9 belongs_to :trainer, optional: true
9 10
@@ -76,10 +77,6 @@ module Pokeviewer
76 uuid 77 uuid
77 end 78 end
78 79
79 def current
80 revisions.last
81 end
82
83 def outsider? 80 def outsider?
84 (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) 81 (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number)
85 end 82 end
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index 281e0aa..0ea12c8 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb
@@ -39,11 +39,11 @@ module Pokeviewer
39 validates :box_14_name, presence: true 39 validates :box_14_name, presence: true
40 40
41 def party 41 def party
42 pokemon.party.includes(revisions: [:species]) 42 pokemon.party.includes(current: [:species])
43 end 43 end
44 44
45 def box(n) 45 def box(n)
46 pokemon.box(n).includes(revisions: [:species]) 46 pokemon.box(n).includes(current: [:species])
47 end 47 end
48 48
49 def box_name(n) 49 def box_name(n)