filtrex icon indicating copy to clipboard operation
filtrex copied to clipboard

Create dump/1 for saving filters

Open rcdilorenzo opened this issue 7 years ago • 3 comments

A particular type of JSON format must be followed to construct a filter. However, no method currently exists to dump a filter to a JSON-encodable format that can be later re-serialized into a filter. The following should work:

import Filtrex.Type.Config
config = defconfig do
  text :title
end

{:ok, filter} = Filtrex.parse_params(config, %{"title_contains" => "Buy"})
assert Filtrex.dump(filter) == %{
  "filter" => %{
    "type" => "all",
    "conditions" => [
      %{"column" => "title", "comparator" => "contains",
        "value" => "Buy", "type" => "text"}
    ],
  "sub_filters" => []
}

rcdilorenzo avatar Aug 16 '17 18:08 rcdilorenzo

It also might be nice to have an Ecto type that could automatically serialize to and from a JSONB-like database field.

rcdilorenzo avatar Aug 16 '17 18:08 rcdilorenzo

I Want to make a pr for this one. I hope you don't mind :)

gen1321 avatar Nov 08 '18 17:11 gen1321

Go for it @gen1321! I certainly don't mind. 😄

rcdilorenzo avatar Nov 10 '18 15:11 rcdilorenzo