Skip to content

Commit

Permalink
Sort all attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nhippenmeyer committed Feb 11, 2022
1 parent 7d10836 commit 4f4841d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 9 additions & 3 deletions lib/generators/administrate/dashboard/dashboard_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ def namespace
end

def attributes
klass.reflections.keys +
klass.columns.map(&:name) -
redundant_attributes
columns = klass.columns.map(&:name).map(&:to_s)

(klass.reflections.keys +
columns.without(%w[id created_at updated_at]) -
redundant_attributes).sort.tap do |result|
result.unshift(klass.primary_key) if klass.primary_key.present?
result.push("created_at") if columns.include?("created_at")
result.push("updated_at") if columns.include?("updated_at")
end
end

def form_attributes
Expand Down
11 changes: 1 addition & 10 deletions lib/generators/administrate/dashboard/templates/dashboard.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
<% if attributes.include?('id') %>
id: <%= field_type('id') %>,
<% end %>
<% attributes.sort.without(%w[id created_at updated_at]).each do |attr| -%>
<% attributes.each do |attr| -%>
<%= attr %>: <%= field_type(attr) %>,
<% end -%>
<% if attributes.include?('created_at') %>
created_at: <%= field_type('created_at') %>,
<% end %>
<% if attributes.include?('updated_at') %>
updated_at: <%= field_type('updated_at') %>,
<% end %>
}.freeze

# COLLECTION_ATTRIBUTES
Expand Down

0 comments on commit 4f4841d

Please sign in to comment.