Skip to content

Commit 02763f8

Browse files
authored
Merge pull request #136 from restarone/addTablesToDomainAdmin
Add tables to domain admin
2 parents 2c4f462 + 962d3ad commit 02763f8

File tree

22 files changed

+320
-62
lines changed

22 files changed

+320
-62
lines changed

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ gem "aws-sdk-s3", require: false
4040
gem 'meta-tags'
4141
gem 'sitemap_generator'
4242
gem 'ahoy_matey'
43+
gem 'ransack'
44+
gem 'will_paginate'
45+
gem "chartkick"
46+
gem 'groupdate'
47+
gem 'local_time'
4348

4449
# Reduces boot times through caching; required in config/boot.rb
4550
gem 'bootsnap', '>= 1.4.4', require: false

Gemfile.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ GEM
164164
rack-test (>= 0.6.3)
165165
regexp_parser (>= 1.5, < 3.0)
166166
xpath (~> 3.2)
167+
chartkick (4.0.4)
167168
childprocess (3.0.0)
168169
comfy_bootstrap_form (4.0.9)
169170
rails (>= 5.0.0)
@@ -195,6 +196,8 @@ GEM
195196
globalid (0.4.2)
196197
activesupport (>= 4.2.0)
197198
gravatar_image_tag (1.2.0)
199+
groupdate (5.2.2)
200+
activesupport (>= 5)
198201
haml (5.2.1)
199202
temple (>= 0.8.0)
200203
tilt
@@ -229,6 +232,7 @@ GEM
229232
listen (3.5.1)
230233
rb-fsevent (~> 0.10, >= 0.10.3)
231234
rb-inotify (~> 0.9, >= 0.9.10)
235+
local_time (2.1.0)
232236
loofah (2.9.0)
233237
crass (~> 1.0.2)
234238
nokogiri (>= 1.5.9)
@@ -312,6 +316,10 @@ GEM
312316
rake (>= 0.8.7)
313317
thor (~> 1.0)
314318
rake (13.0.3)
319+
ransack (2.4.2)
320+
activerecord (>= 5.2.4)
321+
activesupport (>= 5.2.4)
322+
i18n
315323
rb-fsevent (0.10.4)
316324
rb-inotify (0.10.1)
317325
ffi (~> 1.0)
@@ -437,15 +445,18 @@ DEPENDENCIES
437445
capistrano-rbenv
438446
capistrano3-puma
439447
capybara (>= 3.26)
448+
chartkick
440449
comfortable_mexican_sofa!
441450
comfy_blog!
442451
devise
443452
devise_invitable
444453
friendly_id
445454
gravatar_image_tag
455+
groupdate
446456
image_processing (~> 1.2)
447457
jbuilder (~> 2.7)
448458
listen (~> 3.3)
459+
local_time
449460
mailgun-ruby
450461
meta-tags
451462
mocha
@@ -454,6 +465,7 @@ DEPENDENCIES
454465
rack-mini-profiler (~> 2.0)
455466
rails (~> 6.1.3, >= 6.1.3.1)
456467
rails-controller-testing
468+
ransack
457469
ros-apartment
458470
ros-apartment-sidekiq
459471
sass-rails (>= 6)
@@ -469,6 +481,7 @@ DEPENDENCIES
469481
webdrivers
470482
webpacker (~> 5.0)
471483
wicked
484+
will_paginate
472485

473486
RUBY VERSION
474487
ruby 2.6.6p146

app/assets/stylesheets/comfy/admin/cms/custom.sass

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ label[for=layout_app_layout]
1313
select[id=layout_app_layout]
1414
display: none
1515

16+
17+
18+
19+
20+

app/controllers/admin/subdomains_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ class Admin::SubdomainsController < Admin::BaseController
22
before_action :load_subdomain, except: [:index]
33

44
def index
5-
@subdomains = Subdomain.all
5+
params[:q] ||= {}
6+
@subdomains_q = Subdomain.ransack(params[:q])
7+
@subdomains = @subdomains_q.result.paginate(page: params[:page], per_page: 10)
68
end
79

810
def edit

app/controllers/comfy/admin/users_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ class Comfy::Admin::UsersController < Comfy::Admin::Cms::BaseController
44
before_action :ensure_authority_to_manage_users, only: [:index, :new, :invite, :edit, :update, :destroy]
55

66
def index
7-
@users = User.all
7+
params[:q] ||= {}
8+
@users_q = User.ransack(params[:q])
9+
@users = @users_q.result.paginate(page: params[:page], per_page: 10)
810
end
911

1012
def new

app/controllers/comfy/admin/web_settings_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ class Comfy::Admin::WebSettingsController < Comfy::Admin::Cms::BaseController
33
before_action :ensure_authority_to_manage_web
44

55
def edit
6+
params[:q] ||= {}
7+
@visits_q = Subdomain.current.ahoy_visits.ransack(params[:q])
8+
@visits = @visits_q.result.paginate(page: params[:page], per_page: 10)
69
end
710

811
def update

