style: format codebase
This commit is contained in:
@@ -139,7 +139,11 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
|> push_patch(to: path)}
|
||||
end
|
||||
|
||||
def handle_event("storage_location_filter", %{"storage_location_id" => storage_location_id}, socket) do
|
||||
def handle_event(
|
||||
"storage_location_filter",
|
||||
%{"storage_location_id" => storage_location_id},
|
||||
socket
|
||||
) do
|
||||
storage_location_id = String.to_integer(storage_location_id)
|
||||
query_string = build_query_params_with_storage_location(socket, storage_location_id)
|
||||
path = if query_string == "", do: "/", else: "/?" <> query_string
|
||||
@@ -387,7 +391,10 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
|> save_uploaded_image(component_params)
|
||||
|> save_uploaded_datasheet(socket)
|
||||
|
||||
case Inventory.update_component_with_datasheet(socket.assigns.editing_component, updated_params) do
|
||||
case Inventory.update_component_with_datasheet(
|
||||
socket.assigns.editing_component,
|
||||
updated_params
|
||||
) do
|
||||
{:ok, _component} ->
|
||||
{:noreply,
|
||||
socket
|
||||
@@ -496,7 +503,8 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
search: Map.get(overrides, :search, socket.assigns.search),
|
||||
criteria: Map.get(overrides, :criteria, socket.assigns.sort_criteria),
|
||||
category_id: Map.get(overrides, :category_id, socket.assigns.selected_category),
|
||||
storage_location_id: Map.get(overrides, :storage_location_id, socket.assigns.selected_storage_location)
|
||||
storage_location_id:
|
||||
Map.get(overrides, :storage_location_id, socket.assigns.selected_storage_location)
|
||||
}
|
||||
|
||||
params
|
||||
@@ -506,12 +514,14 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
|
||||
defp parse_filter_id(nil), do: nil
|
||||
defp parse_filter_id(""), do: nil
|
||||
|
||||
defp parse_filter_id(id) when is_binary(id) do
|
||||
case Integer.parse(id) do
|
||||
{int_id, ""} -> int_id
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_filter_id(id) when is_integer(id), do: id
|
||||
|
||||
defp build_query_params_with_category(socket, category_id) do
|
||||
@@ -553,7 +563,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
end
|
||||
|
||||
defp category_options(categories) do
|
||||
Hierarchical.select_options(categories, &(&1.parent), "Select a category")
|
||||
Hierarchical.select_options(categories, & &1.parent, "Select a category")
|
||||
end
|
||||
|
||||
defp storage_location_display_name(location) do
|
||||
@@ -561,7 +571,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
end
|
||||
|
||||
defp storage_location_options(storage_locations) do
|
||||
Hierarchical.select_options(storage_locations, &(&1.parent), "No storage location")
|
||||
Hierarchical.select_options(storage_locations, & &1.parent, "No storage location")
|
||||
end
|
||||
|
||||
@impl true
|
||||
@@ -610,7 +620,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
||||
<div class="flex flex-col sm:flex-row gap-4">
|
||||
@@ -687,23 +697,27 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
class="inline-flex items-center px-3 py-2 border border-base-300 text-sm font-medium rounded-md text-base-content bg-base-100 hover:bg-base-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary"
|
||||
>
|
||||
<.icon name="hero-adjustments-horizontal" class="w-4 h-4 mr-2" />
|
||||
<%= if @show_advanced_filters, do: "Hide", else: "More" %> Filters
|
||||
{if @show_advanced_filters, do: "Hide", else: "More"} Filters
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Advanced Filters (Collapsible) -->
|
||||
|
||||
<!-- Advanced Filters (Collapsible) -->
|
||||
<%= if @show_advanced_filters do %>
|
||||
<div class="mt-4 p-4 bg-base-100 border border-base-300 rounded-md">
|
||||
<div class="flex flex-col sm:flex-row gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-base-content mb-2">Storage Location</label>
|
||||
<label class="block text-sm font-medium text-base-content mb-2">
|
||||
Storage Location
|
||||
</label>
|
||||
<form phx-change="storage_location_filter">
|
||||
<select
|
||||
name="storage_location_id"
|
||||
class="block w-full px-3 py-2 border border-base-300 rounded-md shadow-sm bg-base-100 text-base-content focus:outline-none focus:ring-primary focus:border-primary sm:text-sm"
|
||||
>
|
||||
<option value="" selected={is_nil(@selected_storage_location)}>All Storage Locations</option>
|
||||
<option value="" selected={is_nil(@selected_storage_location)}>
|
||||
All Storage Locations
|
||||
</option>
|
||||
<%= for {location_name, location_id} <- Hierarchical.select_options(@storage_locations, &(&1.parent)) do %>
|
||||
<option value={location_id} selected={@selected_storage_location == location_id}>
|
||||
{location_name}
|
||||
@@ -716,7 +730,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Add Component Modal -->
|
||||
<%= if @show_add_form do %>
|
||||
<div class="fixed inset-0 bg-base-content/50 overflow-y-auto h-full w-full z-50">
|
||||
@@ -895,7 +909,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<!-- Edit Component Modal -->
|
||||
<%= if @show_edit_form do %>
|
||||
<div class="fixed inset-0 bg-base-content/50 overflow-y-auto h-full w-full z-50">
|
||||
@@ -1029,8 +1043,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
target="_blank"
|
||||
class="inline-flex items-center text-primary hover:text-primary/80"
|
||||
>
|
||||
<.icon name="hero-document-text" class="w-4 h-4 mr-1" />
|
||||
View PDF
|
||||
<.icon name="hero-document-text" class="w-4 h-4 mr-1" /> View PDF
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1097,7 +1110,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<!-- Components List -->
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-6">
|
||||
<div class="bg-base-100 shadow overflow-hidden sm:rounded-md">
|
||||
@@ -1166,7 +1179,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Content area with image and details -->
|
||||
<div class="flex gap-6">
|
||||
<!-- Large Image -->
|
||||
@@ -1192,7 +1205,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Details -->
|
||||
<div class="flex-1 space-y-4 select-text">
|
||||
<!-- Full Description -->
|
||||
@@ -1201,10 +1214,13 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
<h4 class="text-sm font-medium text-base-content mb-2">Description</h4>
|
||||
<%!-- Keep interpolation inline to prevent whitespace-pre-wrap from preserving template indentation.
|
||||
Use phx-no-format so the formatter won't break the layout. --%>
|
||||
<p phx-no-format class="text-sm text-base-content/70 leading-relaxed whitespace-pre-wrap">{component.description}</p>
|
||||
<p
|
||||
phx-no-format
|
||||
class="text-sm text-base-content/70 leading-relaxed whitespace-pre-wrap"
|
||||
>{component.description}</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<!-- Metadata Grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
|
||||
<%= if component.storage_location do %>
|
||||
@@ -1261,7 +1277,10 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
|
||||
<%= if component.datasheet_filename || component.datasheet_url do %>
|
||||
<div class="flex items-start">
|
||||
<.icon name="hero-document-text" class="w-4 h-4 mr-2 text-base-content/50 mt-0.5 flex-shrink-0" />
|
||||
<.icon
|
||||
name="hero-document-text"
|
||||
class="w-4 h-4 mr-2 text-base-content/50 mt-0.5 flex-shrink-0"
|
||||
/>
|
||||
<div>
|
||||
<span class="font-medium text-base-content">Datasheet:</span>
|
||||
<div class="space-y-1 mt-1">
|
||||
@@ -1284,8 +1303,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
target="_blank"
|
||||
class="inline-flex items-center text-base-content/70 hover:text-primary text-sm"
|
||||
>
|
||||
<.icon name="hero-link" class="w-4 h-4 mr-1" />
|
||||
Original URL
|
||||
<.icon name="hero-link" class="w-4 h-4 mr-1" /> Original URL
|
||||
</a>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1296,7 +1314,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="flex justify-end items-center space-x-2 pt-4 border-t border-base-300">
|
||||
<button
|
||||
@@ -1390,16 +1408,19 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Middle row: Description -->
|
||||
<%= if component.description do %>
|
||||
<div class="mt-1">
|
||||
<%!-- Keep interpolation inline to prevent whitespace-pre-wrap from preserving template indentation.
|
||||
Use phx-no-format so the formatter won't break the layout. --%>
|
||||
<p phx-no-format class="text-sm text-base-content/70 line-clamp-2 whitespace-pre-wrap">{component.description}</p>
|
||||
<p
|
||||
phx-no-format
|
||||
class="text-sm text-base-content/70 line-clamp-2 whitespace-pre-wrap"
|
||||
>{component.description}</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<!-- Bottom row: Metadata -->
|
||||
<div class="mt-2 grid grid-cols-1 sm:grid-cols-3 gap-x-4 gap-y-1 text-sm text-base-content/60">
|
||||
<%= if component.storage_location do %>
|
||||
@@ -1427,7 +1448,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Keywords row -->
|
||||
<%= if component.keywords do %>
|
||||
<div class="mt-2">
|
||||
@@ -1510,7 +1531,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
>
|
||||
<!-- Background overlay -->
|
||||
<div class="absolute inset-0 bg-black bg-opacity-75"></div>
|
||||
|
||||
|
||||
<!-- Modal content -->
|
||||
<div
|
||||
class="relative bg-base-100 rounded-lg shadow-xl max-w-4xl w-full max-h-full overflow-auto"
|
||||
@@ -1528,7 +1549,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Content -->
|
||||
<div class="p-6 bg-base-100 rounded-b-lg">
|
||||
<div class="text-center">
|
||||
|
||||
Reference in New Issue
Block a user