@@ -6,7 +6,6 @@ class Community < ActiveRecord::Base
|
||||
def participants
|
||||
users_participants = users_who_commented +
|
||||
users_who_topics_author +
|
||||
response_author_from_polls_for_proposal +
|
||||
author_from_community
|
||||
users_participants.uniq
|
||||
end
|
||||
@@ -55,14 +54,4 @@ class Community < ActiveRecord::Base
|
||||
def author_from_community
|
||||
from_proposal? ? User.where(id: proposal&.author_id) : User.where(id: investment&.author_id)
|
||||
end
|
||||
|
||||
def response_author_from_polls_for_proposal
|
||||
author_ids = []
|
||||
|
||||
Poll.where(related: proposal).each do |poll|
|
||||
author_ids += poll.questions.pluck(:author_id)
|
||||
end
|
||||
|
||||
User.by_authors(author_ids.uniq)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,6 +23,7 @@ class Poll < ActiveRecord::Base
|
||||
validates :name, presence: true
|
||||
|
||||
validate :date_range
|
||||
validate :only_one_active, unless: :public?
|
||||
|
||||
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
|
||||
|
||||
@@ -35,6 +36,10 @@ class Poll < ActiveRecord::Base
|
||||
scope :published, -> { where('published = ?', true) }
|
||||
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
||||
scope :public_for_api, -> { all }
|
||||
scope :overlaping_with, lambda { |poll|
|
||||
where('? < ends_at and ? >= starts_at', poll.starts_at.beginning_of_day, poll.ends_at.end_of_day)
|
||||
.where.not(id: poll.id)
|
||||
}
|
||||
|
||||
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }
|
||||
|
||||
@@ -97,4 +102,14 @@ class Poll < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def only_one_active
|
||||
if Poll.overlaping_with(self).any?
|
||||
errors.add(:starts_at, I18n.t('activerecord.errors.messages.another_poll_active'))
|
||||
end
|
||||
end
|
||||
|
||||
def public?
|
||||
related.nil?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -33,6 +33,7 @@ class Proposal < ActiveRecord::Base
|
||||
has_many :proposal_notifications, dependent: :destroy
|
||||
has_many :proposal_executed_dashboard_actions, dependent: :destroy
|
||||
has_many :proposal_dashboard_actions, through: :proposal_executed_dashboard_actions
|
||||
has_many :polls, as: :related
|
||||
|
||||
validates :title, presence: true
|
||||
validates :question, presence: true
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<div class="row column communities-participant">
|
||||
|
||||
<ul class="tabs" data-tabs id="communities-show-tabs">
|
||||
|
||||
<li class="tabs-title is-active">
|
||||
<%= link_to "#tab-participants" do %>
|
||||
<h3>
|
||||
<%= t("community.show.tab.participants") %>
|
||||
<span class="js-comments-count">(<%= @participants.count %>)</span>
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<% @participants.each do |participant| %>
|
||||
<%= render 'participant', participant: participant %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
5
app/views/communities/_poll.html.erb
Normal file
5
app/views/communities/_poll.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<%= link_to poll do %>
|
||||
<strong><%= poll.title %></strong>
|
||||
<% end %>
|
||||
<p class="help-text"><%= t('.take_part', from: l(poll.starts_at.to_date), to:(poll.ends_at.to_date)) %></p>
|
||||
<hr>
|
||||
37
app/views/communities/_subnav.html.erb
Normal file
37
app/views/communities/_subnav.html.erb
Normal file
@@ -0,0 +1,37 @@
|
||||
<div class="row column communities-participant">
|
||||
|
||||
<ul class="tabs" data-tabs id="communities-show-tabs">
|
||||
|
||||
<li class="tabs-title is-active">
|
||||
<%= link_to "#tab-participants" do %>
|
||||
<h3>
|
||||
<%= t("community.show.tab.participants") %>
|
||||
<span class="js-comments-count">(<%= @participants.count %>)</span>
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<% if @community.proposal.present? %>
|
||||
<li class="tabs-title">
|
||||
<%= link_to '#tab-polls' do %>
|
||||
<h3>
|
||||
<%= t('.surveys') %>
|
||||
<span class="js-comments-count">(<%= @community.proposal.polls.count %>)</span>
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<div class="tabs-content" data-tabs-content="communities-show-tabs">
|
||||
<div class="tabs-panel is-active" id="tab-participants">
|
||||
<%= render partial: 'participant', collection: @participants %>
|
||||
</div>
|
||||
|
||||
<% if @community.proposal.present? %>
|
||||
<div class="tabs-panel" id="tab-polls">
|
||||
<%= render partial: 'poll', collection: @community.proposal.polls %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -39,8 +39,14 @@
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("community.show.sidebar.participate") %></h2>
|
||||
<%= link_to t("community.show.sidebar.new_topic"), create_topic_link(@community) , class: "button expanded" %>
|
||||
|
||||
<% if @community.proposal&.polls&.current&.any? %>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t('.surveys') %></h2>
|
||||
<%= link_to t('.complete_survey'), @community.proposal.polls.current.first, class: 'button expanded hollow' %>
|
||||
<% end %>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render 'participants' %>
|
||||
<%= render 'subnav' %>
|
||||
|
||||
@@ -358,6 +358,7 @@ en:
|
||||
cannot_comment_valuation: 'You cannot comment a valuation'
|
||||
messages:
|
||||
record_invalid: "Validation failed: %{errors}"
|
||||
another_poll_active: There is another poll active for the given period
|
||||
restrict_dependent_destroy:
|
||||
has_one: "Cannot delete record because a dependent %{record} exists"
|
||||
has_many: "Cannot delete record because dependent %{record} exist"
|
||||
|
||||
@@ -1002,3 +1002,9 @@ en:
|
||||
show:
|
||||
send_notification: Send message to the community
|
||||
author: Author
|
||||
surveys: Surveys
|
||||
complete_survey: Complete the survey
|
||||
participants:
|
||||
surveys: Surveys
|
||||
poll:
|
||||
take_part: Take part from %{from} to %{to}
|
||||
|
||||
@@ -360,6 +360,7 @@ es:
|
||||
cannot_comment_valuation: 'No puedes comentar una evaluación'
|
||||
messages:
|
||||
record_invalid: 'Error de validación: %{errors}'
|
||||
another_poll_active: Hay otra encuesta activa para este periodo.
|
||||
restrict_dependent_destroy:
|
||||
has_one: "No se puede eliminar el registro porque existe una %{record} dependiente"
|
||||
has_many: "No se puede eliminar el registro porque existe %{record} dependientes"
|
||||
|
||||
@@ -1001,3 +1001,9 @@ es:
|
||||
show:
|
||||
send_notification: Enviar mensaje a la Comunidad
|
||||
author: Autor
|
||||
surveys: Encuestas
|
||||
complete_survey: Completa la encuesta
|
||||
participants:
|
||||
surveys: Encuestas
|
||||
poll:
|
||||
take_part: Participa del %{from} al %{to}
|
||||
|
||||
Reference in New Issue
Block a user