app/helpers/application_helper.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
module ApplicationHelper
22
def display_subdomain_name(schema_path)
3-
"#{schema_path}.#{ENV['APP_HOST']}"
3+
subdomain = schema_path != Subdomain::ROOT_DOMAIN_NAME ? schema_path : 'www'
4+
"#{subdomain}.#{ENV['APP_HOST']}"
45
end
6+
7+
def page_entries_info(collection)
8+
model_name = collection.respond_to?(:human_name) ? collection.model_name.human : (collection.first&.model_name&.human || '')
9+
10+
sanitize "Displaying #{model_name} " +
11+
tag.b("#{collection.offset + 1} - #{[collection.per_page * collection.current_page, collection.total_entries].min}") +
12+
' of ' + tag.b(collection.total_entries) +
13+
' in total'
14+
end
515
end

app/helpers/subdomain_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ def web_pages_count(subdomain)
2323
end
2424
end
2525

26+
def forum_threads_count(subdomain)
27+
Apartment::Tenant.switch subdomain.name do
28+
ForumThread.all.size
29+
end
30+
end
31+
32+
def visits_count(subdomain)
33+
Apartment::Tenant.switch subdomain.name do
34+
Ahoy::Visit.all.size
35+
end
36+
end
37+
2638
def html_title(subdomain)
2739
subdomain.html_title ? subdomain.html_title : subdomain.name
2840
end

app/models/subdomain.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def self.current
3030
end
3131
end
3232

33+
def ahoy_visits
34+
Ahoy::Visit.order(started_at: :desc)
35+
end
36+
3337
def initialize_mailbox
3438
Apartment::Tenant.switch self.name do
3539
mailbox = Mailbox.first_or_create

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def self.global_admins
3030
def self.forum_mods
3131
self.where(moderator: true)
3232
end
33+
34+
def previous_ahoy_visits
35+
Ahoy::Visit.where(user_id: self.id).order(started_at: :desc).limit(5)
36+
end
3337

3438
private
3539

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.digg_pagination
2+
.page-info
3+
= page_entries_info @subdomains
4+
= will_paginate @subdomains, container: false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
= search_form_for @subdomains_q, url: admin_subdomains_path do |f|
2+
.form-group
3+
= f.label "name", class: 'col-form-label'
4+
= f.search_field :name_cont, value: params[:q][:name_cont], class: 'form-control'
5+
= f.label "by SEO", class: 'col-form-label'
6+
= f.search_field :keywords_or_description_cont, value: params[:q][:keywords_or_description_cont], class: 'form-control'
7+
= f.label "by HTML meta", class: 'col-form-label'
8+
= f.search_field :html_title_or_blog_title_or_blog_html_title_or_forum_title_or_forum_html_title_cont, value: params[:q][:html_title_or_blog_title_or_blog_html_title_or_forum_title_or_forum_html_title_cont], class: 'form-control'
9+
.text-center
10+
= f.submit class: 'btn btn-primary my-2'
11+
= link_to "Clear Search", request.path, class:"cancel-button"

app/views/admin/subdomains/edit.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
%li= "#{pluralize(emails_count(@subdomain), 'Email')}"
1212
%li= "#{pluralize(web_pages_count(@subdomain), 'Web Page')}"
1313
%li= "#{pluralize(blog_posts_count(@subdomain), 'Blog Post')}"
14+
%li= "#{pluralize(forum_threads_count(@subdomain), 'Forum Thread')}"
1415
= link_to "Destroy Domain (Irreversible)", admin_subdomain_path(id: @subdomain), method: :delete, class: 'btn btn-lg btn-block btn-danger', data: { confirm: 'are you sure? This cannot be undone' }

app/views/admin/subdomains/index.haml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
%h1
22
Active Subdomains
33
.my-5.list-group
4-
- @subdomains.each do |subdomain|
5-
- if subdomain.name
6-
= link_to edit_admin_subdomain_path(id: subdomain.id), class: 'list-group-item list-group-item-action flex-column align-items-start' do
7-
.d-flex.w-100.justify-content-between
8-
%h5
9-
= display_subdomain_name(subdomain.name)
10-
%small
11-
= subdomain.created_at
12-
4+
= render partial: 'search_filters'
5+
= render partial: 'pagination'
6+
%table.table.table-responsive
7+
%thead
8+
%tr
9+
%th{:scope => "col"}
10+
= sort_link @subdomains_q, :name
11+
%th{:scope => "col"}
12+
= sort_link @subdomains_q, :description
13+
%th{:scope => "col"}
14+
= sort_link @subdomains_q, :keywords
15+
%th{:scope => "col"}
16+
= sort_link @subdomains_q, :visitors
17+
%th{:scope => "col"}
18+
= sort_link @subdomains_q, :users
19+
%th{:scope => "col"}
20+
= sort_link @subdomains_q, :created_at
21+
%th{:scope => "col"}
22+
= sort_link @subdomains_q, :updated_at
23+
%th{:scope => "col"}
24+
= sort_link @subdomains_q, :storage_used
25+
- @subdomains.each do |subdomain|
26+
- if subdomain.name
27+
%tr
28+
%td
29+
= link_to display_subdomain_name(subdomain.name), edit_admin_subdomain_path(id: subdomain.id)
30+
%td= subdomain.description
31+
%td= subdomain.keywords
32+
%td= visits_count(subdomain)
33+
%td= users_count(subdomain)
34+
%td= local_time(subdomain.created_at)
35+
%td= local_time(subdomain.updated_at)
36+
%td= number_to_human_size(subdomain.storage_used)
37+
= render partial: 'pagination'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.digg_pagination
2+
.page-info
3+
= page_entries_info @users
4+
= will_paginate @users, container: false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= search_form_for @users_q, url: admin_users_path do |f|
2+
.form-group
3+
= f.label "name", class: 'col-form-label'
4+
= f.search_field :name_cont, value: params[:q][:name_cont], class: 'form-control'
5+
= f.label "email", class: 'col-form-label'
6+
= f.search_field :email_cont, value: params[:q][:email_cont], class: 'form-control'
7+
.text-center
8+
= f.submit class: 'btn btn-primary my-2'
9+
= link_to "Clear Search", request.path, class:"cancel-button"

