Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !20

Create a dashbard generator

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge gw-generator into master May 13, 2015
  • Overview 7
  • Commits 1
  • Pipelines 0
  • Changes 7

Created by: gracewashere

The generator pulls column names and types from the database, using the methods #column_names and column_types.

  • Fill in missing mappings to BaseDashboard#field_registry.

References: http://edgeguides.rubyonrails.org/generators.html https://github.com/ryanb/nifty-generators

When the user runs rails generate dashboard order, they get a file app/dashboards/order_dashboard.rb with the contents:

require "base_dashboard"

class OrderDashboard < BaseDashboard

  # This method returns 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.
  def attribute_types
    {
      id: :integer,
      customer_id: :integer,
      address_line_one: :string,
      address_line_two: :string,
      address_city: :string,
      address_state: :string,
      address_zip: :string,
      created_at: :datetime,
      updated_at: :datetime,
      customer: :belongs_to,
      line_items: :has_many,
    }
  end

  # This method returns an array of attributes
  # that will be displayed on the model's index page.
  def index_page_attributes
    attributes
  end

  # This method returns an array of attributes
  # that will be displayed on the model's show page
  def show_page_attributes
    attributes
  end

  # This method returns an array of attributes
  # that will be displayed on the model's form pages (`new` and `edit`)
  def form_attributes
    attributes - read_only_attributes
  end

  private

  def attributes
    [
      :id,
      :customer_id,
      :address_line_one,
      :address_line_two,
      :address_city,
      :address_state,
      :address_zip,
      :created_at,
      :updated_at,
      :customer,
      :line_items,
    ]
  end

  def read_only_attributes
    [
      :id,
      :created_at,
      :updated_at,
    ]
  end
end

https://trello.com/c/My9ldlzZ

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: gw-generator