View Source Wobserver.Page (Wobserver NG v1.14.0)

Page management for custom commands and pages in api and wobserver.

Link to this section Summary

Types

Accepted page formats.

t()

Page structure.

Functions

Calls the function associated with the command/page.

Find the page for a given command

List all registered pages.

Loads custom pages from configuration and adds them to :wobserver.

Registers a page with :wobserver.

Registers a page with :wobserver.

Link to this section Types

@type data() ::
  t()
  | map()
  | {String.t(), atom(), (... -> any())}
  | {String.t(), atom(), (... -> any()), boolean()}

Accepted page formats.

@type t() :: %Wobserver.Page{
  callback: (... -> any()),
  command: atom(),
  options: keyword(),
  title: String.t()
}

Page structure.

Fields:

  • title, the name of the page. Is used for the web interface menu.
  • command, single atom to associate the page with.
  • callback, function to be evaluated, when the a api is called or page is viewd.
            The result is converted to JSON and displayed.
  • options, map containing options for the page.

Options:

  • api_only (boolean), if set to true the page won't show up in the web interface, but will only be available as API.
  • refresh (float, 0-1), sets the refresh time factor. Used in the web interface to refresh the data on the page. Set to 0 for no refresh.

Link to this section Functions

@spec call(t() | atom()) :: any()

Calls the function associated with the command/page.

Returns the result of the function or :page_not_found, if the page can not be found.

@spec find(command :: atom()) :: t()

Find the page for a given command

Returns :page_not_found, if no page can be found.

@spec list() :: [map()]

List all registered pages.

For every page the following information is given:

  • title
  • command
  • api_only
  • refresh
@spec load_config() :: [any()]

Loads custom pages from configuration and adds them to :wobserver.

To add custom pages set the :pages option. The :pages option must be a list of page data.

The page data can be formatted as:

  • {title, command, callback}
  • {title, command, callback, options}
  • a map with the following fields:
    • title
    • command
    • callback
    • options (optional)

For more information and types see: Wobserver.Page.register/1.

Example:

config :wobserver,
  pages: [
    {"Example", :example, fn -> %{x:  9} end}
  ]
@spec register(page :: data()) :: boolean()

Registers a page with :wobserver.

Returns true if succesfully added. (otherwise false)

The following inputs are accepted:

  • {title, command, callback}
  • {title, command, callback, options}
  • a map with the following fields:
    • title
    • command
    • callback
    • options (optional)

The fields are used as followed:

  • title, the name of the page. Is used for the web interface menu.
  • command, single atom to associate the page with.
  • callback, function to be evaluated, when the a api is called or page is viewd.
            The result is converted to JSON and displayed.
  • options, options for the page.

The following options can be set:

  • api_only (boolean), if set to true the page won't show up in the web interface, but will only be available as API.
  • refresh (float, 0-1), sets the refresh time factor. Used in the web interface to refresh the data on the page. Set to 0 for no refresh.
Link to this function

register(title, command, callback, options \\ [])

View Source
@spec register(
  title :: String.t(),
  command :: atom(),
  callback :: (... -> any()),
  options :: keyword()
) :: boolean()

Registers a page with :wobserver.

The arguments are used as followed:

  • title, the name of the page. Is used for the web interface menu.
  • command, single atom to associate the page with.
  • callback, function to be evaluated, when the a api is called or page is viewd.
            The result is converted to JSON and displayed.
  • options, options for the page.

The following options can be set:

  • api_only (boolean), if set to true the page won't show up in the web interface, but will only be available as API.
  • refresh (float, 0-1), sets the refresh time factor. Used in the web interface to refresh the data on the page. Set to 0 for no refresh.