Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use/Match searchable attributes #113

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/pkg/
/spec/reports/
/tmp/
.idea/
3 changes: 2 additions & 1 deletion app/assets/javascripts/belongs_to_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
$(function() {
$(".field-unit--belongs-to-search select").each(function initializeSelectize(index, element) {
var $element = $(element);
var searchFields = $element.data('search-fields') && $element.data('search-fields').split(',')
$element.selectize({
valueField: 'id',
labelField: 'dashboard_display_name',
searchField: 'dashboard_display_name',
searchField: searchFields || 'dashboard_display_name',
create: false,
searchUrl: $element.data('url') + '?search=',

Expand Down
3 changes: 3 additions & 0 deletions app/views/administrate/application/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection

json.resources resources do |resource|
@dashboard.search_attributes.each do |attr|
json.set! attr, resource.public_send(attr).to_s
end
json.id resource.id
json.dashboard_display_name @dashboard.display_resource(resource)
end
3 changes: 2 additions & 1 deletion app/views/fields/belongs_to_search/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ that displays all possible records to associate with.
<%= f.select(field.permitted_attribute,
nil,
{},
'data-url': polymorphic_url([namespace, field.associated_class], format: :json)) do %>
'data-url': polymorphic_url([namespace, field.associated_class], format: :json),
'data-search-fields': field.dashboard.search_attributes&.join(",")) do %>
<%= options_for_select(field.associated_resource_options, field.selected_option) %>
<% end %>
</div>
4 changes: 4 additions & 0 deletions lib/administrate/field/belongs_to_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def associated_resource_options
def associated_class
super
end

def dashboard
"#{associated_class}Dashboard".constantize.new
end
end
end
end