Comments (2)
I had the same issue and that's where the newest PRs came from (#59 & annkissam/rummage_ecto#66)
They work (I'm using them in production code), but they need to be documented. Basically, it gets rid of the search_form and you can use your own. I think @aditya7iyengar would like to document it better before officially releasing it, so I'd say you don't need to work on implementing this, but it might be tricky to use. In short, if gives the sort and search fields a name, which gets used in the view. It translates those name into a query in a rummage module you'll create for each schema that you want to rummage. That makes the views much simpler, and you can then use your own search form. I'll try to describe it briefly:
in mix.exs
{:rummage_ecto, "~> 1.2", git: "https://github.com/aditya7iyengar/rummage_ecto"},
{:rummage_phoenix, "~> 1.2", git: "https://github.com/aditya7iyengar/rummage_phoenix", branch: "scope_whitelist"},
in your index:
<%= form_for @rummage.changeset, your_controller_path(@conn, :index), [as: "rummage", method: :get], fn f -> %>
<%= inputs_for f, :search, fn f -> %>
<div class="form-group">
<%= label f, :first_name, "First Name", class: "control-label" %>
<%= text_input f, :first_name, class: "form-control" %>
</div>
<% end %>
<div class="form-group">
<%= submit "Search", class: "btn btn-default" %>
</div>
<% end %>
in your_controller:
{rummage, records} = YourApp.Rummage.YourSchema.rummage(params["rummage"], query: query)
render(conn, "index.html", records: records, rummage: rummage)
defmodule YourApp.Rummage.YourSchema do
use Rummage.Schema,
paginate: YourApp.Rummage.Paginate,
sort: YourApp.Rummage.YourSchema.Sort,
search: YourApp.Rummage.YourSchema.Search,
schema: YourApp.YourSchema
end
defmodule YourApp.Rummage.YourSchema.Sort do
use Rummage.Schema.Sort,
default_name: "email",
handlers: [
first_name: %{ci: true},
last_name: %{ci: true},
email: %{ci: true},
]
end
defmodule YourApp.Rummage.YourSchema.Search do
use Rummage.Schema.Search,
handlers: [
first_name: %{search_type: :ilike},
last_name: %{search_type: :ilike},
email: %{search_type: :ilike},
]
end
For all the rummage schema's there's an example here: https://github.com/aditya7iyengar/rummage_ecto/pull/66/files#diff-b99205d171d4be5eb3ae3715078ec7cb
from rummage_phoenix.
Thanks a lot @ericsullivan ! Your hints were a great starting point. I got it to work now but it was a bit tricky as you mentioned.
Maybe it is helpful that I point out what tripped me up for testing or if anyone else is trying this:
- The form_for example you provided did not work for me because it did not nest the parameters properly. Instead of
["rummage"]["search"]["first_name"]
it results in["rummage"]["first_name"]
. In general reusing the f variable should not be reused but replaced by s or so in the nested search form. But that gave me an error. I ended up providing an explicitname: "rummage[search][first_name]"
on the input to get it to work for now but I guess the rummage changeset needs to be implemented differently to get this to work properly. I did not have time to look into it further so far. - The change_assoc_to_a_one_member_list method did not handle the parameters in my basic case properly: From how I used it I got
rummage = %{"search" => %{"field" => "my search text"}}
which leads to a FunctionClauseError (Access.get/3). Since you already mention in the comment that the function is temporary I ended up commenting it out because I don't worry about search in assocs for now.
So a bit hacky but it works for now. I will follow the development of the new api and contribute when I can.
from rummage_phoenix.
Related Issues (20)
- function nil.all/1 is undefined or private HOT 2
- Use a standard form and do mapping of terms to search params in the controller
- sort_link assumes index HOT 1
- switch to using Macro.camelize
- should be able to configure usage of an existing atom
- fix double- `<a>` rendering HOT 1
- Let controller handle association and hidden fields
- Search by custom fragments
- Sort links do not work on show page
- Provide override for search form on what page to submit
- whitelist searchable fields
- protocol Ecto.Queryable not implemented HOT 1
- support action: in sort_link HOT 1
- Unable to run in Phoenix 1.3 HOT 13
- Update LICENSE to Annkissam HOT 1
- Search by two fields with the same name (one for model, one for association) HOT 1
- Collection count greater than per_page, Query never returns null?
- Live View support
- ** (KeyError) key :paginate not found in: %{"paginate" => %{}, "search" => %{}, "sort" => %{}}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rummage_phoenix.