diff --git a/apps/ex_nvr/test/ex_nvr/devices_test.exs b/apps/ex_nvr/test/ex_nvr/devices_test.exs index 0c58feba..2fbf5f6e 100644 --- a/apps/ex_nvr/test/ex_nvr/devices_test.exs +++ b/apps/ex_nvr/test/ex_nvr/devices_test.exs @@ -1,7 +1,7 @@ defmodule ExNVR.DevicesTest do use ExNVR.DataCase - alias ExNVR.{Devices, Recordings} + alias ExNVR.Devices alias ExNVR.Model.{Device, Recording, Run} import ExNVR.DevicesFixtures diff --git a/apps/ex_nvr_web/lib/ex_nvr_web/live/recordings_list_live.ex b/apps/ex_nvr_web/lib/ex_nvr_web/live/recordings_list_live.ex index 86223d26..639c5bb4 100644 --- a/apps/ex_nvr_web/lib/ex_nvr_web/live/recordings_list_live.ex +++ b/apps/ex_nvr_web/lib/ex_nvr_web/live/recordings_list_live.ex @@ -141,15 +141,18 @@ defmodule ExNVRWeb.RecordingListLive do devices: Devices.list(), popup_open: false, filter_params: params, - pagination_params: %{} + pagination_params: %{}, + sort_params: %{} )} end @impl true def handle_params(params, _uri, socket) do + sort_params = Map.take(params, ["order_by", "order_directions"]) + case Recordings.list(params) do {:ok, {recordings, meta}} -> - {:noreply, assign(socket, meta: meta, recordings: recordings)} + {:noreply, assign(socket, meta: meta, recordings: recordings, sort_params: sort_params)} {:error, meta} -> {:noreply, assign(socket, meta: meta)} @@ -163,28 +166,27 @@ defmodule ExNVRWeb.RecordingListLive do socket.assigns.filter_params, socket.assigns.pagination_params ) + |> Map.merge(socket.assigns.sort_params) {:noreply, push_navigate(socket, to: Routes.recording_list_path(socket, :list, params))} end @impl true def handle_event("filter-recordings", filter_params, socket) do - params = - Map.merge( - filter_params, - socket.assigns.pagination_params - ) - {:noreply, socket |> assign(:filter_params, filter_params) - |> push_patch(to: Routes.recording_list_path(socket, :list, params))} + |> assign(:pagination_params, %{}) + |> push_patch(to: Routes.recording_list_path(socket, :list, filter_params))} end @impl true def handle_event("paginate", pagination_params, socket) do pagination_params = Map.merge(socket.assigns.pagination_params, pagination_params) - params = Map.merge(socket.assigns.filter_params, pagination_params) + + params = + Map.merge(socket.assigns.filter_params, pagination_params) + |> Map.merge(socket.assigns.sort_params) {:noreply, socket diff --git a/apps/ex_nvr_web/test/ex_nvr_web/controllers/api/device_controller_test.exs b/apps/ex_nvr_web/test/ex_nvr_web/controllers/api/device_controller_test.exs index d0efea0e..53cda23d 100644 --- a/apps/ex_nvr_web/test/ex_nvr_web/controllers/api/device_controller_test.exs +++ b/apps/ex_nvr_web/test/ex_nvr_web/controllers/api/device_controller_test.exs @@ -3,9 +3,9 @@ defmodule ExNVRWeb.API.DeviceControllerTest do use ExNVRWeb.ConnCase - import ExNVR.{AccountsFixtures, DevicesFixtures, RecordingsFixtures} + import ExNVR.{AccountsFixtures, DevicesFixtures} - alias ExNVR.{Devices, Recordings} + alias ExNVR.Devices @moduletag :tmp_dir @@ -150,10 +150,9 @@ defmodule ExNVRWeb.API.DeviceControllerTest do end test "Delete device", %{conn: conn, device: device} do - response = - conn - |> delete(~p"/api/devices/#{device.id}") - |> response(204) + conn + |> delete(~p"/api/devices/#{device.id}") + |> response(204) refute Devices.get(device.id) end @@ -161,10 +160,9 @@ defmodule ExNVRWeb.API.DeviceControllerTest do test "delete a device by unauthorized user", %{conn: conn, device: device} do user_conn = log_in_user_with_access_token(conn, user_fixture(%{role: :user})) - response = - user_conn - |> delete(~p"/api/devices/#{device.id}") - |> response(403) + user_conn + |> delete(~p"/api/devices/#{device.id}") + |> response(403) end end end