PhoenixKitCatalogue.Export (PhoenixKitCatalogue v0.10.0)

Copy Markdown View Source

Export context for the Catalogue module.

Drives the Export tab: registry of destinations, item selection, and in-memory file generation. Nothing is persisted to disk.

Usage

destinations = Export.destinations()
items        = Export.list_export_items(catalogue_uuids)

{filename, content, mime} = Export.build(%{
  destination: :pro100,
  format: :furniture,
  catalogue_uuids: [uuid1, uuid2]
})

Summary

Functions

Builds the export file in memory.

Finds a destination module by its atom key, or nil if not found.

Returns the list of registered export destination modules. Each element implements PhoenixKitCatalogue.Export.Destination.

Lists non-deleted items for export across one or more catalogues.

Functions

build(params)

@spec build(map()) :: {String.t(), iodata(), String.t()}

Builds the export file in memory.

params is a map with keys:

  • :destination — atom or string destination key (e.g. :pro100 or "pro100")
  • :format — atom or string format key (e.g. :furniture or "furniture")
  • :catalogue_uuids — list of catalogue UUIDs to export
  • :prefix_catalogue — optional; when truthy, PRO100 text formats prefix each item name with its catalogue name ("<catalogue> / <item>"). Default false.

Returns {filename, iodata, mime_type}.

Raises ArgumentError if the destination or format is not recognised, or if catalogue_uuids is nil/missing.

destination_by_key(key)

@spec destination_by_key(atom() | String.t()) :: module() | nil

Finds a destination module by its atom key, or nil if not found.

destinations()

@spec destinations() :: [module()]

Returns the list of registered export destination modules. Each element implements PhoenixKitCatalogue.Export.Destination.

list_export_items(catalogue_uuids)

@spec list_export_items([Ecto.UUID.t()]) :: [PhoenixKitCatalogue.Schemas.Item.t()]

Lists non-deleted items for export across one or more catalogues.

Returns all active items where catalogue_uuid in ^catalogue_uuids and status != "deleted", ordered by catalogue, then category position, then item position, then name. The :catalogue and :category associations are preloaded on every item.

Returns [] when catalogue_uuids is empty.