Sha256: 94f14da3eb03b704d7d0b02e4a8bcc5dde5162a7e298cb88f86952e03bafca69

Contents?: true

Size: 1.54 KB

Versions: 25

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Admin
    ##
    # @example using a custom presenter and stats services
    #   class MyStatsController < ApplicationController
    #     include Hyrax::Admin::StatsBehavior
    #
    #     self.admin_stats_presenter = MyCustomStatsPresenter
    #     self.admin_stats_services = { by_depositor:      CustomDepositorService,
    #                                   depositor_summary: CustomSummaryService }
    #     # see AdminStatsPresenter#initialize for supported services
    #   end
    #
    module StatsBehavior
      extend ActiveSupport::Concern
      included do
        with_themed_layout 'dashboard'

        class_attribute :admin_stats_presenter, :admin_stats_services
        self.admin_stats_presenter = AdminStatsPresenter
        self.admin_stats_services  = {}
      end

      def show
        authorize! :read, Hyrax::Statistics
        stats_filters = params.fetch(:stats_filters, {})
        limit = params.fetch(:limit, "5").to_i
        @presenter = build_presenter(stats_filters, limit)
        add_breadcrumb t(:'hyrax.controls.home'), root_path
        add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
        add_breadcrumb t(:'hyrax.admin.sidebar.statistics'), hyrax.admin_stats_path
      end

      private

      def build_presenter(stats_filters, limit)
        presenter_class = self.class.admin_stats_presenter
        services_opts   = self.class.admin_stats_services

        presenter_class.new(stats_filters, limit, **services_opts)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-5.0.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-5.0.0.rc3 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-5.0.0.rc2 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-5.0.0.rc1 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.6.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-4.0.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-4.0.0.rc3 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-4.0.0.rc2 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-4.0.0.rc1 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.5.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-4.0.0.beta2 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.4.2 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-4.0.0.beta1 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.4.1 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.4.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.3.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.2.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.1.0 app/controllers/concerns/hyrax/admin/stats_behavior.rb
hyrax-3.0.2 app/controllers/concerns/hyrax/admin/stats_behavior.rb