PhoenixKitDashboards.Layouts (PhoenixKitDashboards v0.2.2)

Copy Markdown View Source

Pure helpers for a grid dashboard's layout list — the ordered config["layouts"] entries (%{"id","name","cols","rows"}), each one exactly one screenful on the gapless 25px lattice (see PhoenixKitDashboards.Lattice).

Read/derivation only: reading the (normalized, clamped) list, finding an entry by id, the first/landing id, and minting the next unused id/name for a new layout. This module never touches the Repo — the layout write paths (add_layout / rename_layout / delete_layout / set_grid_dims) stay in PhoenixKitDashboards.Dashboards alongside the CAS persist, which still re-exposes layouts/1, get_layout/2, and first_layout_id/1 as its public API (via defdelegate).

Summary

Functions

The baseline single-layout entry a never-persisted dashboard renders on.

The id of the first (default/landing) layout.

One layout entry by id, or nil.

The dashboard's grid layouts, ordered. A dashboard that has never persisted a layout list gets the default single "Layout 1" (64×36).

Mint a layout id not already used by entries — a short random id ("l" + 8 hex chars), regenerated on the (astronomically unlikely) clash.

The next free "Layout N" name for entries (falls back to "Layout ?").

Functions

default_layout()

@spec default_layout() :: map()

The baseline single-layout entry a never-persisted dashboard renders on.

first_layout_id(dashboard)

@spec first_layout_id(PhoenixKitDashboards.Schemas.Dashboard.t()) :: String.t()

The id of the first (default/landing) layout.

get_layout(dashboard, id)

@spec get_layout(PhoenixKitDashboards.Schemas.Dashboard.t(), String.t()) ::
  map() | nil

One layout entry by id, or nil.

layouts(dashboard)

The dashboard's grid layouts, ordered. A dashboard that has never persisted a layout list gets the default single "Layout 1" (64×36).

new_layout_id(entries)

@spec new_layout_id([map()]) :: String.t()

Mint a layout id not already used by entries — a short random id ("l" + 8 hex chars), regenerated on the (astronomically unlikely) clash.

next_layout_name(entries)

@spec next_layout_name([map()]) :: String.t()

The next free "Layout N" name for entries (falls back to "Layout ?").