Add recommended tab on proposals and debates index.

This commit is contained in:
taitus
2017-07-28 13:43:01 +02:00
parent 01a41b4706
commit fe3bb7a389
15 changed files with 92 additions and 43 deletions

View File

@@ -48,6 +48,7 @@ class Proposal < ActiveRecord::Base
scope :sort_by_relevance, -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_archival_date, -> { archived.sort_by_confidence_score }
scope :sort_by_recommended, -> { order(cached_votes_up: :desc) }
scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago) }
scope :not_archived, -> { where("proposals.created_at > ?", Setting["months_to_archive_proposals"].to_i.months.ago) }
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
@@ -56,6 +57,18 @@ class Proposal < ActiveRecord::Base
scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) }
scope :public_for_api, -> { all }
def self.recommended(user)
proposals_list = where("author_id != ?", user.id)
proposals_list_with_tagged = proposals_list.joins(:tags).where('taggings.taggable_type = ?', self.name)
.where('tags.name IN (?)', user.interests)
if proposals_list_with_tagged.any?
followed_proposals_ids = Proposal.followed_by_user(user).pluck(:id)
proposals_list = proposals_list_with_tagged.where("proposals.id NOT IN (?)", followed_proposals_ids)
end
proposals_list
end
def to_param
"#{id}-#{title}".parameterize
end
@@ -175,6 +188,12 @@ class Proposal < ActiveRecord::Base
(voters + followers).uniq
end
def self.proposals_orders(user)
orders = %w{hot_score confidence_score created_at relevance archival_date}
orders << "recommended" if user.present?
orders
end
protected
def set_responsible_name