HaytniWeb.Shared (Haytni v0.7.0) View Source

Contains shared stuffs between Haytni base plugins.

Mainly handle a message view/template which is intended to replace "abusive" Phoenix.Controller.put_flash/3. put_flash stores messages in session and may have several issues:

  • it can conflict if you use multiple tabs or instances of a same browser
  • excessive reads/writes (depending on the backend)
  • incompatible with HTTP caching

Link to this section Summary

Functions

Momorize the original HTTP referer by adding it to a changeset. Have to be called on new or edit action (not create nor update).

Add a back/cancel link for SharedView.

Returns the path to a Haytni controller

Add a next step link for SharedView.

Set connection to render SharedView/message.html.

Returns the path to the login page.

Link to this section Functions

Link to this function

add_referer_to_changeset(conn, changeset)

View Source

Specs

add_referer_to_changeset(conn :: Plug.Conn.t(), changeset :: Ecto.Changeset.t()) ::
  Ecto.Changeset.t()

Momorize the original HTTP referer by adding it to a changeset. Have to be called on new or edit action (not create nor update).

Link to this function

back_link(conn, struct, default)

View Source

Specs

back_link(conn :: Plug.Conn.t(), struct :: struct(), default :: String.t()) ::
  Plug.Conn.t()

Add a back/cancel link for SharedView.

NOTE: we do not use "javascript:history.back()" as default since this may be inappropriate with Content Security Policy (CSP). But user is free to use it by indicating it as value for default.

Link to this function

haytni_path(conn_or_endpoint, module, fun, action, args \\ [])

View Source

Specs

haytni_path(
  conn_or_endpoint :: Plug.Conn.t() | module(),
  module :: module(),
  fun :: (atom() -> atom()),
  action :: atom(),
  args :: Keyword.t()
) :: String.t()

Returns the path to a Haytni controller

Example:

iex> Elixir.HaytniWeb.Shared.haytni_path(conn, YourApp.Haytni, &(:"haytni_#{&1}_invitation_path"), :new, [[invitation: "ABCD", email: "me@mydomain.com"]])
"/invitations/new?invitation=ABCD&email=me%40mydomain.com"
Link to this function

next_step_link(conn, href, text)

View Source

Specs

next_step_link(conn :: Plug.Conn.t(), href :: String.t(), text :: String.t()) ::
  Plug.Conn.t()

Add a next step link for SharedView.

Link to this function

render_message(conn, module, message, type \\ :info)

View Source

Specs

render_message(
  conn :: Plug.Conn.t(),
  module :: module(),
  message :: String.t(),
  type :: atom()
) :: Plug.Conn.t()

Set connection to render SharedView/message.html.

Link to this function

session_path(conn_or_endpoint, module)

View Source

Specs

session_path(conn_or_endpoint :: Plug.Conn.t() | module(), module :: module()) ::
  String.t()

Returns the path to the login page.