Display proposals and debates recommended when user have not interests.
This commit is contained in:
@@ -321,18 +321,29 @@ class User < ActiveRecord::Base
|
||||
|
||||
def recommended_proposals
|
||||
already_followed_proposals_ids = Proposal.joins(:follows).where("follows.user_id = ?", id).pluck(:id)
|
||||
proposals_list = []
|
||||
|
||||
Proposal.tagged_with(interests, any: true).
|
||||
where("author_id != ? AND id NOT IN (?)", id, already_followed_proposals_ids).
|
||||
order("cached_votes_up DESC").limit(3)
|
||||
if already_followed_proposals_ids.any?
|
||||
proposals_list = Proposal.tagged_with(interests, any: true).
|
||||
where("author_id != ? AND id NOT IN (?)", id, already_followed_proposals_ids)
|
||||
else
|
||||
proposals_list = Proposal.where("author_id != ?", id)
|
||||
end
|
||||
|
||||
proposals_list.order("cached_votes_up DESC").limit(3)
|
||||
end
|
||||
|
||||
def recommended_budget_investments
|
||||
already_followed_investments_ids = Budget::Investment.joins(:follows).where("follows.user_id = ?", id).pluck(:id)
|
||||
investments_list = []
|
||||
if already_followed_investments_ids.any?
|
||||
investments_list = Budget::Investment.tagged_with(interests, any: true).
|
||||
where("author_id != ? AND id NOT IN (?)", id, already_followed_investments_ids)
|
||||
else
|
||||
investments_list = Budget::Investment.where("author_id != ?", id)
|
||||
end
|
||||
|
||||
Budget::Investment.tagged_with(interests, any: true).
|
||||
where("author_id != ? AND id NOT IN (?)", id, already_followed_investments_ids).
|
||||
order("cached_votes_up DESC").limit(3)
|
||||
investments_list.order("cached_votes_up DESC").limit(3)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="orbit" role="region" data-orbit data-use-m-u-i="false">
|
||||
<div class="orbit-wrapper">
|
||||
<ul class="orbit-container no-bullet" tabindex="0" >
|
||||
<% current_user.recommended_debates.each_with_index do |debate, index| %>
|
||||
<% recommended_debates.each_with_index do |debate, index| %>
|
||||
<li class="orbit-slide <%= active_class(index) %>" data-slide="<%= index %>" style="position: relative; <%= slide_display(index) %>" aria-live="polite">
|
||||
<div class="card">
|
||||
<div class="card-section">
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
|
||||
<nav class="orbit-bullets">
|
||||
<% current_user.recommended_debates.each_with_index do |debate, index| %>
|
||||
<% recommended_debates.each_with_index do |debate, index| %>
|
||||
<button data-slide="<%= index %>" class="<%= active_class(index) %>">
|
||||
<span class="show-for-sr">Second slide details.</span>
|
||||
</button>
|
||||
@@ -45,7 +45,7 @@
|
||||
<div class="orbit" role="region" data-orbit data-use-m-u-i="false">
|
||||
<div class="orbit-wrapper">
|
||||
<ul class="orbit-container no-bullet" tabindex="0" >
|
||||
<% current_user.recommended_proposals.each_with_index do |proposal, index| %>
|
||||
<% recommended_proposals.each_with_index do |proposal, index| %>
|
||||
<li class="orbit-slide <%= active_class(index) %>" data-slide="<%= index %>" style="position: relative; <%= slide_display(index) %>" aria-live="polite">
|
||||
<div class="card">
|
||||
<div class="card-section">
|
||||
@@ -61,7 +61,7 @@
|
||||
<div class="truncate"></div>
|
||||
</div>
|
||||
<nav class="orbit-bullets">
|
||||
<% current_user.recommended_proposals.each_with_index do |proposal, index| %>
|
||||
<% recommended_proposals.each_with_index do |proposal, index| %>
|
||||
<button data-slide="<%= index %>" class="<%= active_class(index) %>">
|
||||
<span class="show-for-sr">Second slide details.</span>
|
||||
</button>
|
||||
@@ -79,7 +79,7 @@
|
||||
<div class="orbit" role="region" data-orbit data-use-m-u-i="false">
|
||||
<div class="orbit-wrapper">
|
||||
<ul class="orbit-container no-bullet" tabindex="0" >
|
||||
<% current_user.recommended_budget_investments.each_with_index do |budget_investment, index| %>
|
||||
<% recommended_budget_investments.each_with_index do |budget_investment, index| %>
|
||||
<li class="orbit-slide <%= active_class(index) %>" data-slide="<%= index %>" style="position: relative; <%= slide_display(index) %>" aria-live="polite">
|
||||
<div class="card">
|
||||
<div class="card-section">
|
||||
@@ -95,7 +95,7 @@
|
||||
<div class="truncate"></div>
|
||||
</div>
|
||||
<nav class="orbit-bullets">
|
||||
<% current_user.recommended_budget_investments.each_with_index do |budget_investment, index| %>
|
||||
<% recommended_budget_investments.each_with_index do |budget_investment, index| %>
|
||||
<button data-slide="<%= index %>" class="<%= active_class(index) %>">
|
||||
<span class="show-for-sr">Second slide details.</span>
|
||||
</button>
|
||||
|
||||
@@ -46,4 +46,8 @@
|
||||
</main>
|
||||
<% end %>
|
||||
|
||||
<%= render "recommended_no_image" %>
|
||||
<% if current_user.present? %>
|
||||
<%= render "recommended_no_image", recommended_debates: current_user.recommended_debates,
|
||||
recommended_proposals: current_user.recommended_proposals,
|
||||
recommended_budget_investments: current_user.recommended_budget_investments %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user