Coder Social home page Coder Social logo

thoughtbot / administrate Goto Github PK

View Code? Open in Web Editor NEW
5.8K 5.8K 1.1K 4 MB

A Rails engine that helps you put together a super-flexible admin dashboard.

Home Page: http://administrate-demo.herokuapp.com

License: MIT License

Ruby 34.06% JavaScript 57.75% HTML 5.71% Shell 0.42% SCSS 2.04% Procfile 0.01%
admin-dashboard rails ruby

administrate's People

Contributors

5minpause avatar benmorganio avatar c-lliope avatar croaky avatar danbee avatar deivid-rodriguez avatar dependabot-preview[bot] avatar dependabot[bot] avatar edimossilva avatar edwinwills avatar ianagne avatar jamie avatar jayroh avatar jcmorrow avatar jonatasrancan avatar jordan-brough avatar jubilee2 avatar klaseskilson avatar ndrluis avatar nhippenmeyer avatar nickcharlton avatar odlp avatar pablobm avatar patrickgramatowski avatar pustomytnyk avatar seanpdoyle avatar sedubois avatar shouichi avatar teoljungberg avatar tysongach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

administrate's Issues

Feature Request: Nested Forms

Hi guys,

Thanks in advance for this great project, really good job. I was looking for something like that such a long time.

I was digging around and I have missed and option to build nested forms. I don´t know if there is an easy way to do it. IMHO its needed for the example app when you add line items to an order. Its painful to first create an order, save it then create line items and associate it. This happens on all kind of database models and It would be amazing to have this feature.

I think you can achieve this behaviour by adding custom fields types, overriding form view. Although you must allow nested attributes on your models.

Let me know what do you think about it and set a guidelines to approach this feature.

Thanks in advance and keep pushing!

uninitialized constant DashboardManifest (NameError)

Half the time when I run my rake routes command I get the following error:

