I managed to do, to query database perfectly.
More when I execute “submit the template”, it does not load my filtered information.
I see that it is a small detail that I am letting go …
can you help me?
Controller:
def index(conn, params) do
cdr = Structure.list_cdr()
page = Structure.list_cdr
|> order_by([c], desc: c.calldate)
|> Repo.paginate(params)
date_start = get_in(params, ["date_start"])
date_end = get_in(params, ["date_end"])
filter = Structure.list_cdr()
|> where([c], fragment("? BETWEEN ? AND ?", c.calldate, ^date_start, ^date_end))
|> order_by([c], desc: c.calldate)
|> Repo.paginate(params)
render(conn, "index.html", cdr: cdr, cdr: page.entries, page: page, filter: filter)
end
Template
index.html
<%= render "filter.html", Map.put(assigns, :action, Routes.ecdr_path(@conn, :index)) %>
Template
filter.html
<%= form_for @conn, Routes.ecdr_path(@conn, :index), [method: :get], fn f -> %>
<%= date_input(f, :date_start, class: "form-control", id: "inlineFormInputGroupDatestart", placeholder: "Data") %>
<%= date_input(f, :date_end, class: "form-control", id: "inlineFormInputGroupDateend", placeholder: "Data") %>
<% end %>
Debug:
[info] GET /relatorios
[debug] Processing with GcallWeb.EcdrController.index/2
Parameters: %{"_utf8" => “✓”, “date_end” => “2019-06-08”, “date_start” => “2019-06-01”, “dcontext” => %{“contexto” => “”}, “disposition” => %{“status” => “Todas”}, “dst” => %{“destino” => “”}, “src” => %{“origem” => “”}}
Pipelines: [:browser]
[debug] QUERY OK source=“cdr” db=12.1ms
SELECT count(’’) FROM cdr
AS c0 []
[debug] QUERY OK source=“cdr” db=0.3ms
SELECT c0.calldate
, c0.accountcode
, c0.amaflags
, c0.billsec
, c0.channel
, c0.clid
, c0.dcontext
, c0.disposition
, c0.dst
, c0.dstchannel
, c0.duration
, c0.lastapp
, c0.lastdata
, c0.src
, c0.uniqueid
, c0.userfield
FROM cdr
AS c0 ORDER BY c0.calldate
DESC LIMIT ? OFFSET ? [10, 0]
[debug] QUERY OK source=“cdr” db=0.5ms
SELECT count(’’) FROM cdr
AS c0 WHERE (c0.calldate
BETWEEN ? AND ?) [“2019-06-01”, “2019-06-08”]
[debug] QUERY OK source=“cdr” db=0.5ms
SELECT c0.calldate
, c0.accountcode
, c0.amaflags
, c0.billsec
, c0.channel
, c0.clid
, c0.dcontext
, c0.disposition
, c0.dst
, c0.dstchannel
, c0.duration
, c0.lastapp
, c0.lastdata
, c0.src
, c0.uniqueid
, c0.userfield
FROM cdr
AS c0 WHERE (c0.calldate
BETWEEN ? AND ?) ORDER BY c0.calldate
DESC LIMIT ? OFFSET ? [“2019-06-01”, “2019-06-08”, 10, 0]
[info] Sent 200 in 15ms
[info] Replied phoenix:live_reload :ok