Skip to content

Commit

Permalink
Makes the dashboard more useful, step 1.
Browse files Browse the repository at this point in the history
The welcome widget is now dedicated to the activity of the day. Definitely ripped from Wordpress.
  • Loading branch information
Frédéric de Villamil committed Aug 10, 2013
1 parent 6d44c58 commit c7fd764
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 58 deletions.
26 changes: 18 additions & 8 deletions app/controllers/admin/dashboard_controller.rb
Expand Up @@ -4,19 +4,29 @@ class Admin::DashboardController < Admin::BaseController
require 'rexml/document'

def index
t = Time.new
today = t.strftime("%Y-%m-%d 00:00")

# Since last venue
@newposts_count = Article.published_since(current_user.last_venue).count
@newcomments_count = Feedback.published_since(current_user.last_venue).count

@statposts = Article.published.count
@statcomments = Comment.not_spam.count
@presumedspam = Comment.presumed_spam.count

@categories = Category.count


# Today
@statposts = Article.published.where("published_at > ?", today).count
@statsdrafts = Article.drafts.where("created_at > ?", today).count
@statspages = Page.where("published_at > ?", today).count
@statuses = Status.where("published_at > ?", today).count
@statuserposts = Article.published.where("published_at > ?", today).count(conditions: {user_id: current_user.id})

@statcomments = Comment.where("created_at > ?", today).count
@presumedspam = Comment.presumed_spam.where("created_at > ?", today).count
@confirmed = Comment.ham.where("created_at > ?", today).count
@unconfirmed = Comment.unconfirmed.where("created_at > ?", today).count

@comments = Comment.last_published
@recent_posts = Article.published.limit(5)
@bestof = Article.bestof
@statuserposts = Article.published.count(conditions: {user_id: current_user.id})

@statspam = Comment.spam.count
@inbound_links = inbound_links
@publify_links = publify_dev
Expand Down
1 change: 0 additions & 1 deletion app/models/article.rb
Expand Up @@ -34,7 +34,6 @@ def ham
def spam
where(:state => ["presumed_spam", "spam"])
end

end

with_options(:conditions => { :published => true }, :order => 'created_at ASC') do |this|
Expand Down
3 changes: 3 additions & 0 deletions app/models/comment.rb
Expand Up @@ -11,6 +11,9 @@ class Comment < Feedback
scope :spam, lambda { where(state: 'spam') }
scope :not_spam, lambda { where("state != 'spam'")}
scope :presumed_spam, lambda { where(state: 'presumed_spam')}
scope :presumed_ham, lambda { where(state: 'presumed_ham')}
scope :ham, lambda { where(state: 'ham')}
scope :unconfirmed, lambda { where("state in (?, ?)", "presumed_spam", "presumed_ham")}
scope :last_published, lambda { where(published:true).limit(5).order('created_at DESC') }

def notify_user_via_email(user)
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/dashboard/_overview.html.erb
@@ -1,4 +1,4 @@
<h3><%= _("Getting started") %></h3>
<h3><%= _("Welcome back, %s!", current_user.name ) -%></h3>
<div class='alert alert-info'>
<p>
<%= _("This place gives you a quick overview of what happens on your Publify blog and what you can do. Maybe will you want to %s", dashboard_action_links) %>
Expand Down
49 changes: 27 additions & 22 deletions app/views/admin/dashboard/_welcome.html.erb
@@ -1,24 +1,29 @@
<h3><%= _("Welcome back, %s!", current_user.name ) -%></h3>
<h3><%= _("Today") -%></h3>
<div>
<div class='span12 well'>
<p><%= _("%d articles and %d comments were posted since your last connexion", @newposts_count, @newcomments_count) %></p>
<p><%= _("You're running Publify %s", PUBLIFY_VERSION) %> <%= @version_message %></p>

<div class='well'>
<p><%= _("%d articles and %d comments were posted since your last connexion", @newposts_count, @newcomments_count) %></p>
<p><%= _("You're running Publify %s", PUBLIFY_VERSION) %> <%= @version_message %></p>

