Extract "followers" action from "show" in DashboardsController (#2270)
This commit is contained in:
parent
490645ea92
commit
512c9ee8a0
5 changed files with 50 additions and 30 deletions
|
|
@ -30,6 +30,17 @@ class DashboardsController < ApplicationController
|
|||
order("created_at DESC").includes(:followable).limit(80)
|
||||
end
|
||||
|
||||
def followers
|
||||
fetch_and_authorize_user
|
||||
if params[:which] == "user_followers"
|
||||
@follows = Follow.where(followable_id: @user.id, followable_type: "User").
|
||||
includes(:follower).order("created_at DESC").limit(80)
|
||||
elsif params[:which] == "organization_user_followers"
|
||||
@follows = Follow.where(followable_id: @user.organization_id, followable_type: "Organization").
|
||||
includes(:follower).order("created_at DESC").limit(80)
|
||||
end
|
||||
end
|
||||
|
||||
def pro
|
||||
user_or_org = if params[:org_id]
|
||||
org = Organization.find_by(id: params[:org_id])
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<div class="actions">
|
||||
<a class="action <%= "active" if params[:action] == "show" && (params[:which] == "organization" || params[:which].blank?) %>" href="/dashboard">
|
||||
<a class="action <%= "active" if params[:action] == "show" && (params[:which] == "organization" || params[:which].blank?) %>" href="/dashboard">
|
||||
<span>POSTS</span>
|
||||
<span>(<%= @user.articles_count %>)</span>
|
||||
</a>
|
||||
<a class="action <%= "active" if params[:action] == "show" && (params[:which] == "user_followers" || params[:which] == "organization_user_followers") %>" href="/dashboard/user_followers">
|
||||
<a class="action <%= "active" if params[:action] == "followers" %>" href="/dashboard/user_followers">
|
||||
<span>FOLLOWERS</span>
|
||||
<span>(<%= @user.followers_count %>)</span>
|
||||
</a>
|
||||
|
|
|
|||
31
app/views/dashboards/followers.html.erb
Normal file
31
app/views/dashboards/followers.html.erb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<% title "Dashboard - DEV" %>
|
||||
|
||||
<div class="dashboard-container" id="user-dashboard">
|
||||
<%= render "actions" %>
|
||||
<% if @user.org_admin && @user.organization %>
|
||||
<h1>
|
||||
<a href="/dashboard/user_followers" class="rounded-btn <%= "active" if params[:which] == "user_followers" %>">Personal</a>
|
||||
<a href="/dashboard/organization_user_followers" class="rounded-btn <%= "active" if params[:which] == "organization_user_followers" %>"><%= @user.organization.name %> (<%= @user.organization.followers_count %>)</a>
|
||||
<% if @user.has_role? :pro %>
|
||||
<a class="rounded-btn" href="/dashboard/pro">Pro Analytics</a>
|
||||
<% end %>
|
||||
<% if @user.has_role?(:pro) && @user.organization_id %>
|
||||
<a class="rounded-btn" href="/dashboard/pro/org/<%= @user.organization_id %>">Pro Analytics for <%= @user.organization.name %></a>
|
||||
<% end %>
|
||||
</h1>
|
||||
<% end %>
|
||||
<% @follows.each do |follow| %>
|
||||
<% user = follow.follower %>
|
||||
<% if user %>
|
||||
<div class="single-article">
|
||||
<a href="<%= user.path %>" class="block-link">
|
||||
<h2>
|
||||
<img alt="<%= user.username %> profile image" src="<%= ProfileImage.new(user).get(60) %>" />
|
||||
<%= user.name %>
|
||||
<span class="dashboard-username">@<%= user.username %></span>
|
||||
</h2>
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<% title "Dashboard - DEV" %>
|
||||
|
||||
<div class="dashboard-container" id="user-dashboard">
|
||||
<%= render 'actions' %>
|
||||
<%= render "actions" %>
|
||||
<% if @user.org_admin && @user.organization && (params[:which].blank? || params[:which] == "organization") %>
|
||||
<h1>
|
||||
<a href="/dashboard" class="rounded-btn <%= "active" if params[:which].blank? %>">Personal</a>
|
||||
|
|
@ -13,38 +13,12 @@
|
|||
<a class="rounded-btn" href="/dashboard/pro/org/<%= @user.organization_id %>">Pro Analytics for <%= @user.organization.name %></a>
|
||||
<% end %>
|
||||
</h1>
|
||||
<% elsif @user.org_admin && @user.organization && (params[:which] == "organization_user_followers" || params[:which] == "user_followers") %>
|
||||
<h1>
|
||||
<a href="/dashboard/user_followers" class="rounded-btn <%= "active" if params[:which] == "user_followers" %>">Personal</a>
|
||||
<a href="/dashboard/organization_user_followers" class="rounded-btn <%= "active" if params[:which] == "organization_user_followers" %>"><%= @user.organization.name %> (<%= @user.organization.followers_count %>)</a>
|
||||
<% if @user.has_role? :pro %>
|
||||
<a class="rounded-btn" href="/dashboard/pro">Pro Analytics</a>
|
||||
<% end %>
|
||||
<% if @user.has_role?(:pro) && @user.organization_id %>
|
||||
<a class="rounded-btn" href="/dashboard/pro/org/<%= @user.organization_id %>">Pro Analytics for <%= @user.organization.name %></a>
|
||||
<% end %>
|
||||
</h1>
|
||||
<% end %>
|
||||
<% if @user.org_admin && @user.organization && params[:which] == "organization" %>
|
||||
<%= render "analytics" %>
|
||||
<% @articles.each do |article| %>
|
||||
<%= render "dashboard_article", article: article, org_admin: true %>
|
||||
<% end %>
|
||||
<% elsif params[:which] == "user_followers" || params[:which] == "organization_user_followers" %>
|
||||
<% @follows.each do |follow| %>
|
||||
<% user = params[:which].include?("followers") ? follow.follower : follow.followable %>
|
||||
<% if user %>
|
||||
<div class="single-article">
|
||||
<a href="<%= user.path %>" class="block-link">
|
||||
<h2>
|
||||
<img alt="<%= user.username %> profile image" src="<%= ProfileImage.new(user).get(60) %>" />
|
||||
<%= user.name %>
|
||||
<span class="dashboard-username">@<%= user.username %></span>
|
||||
</h2>
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% elsif @articles.any? %>
|
||||
<%= render "analytics" %>
|
||||
<% if current_user.created_at < 2.weeks.ago %>
|
||||
|
|
|
|||
|
|
@ -261,9 +261,13 @@ Rails.application.routes.draw do
|
|||
get "/dashboard/pro" => "dashboards#pro"
|
||||
get "dashboard/pro/org/:org_id" => "dashboards#pro"
|
||||
get "dashboard/following" => "dashboards#following"
|
||||
get "/dashboard/:which" => "dashboards#followers",
|
||||
constraints: {
|
||||
which: /organization_user_followers|user_followers/
|
||||
}
|
||||
get "/dashboard/:which" => "dashboards#show",
|
||||
constraints: {
|
||||
which: /organization|organization_user_followers|user_followers|reading/
|
||||
which: /organization|reading/
|
||||
}
|
||||
get "/dashboard/:username" => "dashboards#show"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue