From 5462a1e56abf70486dc59593dde6ecb95a072026 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 20 Mar 2024 11:00:31 -0400 Subject: Added some admin dashboard stats --- app/controllers/comments_controller.rb | 2 ++ app/models/global.rb | 20 ++++++++++++++++++++ app/views/admin/dashboard/index.html.haml | 20 +++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/models/global.rb (limited to 'app') diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 368f587..b305d0a 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -35,6 +35,8 @@ class CommentsController < ApplicationController if is_blatant # I am lying. flash.notice = "Comment submitted successfully! It will need to be moderated before it shows up on the blog." + + Global.increment_filtered_comments else if is_spam @comment.status = :pending diff --git a/app/models/global.rb b/app/models/global.rb new file mode 100644 index 0000000..7c7d6d4 --- /dev/null +++ b/app/models/global.rb @@ -0,0 +1,20 @@ +class Global < ApplicationRecord + def self.get_filtered_comments + row = find_by_key("filtered_comments") + if row + row[:int_value] + else + 0 + end + end + + def self.increment_filtered_comments + row = find_by_key("filtered_comments") + if row + row.int_value += 1 + row.save + else + create(key: "filtered_comments", int_value: 1) + end + end +end diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index eaac627..254107c 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -1 +1,19 @@ -Welcome to the the ubiquitous administration panel! +%p Welcome to the the ubiquitous administration panel! +%p Stats: +%ul + %li + %strong Blog posts: + = Blog.count + %li + %strong Approved comments: + = Comment.where(status: :published).count + %li + %strong Filtered comments: + = Global.get_filtered_comments + %li + %strong Quotes: + = Quote.count + %li + %strong Votes: + = Vote.count + (+#{Vote.where(upvote: true).count} / -#{Vote.where(upvote: false).count}) -- cgit 1.4.1