<% if current_user.profile.modules.include? :articles%>
<p><strong><%= _("Content") %></strong></p>
<ul class='unstyled'>
<li> <%= sprintf("%s %d", link_to(_("Total posts:"), :controller => 'admin/content'), @statposts) %></li>
<li> <%= sprintf("%s %d", link_to(_("Your posts:"), :controller => 'admin/content', "search[user_id]" => current_user.id), @statuserposts) %></li>
<li> <%= sprintf("%s %d", link_to(_("Categories:"), :controller => 'admin/categories'), @categories) %></li>
</ul>
<% end %>
<% if current_user.profile.modules.include? :articles %>
<p><strong><%= _("Feedback") %></strong></p>
<ul class='unstyled'>
<li> <%= sprintf("%s %d", link_to(_("Total comments:"), :controller => 'admin/feedback') , @statcomments) %></li>
<li> <%= sprintf("%s %d", link_to(_("Spam comments:"), :controller => 'admin/feedback', :published => 'f'), @statspam) %></li>
<li> <%= sprintf("%s %d", link_to(_("In your spam queue:"), :controller => 'admin/feedback', :presumed_spam => 'f'), @presumedspam) %></li>
</ul>
<% end %>
<div>
<div class='span6'>
<% if current_user.profile.modules.include? :articles%>
<h4 class='page-header'><%= _("Content") %></h4>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statposts, pluralize(@statposts, _("articles"), _("article"), _("articles"))).html_safe, :controller => 'admin/content').html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statuserposts, _("articles writen by you")).html_safe, :controller => 'admin/content', "search[user_id]" => current_user.id).html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statsdrafts, pluralize(@statsdrafts, _("drafts"), _("draft"), _("drafts"))).html_safe, :controller => 'admin/content', "search[state]" => "drafts").html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statspages, pluralize(@statspages, _("pages"), _("page"), _("pages"))).html_safe, :controller => 'admin/pages').html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statuses, pluralize(@statspages, _("short statuses"), _("short status"), _("short statuses"))).html_safe, :controller => 'admin/statuses').html_safe %></p>
<% end %>
</div>
<div class='span6'>
<% if current_user.profile.modules.include? :feedback %>
<h4 class='page-header'><%= _("Feedback") %></h4>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statcomments, _("comments")).html_safe, :controller => 'admin/feedback').html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @confirmed, _("approved")).html_safe, :controller => 'admin/feedback', "ham" => "f").html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @unconfirmed, _("unconfirmed")).html_safe, :controller => 'admin/feedback', "presumed_ham" => "f").html_safe %></p>
<p><%= link_to(sprintf("<strong>%d</strong> %s", @statspam, _("spam")).html_safe, :controller => 'admin/feedback', "spam" => "f").html_safe %></p>
<% end %>
</div>
</div>
</div>
</div>
23 changes: 13 additions & 10 deletions app/views/admin/dashboard/index.html.erb
@@ -1,13 +1,16 @@
<%= render "overview" %>

<div class='dashboard-left'>
<%= render "welcome" %>
<%= render "comments" %>
<%= render "popular" %>
</div>
<div>
<div class='span6'>
<%= render "welcome" %>
<%= render "comments" %>
<%= render "popular" %>
</div>

<div class='dashboard'>
<%= render "inbound" %>
<%= render "posts" %>
<%= render "publify_dev" %>
</div>
<div class='span6'>
<%= render "inbound" %>
<%= render "posts" %>
<%= render "publify_dev" %>
</div>

</div>
32 changes: 16 additions & 16 deletions spec/controllers/admin/dashboard_controller_spec.rb
Expand Up @@ -38,27 +38,31 @@
end

it "should have a link to article listing" do
response.should have_selector("a", :href => "/admin/content" , :content => "Total posts:")
response.should have_selector("a", :href => "/admin/content" , :content => "0 articles")
end

it "should have a link to user's article listing" do
response.should have_selector("a", :href => "/admin/content?search%5Buser_id%5D=#{@henri.id}" , :content => "Your posts:")
response.should have_selector("a", :href => "/admin/content?search%5Buser_id%5D=#{@henri.id}" , :content => "0 articles writen by you")
end

it "should have a link to categories" do
response.should have_selector("a", :href => "/admin/categories" , :content => "Categories:")
it "should have a link to drafts" do
response.should have_selector("a", :href => "/admin/content?search%5Bstate%5D=drafts" , :content => "0 drafts")
end

it "should have a link to pages" do
response.should have_selector("a", :href => "/admin/pages" , :content => "0 pages")
end

it "should have a link to total comments" do
response.should have_selector("a", :href => "/admin/feedback" , :content => "Total comments:")
response.should have_selector("a", :href => "/admin/feedback" , :content => "0 comments")
end

it "should have a link to Spam" do
response.should have_selector("a", :href => "/admin/feedback?published=f" , :content => "Spam comments:")
response.should have_selector("a", :href => "/admin/feedback?spam=f" , :content => "0 spam")
end

it "should have a link to Spam queue" do
response.should have_selector("a", :href => "/admin/feedback?presumed_spam=f" , :content => "In your spam queue:")
response.should have_selector("a", :href => "/admin/feedback?presumed_ham=f" , :content => "0 unconfirmed")
end
end

Expand Down Expand Up @@ -97,27 +101,23 @@
end

it "should have a link to article listing" do
response.should have_selector("a", :href => "/admin/content" , :content => "Total posts:")
response.should have_selector("a", :href => "/admin/content" , :content => "0 articles")
end

it "should have a link to user's article listing" do
response.should have_selector("a", :href => "/admin/content?search%5Buser_id%5D=#{@rene.id}" , :content => "Your posts:")
end

it "should have a link to categories" do
response.should have_selector("a", :href => "/admin/categories" , :content => "Categories:")
response.should have_selector("a", :href => "/admin/content?search%5Buser_id%5D=#{@rene.id}" , :content => "0 articles writen by you")
end

it "should have a link to total comments" do
response.should have_selector("a", :href => "/admin/feedback" , :content => "Total comments:")
response.should have_selector("a", :href => "/admin/feedback" , :content => "0 comments")
end

it "should have a link to Spam" do
response.should have_selector("a", :href => "/admin/feedback?published=f" , :content => "Spam comments:")
response.should have_selector("a", :href => "/admin/feedback?spam=f" , :content => "0 spam")
end

it "should have a link to Spam queue" do
response.should have_selector("a", :href => "/admin/feedback?presumed_spam=f" , :content => "In your spam queue:")
response.should have_selector("a", :href => "/admin/feedback?presumed_ham=f" , :content => "0 unconfirmed")
end
end

Expand Down

0 comments on commit c7fd764

Please sign in to comment.