about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-31 14:38:44 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-31 20:38:44 +0200
commita132332b861f997540f30be1b90ade4648834b5b (patch)
tree312364eef2a971ec97be48f2be71dc7702d6c578
parentb25e42a77f4b3472bc519e8a394b2cfe0e063e4c (diff)
Add Instance class to list admin records (#3443)
-rw-r--r--app/controllers/admin/instances_controller.rb9
-rw-r--r--app/models/instance.rb12
-rw-r--r--app/views/admin/instances/index.html.haml4
3 files changed, 21 insertions, 4 deletions
diff --git a/app/controllers/admin/instances_controller.rb b/app/controllers/admin/instances_controller.rb
index b8f170ec2..ac93248a8 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 000000000..6d5c9c2ab
--- /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 e5955e6bf..be21d6bf7 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