RailsApp/config/routes.rb:26:in `block (2 levels) in <top (required)>': uninitialized constant DashboardManifest (NameError)

I've seen the uninitialized constant DashboardManifest (NameError) error pop up randomly when using generators as well, but the error doesn't seem to appear consistently.

DateTime fields blank out for values that are already set

Fields set as Field::DateTime seem to be automatically emptied out (rather than retaining their on-load value). Assuming this has something to do with the datepicker js, as it flashes the value for a moment presumably before the javascript executes.

Issue with Enums

Showing /Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/administrate-bfb43f43f595/app/views/fields/number/_show.html.erb where line #19 raised:

invalid value for Float(): "user"
Extracted source (around line #10):

          "-"
        else
          format_string % data
        end
      end


Trace of template inclusion: /Users/tom/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/administrate-bfb43f43f595/app/views/administrate/application/show.html.erb

Customizing page views - missing view generators?

Following the documentation after a new set up.
RE: https://administrate-docs.herokuapp.com/customizing_page_views

Following fresh set up on an existing app. running:

✗ rails generate administrate:views:index     
Could not find generator 'administrate:views:index'. Maybe you meant 'administrate:install', 'administrate:dashboard' or 'kaminari:views'

and

✗ rails generate administrate:views:index User
Could not find generator 'administrate:views:index'. Maybe you meant 'administrate:install', 'administrate:dashboard' or 'kaminari:views'
Run `rails generate --help` for more options.

Custom javascript

@Graysonwright How do we add javascripts to the tree for custom fields? I put a ckeditor.js file that initializes ckeditor in:

app/assets/javascripts/administrate

However, it's not being required by the master administrate application.js

Any ideas? Cheers!

Please change the example e-mail addresses to end in @example.com

Your demo has realistic looking e-mail addresses. A lot of those probably are real. Those will get picked up by crawlers and receive spam.

Please change the demo addresses to end in @example.com, that way nobody receives those spam mails.

P.S.: That's also a good idea for all local testing you ever do. If you ever accidentally configure your dev setup with the real e-mail server, nothing bad happens.

Feature Request: Clearing Search

I'd love to be able to easily the clear search by (1) deleting the text or (2) clicking an (X). As of right now, a user needs to click the page link in the navbar or remove the params for the URL. The former is my preferred method, but let me know what you think.

Add example of file upload

Will be good to have a example of how to integrate some form of file upload to people follow. By the way, really nice work on this gem.

How to use with namespaced models.

I have a user model that lives in Platform::User.. I ran the generator with administrate::dashboard Platform::User and this created a user_dashboard.rb and a users_controller.rb.. when I try to go to the users page in admin it fails saying

uninitialized constant Admin::Platform

it points to this line in the controller:

class Admin::Platform::UsersController < Admin::ApplicationController

I tried to remove the Platform:: from the controller and dashboard file but that just produced a similar error but this time saying User was an uninitiatized constant.

thanks!
Gary

Generated dashboard files won't work without tweeking

Version: gem 'administrate', '~> 0.1.0', github: 'thoughtbot/administrate'

The dashboards that are generated with

$ rails generate administrate:install

gives us:

class DesignDashboard < Administrate::BaseDashboard
  def attribute_types
    {  
      id: :integer,
      name: :string,
      description: :string, 
    }
   ......

  end
end

But to get the pages to display without errors I have to implement as per the documentation (For the code to work it needs both ATTRIBUTE_TYPES and attribute_types!
).

ATTRIBUTE_TYPES =     {
        id: Field::Number,
        name: Field::String,
        description: Field::String,
}

looking at the gem in /lib/administrate/base/dashboard.rb
the code still wants to be provided with.
ATTRIBUTES
ATTRIBUTE_TYPES
FORM_ATTRIBUTES
SHOW_PAGE_ATTRIBUTES
COLLECTION_ATTRIBUTES

Once given it works fine.

I am assuming there was a decision to move away from the constants to methods.

Either way the code will not work out of the box by simple running the generate command in the docs.

If it is simply a case of changing a few names in the code I can stick together a PR.

Devise inet fields may be treated as Field::String in Administrate, which results in SQL errors when searching

I'm seeing an ActiveRecord::StatementInvalid error when searching over my Users in Administrate.

Postgres gives the following error:

PG::UndefinedFunction: ERROR:  function lower(inet) does not exist

The SQL query that's erroring looks like:

SELECT  "users".* FROM "users" WHERE (lower(email) LIKE '%george%' OR lower(current_sign_in_ip) LIKE '%george%' ... ) LIMIT 20 OFFSET 0

As far as I can tell, this is because the current_sign_in_ip attribute (managed by Devise) is treated as a String in Administrate:

    current_sign_in_ip: Field::String,

whereas it's actually an inet in Postgres:

t.inet     "current_sign_in_ip"

so attempting to use lower on it fails.

This isn't an urgent issue-- simply deleting the offending attributes from ATTRIBUTE_TYPES in my user_dashboard.rb file allows me to search just fine. The only downside is that I can't see the current_sign_in_ip attribute in Administrate, which really doesn't matter. But I thought it was worth reporting.

Generators trip over irregular inflections

When running rails generate administrate:install in an app with acronyms, the following error occurs:

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym 'SKU'
end
/Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/administrate-0.1.0/lib/generators/administrate/dashboard/dashboard_generator.rb:87:in `const_get': uninitialized constant SkU (NameError)
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/administrate-0.1.0/lib/generators/administrate/dashboard/dashboard_generator.rb:87:in `klass'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/administrate-0.1.0/lib/generators/administrate/dashboard/dashboard_generator.rb:40:in `attributes'
  from (erb):11:in `template'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/2.2.0/erb.rb:863:in `eval'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/2.2.0/erb.rb:863:in `result'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:116:in `block in template'
  from /Users/user/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:53:in `call'

The generators should check the inflectors when generating files.

