NavEx (NavEx v0.1.7)
View SourceNavEx is a navigation history tool that uses adapter pattern and lets you choose between available adapters or just to write your own adapter.
There are 2 available adapters right now - ETS adapter storing user navigation history in the ETS and Session adapter storing user navigation history in user's sessions.
## Configuration:
config :nav_ex,
tracked_methods: ["GET"], # what methods to track
excluded_paths: ["/admin", "/dev], # paths you won't need to keep track on
history_length: 10, # what is the history list length per user
adapter: NavEx.Adapters.ETS # adapter used by NavEx to save data
adapter_config: ... # adapter specific configuration
### ETS Adapter config
adapter_config: %{
identity_key: "nav_ex_identity", # name of the key in session where the user's identity is saved
table_name: :navigation_history # name of the ETS table
}
## Session Adapter config
adapter_config: %{
history_key: "nav_ex_history" # name of the key in session where navigation history is saved
}
Summary
Functions
Used by ExNav.Plug. Takes %Plug.Conn{} as an input.
Takes %Plug.Conn{} or %Phoenix.LiveView.Socket{} as an input. Calls Adapter last_path/1
function.
Takes %Plug.Conn{} or %Phoenix.LiveView.Socket{} as an input. Calls Adapter list/1
function.
Takes %Plug.Conn{} or %Phoenix.LiveView.Socket{} and number as inputs. Calls Adapter path_at/1
function.
Functions
Used by ExNav.Plug. Takes %Plug.Conn{} as an input.
Calls Adapter insert/1
function. Returns {:ok, %Plug.Conn{}}
or {:ok, %Phoenix.LiveView.Socket{}}
tuple.
## Examples
iex(1)> NavEx.insert(conn)
{:ok, %Plug.Conn{...}}
iex(2)> NavEx.insert(socket, "/sample/path")
{:ok, %Phoenix.LiveView.Socket{...}}
Takes %Plug.Conn{} or %Phoenix.LiveView.Socket{} as an input. Calls Adapter last_path/1
function.
## Examples
# for existing user
iex(1)> NavEx.last_path(conn)
{:ok, "/sample/path"}
# for existing user, but without 2 paths
iex(2)> NavEx.last_path(conn)
{:ok, nil}
# for not existing user
iex(3)> NavEx.last_path(conn)
{:error, :not_found}
# for sockets
iex(4)> NavEx.last_path(socket)
{:ok, "/sample/path"}
Takes %Plug.Conn{} or %Phoenix.LiveView.Socket{} as an input. Calls Adapter list/1
function.
## Examples
# for existing user
iex(1)> NavEx.list(conn)
{:ok, ["/sample/path/2", "sample/path/1]}
# for not existing user
iex(2)> NavEx.list(conn)
{:error, :not_found}
# for sockets
iex(3)> NavEx.list(socket)
{:ok, ["/sample/path/2", "sample/path/1]}
Takes %Plug.Conn{} or %Phoenix.LiveView.Socket{} and number as inputs. Calls Adapter path_at/1
function.
## Examples
# for existing user
iex(1)> NavEx.path_at(conn, 5)
{:ok, "/sample/path"}
# for existing user but exceeding paths number
iex(2)> NavEx.path_at(conn, 5)
{:ok, nil}
# for not existing user
iex(3)> NavEx.path_at(conn, 5)
{:error, :not_found}
# exceeding history limit
iex(4)> NavEx.path_at(conn, 999)
** (ArgumentError) Max history depth is 10 counted from 0 to 9. You asked for record number 999.
# for sockets
iex(5)> NavEx.path_at(socket, 5)
{:ok, "/sample/path"}