PhoenixKitPhotos.Viewer (PhoenixKit Photos v0.3.0)

Copy Markdown View Source

Which viewer a library's photos open in.

Two are offered:

  • "photoswipe" — the swipe viewer (PhoenixKitPhotos.Components.PhotoTimeline's pager, engine photoswipe): swipe between photos and videos, pinch and double-tap zoom, drag down to close;
  • "classic" — PhoenixKit's own media viewer (MediaCanvasViewer), one file at a time with its sidebar and comments.

A library chooses one. The choice is this package's own setting for the library (Libraries.module_setting(library, "photos", "viewer"), kept in the library's settings under this package's namespace, so it follows the library and not the browser, and core knows nothing of it). A library that has not chosen follows default/0: config :phoenix_kit_photos, default_viewer: "classic", otherwise "photoswipe". A name stored that this package does not offer (an engine it no longer has) is ignored: the library follows the default.

The viewer's engines (assets/js/viewer) are a finer list than this one: snap is an engine and is not offered here.

Summary

Functions

Whether scope may choose the viewer of library: a user library's owner and managers, and for a system library (Media) the site's owners and admins.

A library's own choice, or nil when it follows the default.

The viewer a library follows until it chooses.

The viewer for a library (or its uuid; nil is Media): its own choice, or the default when it has none or a name this package does not offer.

The viewers a library can choose between, as {name, label}.

What PhotoTimeline's pager takes for a viewer: false for the classic one (the host opens its own on on_open), the engine's name for the swipe viewer.

Sets the viewer of library for scope: a name from options/0, or nil to follow the default. {:error, :not_allowed} for someone who may not, {:error, :unknown_viewer} for a name not offered.

Functions

can_set?(scope, library)

Whether scope may choose the viewer of library: a user library's owner and managers, and for a system library (Media) the site's owners and admins.

chosen(library)

@spec chosen(PhoenixKit.Modules.Storage.Library.t() | String.t() | nil) ::
  String.t() | nil

A library's own choice, or nil when it follows the default.

default()

@spec default() :: String.t()

The viewer a library follows until it chooses.

for_library(library)

@spec for_library(PhoenixKit.Modules.Storage.Library.t() | String.t() | nil) ::
  String.t()

The viewer for a library (or its uuid; nil is Media): its own choice, or the default when it has none or a name this package does not offer.

options()

@spec options() :: [{String.t(), String.t()}]

The viewers a library can choose between, as {name, label}.

pager(name)

@spec pager(String.t()) :: false | String.t()

What PhotoTimeline's pager takes for a viewer: false for the classic one (the host opens its own on on_open), the engine's name for the swipe viewer.

put(scope, library, name)

@spec put(
  PhoenixKit.Users.Auth.Scope.t() | nil,
  PhoenixKit.Modules.Storage.Library.t(),
  String.t() | nil
) ::
  {:ok, PhoenixKit.Modules.Storage.Library.t()}
  | {:error, :not_allowed | :unknown_viewer | term()}

Sets the viewer of library for scope: a name from options/0, or nil to follow the default. {:error, :not_allowed} for someone who may not, {:error, :unknown_viewer} for a name not offered.