# `Masu.Views`
[🔗](https://github.com/hattoriai/masu/blob/v0.1.0/lib/masu/views.ex#L1)

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:

  * `Masu.Views.Ecto`, a table in your database (`use Masu.Views.Ecto,
    repo: MyApp.Repo`, and `mix masu.gen.views` for its migration);
  * `Masu.Views.Memory`, in memory, for development and tests.

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)`.

# `saved`

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

A named view, as the views menu lists it.

# `delete`

```elixir
@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`

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

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

# `list`

```elixir
@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`

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

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

# `save`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
