add reputation view and improve queries
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
class WowCharactersController < ProtectedController
|
||||
def index
|
||||
@wow_characters = current_user.wow_characters.all
|
||||
@wow_characters = current_user.wow_characters.includes(:wow_realm, :wow_race, :wow_class, :wow_character_medium)
|
||||
end
|
||||
|
||||
def show
|
||||
@wow_character = current_user.wow_characters.find(params[:id])
|
||||
@wow_character = current_user.wow_characters.includes(wow_standings: { wow_reputation: { wow_reputation_tier: :wow_reputation_tier_levels }}).find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class WowMountsController < ProtectedController
|
||||
def index
|
||||
@pagy, @wow_mounts = pagy(WowMount.all, items: 12)
|
||||
@pagy, @wow_mounts = pagy(WowMount.includes(:users), items: 12)
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class WowPetsController < ProtectedController
|
||||
def index
|
||||
@pagy, @wow_pets = pagy(WowPet.all, items: 12)
|
||||
@pagy, @wow_pets = pagy(WowPet.includes(:users), items: 12)
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
15
app/helpers/wow_standings_helper.rb
Normal file
15
app/helpers/wow_standings_helper.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module WowStandingsHelper
|
||||
def reput_pourcentage(standing, tier)
|
||||
max = tier.max_value
|
||||
min = tier.min_value
|
||||
value = standing.value
|
||||
|
||||
return 100 if max == min
|
||||
return value * 100 / (max - min) if max.positive? && (min.positive? || min.zero?)
|
||||
return value * -100 / (min - max) if min.negative? && (max.negative? || max.zero?)
|
||||
|
||||
0
|
||||
end
|
||||
end
|
||||
@@ -10,4 +10,6 @@ class WowReputation < ApplicationRecord
|
||||
|
||||
validates :name, presence: true
|
||||
validates :reputation_id, presence: true, uniqueness: true
|
||||
|
||||
scope :meta_reputations, -> { where(meta_wow_reputation: nil) }
|
||||
end
|
||||
|
||||
@@ -6,4 +6,6 @@ class WowReputationTierLevel < ApplicationRecord
|
||||
|
||||
validates :name, presence: true
|
||||
validates :order, presence: true, uniqueness: { scope: :wow_reputation_tier }
|
||||
|
||||
default_scope { order(:order) }
|
||||
end
|
||||
|
||||
8
app/views/wow_characters/_reputations.html.erb
Normal file
8
app/views/wow_characters/_reputations.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<h3>Reputation</h3>
|
||||
|
||||
<% standings.each do |standing| %>
|
||||
<div>
|
||||
<h5><%= standing.wow_reputation.name %></h5>
|
||||
<%= render partial: 'wow_characters/standing', locals: { standing: standing, tier: standing.wow_reputation.wow_reputation_tier.wow_reputation_tier_levels[standing.tier] } %>
|
||||
</div>
|
||||
<% end %>
|
||||
3
app/views/wow_characters/_standing.html.erb
Normal file
3
app/views/wow_characters/_standing.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="progress">
|
||||
<div class="progress-bar" role="progressbar" style="width: <%= reput_pourcentage(standing, tier) %>%" aria-valuenow="<%= standing.raw %>" aria-valuemin="<%= tier.min_value %>" aria-valuemax="<%= tier.max_value %>"><%= tier.name %></div>
|
||||
</div>
|
||||
@@ -16,6 +16,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-7">
|
||||
Post du perso
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<%= render partial: 'wow_characters/reputations', locals: { standings: @wow_character.wow_standings } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user