LiveUI

Set of macros for building Phoenix.LiveView modules to help manage database records.

This is done by configuring default implementation of LiveUI for a given Ecto.Schema struct and initializing basic Index and Show live modules. This will in turn build the infrastructure for displaying and processing data without need to write boilerplate code associated with m:Phoenix.LiveView#callbacks callbacks and HEEX templates.

LiveUI has the following features:

LiveUI is possible because of these libraries:

Installation

Cldr

Add Cldr module:

  defmodule MyApp.Cldr do
    use Cldr,
      default_locale: "en",
      otp_app: :my_app,
      providers: [Cldr.Number, Money, Cldr.Calendar, Cldr.DateTime],
      gettext: MyAppWeb.Gettext
  end

LiveSelect

Add hook to assets/js/app.js - https://hexdocs.pm/live_select/readme.html#javascript-hooks

Petal components

Instalation guide - https://petal.build/components#install_petal_components

Configuration

# live ui
config :live_ui,
  debug: true,
  repo: MyApp.Repo,
  cldr: MyApp.Cldr,
  ignored_fields: [:token, :hashed_password, :first_version_id, :current_version_id]

# petal components
config :petal_components, :error_translator_function, {MyAppWeb.CoreComponents, :translate_error}

# flop
config :flop, repo: MyApp.Repo, default_limit: 10, max_limit: 100

# cldr
config :ex_cldr, default_backend: LiveUI.Cldr
config :my_app, LiveUI.Cldr, locales: ["en"]

# paper trail (optional)
config :paper_trail,
  repo: MyApp.Repo,
  originator: [name: :user, model: MyApp.User],
  strict_mode: true

There is a sample aplication bundled with the project that has all these set up, just run mix ecto.setup to generate some random data and start the server with iex -S mix phx.server. Admin credentials are admin@example.com/password.

Minimal setup

Ecto schema:

defmodule MyApp.User do
  use Ecto.Schema

  schema "users" do
    field :name, :string
    field :email, :string
    timestamps()
  end
end

Router entry:

scope "/", MyAppWeb do
  live_ui("/users", UserLive, MyApp.User)
end

Protocol file:

defimpl LiveUI, for: MyApp.User do
  use LiveUI.Protocol
end

Live modules:

defmodule MyAppWeb.UserLive.Index do
  use LiveUI.Views.Index, for: MyApp.User
end

defmodule MyAppWeb.UserLive.Show do
  use LiveUI.Views.Show, for: MyApp.User
end

Is it any good?

Yes