Skip to content

Commit 6ffe728

Browse files
committed
Added cancancan and actiontext. Changed some controllers and models
1 parent 1cee66a commit 6ffe728

36 files changed

+259
-147
lines changed

.solargraph.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ formatter:
1919
extra_args: []
2020
require_paths: []
2121
plugins:
22-
- solargraph-rails
22+
- solargraph-rails
2323
max_files: 5000

Gemfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ gem 'meta-tags'
7373

7474
gem 'cancancan'
7575

76-
gem "activeadmin", "~> 3.0"
76+
gem 'activeadmin'
7777

78-
gem "faker", "~> 3.2"
78+
gem 'faker'
7979

80-
gem "bootstrap", "~> 5.2"
80+
gem 'bootstrap'
81+
82+
gem "importmap-rails", "~> 1.2"

Gemfile.lock

+12-6
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ GEM
8888
bindex (0.8.1)
8989
bootsnap (1.16.0)
9090
msgpack (~> 1.2)
91-
bootstrap (5.2.3)
91+
bootstrap (5.3.1)
9292
autoprefixer-rails (>= 9.1.0)
93-
popper_js (>= 2.11.6, < 3)
93+
popper_js (>= 2.11.8, < 3)
9494
sassc-rails (>= 2.0.0)
9595
builder (3.2.4)
9696
cancancan (3.5.0)
@@ -133,6 +133,9 @@ GEM
133133
image_processing (1.12.2)
134134
mini_magick (>= 4.9.5, < 5)
135135
ruby-vips (>= 2.0.17, < 3)
136+
importmap-rails (1.2.1)
137+
actionpack (>= 6.0.0)
138+
railties (>= 6.0.0)
136139
inherited_resources (1.13.1)
137140
actionpack (>= 5.2, < 7.1)
138141
has_scope (~> 0.6)
@@ -191,13 +194,15 @@ GEM
191194
nio4r (2.5.9)
192195
nokogiri (1.15.4-x86_64-darwin)
193196
racc (~> 1.4)
197+
nokogiri (1.15.4-x86_64-linux)
198+
racc (~> 1.4)
194199
orm_adapter (0.5.0)
195200
parallel (1.23.0)
196201
parser (3.2.2.3)
197202
ast (~> 2.4.1)
198203
racc
199204
pg (1.5.3)
200-
popper_js (2.11.7)
205+
popper_js (2.11.8)
201206
public_suffix (5.0.3)
202207
puma (6.3.0)
203208
nio4r (~> 2.0)
@@ -316,15 +321,16 @@ PLATFORMS
316321
x86_64-linux
317322

318323
DEPENDENCIES
319-
activeadmin (~> 3.0)
324+
activeadmin
320325
bootsnap
321-
bootstrap (~> 5.2)
326+
bootstrap
322327
cancancan
323328
capybara
324329
debug
325330
devise
326-
faker (~> 3.2)
331+
faker
327332
image_processing (~> 1.2)
333+
importmap-rails (~> 1.2)
328334
jbuilder
329335
json
330336
kaminari

app/admin/admin_users.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
ActiveAdmin.register AdminUser do
2-
permit_params :email,
2+
permit_params :avatar,
3+
:email,
34
:name,
45
:body,
6+
:role,
57
:posts_count,
68
:pages_count,
79
:password,
810
:password_confirmation
911

1012
index do
1113
selectable_column
12-
id_column
14+
column 'Avatar' do |admin_user|
15+
if admin_user.avatar.attached?
16+
image_tag admin_user.avatar, size: '50x50'
17+
else
18+
para 'No avatar'
19+
end
20+
end
1321
column :email
1422
column :name
23+
column :role
1524
column :posts_count
1625
column :pages_count
1726
column :current_sign_in_at
@@ -23,7 +32,7 @@
2332
show do |admin_user|
2433
panel 'Avatar' do
2534
if admin_user.avatar.attached?
26-
image_tag admin_user.avatar
35+
image_tag admin_user.avatar, size: '500x500'
2736
else
2837
para 'No avatar'
2938
end
@@ -36,6 +45,7 @@
3645
attributes_table do
3746
row :name
3847
row :email
48+
row :role
3949
row :posts_count
4050
row :pages_count
4151
row :reset_password_token
@@ -52,6 +62,7 @@
5262

