Giter Club home page Giter Club logo

trestle-search's People

Contributors

andresg4 avatar dependabot[bot] avatar leohige avatar makketagg avatar martio avatar spohlenz avatar vbrazo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

trestle-search's Issues

Search into a Trestle tab

Hi guys! I'm trying to implement a simple search bar into a Trestle tab but I can't find any documentation about how to do it!

Can you helpe?

search not working ?

this is not working (nothing filtered)

  collection do
    Customer.order(name: :asc)
  end

  search do |q|
    # puts "test" # when adding debugging statements this doesn't seem to be called
    collection.where("name LIKE ?", "%#{q}%")
  end

while this is actually doing the filter (if manually adding the q param)

  collection do
    Customer.order(name: :asc).where("name LIKE ?", "%#{params[:q]}%")
  end

the infrastructure recognises the presence of the search block as a search input is shown. but i've added some debugging statement in the search block and it doesn't seem to be called ?

Search on author of a post/book

I have a book/post table with author_id linking to author table (belongs_to :author).
I am trying to add the author's name in the search but I keep getting errors because it seems that the author table is not getting linked in the query.

I've tried to add the authors table as follows:

  collection do
    # Set the default order when manual sorting is not applied
    Book.order(created_at: :desc).includes(:author)
  end
  collection do
    model.includes(:author)
  end

I've also tried to add in the author in the search query:

  search do |query|
    query ? collection.joins(:author).where("author.name ILIKE ?", "%#{query}%" ) : collection
  end

However I keep getting errors such as:

PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "author"
LINE 1: ...s" ON "authors"."id" = "books"."author_id" WHERE (author.nam...

How can I perform a search on a linked table ?

search query scope

As in the docs, I set a scope like

In Company.rb model

scope :staff_between, ->(from, to) { joins(:job_histories).group('companies.id').having("count(company_id) >= :from AND count(comapny_id) <= :to", from: from, to: to) }

so I can call inside companies_admin.rb
scope :small, -> { Company.staff_between(1, 10) }, label: "1 to 25 collaborators"

But the group() creates an unexpected bahaviour when the results are counted at display
Screenshot_20200502_143929

Is there a way to circumvent that ? the count done to return the badge number gives an hash of results instead

Reference to Users table instead of Administrator when login - Rails 6.rc1

Hi,

Not sure why but when I installed this gem and go to the admin pages, it will jump to the Users table (Devise gem) to authorise instead of the Administrators table.

As a consequence, a normal user (from Users table) can access to the Admin zone as long as he's logged in.

If I remove this gem from the Gemfile, everything is working perfectly.

`collection` is nil in custom scope block when using this gem

After installing this gem, this does not work anymore (simplified code):

collection do
  Order.all
end

scopes do
  scope :my_orders, -> { collection }
end

The error is

wrong number of arguments (given 0, expected 1)

referencing to the call to collection.

I worked around this by defining collection globally:

collection = Order.all

scopes do
  scope :my_orders, -> { collection }
end

But that's just a workaround.

Custom placeholders

Hi!

Would it be possible to define a custom placeholder for a search field ? It would allow you to have different placeholders on your different views, for example to describe the behaviour of each search bar.

Thank you !

Not compatible with Rails 6 / Zeitwerk autoloader

Using this gem within a Rails 6 application conflicts with Zeitwerk autoloader.

Example

Add this lines to the Gemfile of brand new Rails 6 application:

gem 'trestle'
gem 'trestle-search'

Run bundle exec rake test and look at this deprecation message:

DEPRECATION WARNING: Initialization autoloaded the constants ActionText::ContentHelper, ActionText::TagHelper, Trestle::AvatarHelper, Trestle::ContainerHelper, Trestle::DisplayHelper, Trestle::FlashHelper, Trestle::FormHelper, Trestle::FormatHelper, Trestle::GridHelper, Trestle::HeadingsHelper, Trestle::HookHelper, Trestle::I18nHelper, Trestle::IconHelper, Trestle::NavigationHelper, Trestle::PaginationHelper, Trestle::PanelHelper, Trestle::ParamsHelper, Trestle::SortHelper, Trestle::StatusHelper, Trestle::TabHelper, Trestle::TableHelper, Trestle::TimestampHelper, Trestle::ToolbarsHelper, and Trestle::UrlHelper.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload ActionText::ContentHelper, for example,
the expected changes won't be reflected in that stale Module object.

These autoloaded constants have been unloaded.

Please, check the "Autoloading and Reloading Constants" guide for solutions.
 (called from <main> at /Users/ledermann/Playground/trestle-test/config/environment.rb:5)

Using a project with Trestle but without the gem trestle-search works fine.

Sorting on a calculated field

My listing of authors has a book count column. I'd like to be to sort on that. I am trying:

    column :books , sort: :books_count  do |auth|
       auth.books.count
    end

I've tried to set it up as follows:

collection do
   # Set the default order when manual sorting is not applied
   Author.order(created_at: :desc).includes(:books)
 end
 collection do
   model.includes(:books)
 end

 sort_column :books_count do |collection, order|
   collection.joins(:books).merge(Book.order(count: order))
 end

However, I am just not able to get the sort_column part correct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.