From c7fd764fe715ccc625c6a5f72a3a4d7ff0a9370b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20de=20Villamil?= Date: Sat, 10 Aug 2013 21:38:09 +0200 Subject: [PATCH] Makes the dashboard more useful, step 1. The welcome widget is now dedicated to the activity of the day. Definitely ripped from Wordpress. --- app/controllers/admin/dashboard_controller.rb | 26 +++++++--- app/models/article.rb | 1 - app/models/comment.rb | 3 ++ app/views/admin/dashboard/_overview.html.erb | 2 +- app/views/admin/dashboard/_welcome.html.erb | 49 ++++++++++--------- app/views/admin/dashboard/index.html.erb | 23 +++++---- .../admin/dashboard_controller_spec.rb | 32 ++++++------ 7 files changed, 78 insertions(+), 58 deletions(-) diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 100b41c9c3..4850337815 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -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 diff --git a/app/models/article.rb b/app/models/article.rb index 0b93788b91..a57714a958 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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| diff --git a/app/models/comment.rb b/app/models/comment.rb index 3797503375..619637ae05 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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) diff --git a/app/views/admin/dashboard/_overview.html.erb b/app/views/admin/dashboard/_overview.html.erb index 3044071bcf..7895f7ecc2 100644 --- a/app/views/admin/dashboard/_overview.html.erb +++ b/app/views/admin/dashboard/_overview.html.erb @@ -1,4 +1,4 @@ -

<%= _("Getting started") %>

+

<%= _("Welcome back, %s!", current_user.name ) -%>

<%= _("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) %> diff --git a/app/views/admin/dashboard/_welcome.html.erb b/app/views/admin/dashboard/_welcome.html.erb index 16c849758c..944aa27326 100644 --- a/app/views/admin/dashboard/_welcome.html.erb +++ b/app/views/admin/dashboard/_welcome.html.erb @@ -1,24 +1,29 @@ -

<%= _("Welcome back, %s!", current_user.name ) -%>

+

<%= _("Today") -%>

+
+
+

<%= _("%d articles and %d comments were posted since your last connexion", @newposts_count, @newcomments_count) %>

+

<%= _("You're running Publify %s", PUBLIFY_VERSION) %> <%= @version_message %>

-
-

<%= _("%d articles and %d comments were posted since your last connexion", @newposts_count, @newcomments_count) %>

-

<%= _("You're running Publify %s", PUBLIFY_VERSION) %> <%= @version_message %>

- - <% if current_user.profile.modules.include? :articles%> -

<%= _("Content") %>

-
    -
  • <%= sprintf("%s %d", link_to(_("Total posts:"), :controller => 'admin/content'), @statposts) %>
  • -
  • <%= sprintf("%s %d", link_to(_("Your posts:"), :controller => 'admin/content', "search[user_id]" => current_user.id), @statuserposts) %>
  • -
  • <%= sprintf("%s %d", link_to(_("Categories:"), :controller => 'admin/categories'), @categories) %>
  • -
- <% end %> - - <% if current_user.profile.modules.include? :articles %> -

<%= _("Feedback") %>

-
    -
  • <%= sprintf("%s %d", link_to(_("Total comments:"), :controller => 'admin/feedback') , @statcomments) %>
  • -
  • <%= sprintf("%s %d", link_to(_("Spam comments:"), :controller => 'admin/feedback', :published => 'f'), @statspam) %>
  • -
  • <%= sprintf("%s %d", link_to(_("In your spam queue:"), :controller => 'admin/feedback', :presumed_spam => 'f'), @presumedspam) %>
  • -
- <% end %> +
+
+ <% if current_user.profile.modules.include? :articles%> + +

<%= link_to(sprintf("%d %s", @statposts, pluralize(@statposts, _("articles"), _("article"), _("articles"))).html_safe, :controller => 'admin/content').html_safe %>

+

<%= link_to(sprintf("%d %s", @statuserposts, _("articles writen by you")).html_safe, :controller => 'admin/content', "search[user_id]" => current_user.id).html_safe %>

+

<%= link_to(sprintf("%d %s", @statsdrafts, pluralize(@statsdrafts, _("drafts"), _("draft"), _("drafts"))).html_safe, :controller => 'admin/content', "search[state]" => "drafts").html_safe %>

+

<%= link_to(sprintf("%d %s", @statspages, pluralize(@statspages, _("pages"), _("page"), _("pages"))).html_safe, :controller => 'admin/pages').html_safe %>

+

<%= link_to(sprintf("%d %s", @statuses, pluralize(@statspages, _("short statuses"), _("short status"), _("short statuses"))).html_safe, :controller => 'admin/statuses').html_safe %>

+ <% end %> +
+
+ <% if current_user.profile.modules.include? :feedback %> + +

<%= link_to(sprintf("%d %s", @statcomments, _("comments")).html_safe, :controller => 'admin/feedback').html_safe %>

+

<%= link_to(sprintf("%d %s", @confirmed, _("approved")).html_safe, :controller => 'admin/feedback', "ham" => "f").html_safe %>

+

<%= link_to(sprintf("%d %s", @unconfirmed, _("unconfirmed")).html_safe, :controller => 'admin/feedback', "presumed_ham" => "f").html_safe %>

+

<%= link_to(sprintf("%d %s", @statspam, _("spam")).html_safe, :controller => 'admin/feedback', "spam" => "f").html_safe %>

+ <% end %> +
+
+
diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 0d871c29ff..c307cecc1e 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -1,13 +1,16 @@ <%= render "overview" %> -
- <%= render "welcome" %> - <%= render "comments" %> - <%= render "popular" %> -
+
+
+ <%= render "welcome" %> + <%= render "comments" %> + <%= render "popular" %> +
-
- <%= render "inbound" %> - <%= render "posts" %> - <%= render "publify_dev" %> -
+
+ <%= render "inbound" %> + <%= render "posts" %> + <%= render "publify_dev" %> +
+ +
\ No newline at end of file diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index f459f79a9b..9811143e6f 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -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 @@ -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