Create helper for active menus and show stats or results on poll subnav

This commit is contained in:
decabeza
2019-01-23 17:45:42 +01:00
parent 62088bc635
commit 4498c26ff7
2 changed files with 19 additions and 3 deletions

View File

@@ -49,4 +49,19 @@ module PollsHelper
question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at > vote.updated_at }
end
def show_stats_or_results?
@poll.expired? && (@poll.results_enabled? || @poll.stats_enabled?)
end
def results_menu?
controller_name == "polls" && action_name == "results"
end
def stats_menu?
controller_name == "polls" && action_name == "stats"
end
def info_menu?
controller_name == "polls" && action_name == "show"
end
end

View File

@@ -1,8 +1,9 @@
<% if show_stats_or_results? %>
<div class="row margin-top">
<div class="small-12 column">
<ul class="menu simple clear">
<% if controller_name == "polls" && action_name == "results" %>
<% if @poll.results_enabled? %>
<% if results_menu? %>
<li class="is-active">
<h2><%= t("polls.show.results_menu") %></h2>
</li>
@@ -11,8 +12,8 @@
<% end %>
<% end %>
<% if controller_name == "polls" && action_name == "stats" %>
<% if @poll.stats_enabled? %>
<% if stats_menu? %>
<li class="is-active">
<h2><%= t("polls.show.stats_menu") %></h2>
</li>
@@ -21,7 +22,7 @@
<% end %>
<% end %>
<% if controller_name == "polls" && action_name == "show" %>
<% if info_menu? %>
<li class="is-active">
<h2><%= t("polls.show.info_menu") %></h2>
</li>