Sha256: 57c09494d9d955c490a5c7c19131b5c4ae9097e35daa7bec09b9d4a87622ef00

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

module ActiveAdminVersioning
  module ActiveAdmin
    module DSL
      def versioning
        return unless enabled_paper_trail?

        active_admin_namespace = config.namespace.name

        controller { include ActiveAdminVersioning::ActiveAdmin::ResourceController }

        member_action(:versions) do
          @versions   = resource.versions.reorder(id: :desc, created_at: :desc).page(params[:page])
          @page_title = ::PaperTrail::Version.model_name.human
          render "versions"
        end

        with_options only: :show do
          action_item :version do
            link_to [:versions, active_admin_namespace, resource_instance_name] do
              ::PaperTrail::Version.model_name.human
            end
          end

          sidebar ::PaperTrail::Version.model_name.human do
            if versions.present?
              attributes_table_for versions[0] do
                row ::PaperTrail::Version.model_name.human do |_|
                  version_number
                end
                row :event, &:event_i18n
                row :whodunnit do |record|
                  record.send(ActiveAdminVersioning.configuration.whodunnit_attribute_name).presence ||
                      span(t("views.version.unknown_user"), class: "empty")
                end
                row :created_at
              end
              paginate versions, theme: :version
            else
              I18n.t("views.version.empty", model_name: ::PaperTrail::Version.model_name.human)
            end
          end
        end
      end

      private

      def enabled_paper_trail?
        if config.resource_class.respond_to?(:paper_trail)
          config.resource_class.paper_trail.try(:enabled?)
        else
          config.resource_class.try(:paper_trail_enabled_for_model?)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_admin_versioning-0.3.0 lib/active_admin_versioning/active_admin/dsl.rb
active_admin_versioning-0.2.3 lib/active_admin_versioning/active_admin/dsl.rb