Generate `SHOW_PAGE_ATTRIBUTES` as an explicit array
Created by: mcmire
Right now, COLLECTION_ATTRIBUTES
, SHOW_PAGE_ATTRIBUTES
, and FORM_ATTRIBUTES
use ATTRIBUTE_TYPES.keys
as a base set of attributes. It would follow, then, that in order to re-order fields that appear in a form or table, you re-order the keys in ATTRIBUTE_TYPES
. However, this seems a little odd, because ATTRIBUTE_TYPES
is a hash, and so the order of its keys should be irrelevant. (It just so happens that hashes in Ruby are now ordered, but they really shouldn't be, and we shouldn't be assuming they are.)
So here's a suggestion: introduce a BASE_ATTRIBUTES
constant that all of the other *_ATTRIBUTES
constants use. The dashboard generator would have to set this to an explicit array based on the columns the model has, but then we'd encourage people to modify this array instead of ATTRIBUTE_TYPES
. While we're at it, it might be useful to place ATTRIBUTE_TYPES
first.
So a dashboard class would look like this:
ATTRIBUTE_TYPES = {
author: Field::BelongsTo.with_options(class_name: "User"),
content: Field::Text,
id: Field::Number,
...
}
BASE_ATTRIBUTES = [
:author,
:content,
:id,
...
]
READ_ONLY_ATTRIBUTES = [
:id,
:created_at,
:updated_at
]
TABLE_ATTRIBUTES = BASE_ATTRIBUTES.first(4)
SHOW_PAGE_ATTRIBUTES = BASE_ATTRIBUTES
FORM_ATTRIBUTES = BASE_ATTRIBUTES - READ_ONLY_ATTRIBUTES