5363
filter :email
5464
filter :name
65+
filter :role
5566
filter :posts_count
5667
filter :pages_count
5768
filter :current_sign_in_at
@@ -65,6 +76,7 @@
6576
f.input :email
6677
f.input :name
6778
f.input :body
79+
f.input :role
6880
f.input :avatar, as: :file
6981
f.input :password
7082
f.input :password_confirmation

app/admin/categories.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
permit_params :meta_title,
33
:meta_description,
44
:meta_keywords,
5+
:description,
56
:title,
67
:posts_count
78

89
index do
910
selectable_column
10-
id_column
1111
column :title
1212
column :posts_count
13-
column :updated_at
1413
column :created_at
1514
actions
1615
end
@@ -36,11 +35,21 @@
3635
filter :created_at
3736

3837
form do |f|
38+
div do
39+
javascript_importmap_tags
40+
end
3941
f.inputs 'Content' do
4042
f.semantic_errors
4143
f.input :title
42-
f.input :description
4344
end
45+
46+
f.inputs 'Body' do
47+
f.semantic_errors
48+
li style: 'margin: 10px;' do
49+
f.rich_text_area :description
50+
end
51+
end
52+
4453
f.inputs 'Meta data' do
4554
f.semantic_errors
4655
f.input :meta_title

app/admin/comments.rb

+5-10
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,18 @@
44
:post_id,
55
:user_id
66

7-
batch_action :published do |ids|
8-
batch_action_collection.find(ids).each do |comment|
9-
comment.update(published: true)
10-
end
7+
batch_action :publish do |ids|
8+
Comment.where(id: ids).update_all(published: true)
119
redirect_to admin_comments_path, notice: 'Comment(s) was published'
1210
end
1311

14-
batch_action :not_published do |ids|
15-
batch_action_collection.find(ids).each do |comment|
16-
comment.update(published: false)
17-
end
12+
batch_action :not_publish do |ids|
13+
Comment.where(id: ids).update_all(published: false)
1814
redirect_to admin_comments_path, notice: 'Comment(s) was not published'
1915
end
2016

2117
index do
2218
selectable_column
23-
id_column
2419
column :user
2520
column :body
2621
column :post
@@ -32,7 +27,7 @@
3227
filter :published
3328
filter :body
3429
filter :post
35-
filter :user, as: :select, collection: User.all.map { |u| [u.email, u.id] }
30+
filter :user, collection: User.all.map { |u| [u.email, u.id] }
3631
filter :updated_at
3732
filter :created_at
3833

app/admin/likes.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
index do
55
selectable_column
6-
id_column
76
column :user
87
column :record
98
column :created_at
109
actions
1110
end
1211

13-
filter :user, as: :select, collection: User.all.map { |u| [u.email, u.id] }
12+
filter :user, collection: User.all.map { |u| [u.email, u.id] }
1413
filter :record_type
1514
filter :created_at
1615
filter :updated_at

app/admin/pages.rb

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77
:published,
88
:admin_user_id
99

10-
batch_action :published do |ids|
11-
batch_action_collection.find(ids).each do |page|
12-
page.update(published: true)
13-
end
10+
batch_action :publish do |ids|
11+
Page.where(id: ids).update_all(published: true)
1412
redirect_to admin_pages_path, notice: 'Page(s) was published'
1513
end
1614

17-
batch_action :not_published do |ids|
18-
batch_action_collection.find(ids).each do |page|
19-
page.update(published: false)
20-
end
15+
batch_action :not_publish do |ids|
16+
Page.where(id: ids).update_all(published: false)
2117
redirect_to admin_pages_path, notice: 'Page(s) was not published'
2218
end
2319

