Skip to content

Conversation

shekibobo
Copy link
Contributor

This is a feature, I'd love to see get brought in, but #881 hasn't seen any activity in months. I've rebased the effective changes with the current master as a starting point on fleshing out this feature. I haven't tested this in any real projects yet, but might tackle it this morning. If anyone has any thoughts on implementation/styling/whatever, feel free to let me know.

@shekibobo
Copy link
Contributor Author

The result should be pretty much the same as @michaek's branch at this point, but this is brought up to date with master. I saw that his branch was about a year out of date, so I did the rebase myself and adjusted tests as necessary (since the sort attribute was added to Post). The last request on #881 was to rebase with master, and it never happened, so I thought I might try to take on the feature myself. I don't expect that this is ready to merge yet, but I do plan on looking in to at least adding styling (which @michaek noted was lacking).

@seanlinsley
Copy link
Contributor

Yeah no I understand, and thanks for taking this on 💚

});
});

});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So first, that very last parenthesis shouldn't be there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a considerably more readable version, though I haven't yet tried it out.

# app/assets/javascripts/active_admin/components/has_many_sortable.js.coffee
reindexSort = ($context, inputName)->
  $sortInputs = $("input[name$='#{inputName}']", $context)
  $sortInputs.each (index)->
    $(@).val(index)

$('.has_many.sortable').each ->
  $hasMany  = $(@)
  inputName = $hasMany.attr('data-sortable-input')

  $("li[id$='#{inputName}']", $hasMany).hide()
  reindexSort($hasMany, inputName)

  $(@).sortable
    items: 'fieldset',
    update: (event, ui)->
      reindexSort($hasMany, inputName)

@seanlinsley
Copy link
Contributor

Still going to work on this @shekibobo?

@shekibobo
Copy link
Contributor Author

I've got a little together, but I can't get anything to work in the test app. I'm not sure what I'm missing, but even after generating a new app, the generated (I think) test_rails_app/public/javascripts/application.js doesn't have anything about sortable in it.

I just pushed up some of the stuff I've been working with, including your coffeescript rewrite, though as I said, I haven't been able to successfully test it manually.

I did update this to the latest master branch, just to keep it in sync.

@seanlinsley
Copy link
Contributor

Why would anything be in public/javascripts/application.js?

Active Admin's javascript is included in your application implicitly when from you have this:

# in my case, app/assets/javascripts/active_admin.js.coffee
#= require active_admin/base
$ ->
  $(".foo").bar()
// though the default is active_admin.js
//= require active_admin/base
$( function(){
  $(".foo").bar();
});

It's specifically that require call that does the magic.

@seanlinsley
Copy link
Contributor

Ping :)

@shekibobo
Copy link
Contributor Author

Unfortunately have not had a lot of time to work on this, but I've just rebased it on to the latest master to try to keep it up to date.

@seanlinsley
Copy link
Contributor

(ping)

@shekibobo
Copy link
Contributor Author

Yeah, I know. 🐢 Javascript is not my strong suit, but I might be getting a better hang of the codebase these days. One of the big issues I had with this was trying to render out some kind of handle within the has_many fieldsets. Rendering arbitrary stuff inside of an AA form seems like a high-friction task. I might try and revisit this one this weekend.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.14%) when pulling 4d59a95 on shekibobo:sortable-has-many into 0f663e3 on gregbell:master.

@igorbernstein igorbernstein mentioned this pull request Nov 4, 2013
@shekibobo
Copy link
Contributor Author

I'm going to close this in favor of #2656.

@shekibobo shekibobo closed this Nov 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants