improve reputation display and flash messages

This commit is contained in:
2021-05-03 21:24:06 +02:00
parent bb6b5e3362
commit 62cdf32593
6 changed files with 50 additions and 9 deletions

View File

@@ -7,5 +7,7 @@ class WowCharactersController < ProtectedController
def show def show
@wow_character = current_user.wow_characters.includes(wow_standings: { wow_reputation: { wow_reputation_tier: :wow_reputation_tier_levels }}).find(params[:id]) @wow_character = current_user.wow_characters.includes(wow_standings: { wow_reputation: { wow_reputation_tier: :wow_reputation_tier_levels }}).find(params[:id])
meta_reputation_ids = @wow_character.wow_standings.map { |standing| standing.wow_reputation.meta_wow_reputation_id }.uniq
@meta_wow_reputations = WowReputation.find(meta_reputation_ids)
end end
end end

View File

@@ -2,4 +2,19 @@
module ApplicationHelper module ApplicationHelper
include Pagy::Frontend include Pagy::Frontend
def bootstrap_class_for_flash(flash_type)
case flash_type
when 'success'
'alert-success'
when 'error'
'alert-danger'
when 'alert'
'alert-warning'
when 'notice'
'alert-primary'
else
'alert-secondary'
end
end
end end

View File

@@ -0,0 +1,8 @@
<div class="container-fluid">
<% flash.each do |type, msg| %>
<div class="alert <%= bootstrap_class_for_flash(type) %> alert-dismissible fade show" role="alert">
<%= msg %>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<% end %>
</div>

View File

@@ -13,8 +13,7 @@
<body> <body>
<%= render 'layouts/navbar' %> <%= render 'layouts/navbar' %>
<p class="notice"><%= notice %></p> <%= render partial: 'layouts/flash', flash: flash %>
<p class="alert"><%= alert %></p>
<div class="container-fluid"> <div class="container-fluid">
<%= yield %> <%= yield %>
</div> </div>

View File

@@ -1,8 +1,25 @@
<h3>Reputation</h3> <h3>Reputations</h3>
<% standings.each do |standing| %> <div class="accordion" id="wow_reputation_accordion">
<div> <% standings.each do |reputation_group| %>
<div class="accordion-item">
<h3 class="accordion-header" id="heading_<%= reputation_group[0] %>">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse_<%= reputation_group[0] %>" aria-expanded="true" aria-controls="collapse_<%= reputation_group[0] %>">
<% if reputation_group[0] %>
<%= meta_wow_reputations.find { |n| n.id == reputation_group[0] }.name %>
<% else %>
Other
<% end %>
</button>
</h3>
<div id="collapse_<%= reputation_group[0] %>" class="accordion-collapse collapse collapsed" aria-labelledby="heading_<%= reputation_group[0] %>" data-bs-parent="#wow_reputation_accordion">
<% reputation_group[1].each do |standing| %>
<div class="accordion-body">
<h5><%= standing.wow_reputation.name %></h5> <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] } %> <%= render partial: 'wow_characters/standing', locals: { standing: standing, tier: standing.wow_reputation.wow_reputation_tier.wow_reputation_tier_levels[standing.tier] } %>
</div> </div>
<% end %> <% end %>
</div>
</div>
<% end %>
</div>

View File

@@ -18,7 +18,7 @@
<div class="col-7"> <div class="col-7">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<%= render partial: 'wow_characters/reputations', locals: { standings: @wow_character.wow_standings } %> <%= render partial: 'wow_characters/reputations', locals: { standings: @wow_character.wow_standings.group_by { |standing| standing.wow_reputation.meta_wow_reputation_id }, meta_wow_reputations: @meta_wow_reputations } %>
</div> </div>
</div> </div>
</div> </div>