Add following tab to user public page.

This commit is contained in:
taitus
2017-06-30 18:26:46 +02:00
committed by Senén Rodero Rodríguez
parent 52e195d837
commit 7e2e94d709
10 changed files with 79 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
class UsersController < ApplicationController
has_filters %w{proposals debates budget_investments comments}, only: :show
has_filters %w{proposals debates budget_investments comments follows}, only: :show
load_and_authorize_resource
helper_method :author?
@@ -17,7 +17,8 @@ class UsersController < ApplicationController
proposals: Proposal.where(author_id: @user.id).count,
debates: (Setting['feature.debates'] ? Debate.where(author_id: @user.id).count : 0),
budget_investments: (Setting['feature.budgets'] ? Budget::Investment.where(author_id: @user.id).count : 0),
comments: only_active_commentables.count)
comments: only_active_commentables.count,
follows: @user.follows.count)
end
def load_filtered_activity
@@ -26,7 +27,8 @@ class UsersController < ApplicationController
when "proposals" then load_proposals
when "debates" then load_debates
when "budget_investments" then load_budget_investments
when "comments" then load_comments
when "comments" then load_comments
when "follows" then load_follows
else load_available_activity
end
end
@@ -44,6 +46,9 @@ class UsersController < ApplicationController
elsif @activity_counts[:comments] > 0
load_comments
@current_filter = "comments"
elsif @activity_counts[:follows] > 0
load_follows
@current_filter = "follows"
end
end
@@ -63,8 +68,9 @@ class UsersController < ApplicationController
@budget_investments = Budget::Investment.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
end
def load_interests
@user.interests
def load_follows
@followable_types = @user.follows.pluck(:followable_type).uniq
@follows = @user.follows
end
def valid_access?

View File

@@ -52,6 +52,18 @@ module FollowsHelper
"unfollow-drop-#{entity_full_name(followable)}-#{followable.id}"
end
def entity_title(title)
entity = title.gsub('::', '/').downcase
t("activerecord.models.#{entity}.other")
end
def entity_icon(entity)
case entity
when "Proposal" then "proposals"
when "Budget::Investment" then "budget"
end
end
private
def followed?(followable)

View File

@@ -41,4 +41,4 @@ module UsersHelper
current_user && current_user.administrator?
end
end
end

View File

@@ -1,4 +1,4 @@
<%= render "following" %>
<%= render "following" if @follows.present? %>
<%= render "proposals" if @proposals.present? %>
<%= render "debates" if @debates.present? && feature?(:debates) %>
<%= render "budget_investments" if @budget_investments.present? && feature?(:budgets) %>

View File

@@ -0,0 +1,11 @@
<tr id="budget_investment_<%= budget_investment.id %>">
<td>
<%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %>
</td>
<td class="text-right">
<% if can? :destroy, budget_investment %>
<%= link_to t('shared.delete'), budget_investment_path(budget_investment.budget, budget_investment),
method: :delete, class: "button hollow alert" %>
<% end %>
</td>
</tr>

View File

@@ -1,16 +1,6 @@
<table id="budget_investments_list" class="clear activity-budget-investments">
<% @budget_investments.each do |budget_investment| %>
<tr id="budget_investment_<%= budget_investment.id %>">
<td>
<%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %>
</td>
<td class="text-right">
<% if can? :destroy, budget_investment %>
<%= link_to t('shared.delete'), budget_investment_path(budget_investment.budget, budget_investment),
method: :delete, class: "button hollow alert" %>
<% end %>
</td>
</tr>
<%= render "budget_investment", budget_investment: budget_investment %>
<% end %>
</table>

View File

@@ -1,34 +1,34 @@
<ul class="accordion" data-accordion data-allow-all-closed="true">
<% (1..2).each do |i| %>
<% @followable_types.each do |followable_type| %>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title">
<!--
ROR Need to change icon for each panel, example: use icon-proposal or icon-debates
<strong><i class="icon-proposals"></i>
Propuestas</strong>
-->
<span class="icon">
<i class="icon icon-debates"></i>
<i class="icon icon-<%= entity_icon(followable_type) %>"></i>
</span>
<span class="title">
<strong>Debate.title</strong>
<strong><%= entity_title(followable_type) %></strong>
</span>
</a>
<div class="accordion-content" data-tab-content>
<table>
<tbody>
<% (1..3).each do |i| %>
<tr>
<td>
<%= link_to "add translation", nil %>
<br>
This is longer content Donec id elit non mi porta gravida at eget metus.
</td>
</tr>
<% @follows.where(followable_type: followable_type).each do |follow| %>
<% if followable_type == "Proposal" %>
<%= render "proposal", proposal: follow.followable %>
<% elsif followable_type == "Budget::Investment" %>
<%= render "budget_investment", budget_investment: follow.followable %>
<% end %>
<% end %>
</tbody>
</table>
</div>
</li>
<% end %>
</ul>

View File

@@ -0,0 +1,25 @@
<tr id="proposal_<%= proposal.id %>">
<td>
<%= link_to proposal.title, proposal, proposal.retired? ? {class: 'retired'} : {} %>
<br>
<%= proposal.summary %>
</td>
<% if author? %>
<td class="text-center">
<%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id),
class: 'button hollow' %>
</td>
<td class="text-center">
<% if proposal.retired? %>
<span class="label alert"><%= t('users.proposals.retired') %></span>
<% else %>
<%= link_to t('users.proposals.retire'),
retire_form_proposal_path(proposal),
class: 'button hollow alert' %>
<% end %>
</td>
<% end %>
</tr>

View File

@@ -1,30 +1,6 @@
<table class="clear activity-proposals">
<% @proposals.each do |proposal| %>
<tr id="proposal_<%= proposal.id %>">
<td>
<%= link_to proposal.title, proposal, proposal.retired? ? {class: 'retired'} : {} %>
<br>
<%= proposal.summary %>
</td>
<% if author? %>
<td class="text-center">
<%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id),
class: 'button hollow' %>
</td>
<td class="text-center">
<% if proposal.retired? %>
<span class="label alert"><%= t('users.proposals.retired') %></span>
<% else %>
<%= link_to t('users.proposals.retire'),
retire_form_proposal_path(proposal),
class: 'button hollow alert' %>
<% end %>
</td>
<% end %>
</tr>
<%= render "proposal", proposal: proposal %>
<% end %>
</table>

View File

@@ -38,10 +38,6 @@
<% end %>
<% end %>
<% end %>
<!-- ROR Add this li above when the functionality exists-->
<li>
Add translate
<li>
<%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %>
</ul>