Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User page: new following section #1750

Merged
merged 17 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/assets/stylesheets/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1932,8 +1932,39 @@ table {
.activity {
margin-bottom: $line-height * 2;

.accordion li {
margin-bottom: $line-height / 2;

.accordion-title {
border-bottom: 1px solid $border;
background: #f8f9fb;
font-size: $small-font-size;
padding: $line-height / 2;
}

.accordion-content {
padding: 0;
}
}

.accordion .title {
display: block;
line-height: $line-height;
}

.accordion .icon {
font-size: rem-calc(20);
float: left;
margin-right: $line-height / 3;

&.icon-debates {
margin-top: rem-calc(3);
}
}

table {
border: 0;
margin-bottom: 0;
}

td {
Expand Down
26 changes: 13 additions & 13 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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?
helper_method :author_or_admin?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really understand the reason to remove author_or_admin? method and its usage, can you explain a bit further? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bertocq The main reason is that apparently it was not being used anywhere in the application.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 you're right, I did a project search and no use, although sometimes looking for the method string is not enough if you do compose de method name with a string interpolation like send("#{this}_or_#{that}") but that's not the case I guess based on the specs passing ^_^

Nice catch & cleanup 👏 😄

helper_method :valid_interests_access?

def show
load_filtered_activity if valid_access?
load_interests if valid_interests_access?
end

private
Expand All @@ -17,7 +16,8 @@ def set_activity_counts
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
Expand All @@ -26,7 +26,8 @@ def load_filtered_activity
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
Expand All @@ -44,6 +45,9 @@ def load_available_activity
elsif @activity_counts[:comments] > 0
load_comments
@current_filter = "comments"
elsif @activity_counts[:follows] > 0
load_follows
@current_filter = "follows"
end
end

Expand All @@ -63,8 +67,8 @@ def load_budget_investments
@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
@follows = @user.follows.group_by(&:followable_type)
end

def valid_access?
Expand All @@ -75,12 +79,8 @@ def valid_interests_access?
@user.public_interests || authorized_current_user?
end

def author?
@author ||= current_user && (current_user == @user)
end

def author_or_admin?
@author_or_admin ||= current_user && (author? || current_user.administrator?)
def author?(proposal)
proposal.author_id == current_user.id if current_user
end

def authorized_current_user?
Expand Down
32 changes: 27 additions & 5 deletions app/helpers/follows_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ def show_unfollow_action?(followable)
end

def follow_entity_text(followable)
entity = followable.class.name.gsub('::', '/').downcase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 nice cleaning up on the side! 💪

entity = followable.class.name.underscore
t('shared.follow_entity', entity: t("activerecord.models.#{entity}.one").downcase)
end

def follow_entity_title(followable)
entity = followable.class.name.gsub('::', '/').downcase
entity = followable.class.name.underscore
t('shared.follow_entity_title', entity: t("activerecord.models.#{entity}.one").downcase)
end

def unfollow_entity_text(followable)
entity = followable.class.name.gsub('::', '/').downcase
entity = followable.class.name.underscore
t('shared.unfollow_entity', entity: t("activerecord.models.#{entity}.one").downcase)
end

def entity_full_name(followable)
name = followable.class.name
name.downcase.gsub("::", "-")
followable.class.name.parameterize
end

def follow_link_wrapper_id(followable)
Expand All @@ -52,6 +51,29 @@ def unfollow_drop_id(followable)
"unfollow-drop-#{entity_full_name(followable)}-#{followable.id}"
end

def entity_title(title)
t("activerecord.models.#{title.underscore}.other")
end

def entity_icon(entity)
{
proposals: 'Proposal',
budget: 'Budget::Investment'
}.invert[entity]
end

def entity_class_name(followable)
followable.class.to_s.parameterize.gsub('-','_')
end

def render_follow(follow)
followable = follow.followable
partial = entity_class_name(followable)
locals = {entity_class_name(followable).to_sym => followable}

render partial, locals
end

private

def followed?(followable)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def current_administrator?
current_user && current_user.administrator?
end

end
end
2 changes: 1 addition & 1 deletion app/models/abilities/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def initialize(user)
can :create, Budget::Investment, budget: { phase: "accepting" }
can :suggest, Budget::Investment, budget: { phase: "accepting" }
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
can :vote, Budget::Investment, budget: { phase: "selecting" }
can :vote, Budget::Investment, budget: { phase: "selecting" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^_^ /bertocq likes this

can [:show, :create], Budget::Ballot, budget: { phase: "balloting" }
can [:create, :destroy], Budget::Ballot::Line, budget: { phase: "balloting" }

Expand Down
1 change: 1 addition & 0 deletions app/views/users/_activity_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= 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) %>
Expand Down
11 changes: 11 additions & 0 deletions app/views/users/_budget_investment.html.erb
Original file line number Diff line number Diff line change
@@ -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>
12 changes: 1 addition & 11 deletions app/views/users/_budget_investments.html.erb
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
30 changes: 30 additions & 0 deletions app/views/users/_following.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<ul class="accordion" data-accordion data-allow-all-closed="true">

<% @follows.each do |followable_type, follows| %>

<li class="accordion-item" data-accordion-item>

<a href="#" class="accordion-title">
<span class="icon">
<i class="icon icon-<%= entity_icon(followable_type) %>"></i>
</span>
<span class="title">
<strong><%= entity_title(followable_type) %></strong>
</span>
</a>

<div class="accordion-content" data-tab-content>
<table>
<tbody>
<% follows.each do |follow| %>
<%= render_follow(follow) %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@voodoorai2000 nice refactor! 😍

<% end %>
</tbody>
</table>
</div>

</li>

<% end %>

</ul>
34 changes: 34 additions & 0 deletions app/views/users/_proposal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<tr id="proposal_<%= proposal.id %>">
<td>
<%= link_to proposal.title, proposal, proposal.retired? ? { class: 'retired' } : {} %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that ? { class: 'retired' } : {} :) I think I have added some class="" around :( couldn't figure out this was the way 👏

<br>
<%= proposal.summary %>
</td>

<% if proposal.retired? %>

<td class="text-center">
<span class="label alert"><%= t('users.proposals.retired') %></span>
</td>

<% elsif author?(proposal) %>

<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>
26 changes: 1 addition & 25 deletions app/views/users/_proposals.html.erb
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<p><%= t('users.show.private_activity') %></p>
<% end %>

<% if @user.public_interests || @authorized_current_user %>
<% if valid_interests_access? %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

<div id="public_interests" class="public-interests">
<h4><%= t('account.show.public_interests_title_list') %></h4>
<% @user.interests.in_groups_of(10, false) do |interests_group| %>
Expand Down
Loading