@@ -20,6 +20,7 @@
|
||||
// 18. Comments
|
||||
// 19. Flags
|
||||
// 20. Accesibility
|
||||
// 21. Activity
|
||||
//
|
||||
|
||||
// 01. Variables
|
||||
@@ -2015,3 +2016,58 @@ table {
|
||||
clip: rect(0, 0, 0, 0);
|
||||
border: 0;
|
||||
}
|
||||
|
||||
// 21. Activity
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
.activity {
|
||||
margin-bottom: rem-calc(48);
|
||||
margin-top: rem-calc(24);
|
||||
|
||||
.sub-nav {
|
||||
background: none;
|
||||
border-bottom: 1px solid $border;
|
||||
border-radius: 0;
|
||||
padding-bottom: 0;
|
||||
|
||||
dd.active {
|
||||
background: none;
|
||||
border-bottom: 2px solid $brand;
|
||||
border-radius: 0;
|
||||
color: $brand;
|
||||
}
|
||||
}
|
||||
|
||||
table {
|
||||
border: 0;
|
||||
|
||||
td {
|
||||
padding-left: rem-calc(36);
|
||||
position: relative;
|
||||
|
||||
&:before {
|
||||
color: $brand;
|
||||
font-family: "icons" !important;
|
||||
font-size: rem-calc(24);
|
||||
left: 4px;
|
||||
position: absolute;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
&.activity-comments td:before {
|
||||
content: "e";
|
||||
top: 18px;
|
||||
}
|
||||
|
||||
&.activity-debates td:before {
|
||||
content: "i";
|
||||
top: 14px;
|
||||
}
|
||||
|
||||
&.activity-proposals td:before {
|
||||
content: "h";
|
||||
top: 18px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,8 +416,15 @@
|
||||
}
|
||||
|
||||
.author {
|
||||
color: $text;
|
||||
font-weight: bold;
|
||||
|
||||
a {
|
||||
color: $link !important;
|
||||
|
||||
&:hover {
|
||||
color: $link-hover !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aside {
|
||||
|
||||
@@ -25,7 +25,7 @@ class AccountController < ApplicationController
|
||||
if @account.organization?
|
||||
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name])
|
||||
else
|
||||
params.require(:account).permit(:username, :email_on_comment, :email_on_comment_reply)
|
||||
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
60
app/controllers/users_controller.rb
Normal file
60
app/controllers/users_controller.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
class UsersController < ApplicationController
|
||||
has_filters %w{proposals debates comments}, only: :show
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def show
|
||||
load_filtered_activity if valid_access?
|
||||
end
|
||||
|
||||
private
|
||||
def set_activity_counts
|
||||
@activity_counts = HashWithIndifferentAccess.new(
|
||||
proposals: Proposal.where(author_id: @user.id).count,
|
||||
debates: Debate.where(author_id: @user.id).count,
|
||||
comments: Comment.where(user_id: @user.id).count)
|
||||
end
|
||||
|
||||
def load_filtered_activity
|
||||
set_activity_counts
|
||||
case params[:filter]
|
||||
when "proposals" then load_proposals
|
||||
when "debates" then load_debates
|
||||
when "comments" then load_comments
|
||||
else load_available_activity
|
||||
end
|
||||
end
|
||||
|
||||
def load_available_activity
|
||||
if @activity_counts[:proposals] > 0
|
||||
load_proposals
|
||||
@current_filter = "proposals"
|
||||
elsif @activity_counts[:debates] > 0
|
||||
load_debates
|
||||
@current_filter = "debates"
|
||||
elsif @activity_counts[:comments] > 0
|
||||
load_comments
|
||||
@current_filter = "comments"
|
||||
end
|
||||
end
|
||||
|
||||
def load_proposals
|
||||
@proposals = Proposal.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def load_debates
|
||||
@debates = Debate.where(author_id: @user.id).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def load_comments
|
||||
@comments = Comment.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def valid_access?
|
||||
@user.public_activity || authorized_current_user?
|
||||
end
|
||||
|
||||
def authorized_current_user?
|
||||
@authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?)
|
||||
end
|
||||
end
|
||||
@@ -5,6 +5,7 @@ module Abilities
|
||||
def initialize(user)
|
||||
can :read, Debate
|
||||
can :read, Proposal
|
||||
can :read, User
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,6 +31,13 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :public_activity do %>
|
||||
<%= f.check_box :public_activity, label: false %>
|
||||
<span class="checkbox"><%= t("account.show.public_activity_label") %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h2><%= t("account.show.notifications")%></h2>
|
||||
|
||||
<div>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<% if comment.user.hidden? || comment.user.erased? %>
|
||||
<span class="user-name"><%= t("comments.comment.user_deleted") %></span>
|
||||
<% else %>
|
||||
<span class="user-name"><%= comment.user.name %></span>
|
||||
<span class="user-name"><%= link_to comment.user.name, user_path(comment.user) %></span>
|
||||
<% if comment.user.official? %>
|
||||
•
|
||||
<span class="label round level-<%= comment.user.official_level %>">
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<ul class="right">
|
||||
<% if user_signed_in? %>
|
||||
<li>
|
||||
<%= link_to(t("layouts.header.my_activity_link"), user_path(current_user)) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to(t("layouts.header.my_account_link"), account_path) %>
|
||||
</li>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</span>
|
||||
<% else %>
|
||||
<span class="author">
|
||||
<%= resource.author.name %>
|
||||
<%= link_to resource.author.name, user_path(resource.author) %>
|
||||
</span>
|
||||
<% if resource.author.official? %>
|
||||
•
|
||||
|
||||
3
app/views/users/_activity_page.html.erb
Normal file
3
app/views/users/_activity_page.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= render "proposals" if @proposals.present? %>
|
||||
<%= render "debates" if @debates.present? %>
|
||||
<%= render "comments" if @comments.present? %>
|
||||
13
app/views/users/_comments.html.erb
Normal file
13
app/views/users/_comments.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<table class="clear activity-comments">
|
||||
<% @comments.each do |comment| %>
|
||||
<tr id="debate_<%= comment.id %>">
|
||||
<td>
|
||||
<%= comment.commentable.hidden? ? comment.commentable.title : link_to(comment.commentable.title, comment.commentable) %>
|
||||
<br>
|
||||
<%= comment.body %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @comments %>
|
||||
11
app/views/users/_debates.html.erb
Normal file
11
app/views/users/_debates.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<table class="clear activity-debates">
|
||||
<% @debates.each do |debate| %>
|
||||
<tr id="debate_<%= debate.id %>">
|
||||
<td>
|
||||
<%= link_to debate.title, debate %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @debates %>
|
||||
13
app/views/users/_proposals.html.erb
Normal file
13
app/views/users/_proposals.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<table class="clear activity-proposals">
|
||||
<% @proposals.each do |proposal| %>
|
||||
<tr id="proposal_<%= proposal.id %>">
|
||||
<td>
|
||||
<%= link_to proposal.title, proposal %>
|
||||
<br>
|
||||
<%= proposal.summary %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @proposals %>
|
||||
29
app/views/users/show.html.erb
Normal file
29
app/views/users/show.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<section role="main">
|
||||
<div class="activity row">
|
||||
<div class="small-12 column">
|
||||
|
||||
<h2><%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %></h2>
|
||||
|
||||
<% if @user.public_activity || @authorized_current_user %>
|
||||
<dl class="sub-nav">
|
||||
<% @valid_filters.each do |filter| %>
|
||||
<% if @activity_counts[filter] > 0 %>
|
||||
<% if @current_filter == filter %>
|
||||
<dd class="active"> <%= t("users.show.filters.#{filter}", count: @activity_counts[filter]) %></dd>
|
||||
<% else %>
|
||||
<dd><%= link_to t("users.show.filters.#{filter}", count: @activity_counts[filter]),
|
||||
current_path_with_query_params(filter: filter, page: 1) %></dd>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %>
|
||||
</dl>
|
||||
|
||||
<%= render "activity_page" %>
|
||||
<% else %>
|
||||
<p><%= t('users.show.private_activity') %></p>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user