-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from goosys/wip/issue-8
Wip/issue 8
- Loading branch information
Showing
7 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<% | ||
attribute_labels ||= {} | ||
attribute_types ||= @dashboard.attribute_types.select { |key, _value| @dashboard.collection_attributes.include?(key) } | ||
options ||= {} | ||
form_options = { html: { 'data-administrate-ransack-filters': '1' } } | ||
namespace = local_assigns[:namespace] || :admin | ||
if local_assigns.has_key?(:search_path) | ||
form_path = @ransack_results | ||
form_options[:url] = search_path | ||
clear_filters_path = search_path | ||
else | ||
form_path = [namespace, @ransack_results] | ||
clear_filters_path = url_for(url_for([namespace, @ransack_results.klass])) | ||
end | ||
%> | ||
<%# render 'administrate_ransack/javascript' %> | ||
<%= search_form_for form_path, form_options do |f| %> | ||
<div class="filters"> | ||
<% attribute_types.each do |field, type| %> | ||
<% label = attribute_labels.include?(field) ? attribute_labels[field] : nil %> | ||
<% model = @ransack_results.klass %> | ||
<% input_type = type.is_a?(Administrate::Field::Deferred) ? type.deferred_class.to_s : type.to_s %> | ||
<% next if field == :id %> | ||
<% next if input_type == 'Administrate::Field::Refile' %> | ||
<% next if input_type == 'Administrate::Field::Enumerize' && (@ransack_results.klass.respond_to?("with_#{field}").blank? || @ransack_results.klass.ransackable_scopes.map(&:to_s).include?("with_#{field}").blank?) %> | ||
<% next if input_type == 'Administrate::Field::String' && !(f.search_field "#{field}_cont" rescue nil) %> | ||
<% component = AdministrateRansack::FILTERS[input_type] || 'field_other' %> | ||
|
||
<div class="filter filter-<%= field.to_s.parameterize %> <%= input_type.parameterize %>"> | ||
<% case input_type %> | ||
<% when 'Administrate::Field::Enumerize' %> | ||
<% options = @ransack_results.klass.public_send(field.to_s).values.map {|w| [w.text, w]} %> | ||
<%= f.label label || field %> | ||
<%= f.select "with_#{field}", options, {include_blank: true}, data: {controller: :select} %> | ||
<% else %> | ||
<% field_options = options.is_a?(Hash) ? (options[field.to_s] || {}) : {} %> | ||
<%= render "administrate_ransack/components/#{component}", form: f, model: model, field: field, label: label, type: type, options: field_options %> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
||
<%= render 'administrate_ransack/components/filter_buttons', form: f, clear_filters_path: clear_filters_path %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "administrate/base_dashboard" | ||
require "administrate/page/collection" | ||
|
||
Administrate::Page::Collection.prepend ( | ||
Module.new { | ||
def collection_filter_types | ||
dashboard.collection_filter_types | ||
end | ||
} | ||
) | ||
|
||
Administrate::BaseDashboard.prepend ( | ||
Module.new { | ||
def collection_filter_types | ||
self.class::COLLECTION_FILTER_TYPES | ||
end | ||
} | ||
) | ||
|
||
Administrate::BaseDashboard.const_set(:COLLECTION_FILTER_TYPES, {}.freeze) |
22 changes: 22 additions & 0 deletions
22
spec/administrate/views/administrate/application/_index_header_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "rails_helper" | ||
|
||
describe "administrate/application/_index_header", type: :view do | ||
before do | ||
view.lookup_context.prepend_view_paths [File.expand_path("../../../../../app/views", __dir__)] #TODO | ||
end | ||
|
||
context "when the controller is not ransack searchable" do | ||
it "does not render the ransack search form" do | ||
allow(view).to receive(:content_for).and_return(nil) | ||
allow(view).to receive(:show_search_bar).and_return(false) | ||
allow(view).to receive(:new_resource).and_return(nil) | ||
allow(view).to receive(:accessible_action?).and_return(false) | ||
stub_template "administrate_ransack/filters" => "<div class='ransack-filters-container'></div>" | ||
|
||
assign(:ransack_results, nil) | ||
render | ||
|
||
expect(rendered).not_to match("ransack-filters-container") | ||
end | ||
end | ||
end |