From 2f1d6ce25f96523d08c07af0a10730ab8eb2459d Mon Sep 17 00:00:00 2001 From: Maximilian Haack Date: Tue, 2 Apr 2019 17:12:58 -0400 Subject: [PATCH] Generate dashbaord for `PaperTrail::Version` ``` rails generate administrate:dashboard PaperTrail::Version ``` --- app/controllers/admin/versions_controller.rb | 21 +++++++ app/dashboards/version_dashboard.rb | 58 ++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 app/controllers/admin/versions_controller.rb create mode 100644 app/dashboards/version_dashboard.rb diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb new file mode 100644 index 0000000..0e4836d --- /dev/null +++ b/app/controllers/admin/versions_controller.rb @@ -0,0 +1,21 @@ +module Admin + class PaperTrail::VersionsController < Admin::ApplicationController + # To customize the behavior of this controller, + # you can overwrite any of the RESTful actions. For example: + # + # def index + # super + # @resources = PaperTrail::Version. + # page(params[:page]). + # per(10) + # end + + # Define a custom finder by overriding the `find_resource` method: + # def find_resource(param) + # PaperTrail::Version.find_by!(slug: param) + # end + + # See https://administrate-prototype.herokuapp.com/customizing_controller_actions + # for more information + end +end diff --git a/app/dashboards/version_dashboard.rb b/app/dashboards/version_dashboard.rb new file mode 100644 index 0000000..266b07d --- /dev/null +++ b/app/dashboards/version_dashboard.rb @@ -0,0 +1,58 @@ +require "administrate/base_dashboard" + +class PaperTrail::VersionDashboard < Administrate::BaseDashboard + # ATTRIBUTE_TYPES + # a hash that describes the type of each of the model's fields. + # + # Each different type represents an Administrate::Field object, + # which determines how the attribute is displayed + # on pages throughout the dashboard. + ATTRIBUTE_TYPES = { + item: Field::Polymorphic, + id: Field::Number, + event: Field::String, + whodunnit: Field::String, + object: Field::Text, + created_at: Field::DateTime, + }.freeze + + # COLLECTION_ATTRIBUTES + # an array of attributes that will be displayed on the model's index page. + # + # By default, it's limited to four items to reduce clutter on index pages. + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = [ + :item, + :id, + :event, + :whodunnit, + ].freeze + + # SHOW_PAGE_ATTRIBUTES + # an array of attributes that will be displayed on the model's show page. + SHOW_PAGE_ATTRIBUTES = [ + :item, + :id, + :event, + :whodunnit, + :object, + :created_at, + ].freeze + + # FORM_ATTRIBUTES + # an array of attributes that will be displayed + # on the model's form (`new` and `edit`) pages. + FORM_ATTRIBUTES = [ + :item, + :event, + :whodunnit, + :object, + ].freeze + + # Overwrite this method to customize how versions are displayed + # across all pages of the admin dashboard. + # + # def display_resource(version) + # "PaperTrail::Version ##{version.id}" + # end +end