Skip to content

Instantly share code, notes, and snippets.

@acrolink
Last active January 4, 2017 11:28
Show Gist options
  • Select an option

  • Save acrolink/dba8a0a5e62dc49ee3c95d81e5139443 to your computer and use it in GitHub Desktop.

Select an option

Save acrolink/dba8a0a5e62dc49ee3c95d81e5139443 to your computer and use it in GitHub Desktop.

Revisions

  1. acrolink revised this gist Jan 4, 2017. 1 changed file with 8 additions and 10 deletions.
    18 changes: 8 additions & 10 deletions policy_controller.ex
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,19 @@
    ..
    def index(conn, _params) do

    page =
    Policy
    |> QueryFilter.filter(%Policy{}, _params, [:client_id])
    |> QueryFilter.filter(%Policy{}, _params, [:client_id])
    |> join(:left, [p], c in Client, p.client_id == c.id)
    |> where([p, c], c.user_id == ^conn.assigns.current_user.id)
    |> preload([p, c], [client: c])
    |> Repo.paginate(_params)
    |> Repo.paginate(_params)

    render conn, :index,
    policies: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: page.total_pages,
    total_entries: page.total_entries,
    policies: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: page.total_pages,
    total_entries: page.total_entries,
    page: page,

    end
    ..
  2. acrolink created this gist Jan 4, 2017.
    10 changes: 10 additions & 0 deletions index.html.eex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <h2>Listing policies</h2>

    <form action="/policies" method="get">
    <%= select nil, :client_id, @clients, name: 'client_id' %>
    <input type="submit" value="Submit">
    </form>

    <%= pagination_links @page %>

    <!-- HTML displaying the data rows -->
    21 changes: 21 additions & 0 deletions policy_controller.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    ..
    def index(conn, _params) do

    page =
    Policy
    |> QueryFilter.filter(%Policy{}, _params, [:client_id])
    |> join(:left, [p], c in Client, p.client_id == c.id)
    |> where([p, c], c.user_id == ^conn.assigns.current_user.id)
    |> preload([p, c], [client: c])
    |> Repo.paginate(_params)

    render conn, :index,
    policies: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: page.total_pages,
    total_entries: page.total_entries,
    page: page,

    end
    ..