Basics of pro dashboard (#1971)
This commit is contained in:
parent
7e568921a8
commit
8d0f0946a0
6 changed files with 85 additions and 0 deletions
|
|
@ -29,4 +29,18 @@ class DashboardsController < ApplicationController
|
|||
# Updates analytics in background if appropriate:
|
||||
ArticleAnalyticsFetcher.new.delay.update_analytics(current_user.id) if @articles
|
||||
end
|
||||
|
||||
def pro
|
||||
authorize current_user, :pro_user?
|
||||
@this_week_reactions_count = Reaction.where(reactable_id: current_user.articles.pluck(:id), reactable_type: "Article").where("created_at > ?", 1.week.ago).size
|
||||
@last_week_reactions_count = Reaction.where(reactable_id: current_user.articles.pluck(:id), reactable_type: "Article").where("created_at > ? AND created_at < ?", 2.weeks.ago, 1.week.ago).size
|
||||
@this_month_reactions_count = Reaction.where(reactable_id: current_user.articles.pluck(:id), reactable_type: "Article").where("created_at > ?", 1.month.ago).size
|
||||
@last_month_reactions_count = Reaction.where(reactable_id: current_user.articles.pluck(:id), reactable_type: "Article").where("created_at > ? AND created_at < ?", 2.months.ago, 1.months.ago).size
|
||||
@this_week_followers_count = Follow.where(followable_id: current_user.id, followable_type: "User").where("created_at > ?", 1.week.ago).size
|
||||
@last_week_followers_count = Follow.where(followable_id: current_user.id, followable_type: "User").where("created_at > ? AND created_at < ?", 2.weeks.ago, 1.week.ago).size
|
||||
@this_month_followers_count = Follow.where(followable_id: current_user.id, followable_type: "User").where("created_at > ?", 1.month.ago).size
|
||||
@last_month_followers_count = Follow.where(followable_id: current_user.id, followable_type: "User").where("created_at > ? AND created_at < ?", 2.months.ago, 1.months.ago).size
|
||||
@reactors = User.
|
||||
where(id: Reaction.where(reactable_id: current_user.articles.pluck(:id), reactable_type: "Article").order("created_at DESC").limit(100).pluck(:user_id))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ class Role < ApplicationRecord
|
|||
chatroom_beta_tester
|
||||
banned_from_mentorship
|
||||
comment_banned
|
||||
pro
|
||||
)
|
||||
}
|
||||
scopify
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ class UserPolicy < ApplicationPolicy
|
|||
current_user? || user_admin? || minimal_admin?
|
||||
end
|
||||
|
||||
def pro_user?
|
||||
p user.has_role? :pro
|
||||
current_user? && user.has_role?(:pro)
|
||||
end
|
||||
|
||||
def moderation_routes?
|
||||
user.has_role?(:trusted) && !user.banned
|
||||
end
|
||||
|
|
|
|||
39
app/views/dashboards/pro.html.erb
Normal file
39
app/views/dashboards/pro.html.erb
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<div class="dashboard-container" id="user-dashboard">
|
||||
<h1 style="text-align: center;font-size:3em">DevRel Pro 💪</h1>
|
||||
<p>Welcome to the DevRel pro dashboard. Where DevRel professionals can make data-driven decisions about the developer ecosystem.</p>
|
||||
<p>This dashboard will highlight deep insights especially relevant to dev rel.</p>
|
||||
<hr />
|
||||
<h2>Reactions Summary (❤🦄🔖)</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<%= @this_week_reactions_count %> reactions this week (<%= @last_week_reactions_count.positive? ? (@this_week_reactions_count.to_f / @last_week_reactions_count.to_f) * 100 : "infinity " %>% of previous week)
|
||||
</li>
|
||||
<li>
|
||||
<%= @this_month_reactions_count %> reactions this month (<%= @last_month_reactions_count.positive? ? (@this_month_reactions_count.to_f / @last_month_reactions_count.to_f) * 100 : "infinity " %>% of previous month)
|
||||
</li>
|
||||
</ul>
|
||||
<h2>New Followers Summary (👩💻👨💻)</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<%= @this_week_followers_count %> new followers this week (<%= @last_week_followers_count.positive? ? (@this_week_followers_count.to_f / @last_week_followers_count.to_f) * 100 : "infinity " %>% of previous week)
|
||||
</li>
|
||||
<li>
|
||||
<%= @this_month_followers_count %> new followers this month (<%= @last_month_followers_count.positive? ? (@this_month_followers_count.to_f / @last_month_followers_count.to_f) * 100 : "infinity " %>% of previous month)
|
||||
</li>
|
||||
</ul>
|
||||
<h2>Activity</h2>
|
||||
<h3>People who recently reacted (❤🦄🔖) to your content:</h3>
|
||||
<div style="height: 400px; overflow: scroll;">
|
||||
<% @reactors.each do |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 %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -253,6 +253,7 @@ Rails.application.routes.draw do
|
|||
get "/settings/(:tab)" => "users#edit"
|
||||
get "/signout_confirm" => "users#signout_confirm"
|
||||
get "/dashboard" => "dashboards#show"
|
||||
get "/dashboard/pro" => "dashboards#pro"
|
||||
get "/dashboard/:which" => "dashboards#show",
|
||||
constraints: {
|
||||
which: /organization|organization_user_followers|user_followers|following_users|following|reading/
|
||||
|
|
|
|||
|
|
@ -98,4 +98,29 @@ RSpec.describe "Dashboards", type: :request do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /dashboard/pro" do
|
||||
context "when not logged in" do
|
||||
it "raises unauthorized" do
|
||||
get "/dashboard/pro"
|
||||
expect(response).to redirect_to("/enter")
|
||||
end
|
||||
end
|
||||
|
||||
context "when user does not have permission" do
|
||||
it "raises unauthorized" do
|
||||
login_as user
|
||||
expect { get "/dashboard/pro" }.to raise_error(Pundit::NotAuthorizedError)
|
||||
end
|
||||
end
|
||||
|
||||
context "when user has pro permission" do
|
||||
it "shows page properly" do
|
||||
user.add_role(:pro)
|
||||
login_as user
|
||||
get "/dashboard/pro"
|
||||
expect(response.body).to include("pro")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue