about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/comments_controller.rb2
-rw-r--r--app/models/global.rb20
-rw-r--r--app/views/admin/dashboard/index.html.haml20
-rw-r--r--db/migrate/20240320145033_create_globals.rb11
-rw-r--r--db/schema.rb10
-rw-r--r--test/fixtures/globals.yml11
-rw-r--r--test/models/global_test.rb7
7 files changed, 79 insertions, 2 deletions
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
35 if is_blatant 35 if is_blatant
36 # I am lying. 36 # I am lying.
37 flash.notice = "Comment submitted successfully! It will need to be moderated before it shows up on the blog." 37 flash.notice = "Comment submitted successfully! It will need to be moderated before it shows up on the blog."
38
39 Global.increment_filtered_comments
38 else 40 else
39 if is_spam 41 if is_spam
40 @comment.status = :pending 42 @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 @@
1class Global < ApplicationRecord
2 def self.get_filtered_comments
3 row = find_by_key("filtered_comments")
4 if row
5 row[:int_value]
6 else
7 0
8 end
9 end
10
11 def self.increment_filtered_comments
12 row = find_by_key("filtered_comments")
13 if row
14 row.int_value += 1
15 row.save
16 else
17 create(key: "filtered_comments", int_value: 1)
18 end
19 end
20end
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 @@
1Welcome to the the ubiquitous administration panel! 1%p Welcome to the the ubiquitous administration panel!
2%p Stats:
3%ul
4 %li
5 %strong Blog posts:
6 = Blog.count
7 %li
8 %strong Approved comments:
9 = Comment.where(status: :published).count
10 %li
11 %strong Filtered comments:
12 = Global.get_filtered_comments
13 %li
14 %strong Quotes:
15 = Quote.count
16 %li
17 %strong Votes:
18 = Vote.count
19 (+#{Vote.where(upvote: true).count} / -#{Vote.where(upvote: false).count})
diff --git a/db/migrate/20240320145033_create_globals.rb b/db/migrate/20240320145033_create_globals.rb new file mode 100644 index 0000000..6ac9a29 --- /dev/null +++ b/db/migrate/20240320145033_create_globals.rb
@@ -0,0 +1,11 @@
1class CreateGlobals < ActiveRecord::Migration[7.1]
2 def change
3 create_table :globals do |t|
4 t.string :key
5 t.string :string_value
6 t.integer :int_value
7
8 t.timestamps
9 end
10 end
11end
diff --git a/db/schema.rb b/db/schema.rb index b036d7f..9cfdf57 100644 --- a/db/schema.rb +++ b/db/schema.rb
@@ -10,7 +10,7 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema[7.1].define(version: 2023_10_30_181440) do 13ActiveRecord::Schema[7.1].define(version: 2024_03_20_145033) do
14 create_table "active_storage_attachments", force: :cascade do |t| 14 create_table "active_storage_attachments", force: :cascade do |t|
15 t.string "name", null: false 15 t.string "name", null: false
16 t.string "record_type", null: false 16 t.string "record_type", null: false
@@ -118,6 +118,14 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_30_181440) do
118 t.date "finished_on" 118 t.date "finished_on"
119 end 119 end
120 120
121 create_table "globals", force: :cascade do |t|
122 t.string "key"
123 t.string "string_value"
124 t.integer "int_value"
125 t.datetime "created_at", null: false
126 t.datetime "updated_at", null: false
127 end
128
121 create_table "lingo_scores", force: :cascade do |t| 129 create_table "lingo_scores", force: :cascade do |t|
122 t.integer "user_id", limit: 8 130 t.integer "user_id", limit: 8
123 t.string "username" 131 t.string "username"
diff --git a/test/fixtures/globals.yml b/test/fixtures/globals.yml new file mode 100644 index 0000000..bb636b7 --- /dev/null +++ b/test/fixtures/globals.yml
@@ -0,0 +1,11 @@
1# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
3one:
4 key: MyString
5 string_value: MyString
6 int_value: 1
7
8two:
9 key: MyString
10 string_value: MyString
11 int_value: 1
diff --git a/test/models/global_test.rb b/test/models/global_test.rb new file mode 100644 index 0000000..2e42136 --- /dev/null +++ b/test/models/global_test.rb
@@ -0,0 +1,7 @@
1require "test_helper"
2
3class GlobalTest < ActiveSupport::TestCase
4 # test "the truth" do
5 # assert true
6 # end
7end