Issue: undefined method `per'

I am hitting this error no matter how many models I remove form my DashboardManifest when visiting localhost:3000/admin.

Currently running rails 4.2.4

The gem installed with no issues and the install ran perfectly with no issues. I chose to not configure anything until I could get the base up and running, however it looks like that is not possible. I checked to make sure all dependencies were also installed properly. Any ideas as to what could be causing this error?

method_missing - activerecord (4.2.4) lib/active_record/relation/delegation.rb

      elsif array_delegable?(method)
        to_a.public_send(method, *args, &block)
      elsif arel.respond_to?(method)
        arel.public_send(method, *args, &block)
      else
        super
      end
    end
  end
end

undefined method `new' for nil:NilClass on custom attribute

Every time I try to add a custom attribute to the show page, I get the following error from this code

def attribute_field(dashboard, resource, attribute_name, page)
    value = get_attribute_value(resource, attribute_name)

    dashboard.
      attribute_types[attribute_name].
      new(attribute_name, value, page)
end

I used the gravatar example as a base.

I am trying to display a standard paperclip model.attachment.url(:thumb)

Generate `SHOW_PAGE_ATTRIBUTES` as an explicit array

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

Smart Searching

The long-term plan for the search bar is to support structured queries, to allow people to do complex searches over the data from a single field.

We'd like to support:

  • Searching numeric fields for values greater than, less than, or equal to a given number
  • Searching text fields for text including a given string
  • Searching boolean fields by true or false value
  • More than one of these ^ in the same search

Bonus points for a scheme that will let us search custom field types using dev-defined strategies.

I want to open up a discussion about the best way to structure the search queries.

  • If you know of other apps or projects that do multi-field search well, please share them for inspiration.
  • If you have an opinion on what the query structure should look like, chime in!

Feature Request: Make it ORM-agnostic

We are using Sequel and are looking for a decent admin (which is a problem even if using ActiveRecord). Since this project still seems young and showing promise, it would be nice if you could extract ORM-specific operations into a separate module so they can more easily be changed for a different ORM.

I think the only difficult thing I found in respect to Sequel was assoc_ids getter/setter which does not exist in Sequel. But it's not that big of a deal as it is not too hard to implement (although it would be nicer if this could be handled in the controller instead of unconditionally offloading it to the model, which may not be able to handle it in some ORMs).

I got most of it working with these monkey-patches: https://gist.github.com/mrbrdo/56da0dd984b4191a7273

I would be willing to provide Sequel implementations for such a module.

Cheers

Feature Request: Batch Editing

Batch editing, like what's provided by active_admin is a big feature that seems to be missing in administrate for now.

PG::UndefinedTable: ERROR: relation "read_marks" does not exist

When I run:

rails generate administrate:install

I get:

 postgresql_adapter.rb:596:in `async_exec': PG::UndefinedTable: ERROR:  relation "read_marks" does not exist (ActiveRecord::StatementInvalid)
LINE 5:                WHERE a.attrelid = '"read_marks"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"read_marks"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

Custom field types not work

http://administrate-docs.herokuapp.com/adding_custom_field_types, i followed this, but got error:

require "administrate/base_dashboard"
# lib/administrate/fields/gravatar.rb
# (location of the file does not matter)
# require 'digest/md5'


class PostDashboard < 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 = {
    id: Field::Number,
    title: Field::Gravatar,
    body: Field::Text,
    created_at: Field::DateTime,
    updated_at: Field::DateTime,
  }

  # 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 = [
    :id,
    :title,
    :body,
    :created_at,
  ]

  # SHOW_PAGE_ATTRIBUTES
  # an array of attributes that will be displayed on the model's show page.
  SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys

  # FORM_ATTRIBUTES
  # an array of attributes that will be displayed
  # on the model's form (`new` and `edit`) pages.
  FORM_ATTRIBUTES = [
    :title,
    :body,
    :updated_at
  ]
end
uninitialized constant Administrate::Field::Gravatar

issues with `rake routes`

Half the time when I run my rake routes command I get the following error:

RailsApp/config/routes.rb:26:in `block (2 levels) in <top (required)>': uninitialized constant DashboardManifest (NameError)

