style: format codebase

This commit is contained in:
Schuwi
2025-09-20 11:52:43 +02:00
parent aaf278f7f9
commit c6c218970c
20 changed files with 722 additions and 385 deletions

View File

@@ -19,7 +19,7 @@ defmodule ComponentsElixir.Inventory do
locations =
StorageLocation
|> order_by([sl], asc: sl.name)
|> preload([parent: [parent: [parent: [parent: :parent]]]])
|> preload(parent: [parent: [parent: [parent: :parent]]])
|> Repo.all()
# Ensure AprilTag SVGs exist for all locations
@@ -162,7 +162,7 @@ defmodule ComponentsElixir.Inventory do
"""
def list_categories do
Category
|> preload([parent: [parent: [parent: [parent: :parent]]]])
|> preload(parent: [parent: [parent: [parent: :parent]]])
|> Repo.all()
end
@@ -217,8 +217,15 @@ defmodule ComponentsElixir.Inventory do
# Verify the category exists before getting descendants
case Enum.find(categories, &(&1.id == category_id)) do
nil -> []
_category -> ComponentsElixir.Inventory.Hierarchical.descendant_ids(categories, category_id, &(&1.parent_id))
nil ->
[]
_category ->
ComponentsElixir.Inventory.Hierarchical.descendant_ids(
categories,
category_id,
& &1.parent_id
)
end
end
@@ -233,13 +240,21 @@ defmodule ComponentsElixir.Inventory do
for typical storage location tree sizes (hundreds of locations). For very large storage location trees,
a recursive CTE query could be used instead.
"""
def get_storage_location_and_descendant_ids(storage_location_id) when is_integer(storage_location_id) do
def get_storage_location_and_descendant_ids(storage_location_id)
when is_integer(storage_location_id) do
storage_locations = list_storage_locations()
# Verify the storage location exists before getting descendants
case Enum.find(storage_locations, &(&1.id == storage_location_id)) do
nil -> []
_storage_location -> ComponentsElixir.Inventory.Hierarchical.descendant_ids(storage_locations, storage_location_id, &(&1.parent_id))
nil ->
[]
_storage_location ->
ComponentsElixir.Inventory.Hierarchical.descendant_ids(
storage_locations,
storage_location_id,
& &1.parent_id
)
end
end
@@ -306,7 +321,7 @@ defmodule ComponentsElixir.Inventory do
}
defp get_sort_order(criteria) do
Map.get(@sort_orders, criteria, [asc: :name, asc: :id])
Map.get(@sort_orders, criteria, asc: :name, asc: :id)
end
@doc """
@@ -338,10 +353,12 @@ defmodule ComponentsElixir.Inventory do
case ComponentsElixir.DatasheetDownloader.download_pdf_from_url(url) do
{:ok, filename} ->
Map.put(attrs, "datasheet_filename", filename)
{:error, _reason} ->
# Continue without datasheet file if download fails
attrs
end
_ ->
attrs
end
@@ -372,13 +389,18 @@ defmodule ComponentsElixir.Inventory do
{:ok, filename} ->
# Delete old datasheet file if it exists
if component.datasheet_filename do
ComponentsElixir.DatasheetDownloader.delete_datasheet_file(component.datasheet_filename)
ComponentsElixir.DatasheetDownloader.delete_datasheet_file(
component.datasheet_filename
)
end
Map.put(attrs, "datasheet_filename", filename)
{:error, _reason} ->
# Keep existing filename if download fails
attrs
end
_ ->
attrs
end