2420
index do
2521
selectable_column
26-
id_column
2722
column :title
2823
column :admin_user
2924
column :published
@@ -55,6 +50,10 @@
5550
filter :updated_at
5651

5752
form do |f|
53+
div do
54+
javascript_importmap_tags
55+
end
56+
5857
f.inputs 'Attached' do
5958
f.semantic_errors
6059
f.input :admin_user
@@ -63,10 +62,16 @@
6362
f.inputs 'Content' do
6463
f.semantic_errors
6564
f.input :title
66-
f.input :body
6765
f.input :published
6866
end
6967

68+
f.inputs 'Body' do
69+
f.semantic_errors
70+
li style: 'margin: 10px' do
71+
f.rich_text_area :body
72+
end
73+
end
74+
7075
f.inputs 'Meta data' do
7176
f.semantic_errors
7277
f.input :meta_title

app/admin/posts.rb

+29-20
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,37 @@
33
:meta_description,
44
:meta_keywords,
55
:title,
6+
:description,
7+
:body,
68
:published,
79
:comments_enabled,
810
:category_id,
911
:likes_count,
1012
:comments_count,
1113
:admin_user_id
1214

13-
batch_action :published do |ids|
14-
batch_action_collection.find(ids).each do |post|
15-
post.update(published: true)
16-
end
15+
batch_action :publish do |ids|
16+
Post.where(id: ids).update_all(published: true)
1717
redirect_to admin_posts_path, notice: 'Post(s) was published'
1818
end
1919

20-
batch_action :not_published do |ids|
21-
batch_action_collection.find(ids).each do |post|
22-
post.update(published: false)
23-
end
20+
batch_action :not_publish do |ids|
21+
Post.where(id: ids).update_all(published: false)
2422
redirect_to admin_posts_path, notice: 'Post(s) was not published'
2523
end
2624

27-
batch_action :comments_enabled do |ids|
28-
batch_action_collection.find(ids).each do |post|
29-
post.update(comments_enabled: true)
30-
end
25+
batch_action :comments_enable do |ids|
26+
Post.where(id: ids).update_all(comments_enabled: true)
3127
redirect_to admin_posts_path, notice: 'Comment(s) were enabled'
3228
end
3329

34-
batch_action :comments_disabled do |ids|
35-
batch_action_collection.find(ids).each do |post|
36-
post.update(comments_enabled: false)
37-
end
30+
batch_action :comments_disable do |ids|
31+
Post.where(id: ids).update_all(comments_enabled: false)
3832
redirect_to admin_posts_path, notice: 'Comment(s) were disabled'
3933
end
4034

4135
index do
4236
selectable_column
43-
id_column
4437
column :title
4538
column :published
4639
column :comments_enabled
@@ -88,21 +81,37 @@
8881
filter :updated_at
8982

9083
form do |f|
84+
div do
85+
javascript_importmap_tags
86+
end
87+
9188
f.inputs 'Attached' do
9289
f.semantic_errors
9390
f.input :category
9491
f.input :admin_user
9592
end
9693

97-
f.inputs 'Content' do
94+
f.inputs 'Settings' do
9895
f.semantic_errors
9996
f.input :title
100-
f.input :body
101-
f.input :description
10297
f.input :published
10398
f.input :comments_enabled
10499
end
105100

101+
f.inputs 'Description' do
102+
f.semantic_errors
103+
li style: 'margin: 10px' do
104+
f.rich_text_area :description
105+
end
106+
end
107+
108+
f.inputs 'Body' do
109+
f.semantic_errors
110+
li style: 'margin: 10px' do
111+
f.rich_text_area :body
112+
end
113+
end
114+
106115
f.inputs 'Meta data' do
107116
f.semantic_errors
108117
f.input :meta_title

0 commit comments

Comments
 (0)