Other times my routes print correctly to the console, but there's no listing for my admin namespaced routes.

I've seen the uninitialized constant DashboardManifest (NameError) error pop up randomly when using generators as well, but the error doesn't seem to appear consistently.

Don't use `#to_s` to display models in Administrate.

Just a minor note to request the documentation of the use of the to_s method for better representing objects across the various Administrate dashboards. E.g. has_many select lists and belongs_to on index lists. This might catch out some newer Rails/Ruby users if not explicitly mentioned...

Something along the lines of:

to_s is the standard Ruby method for converting an object to a string. You can define to_s on your model class when you want a custom string representation.

Example:

class Tag < ActiveRecord::Base
  def to_s
    name
  end
end

Thus instead of displaying #<Tag:0x007fad07b7ad98>, we can display the actual name of the tag.

Thoughts?

How to customize the displayed text for an associated model?

At https://administrate-prototype.herokuapp.com/admin/orders it looks like each order belongs to a Customer. This association is rendered nicely as:

prototype

Within my own app, I have a similar relationship: Student belongs to School. After setting up Administrate within my own app, I see the following out-of-the-box:

my prototype

Instead of displaying #<School:0x0000000aa98080> or similar, I want to customize the link text based on the attributes of that school model (similar to the prototype, which uses the Customer's full name). How can I do this? The docs at http://administrate-docs.herokuapp.com/ don't seem to cover this.

Dashboard Manifest generator

Rather than running rails generate administrate:install and going through the overwrite prompts for each model, would it be possible to have a single-model generator for when new models get added to an application?

Move sample Rails app to separate repo or folder

Currently the sample Rails application is taking up most of the root file path, and the administrate gem itself is nested under the administrate folder. It might make more sense if the gem itself took up the root file path, and if the sample app is moved to a separate repository, or to a "sample_app" directory.

Selector for belongs_to needs include_blank: true if column is nullable

If you have a foreign key on your model and it belongs_to another model, but the foreign key column is not defined with null: false, then the select box that's rendered for that attribute should not be set to a value from the second model by default, i.e., it needs be rendered with include_blank: true.

Demo source code

I've had a brief play, but have a few questions.
I'm sure the demo source code will answer most of them, but darned if I can find it ?
Thanks, Dave

Plugin structure and best practices

Hey guys,

I've been waiting for you to release this to the public, it's great so far! Are you planning to put together a set of best practices for creating addons/plugins to add field types like WYSIWYG editors and integrations with things like Paperclip? It would be awesome to be able to share them and find useful extensions in a directory of some sort...

Cheers,
Rikki

Implicit dependencies on the Rails Asset Pipeline

When I added Administrate to my Rails app, things were broken out of the box. My app is designed to be an API backend only, and didn't include Sprockets or several other necessary Rails Asset Pipeline gems.

I'm not a Rails expert, so I can't speak to how this issue should be handled in general. But you might find it worthwhile to make these dependencies explicit within Administrate.

For reference, I was able to load the Administrate dashboard after adding the following to my Gemfile

gem 'sprockets-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'

(EDIT: this list is neither minimal nor exhaustive-- I just copy/pasted from the Rails Guides. As grayson mentioned below, the 'coffee-rails' gem shouldn't be needed.)

and uncommenting the line

gem 'sprockets-rails'

in /config/application.rb.

Add a way to customize order of options in select for `belongs_to`

The field for a belongs_to column is a select box, whose options are the values of the associated model. It's helpful to see the options in a sorted order, especially if there are a lot of options. Perhaps the easiest thing to do is to sort by to_s now, and provide a way to customize the order later.

File to import not found or unreadable

Sass::SyntaxError in Admin::Model#index

Showing ... gems/2.2.0/gems/administrate-0.1.0/app/views/layouts/administrate/application.html.erb where line #23 raised:

File to import not found or unreadable: normalize-rails/normalize.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.