Skip to content

Commit

Permalink
Generate dashbaord for PaperTrail::Version
Browse files Browse the repository at this point in the history
```
rails generate administrate:dashboard PaperTrail::Version
```
  • Loading branch information
coffeejunk committed Apr 2, 2019
1 parent b546a2b commit 2f1d6ce
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/controllers/admin/versions_controller.rb
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions app/dashboards/version_dashboard.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2f1d6ce

Please sign in to comment.