Creating Query Filters in the Database and Display in html

I just created a template with lots of filter options.

Date Home(type: date)
End Date(type: date)
Status by “select fixed”(type: select)
Source(type: text)

Note:
In this date field I want to put a “between”,

column of the bank that exists, the date is called
field :calldate, :naive_datetime

Now I need to make this template do a select directly in the database as the fields are filled.

And be shown only what was passed.
I do not intend to use rummage_phoenix

Can you help me?

Below is my files

Template:

Date:

    <div class="input-group-prepend">
      <div class="input-group-text"><i class="fas fa-calendar-alt"></i></div>
    </div>
    <input type="date" class="form-control" id="inlineFormInputGroupDatestart" placeholder="Data">
  </div>

Select:

 <select class="custom-select my-1 mr-sm-2" id="inlineFormCustomSelectPref">
   <option selected></option>
   <option value="">Todas</option>
   <option value="Atendida">Atendida</option>
 </select>

Source

    <div class="input-group-prepend">
       <div class="input-group-text"><i class="fas fa-map-marker"></i></div>
       </div>
    <input type="text" class="form-control" id="inlineFormInputGroupSource" placeholder="Origem">
  </div>

Page Controller:

  import Ecto.Query

  def index(conn, params) do
    cdr = Structure.list_cdr()

   page = Structure.list_cdr
	|> order_by([c], desc: c.calldate)
        |> Repo.paginate(params)

    render(conn, "index.html", cdr: cdr, cdr: page.entries, page: page)
  end

What ‘specifically’ are you needing help with?

I needed to make a screen where the user searches the database directly

I solved it as follows …

controller

  def index(conn, params) do

    page = Structure.list_cdr
      |> order_by([c], desc: c.calldate)
      |> Repo.paginate(params)
    
    filter = Structure.list_filter(params)
    date_start = get_in(params, ["date_start"])
    date_end = get_in(params, ["date_end"])
    status = get_in(params, ["status"])
    origem = get_in(params, ["origem"])
    destino = get_in(params, ["destino"])
    contexto = get_in(params, ["contexto"])
       
   render(conn, "index.html", cdr: page.entries, page: page, cdr: filter.entries, 
   filter: filter, date_start: date_start, date_end: date_end, status: status, origem: origem,
   destino: destino, contexto: contexto)

list_filter

 def list_filter(params) do
     Ecdr
     |> where_calldate(params)
     |> where_status(params)
     |> where_origem(params)
     |> order_by([c], desc: c.calldate)
     |> Repo.paginate(params)
 end

Thank you for your interest in helping me.

1 Like