feat: datasheet upload and auto-retrieve
- store datasheet PDFs on the server - download PDF automatically when given a link
This commit is contained in:
@@ -18,6 +18,7 @@ defmodule ComponentsElixir.Inventory.Component do
|
||||
field :legacy_position, :string
|
||||
field :count, :integer, default: 0
|
||||
field :datasheet_url, :string
|
||||
field :datasheet_filename, :string
|
||||
field :image_filename, :string
|
||||
|
||||
belongs_to :category, Category
|
||||
@@ -29,7 +30,7 @@ defmodule ComponentsElixir.Inventory.Component do
|
||||
@doc false
|
||||
def changeset(component, attrs) do
|
||||
component
|
||||
|> cast(attrs, [:name, :description, :keywords, :position, :count, :datasheet_url, :image_filename, :category_id, :storage_location_id])
|
||||
|> cast(attrs, [:name, :description, :keywords, :position, :count, :datasheet_url, :datasheet_filename, :image_filename, :category_id, :storage_location_id])
|
||||
|> validate_required([:name, :category_id])
|
||||
|> validate_length(:name, min: 1, max: 255)
|
||||
|> validate_length(:description, max: 2000)
|
||||
@@ -59,6 +60,14 @@ defmodule ComponentsElixir.Inventory.Component do
|
||||
|> cast(attrs, [:image_filename])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Changeset for updating component datasheet.
|
||||
"""
|
||||
def datasheet_changeset(component, attrs) do
|
||||
component
|
||||
|> cast(attrs, [:datasheet_filename])
|
||||
end
|
||||
|
||||
defp validate_url(changeset, field) do
|
||||
validate_change(changeset, field, fn ^field, url ->
|
||||
if url && url != "" do
|
||||
@@ -78,6 +87,12 @@ defmodule ComponentsElixir.Inventory.Component do
|
||||
def has_image?(%__MODULE__{image_filename: filename}) when is_binary(filename), do: true
|
||||
def has_image?(_), do: false
|
||||
|
||||
@doc """
|
||||
Returns true if the component has a datasheet file.
|
||||
"""
|
||||
def has_datasheet?(%__MODULE__{datasheet_filename: filename}) when is_binary(filename), do: true
|
||||
def has_datasheet?(_), do: false
|
||||
|
||||
@doc """
|
||||
Returns the search text for this component.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user