adds user's public show page
This commit is contained in:
committed by
Juanjo Bazán
parent
4694cf1f64
commit
7f1fe034a3
54
app/controllers/users_controller.rb
Normal file
54
app/controllers/users_controller.rb
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
class UsersController < ApplicationController
|
||||||
|
has_filters %w{proposals debates comments}, only: :show
|
||||||
|
|
||||||
|
load_and_authorize_resource
|
||||||
|
|
||||||
|
before_action :set_activity_counts, only: :show
|
||||||
|
|
||||||
|
def show
|
||||||
|
load_filtered_activity
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
end
|
||||||
@@ -5,6 +5,7 @@ module Abilities
|
|||||||
def initialize(user)
|
def initialize(user)
|
||||||
can :read, Debate
|
can :read, Debate
|
||||||
can :read, Proposal
|
can :read, Proposal
|
||||||
|
can :read, User
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
15
app/views/users/show.html.erb
Normal file
15
app/views/users/show.html.erb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<h1><%= avatar_image(@user, seed: @user.id, size: 60) %> <%= @user.name %></h1>
|
||||||
|
|
||||||
|
<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>
|
||||||
@@ -324,6 +324,19 @@ en:
|
|||||||
check: "Select"
|
check: "Select"
|
||||||
check_all: "All"
|
check_all: "All"
|
||||||
check_none: "None"
|
check_none: "None"
|
||||||
|
users:
|
||||||
|
show:
|
||||||
|
filters:
|
||||||
|
proposals:
|
||||||
|
one: "1 Proposal"
|
||||||
|
other: "%{count} Proposals"
|
||||||
|
debates:
|
||||||
|
one: "1 Debate"
|
||||||
|
other: "%{count} Debates"
|
||||||
|
comments:
|
||||||
|
one: "1 Comment"
|
||||||
|
other: "%{count} Comments"
|
||||||
|
no_activity: "Usuario sin actividad pública"
|
||||||
unauthorized:
|
unauthorized:
|
||||||
default: "You do not have permission to access this page."
|
default: "You do not have permission to access this page."
|
||||||
manage:
|
manage:
|
||||||
|
|||||||
@@ -324,6 +324,19 @@ es:
|
|||||||
check: "Seleccionar"
|
check: "Seleccionar"
|
||||||
check_all: "Todos"
|
check_all: "Todos"
|
||||||
check_none: "Ninguno"
|
check_none: "Ninguno"
|
||||||
|
users:
|
||||||
|
show:
|
||||||
|
filters:
|
||||||
|
proposals:
|
||||||
|
one: "1 Propuesta"
|
||||||
|
other: "%{count} Propuestas"
|
||||||
|
debates:
|
||||||
|
one: "1 Debate"
|
||||||
|
other: "%{count} Debates"
|
||||||
|
comments:
|
||||||
|
one: "1 Comentario"
|
||||||
|
other: "%{count} Comentarios"
|
||||||
|
no_activity: "Usuario sin actividad pública"
|
||||||
unauthorized:
|
unauthorized:
|
||||||
default: "No tienes permiso para acceder a esta página."
|
default: "No tienes permiso para acceder a esta página."
|
||||||
manage:
|
manage:
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :users, only: [:show]
|
||||||
|
|
||||||
resource :account, controller: "account", only: [:show, :update, :delete] do
|
resource :account, controller: "account", only: [:show, :update, :delete] do
|
||||||
collection { get :erase }
|
collection { get :erase }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user