|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "administrate/base_dashboard" |
| 4 | + |
| 5 | +class RegionDashboard < Administrate::BaseDashboard |
| 6 | + # ATTRIBUTE_TYPES |
| 7 | + # a hash that describes the type of each of the model's fields. |
| 8 | + # |
| 9 | + # Each different type represents an Administrate::Field object, |
| 10 | + # which determines how the attribute is displayed |
| 11 | + # on pages throughout the dashboard. |
| 12 | + ATTRIBUTE_TYPES = { |
| 13 | + id: Field::Number, |
| 14 | + name: Field::String, |
| 15 | + display_name: Field::String, |
| 16 | + slug: Field::String, |
| 17 | + description: Field::Text, |
| 18 | + rights_designation: Field::Select.with_options( |
| 19 | + collection: Region.rights_designations.keys.map { |k| [k.titleize, k] } |
| 20 | + ), |
| 21 | + agencies: Field::HasMany, |
| 22 | + people: Field::HasMany, |
| 23 | + created_at: Field::DateTime, |
| 24 | + updated_at: Field::DateTime |
| 25 | + }.freeze |
| 26 | + |
| 27 | + # COLLECTION_ATTRIBUTES |
| 28 | + # an array of attributes that will be displayed on the model's index page. |
| 29 | + # |
| 30 | + # By default, it's limited to four items to reduce clutter on index pages. |
| 31 | + # Feel free to add, remove, or rearrange items. |
| 32 | + COLLECTION_ATTRIBUTES = %i[ |
| 33 | + display_name |
| 34 | + description |
| 35 | + agencies |
| 36 | + ].freeze |
| 37 | + |
| 38 | + # SHOW_PAGE_ATTRIBUTES |
| 39 | + # an array of attributes that will be displayed on the model's show page. |
| 40 | + SHOW_PAGE_ATTRIBUTES = %i[ |
| 41 | + display_name |
| 42 | + slug |
| 43 | + description |
| 44 | + rights_designation |
| 45 | + agencies |
| 46 | + people |
| 47 | + created_at |
| 48 | + updated_at |
| 49 | + ].freeze |
| 50 | + |
| 51 | + # FORM_ATTRIBUTES |
| 52 | + # an array of attributes that will be displayed |
| 53 | + # on the model's form (`new` and `edit`) pages. |
| 54 | + FORM_ATTRIBUTES = %i[ |
| 55 | + name |
| 56 | + slug |
| 57 | + description |
| 58 | + rights_designation |
| 59 | + ].freeze |
| 60 | + |
| 61 | + # COLLECTION_FILTERS |
| 62 | + # a hash that defines filters that can be used while searching via the search |
| 63 | + # field of the dashboard. |
| 64 | + # |
| 65 | + # For example to add an option to search for open resources by typing "open:" |
| 66 | + # in the search field: |
| 67 | + # |
| 68 | + # COLLECTION_FILTERS = { |
| 69 | + # open: ->(resources) { resources.where(open: true) } |
| 70 | + # }.freeze |
| 71 | + COLLECTION_FILTERS = {}.freeze |
| 72 | + |
| 73 | + # Overwrite this method to customize how regions are displayed |
| 74 | + # across all pages of the admin dashboard. |
| 75 | + # |
| 76 | + def display_resource(region) |
| 77 | + region.display_name |
| 78 | + end |
| 79 | +end |
0 commit comments