Masu.Views behaviour (Masu v0.1.0)

Copy Markdown View Source

Where a grid keeps people's views: the last view of each person, which the grid restores when they come back, and named views ("My open orders") that a person saves for themselves or shares with everyone.

<.data_grid id="orders" source={Order} repo={Repo} views={MyApp.GridViews} user={@user}>

views is a module of this behaviour. Masu has two:

A store of your own implements the callbacks below. A view is kept as its params (see Masu.View): a map of strings, what differs from the grid's own view. grid is the grid's views_key (its id unless given) and user the grid's user; a person is to_string(user.id).

Summary

Types

A named view, as the views menu lists it.

Callbacks

Deletes a named view of the person's (not one of someone else's).

The person's last view of the grid, or nil.

The named views the person may apply: their own and the shared ones, by name.

Keeps the person's view of the grid, as it changes.

Saves a named view of the person's: a view of theirs with that name is replaced. shared shows it to everyone who has the grid.

Types

saved()

@type saved() :: %{
  id: String.t(),
  name: String.t(),
  shared: boolean(),
  mine: boolean(),
  params: map()
}

A named view, as the views menu lists it.

Callbacks

delete(grid, user, id)

@callback delete(grid :: String.t(), user :: map(), id :: String.t()) :: :ok

Deletes a named view of the person's (not one of someone else's).

last(grid, user)

@callback last(grid :: String.t(), user :: map()) :: map() | nil

The person's last view of the grid, or nil.

list(grid, user)

@callback list(grid :: String.t(), user :: map()) :: [saved()]

The named views the person may apply: their own and the shared ones, by name.

put_last(grid, user, params)

@callback put_last(grid :: String.t(), user :: map(), params :: map()) :: :ok

Keeps the person's view of the grid, as it changes.

save(grid, user, name, params, shared)

@callback save(
  grid :: String.t(),
  user :: map(),
  name :: String.t(),
  params :: map(),
  shared :: boolean()
) ::
  {:ok, saved()} | {:error, String.t()}

Saves a named view of the person's: a view of theirs with that name is replaced. shared shows it to everyone who has the grid.