From 62cdf32593e7869e446d9952ae9960a19297f514 Mon Sep 17 00:00:00 2001 From: Etienne Ischer Date: Mon, 3 May 2021 21:24:06 +0200 Subject: [PATCH] improve reputation display and flash messages --- app/controllers/wow_characters_controller.rb | 2 ++ app/helpers/application_helper.rb | 15 ++++++++++ app/views/layouts/_flash.html.erb | 8 +++++ app/views/layouts/application.html.erb | 3 +- .../wow_characters/_reputations.html.erb | 29 +++++++++++++++---- app/views/wow_characters/show.html.erb | 2 +- 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 app/views/layouts/_flash.html.erb diff --git a/app/controllers/wow_characters_controller.rb b/app/controllers/wow_characters_controller.rb index ecc6616..3ab0c7e 100644 --- a/app/controllers/wow_characters_controller.rb +++ b/app/controllers/wow_characters_controller.rb @@ -7,5 +7,7 @@ class WowCharactersController < ProtectedController def show @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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0e0edb4..c2564db 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,4 +2,19 @@ module ApplicationHelper 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 diff --git a/app/views/layouts/_flash.html.erb b/app/views/layouts/_flash.html.erb new file mode 100644 index 0000000..5f39ada --- /dev/null +++ b/app/views/layouts/_flash.html.erb @@ -0,0 +1,8 @@ +
+ <% flash.each do |type, msg| %> + + <% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7385d45..72582a8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,8 +13,7 @@ <%= render 'layouts/navbar' %> -

<%= notice %>

-

<%= alert %>

+ <%= render partial: 'layouts/flash', flash: flash %>
<%= yield %>
diff --git a/app/views/wow_characters/_reputations.html.erb b/app/views/wow_characters/_reputations.html.erb index ff3fdb8..93c67c8 100644 --- a/app/views/wow_characters/_reputations.html.erb +++ b/app/views/wow_characters/_reputations.html.erb @@ -1,8 +1,25 @@ -

Reputation

+

Reputations

-<% standings.each do |standing| %> -
-
<%= standing.wow_reputation.name %>
- <%= render partial: 'wow_characters/standing', locals: { standing: standing, tier: standing.wow_reputation.wow_reputation_tier.wow_reputation_tier_levels[standing.tier] } %> +
+ <% standings.each do |reputation_group| %> +
+

+ +

+ +
+ <% end %>
-<% end %> diff --git a/app/views/wow_characters/show.html.erb b/app/views/wow_characters/show.html.erb index 4a70eb4..630246c 100644 --- a/app/views/wow_characters/show.html.erb +++ b/app/views/wow_characters/show.html.erb @@ -18,7 +18,7 @@
- <%= 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 } %>