Surface scan+import errors
This commit is contained in:
@@ -26,7 +26,19 @@ defmodule MusicLibrary.BarcodeScan do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def import(scan_result, current_time) do
|
def import_results(scan_results, current_time) do
|
||||||
|
Enum.reduce(scan_results, [], fn scan_result, errors ->
|
||||||
|
case import_result(scan_result, current_time) do
|
||||||
|
{:error, reason} ->
|
||||||
|
[{scan_result.number, reason} | errors]
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
errors
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp import_result(scan_result, current_time) do
|
||||||
case scan_result.status do
|
case scan_result.status do
|
||||||
:new ->
|
:new ->
|
||||||
Records.import_from_musicbrainz_release(scan_result.release.id,
|
Records.import_from_musicbrainz_release(scan_result.release.id,
|
||||||
|
|||||||
@@ -193,18 +193,30 @@ defmodule MusicLibraryWeb.BarcodeScannerComponent do
|
|||||||
|
|
||||||
def handle_event("import_releases", _params, socket) do
|
def handle_event("import_releases", _params, socket) do
|
||||||
current_time = DateTime.utc_now()
|
current_time = DateTime.utc_now()
|
||||||
# TODO: error handling when a release fails to import
|
|
||||||
:ok =
|
socket =
|
||||||
Enum.each(socket.assigns.scan_results, fn scan_result ->
|
case BarcodeScan.import_results(socket.assigns.scan_results, current_time) do
|
||||||
BarcodeScan.import(scan_result, current_time)
|
[] ->
|
||||||
end)
|
put_flash(socket, :info, gettext("Records imported successfully"))
|
||||||
|
|
||||||
|
errors ->
|
||||||
|
errors_summary =
|
||||||
|
Enum.map_join(errors, "\n", fn {number, reason} ->
|
||||||
|
"#{number}: #{inspect(reason)}"
|
||||||
|
end)
|
||||||
|
|
||||||
|
put_flash(
|
||||||
|
socket,
|
||||||
|
:error,
|
||||||
|
gettext("Some records could not be imported: %{summary}", summary: errors_summary)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
qs = %{order: :purchase}
|
qs = %{order: :purchase}
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:scan_results, [])
|
|> assign(:scan_results, [])
|
||||||
|> put_flash(:info, gettext("Records imported successfully"))
|
|
||||||
|> push_patch(to: ~p"/collection?#{qs}")}
|
|> push_patch(to: ~p"/collection?#{qs}")}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -641,7 +641,7 @@ msgstr ""
|
|||||||
msgid "Importing..."
|
msgid "Importing..."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/barcode_scanner_component.ex:207
|
#: lib/music_library_web/components/barcode_scanner_component.ex:200
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Records imported successfully"
|
msgid "Records imported successfully"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -690,3 +690,8 @@ msgstr ""
|
|||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Barcode not found"
|
msgid "Barcode not found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: lib/music_library_web/components/barcode_scanner_component.ex:211
|
||||||
|
#, elixir-autogen, elixir-format
|
||||||
|
msgid "Some records could not be imported: %{summary}"
|
||||||
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user