Instances list in admin (#2095)
* Add admin/instances index action * Add link to instances admin page * View lists instances * Instances, grouped by domain, ordered by count * Use Account.remote scope * Extract method: Account.by_domain_accounts
This commit is contained in:
parent
66d8f99a30
commit
55e1503522
8 changed files with 66 additions and 0 deletions
15
app/controllers/admin/instances_controller.rb
Normal file
15
app/controllers/admin/instances_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class InstancesController < BaseController
|
||||
def index
|
||||
@instances = ordered_instances.page(params[:page])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ordered_instances
|
||||
Account.remote.by_domain_accounts
|
||||
end
|
||||
end
|
||||
end
|
|
@ -68,6 +68,7 @@ class Account < ApplicationRecord
|
|||
scope :suspended, -> { where(suspended: true) }
|
||||
scope :recent, -> { reorder(id: :desc) }
|
||||
scope :alphabetic, -> { order(domain: :asc, username: :asc) }
|
||||
scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
|
||||
|
||||
def follow!(other_account)
|
||||
active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
|
||||
|
|
15
app/views/admin/instances/index.html.haml
Normal file
15
app/views/admin/instances/index.html.haml
Normal file
|
@ -0,0 +1,15 @@
|
|||
- content_for :page_title do
|
||||
= t('admin.instances.title')
|
||||
|
||||
%table.table
|
||||
%thead
|
||||
%tr
|
||||
%th= t('admin.instances.domain_name')
|
||||
%th= t('admin.instances.account_count')
|
||||
%tbody
|
||||
- @instances.each do |instance|
|
||||
%tr
|
||||
%td= instance.domain
|
||||
%td= instance.accounts_count
|
||||
|
||||
= paginate @instances
|
Loading…
Add table
Add a link
Reference in a new issue