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

Search scopes #276

Closed
wants to merge 95 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
df6e8cb
colon at last char could mean use a model scope
nando Nov 26, 2015
1747a5a
new feature: admin searches using a model scope
nando Nov 27, 2015
c84dd78
gems upgrade to fix nokogiri vulnerability
nando Nov 27, 2015
77dc494
avoid hound violations
nando Nov 27, 2015
e2c52a2
hopefully last Houndci fixes...
nando Nov 27, 2015
022590f
spec to ignore malicious scope searches (fix pending)
nando Dec 2, 2015
23104a7
Search::BLACKLISTED_WORDS avoids malicious scopes
nando Dec 3, 2015
948305d
petting HoundCI
nando Dec 3, 2015
6916c97
Search splits the scope and the term in the query (wip)
nando Dec 4, 2015
71796b8
Merge branch 'master' into search_scopes
nando Dec 6, 2015
3d4d80f
Admin searches *into* a model scope
nando Dec 6, 2015
43c79af
Merge branch 'master' into search_scopes
nando Dec 6, 2015
4aee009
Merge branch 'master' into search_scopes
nando Dec 7, 2015
5de68c5
Merge branch 'master' into search_scopes
nando Dec 9, 2015
ce096e7
Merge branch 'master' into search_scopes
nando Dec 10, 2015
fc749c5
Merge branch 'master' into search_scopes
nando Dec 13, 2015
104b23c
double-quoting a string
nando Dec 13, 2015
a37e91b
Merge branch 'master' into search_scopes
nando Dec 15, 2015
cb6dc90
much better than send anything is public_send it
nando Dec 16, 2015
8802956
Merge branch 'master' into search_scopes
nando Dec 17, 2015
797d99c
Dashboard's COLLECTION_SCOPES for the index page (WIP)
nando Dec 17, 2015
fce4e5b
link_to_unless_current in index scope buttons
nando Dec 18, 2015
92d3855
Merge branch 'master' into collection_scopes
nando Dec 22, 2015
2a375ec
Merge branch 'master' into search_scopes
nando Dec 22, 2015
b73de10
Dashboard's COLLECTION_SCOPES for the index page (2/2)
nando Dec 22, 2015
14bcced
Merge branch 'collection_scopes' into search_scopes
nando Dec 22, 2015
cc634fc
debug change reverted
nando Dec 22, 2015
86f3e8e
Hound fixes
nando Dec 22, 2015
063b503
search into scope syntax changed
nando Dec 23, 2015
d508ad7
refactorization finished
nando Dec 23, 2015
cd48500
regexp refactor
nando Dec 23, 2015
c71f75a
now i feel bad about this stupid joke
nando Dec 24, 2015
47e6128
scenario "admin clicks a scope button"
nando Dec 24, 2015
dcdcbf9
scope button link fixed
nando Dec 24, 2015
7fbf27e
COLLECTION_SCOPES defined for the feature specs
nando Dec 24, 2015
fffdd86
Hound fix
nando Dec 25, 2015
42bb6ce
Search#new extracts #scopes&#words from the query
nando Dec 25, 2015
a95b716
trailing whitespaces removed
nando Dec 25, 2015
9c3819b
admin searches a word inside two model scopes
nando Dec 25, 2015
5c4966c
Scopes with an argument (feature spec pending)
nando Dec 27, 2015
ba68fdf
Scopes with argument feature spec
nando Dec 28, 2015
e0d3fb6
*if* indentation like hound says it should be
nando Dec 28, 2015
9e29782
COLLECTION_SCOPES accepts strings with (argument)
nando Dec 29, 2015
9742470
Hound fixes
nando Dec 29, 2015
320d239
COLLECTION_SCOPES as a hash w/ scopes' arrays
nando Dec 30, 2015
2616bbd
scope-buttons class style
nando Jan 7, 2016
8f67444
Merge branch 'master' into search_scopes
nando Jan 8, 2016
a48b4e4
avoided needless SQL query for only scope search
nando Jan 9, 2016
318f40f
Hound fixes
nando Jan 9, 2016
d57583c
fix in #scope_groups
nando Jan 18, 2016
c026d41
Merge branch 'master' into search_scopes
nando Jan 18, 2016
45165b1
Merge branch 'master' into search_scopes
nando Jan 20, 2016
8649b87
buttons-group style&component + use in scope groups
nando Jan 20, 2016
73ab8eb
Merge remote-tracking branch 'upstream/master' into search_scopes
nando Jan 21, 2016
5b94dda
calling #freeze in the BLACKLISTED_WORDS value
nando Jan 21, 2016
413e94e
several Hound tweaks
nando Jan 21, 2016
1466905
raw user's Search#scopes_with_arguments inputs
nando Jan 22, 2016
ff776ed
Search#new(resolver, query) cleans the users query
nando Jan 22, 2016
917f256
partial for _scope_buttons_group
nando Jan 22, 2016
2c62488
Collection#scoped_with?(scope) + use in partial
nando Jan 22, 2016
d307ebb
Page::Collection's #scope_groups&#scope_names spec
nando Jan 22, 2016
846208a
Page::Collection#scope_group(scope)
nando Jan 22, 2016
eedbd9e
Collection#scoped_groups in the current query
nando Jan 23, 2016
6b9478b
Mock dashboards moved to spec_helper to be shared
nando Jan 23, 2016
c939b84
Page::Colletion's specs refactorization
nando Jan 23, 2016
61c56d9
Collection#current_scope_of(group)
nando Jan 23, 2016
b1cf880
Collection#term_using_scope adds/updates the query term with the give…
nando Jan 23, 2016
f126156
Hound tweaks
nando Jan 24, 2016
433409f
Merge branch 'master' into search_scopes
nando Jan 24, 2016
0f6ff85
use of page.term_using_scope in the index view
nando Jan 24, 2016
cfa40cc
ApplicationHelper#translated_scope(scope, i18n_scope)
nando Jan 25, 2016
be85f0f
"Filter" translations added (only zh-CN&zh-TW missing)
nando Jan 25, 2016
679b358
missing Chinese translations added
nando Jan 25, 2016
2ea34a8
check scope's arity while searching them in the query
nando Jan 27, 2016
5f9cb3b
Hound tweaks
nando Jan 27, 2016
5f448de
hound fix
nando Jan 27, 2016
cbffcdb
Scope's arity hack removed
nando Jan 28, 2016
46cfe4a
Bourbon button-group style for scope buttons groups
nando Jan 28, 2016
6e808cd
"wildcarded" scopes to search "<scope>:<argument>"
nando Jan 28, 2016
360ec3f
Hound fixes
nando Jan 29, 2016
5735a19
oops! restoring the missed buttons background
nando Jan 29, 2016
c3f7293
ending multiline array with a comma
nando Jan 29, 2016
5ef54fa
use #casecmp instead of (innecesary) #downcase.eq (thanks hound!)
nando Jan 29, 2016
0140edc
double-quoting a string
nando Jan 29, 2016
63a9054
"Disable scopes" feature and used by default (in the generated dashbo…
nando Feb 6, 2016
b6dcb80
extra line removed
nando Feb 6, 2016
a4264f1
explanations in generated dashboard improved
nando Feb 6, 2016
254140c
Merge branch 'master' into search_scopes
nando Feb 14, 2016
cc62974
extra space removed
nando Feb 16, 2016
8c672e3
Merge branch 'master' into search_scopes
nando Feb 21, 2016
b99024e
Merge branch 'master' into search_scopes
nando Mar 10, 2016
e8fddd0
Button to disable active scope in Dashboard index
nando Mar 10, 2016
d877b91
Collection#term_without_scope don't care if defined
nando Mar 10, 2016
368dd2b
Merge branch 'master' into search_scopes
nando Apr 23, 2016
e76877a
Merge branch 'master' into search_scopes
nando May 18, 2016
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
9 changes: 9 additions & 0 deletions lib/administrate/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ def initialize(resolver, term)
def run
if @term.blank?
resource_class.all
elsif (@scope = search_scope)
resource_class.send @scope
else
resource_class.where(query, *search_terms)
end
end

def search_scope
if (@term[-1, 1] == ':')

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

possible_scope = @term[0..-2]
possible_scope if resource_class.respond_to?(possible_scope)
end
end

private

delegate :resource_class, to: :resolver
Expand Down
2 changes: 2 additions & 0 deletions spec/example_app/app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Customer < ActiveRecord::Base
validates :name, presence: true
validates :email, presence: true

scope :subscribed, -> { where(email_subscriber: true) }

def lifetime_value
orders.map(&:total_price).reduce(0, :+)
end
Expand Down
13 changes: 13 additions & 0 deletions spec/features/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@
expect(page).to have_content(email_match.email)
expect(page).not_to have_content(mismatch.email)
end

scenario "admin searches using a model scope", :js do
query = "subscribed:"
subscribed_customer = create(:customer, name: "Dan Croak", email_subscriber: true)

Choose a reason for hiding this comment

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

Line is too long. [86/80]

other_customer = create(:customer, name: "Foo Bar", email_subscriber: false)

visit admin_customers_path
fill_in :search, with: query
page.execute_script("$('.search').submit()")

expect(page).to have_content(subscribed_customer.name)
expect(page).not_to have_content(other_customer.name)
end
end