Reduce duplicated code and simplify code related with link_to_poll method
This commit is contained in:
@@ -8,13 +8,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="poll-info">
|
<div class="poll-info">
|
||||||
<% if poll.questions.one? %>
|
<h4><%= link_to header_text, path %></h4>
|
||||||
<h4><%= link_to_poll poll.questions.first.title, poll %></h4>
|
|
||||||
<div class="dates"><%= dates %></div>
|
<div class="dates"><%= dates %></div>
|
||||||
<% else %>
|
<% if poll.questions.many? %>
|
||||||
<h4><%= link_to_poll poll.name, poll %></h4>
|
|
||||||
<div class="dates"><%= dates %></div>
|
|
||||||
|
|
||||||
<ul class="margin-top">
|
<ul class="margin-top">
|
||||||
<% poll.questions.sort_for_list.each do |question| %>
|
<% poll.questions.sort_for_list.each do |question| %>
|
||||||
<li><%= question.title %></li>
|
<li><%= question.title %></li>
|
||||||
@@ -25,9 +21,5 @@
|
|||||||
<%= render SDG::TagListComponent.new(poll, limit: 5, linkable: false) %>
|
<%= render SDG::TagListComponent.new(poll, limit: 5, linkable: false) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if poll.expired? %>
|
<%= link_to link_text, path, class: "button hollow expanded" %>
|
||||||
<%= link_to_poll t("polls.index.participate_button_expired"), poll, class: "button hollow expanded" %>
|
|
||||||
<% else %>
|
|
||||||
<%= link_to_poll t("polls.index.participate_button"), poll, class: "button hollow expanded" %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,13 +12,29 @@ class Polls::PollComponent < ApplicationComponent
|
|||||||
t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date))
|
t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date))
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_poll(text, poll, options = {})
|
def header_text
|
||||||
if can?(:results, poll)
|
if poll.questions.one?
|
||||||
link_to text, results_poll_path(id: poll.slug || poll.id), options
|
poll.questions.first.title
|
||||||
elsif can?(:stats, poll)
|
|
||||||
link_to text, stats_poll_path(id: poll.slug || poll.id), options
|
|
||||||
else
|
else
|
||||||
link_to text, poll_path(id: poll.slug || poll.id), options
|
poll.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def link_text
|
||||||
|
if poll.expired?
|
||||||
|
t("polls.index.participate_button_expired")
|
||||||
|
else
|
||||||
|
t("polls.index.participate_button")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def path
|
||||||
|
if can?(:results, poll)
|
||||||
|
results_poll_path(id: poll.slug || poll.id)
|
||||||
|
elsif can?(:stats, poll)
|
||||||
|
stats_poll_path(id: poll.slug || poll.id)
|
||||||
|
else
|
||||||
|
poll_path(id: poll.slug || poll.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user