Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Selects in forms #7

Open
wants to merge 39 commits into from

3 participants

leizzer Tomás Pollak David Allison
leizzer

Hello,

Your work saved me time.

I need some features, so I used the time you save me for add, in this case, a select (drop down) in forms where the model belongs to other.

I only use datamapper, so I changed the datamapper Bowtie::ClassMethods#relation_keys_include? method for something that I can use in the view. I couldn't run automated tests, I didn't see any in the gem :(

If you don't like my work it is OK, but I would really like to see a feature like this.

Thank you for your work.

Tomás Pollak
Owner

Hi @leizzer, glad to hear Bowtie was useful to you. I just checked your code and it looks fine, but I have a problem with just one thing: the model.all.map call when building the <select> combobox.

That means that if there 1M records you will not only fetch all those 1M records, but you'll also instantiate each one of them meaning the app ill start eating RAM as hell.

In other words, I think the idea is great, I'm just not sure about the implementation. Perhaps using an autocomplete field would work better, in fact, we could use it to show suggestions not only for _id fields but for any field (e.g. when modifying the state field of a record it could get a list of all available states in all records in the DB).

What do you think?

leizzer

Hi.

You are right about the model.all.map, but I couldn't figure out another way because the method (to_option_select) is called but it isn't a model property.

I think that an autocomplete is a good idea if it can solve the problem of loading so many instances. It all depends on what kind of autocomplete, it's more common that the parent model only have a bunch of entries (in my case around 10) and a drop down is useful for the user to select what they want without knowing the entries that already exist. In other words a mix of autocomplete and dropdown could be a good approach. (I don't remember how rails admin does these things)

Talking about using this for other things more than the _id fields: yes, it's good too. It can load options for Enum properties (in datamapper: peroperty :sex, Enum["f", "m"] ) I think this should be easy to load.

I will be extending bowtie as we need. Some feature that I'm thinking about are: exclude columns in index tables ( e.g. I want hide the password column) and friendly labels (e.g. Change uuid label for Membership Number)(maybe we could implement I18n here)...

I think railsamdmin use a config file for extra tuning, but I really like how I can add bowtie to my project without work..

Thanks for your time.

Tomás Pollak
Owner

A select box for enum fields (or the ones that have an explicit 'validates inclusion in') sounds great, but I'm still not sure what's the best strategy for association ID's. Does Rails Admin solve this in a specific way?

leizzer

Hi,

I found that Rails Admin uses a lot of js/ajax.