app/views/comfy/admin/users/edit.haml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,71 @@
3232
%label
3333
Can manage and invite users
3434
= f.submit "Update", class: 'btn btn-success'
35-
= link_to "Remove", admin_user_path(id: @user.id), method: :delete, class: 'btn btn-sm btn-danger', data: { confirm: 'Are you sure you want to remove this user? This cannot be undone' }
35+
= link_to "Remove", admin_user_path(id: @user.id), method: :delete, class: 'btn btn-sm btn-danger', data: { confirm: 'Are you sure you want to remove this user? This cannot be undone' }
36+
%hr/
37+
%main{class: 'my-5'}
38+
%h3
39+
Stats
40+
.card
41+
%ul.list-group.list-group-flush
42+
%li.list-group-item
43+
sign ins:
44+
= @user.sign_in_count
45+
%li.list-group-item
46+
current sign in:
47+
= @user.current_sign_in_at
48+
%li.list-group-item
49+
last sign in:
50+
= @user.last_sign_in_at
51+
%li.list-group-item
52+
current session IP:
53+
= @user.current_sign_in_ip
54+
%li.list-group-item
55+
last session IP:
56+
= @user.last_sign_in_ip
57+
%li.list-group-item
58+
created at:
59+
= local_time(@user.created_at)
60+
%li.list-group-item
61+
updated at:
62+
= local_time(@user.created_at)
63+
%li.list-group-item
64+
confirmed at:
65+
= @user.confirmed_at
66+
%li.list-group-item
67+
confirmation sent at:
68+
= @user.confirmation_sent_at
69+
%li.list-group-item
70+
locked at:
71+
= @user.locked_at
72+
73+
%main{class: 'my-5'}
74+
%h3
75+
Sessions
76+
.card
77+
.table-responsive
78+
%table.table.table-bordered
79+
%thead
80+
%tr
81+
%th Timestamp
82+
%th IP
83+
%th OS
84+
%th Browser
85+
%th Device Type
86+
%th Country
87+
%th Region
88+
%th City
89+
%th User Agent
90+
- @user.previous_ahoy_visits.each do |v|
91+
%tr
92+
%th= v.started_at.strftime('%I:%M %P - %b %d, %Y')
93+
%th= v.ip
94+
%th= v.os
95+
%th= v.browser
96+
%th= v.device_type
97+
%th= v.country
98+
%th= v.region
99+
%th= v.city
100+
%th.text-wrap.text-break= v.user_agent
101+
102+

app/views/comfy/admin/users/index.html.haml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22
= link_to I18n.t('views.comfy.users.index.header.action'), new_admin_user_path, class: 'btn btn-secondary float-right'
33
.h2
44
= I18n.t('views.comfy.users.index.header.title')
5-
- @users.each do |user|
6-
= link_to edit_admin_user_path(id: user.id) do
7-
.card.my-3
8-
.card-body
9-
.card-title
10-
= user.email
11-
.card-subtitle.mb-2.text-muted
12-
= user.created_at
5+
= render partial: 'search_filters'
6+
= render partial: 'pagination'
7+
%table.table.table-responsive
8+
%thead
9+
%tr
10+
%th{:scope => "col"}
11+
= sort_link @users_q, :email
12+
%th{:scope => "col"}
13+
= sort_link @users_q, :name
14+
%th{:scope => "col"}
15+
= sort_link @users_q, :current_sign_in_at
16+
%th{:scope => "col"}
17+
= sort_link @users_q, :last_sign_in_at
18+
%th{:scope => "col"}
19+
- @users.each do |user|
20+
%tr
21+
%td= link_to user.email, edit_admin_user_path(id: user.id)
22+
%td= user.name
23+
%td= user.current_sign_in_at
24+
%td= user.last_sign_in_at
25+
= render partial: 'pagination'

0 commit comments

Comments
 (0)