diff --git a/lib/nerves_hub/devices/filtering.ex b/lib/nerves_hub/devices/filtering.ex index 13625e962..40e83486d 100644 --- a/lib/nerves_hub/devices/filtering.ex +++ b/lib/nerves_hub/devices/filtering.ex @@ -83,6 +83,12 @@ defmodule NervesHub.Devices.Filtering do where(query, [d], ilike(d.identifier, ^"%#{value}%")) end + def filter(query, _filters, :deployment_id, nil), do: query + + def filter(query, _filters, :deployment_id, value) do + where(query, [d], d.deployment_id == ^value) + end + def filter(query, _filters, :tag, value) do build_tag_filter(query, value) end diff --git a/lib/nerves_hub_web/live/devices/index-new.html.heex b/lib/nerves_hub_web/live/devices/index-new.html.heex index a1fe7344d..137716369 100644 --- a/lib/nerves_hub_web/live/devices/index-new.html.heex +++ b/lib/nerves_hub_web/live/devices/index-new.html.heex @@ -331,6 +331,15 @@ +
+ + +
+ + <%= for deployment <- @deployments do %> + + <% end %> + +
diff --git a/test/nerves_hub_web/live/devices/index_test.exs b/test/nerves_hub_web/live/devices/index_test.exs index 6eb83d7ee..b62efde1e 100644 --- a/test/nerves_hub_web/live/devices/index_test.exs +++ b/test/nerves_hub_web/live/devices/index_test.exs @@ -232,6 +232,22 @@ defmodule NervesHubWeb.Live.Devices.IndexTest do assert change =~ "1 devices found" end + test "filters devices by deployment_id", %{conn: conn, fixture: fixture} do + %{device: device, firmware: firmware, org: org, product: product, deployment: deployment} = + fixture + + device2 = Fixtures.device_fixture(org, product, firmware) + + Repo.update!(Ecto.Changeset.change(device, deployment_id: deployment.id)) + + {:ok, view, _html} = live(conn, device_index_path(fixture)) + + change = render_change(view, "update-filters", %{"deployment_id" => deployment.id}) + assert change =~ device.identifier + refute change =~ device2.identifier + assert change =~ "1 devices found" + end + test "select device", %{conn: conn, fixture: fixture} do %{device: _device, firmware: firmware, org: org, product: product} = fixture