Rails Admin do something similar, but it sets a limit. (https://github.com/sferik/rails_admin/tree/master/lib/rails_admin/config/fields/association.rb:43).

They don't use an html select, they create something similar with js (jquery ui-autocomplete). And I don't know what they do with the rest of the registers. (http://rails-admin-tb.herokuapp.com/admin/team/58/edit).

Tomás Pollak
Owner

Looks like that's the only way! I guess we could use the Ajax version of the chosen library for this. It would look much cooler too. :)

leizzer

It looks nice. How do you want to proceed? Tomorrow if I have time I could try to add this.

Edit: human error with the cellphone

leizzer leizzer closed this
leizzer leizzer reopened this
leizzer

Oh man! I closed it too! I'll never use the cellphone for comment in github again.

Tomás Pollak
Owner

Haha, no problem. Let me know if you have any questions.

leizzer

I added the no-ajax version of chosen.js.

I use no-ajax because my first step was make it work. Now I see that the ajax-chosen is an other plugin. I don't know how to implement a "selected" option in ajax-chosen. Maybe you have an idea but I don't want to lose the selected option on Edit.

Tomás Pollak
Owner

Awesome! I'll take a deeper look at the code when I have a minute. :)

leizzer added some commits
leizzer leizzer working model expansion with Bowtie::Models::Extensions 68be1dd
leizzer leizzer adding support for exclude fields on Bowtie::Models::Extensions 30f160e
leizzer leizzer adding bowtie customization explanation in README.md. 4b7cbb1
leizzer leizzer fixing README.md 09bbc76
leizzer leizzer Modifing comment in bowtie_config.rb ec092f8
leizzer leizzer adding property-field-mapper to config c14ea72
leizzer leizzer adding more type support 6448658
leizzer leizzer WIP: Right know, the dynamic typing in ruby is breaking my work. I'll…
… need to add some logic in addapters
35298f0
leizzer leizzer Type mapping added to datamapper adapter fa63d95
leizzer leizzer adding Datamapper::Property::Boolean type to the dm adapter type regi…
…stry
3badc76
leizzer leizzer adding support for file fields 417134e
leizzer leizzer fixing error on no-extra_fields ed33e8b
leizzer leizzer adding support for multipart forms a0ad833
leizzer leizzer adding the value to textarea da82edb
leizzer leizzer adding datetimepicker jquery plugin dbd8edc
leizzer leizzer adding field recognition for datetime 0309dfa
leizzer leizzer adding select field for Enum properties in datamapper. Not implemente…
…d in Mongomapper :(
b5bc4ac
leizzer leizzer fixing problem in datamapper adapter. If I use @resource.model.send(n…
…ame), and name is :name, it will return the class name; so I add an extra check
430f8b3
leizzer leizzer adding time picker f433dbf
leizzer leizzer addint date field type 2a57765
leizzer leizzer Rescuing from no method error in datamapper adapter 9b6151d
leizzer leizzer seting Bowtie.config.excluded_models to [] 5aa06eb
leizzer leizzer adding footer customization and info in README c63b550
leizzer

Hi, change a lot in my "config" branch and I need to move on merging it to master.

I will wait some days because if I do the merge the commits in "config" will be added to the pull request.

Tomás Pollak
Owner

Hey Leizzer,

Sorry for the delay, I just got back from a trip. I just pulled your code and it looks that there are still some bolts missing. At least the mongomapper adapter is missing the adapter_fields_registry and when trying to load the admin panel I get a nasty error:

ArgumentError at /admin/albums -- wrong number of arguments (2 for 1)

[line 44] ../lib/bowtie/helpers.rb in const_defined?
      if ::Bowtie::Models::Extensions.const_defined?(model.to_s, false) && !model.include?(::Bowtie::Models::Extensions.const_get(model.to_s, false))

Besides that, everything looks good. Though I wasn't able to test it thoroughly, it seems like the customization options you added are entirely optional which is good (this gem is meant to work out of the box). Personally I've been wanting to add the ability of specifying custom methods to call on an object directly through the panel, and it looks like it could fit nicely in your Bowtie::Config class.

Just to give you a rough idea of what I have in mind:

class Author
  many :posts
  key :published_posts, Integer, :default => 0
end

class Post
  belongs_to :author
  belongs_to :blog

  def publish
    update_attribute(:state, :published)
    author.increment(:published_posts => 1)
    blog.refresh_sitemap # or whatever
  end

  def unpublish
     # like the one above but all the way around
  end

end

##########

module Bowtie::Models::Extensions
 module User
   def bowtie_methods
     %w(publish unpublish)
   end
 end
end
Tomás Pollak
Owner

By the way, looking deeper at the customization syntax I think it could be simplified a bit for readability. What do you think of using something like this?

Bowtie.extend do

  model :users do
    option_text lambda { |u| "#{u.name}" }
    include_fields :avatar
    exclude_fields :encrypted_password
  end

  model :posts do
    option_text lambda { |p| "#{p.title} by #{p.author.name}" }
    show_actions :publish, :unpublish
  end

end
leizzer

Hello,
That error you mention is on my Master branch?

In the branch "config" I didn't paid to much attention to mongoid because I was on a hurry.

Some days ago I see that the gemspec generate errors on my host/server because of the "á" on your name. I added the utf-8 specified on the top, but it still failing. That have to be removed, I think. (I know that the OS can be configured, my computer is configured but it will be simpler).

Tell me if there are something that are stopping you to accept this pull request.

I will ask for merge my config branch in other pull request after take care of mongoid.

About the DSL you are talking about. It looks nice. But like I said, I have no time :(
I like that DSL, because it looks simple and I don like to learn a complex DSL for this.

Tomás Pollak
Owner

Yes that error is on your branch, and it's not Mongoid what I'm using, it's MongoMapper. Hope that you can give it a bit of time so we can get this merged -- unfortunately it can't be done as it is. :(

leizzer

I spend a time today checking the error you commented.

"field_registry" and "Extensions" are in the branch "config"; here we are talking only about the "master" branch. Where the changes only add the dropdown.

Test the master branch. I'll make an other pull request for "config" after this one.

Using "git://github.com/leizzer/bowtie.git" (branch Master) in a new project I have no problem.

Tomás Pollak
Owner

Awesome, let me know when your pull is up so I can merge again and try it out.

leizzer

Ok, I merged 'Config' into 'Master'.

I didn't have any error in my project using DataMapper, could you try it?.

I tested it with and without using Bowtie Extensions in my app.

David Allison

Hi @leizzer -- Are you still actively developing bowtie in this fork? I was trying out your fork but couldn't get it to run (whereas the main branch is less recent, but does run).

Hello David,

I'm not using the gem in my new project. Could you give me 1 or 2 days to reviews what is going on?

What DB are you using?

Thanks

Hi --
Sure - we're using MySQL with DM. I just wanted to check on the status of your fork and/or see if you had found a replacement to bowtie that you felt worked better (if you're no longer using it).

Best,
David

Hi,
I'm not using it now because the new project is with Rails, they were using "mongoid" and "active admin" before I join them.

Bowtie have to be polished a little, some months ago I was thinking in a "new" gem from my fork since the pull-request was never merged. But I don't have the time now.

Regards

I see - do you recall if your fork was working at any point in the past? I kept getting an error when trying to run it.

Yes, I was using it on production. What is the error?

When you say "main branch" you mean my master branch or the original from Tomas?

Because the only difference between my two branches is the gemspec

I just tried master in one of my old project and it's still working.

Bests,
leizzer

Cool - maybe I'm missing something in my config, then? Using the default (Tomas) master, I get the bowtie interface to show up, but in the Leizzer master branch, I get an error like this one:
Screen Shot 2013-03-14 at 11 05 28 AM

Any thoughts on why it wouldn't see the constant (Model) within the master branch?

Sorry, no clue.

That error is hard to follow.
Sorry.

Btw I never use it with Rails. I used bowtie in sinatra apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 8, 2012
  1. leizzer

    first dirty approach

    leizzer authored
Commits on Aug 9, 2012
  1. leizzer
  2. leizzer
  3. leizzer
  4. leizzer
  5. leizzer

    changing helper render_relationship_in_select for not include the id …

    leizzer authored
    …and moving apart from eval
Commits on Aug 22, 2012
  1. leizzer
  2. leizzer

    adding place holder to select

    leizzer authored
  3. leizzer

    Adding place holder to select

    leizzer authored
Commits on Aug 23, 2012
  1. leizzer
  2. leizzer
  3. leizzer
  4. leizzer
  5. leizzer
  6. leizzer
  7. leizzer

    fixing README.md

    leizzer authored
  8. leizzer
Commits on Aug 27, 2012
  1. leizzer
  2. leizzer

    adding more type support

    leizzer authored
  3. leizzer

    WIP: Right know, the dynamic typing in ruby is breaking my work. I'll…

    leizzer authored
    … need to add some logic in addapters
  4. leizzer
  5. leizzer
  6. leizzer

    adding support for file fields

    leizzer authored
Commits on Aug 28, 2012
  1. leizzer
  2. leizzer
  3. leizzer

    adding the value to textarea

    leizzer authored
  4. leizzer
  5. leizzer
Commits on Aug 29, 2012
  1. leizzer
  2. leizzer

    fixing problem in datamapper adapter. If I use @resource.model.send(n…

    leizzer authored
    …ame), and name is :name, it will return the class name; so I add an extra check
  3. leizzer

    adding time picker

    leizzer authored
  4. leizzer

    addint date field type

    leizzer authored
  5. leizzer
Commits on Sep 19, 2012
  1. leizzer
  2. leizzer
  3. leizzer

    Update bowtie.gemspec

    leizzer authored
  4. leizzer
  5. leizzer

    Update bowtie.gemspec

    leizzer authored
Commits on Oct 3, 2012
  1. leizzer

    wip

    leizzer authored
Something went wrong with that request. Please try again.