From a132332b861f997540f30be1b90ade4648834b5b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 31 May 2017 14:38:44 -0400 Subject: [PATCH] Add Instance class to list admin records (#3443) --- app/controllers/admin/instances_controller.rb | 9 +++++++-- app/models/instance.rb | 12 ++++++++++++ app/views/admin/instances/index.html.haml | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 app/models/instance.rb diff --git a/app/controllers/admin/instances_controller.rb b/app/controllers/admin/instances_controller.rb index b8f170ec28..ac93248a85 100644 --- a/app/controllers/admin/instances_controller.rb +++ b/app/controllers/admin/instances_controller.rb @@ -3,13 +3,18 @@ module Admin class InstancesController < BaseController def index - @instances = ordered_instances.page(params[:page]) + @instances = ordered_instances end private + def paginated_instances + Account.remote.by_domain_accounts.page(params[:page]) + end + helper_method :paginated_instances + def ordered_instances - Account.remote.by_domain_accounts + paginated_instances.map { |account| Instance.new(account) } end end end diff --git a/app/models/instance.rb b/app/models/instance.rb new file mode 100644 index 0000000000..6d5c9c2ab6 --- /dev/null +++ b/app/models/instance.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Instance + include ActiveModel::Model + + attr_accessor :domain, :accounts_count + + def initialize(account) + @domain = account.domain + @accounts_count = account.accounts_count + end +end diff --git a/app/views/admin/instances/index.html.haml b/app/views/admin/instances/index.html.haml index e5955e6bf7..be21d6bf7b 100644 --- a/app/views/admin/instances/index.html.haml +++ b/app/views/admin/instances/index.html.haml @@ -7,6 +7,6 @@ %th= t('admin.instances.domain_name') %th= t('admin.instances.account_count') %tbody - = render partial: 'instance', collection: @instances + = render @instances -= paginate @instances += paginate paginated_instances