Wobserver v0.1.10 Wobserver.Page View Source
Page management for custom commands and pages in api and wobserver.
Link to this section Summary
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
data() View Source
Accepted page formats.
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 to0for no refresh.
Link to this section Functions
call(command)
View Source
call(Wobserver.Page.t() | atom()) :: any()
call(Wobserver.Page.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.
find(command)
View Source
find(command :: atom()) :: Wobserver.Page.t()
find(command :: atom()) :: Wobserver.Page.t()
Find the page for a given command
Returns :page_not_found, if no page can be found.
list()
View Source
list() :: [map()]
list() :: [map()]
List all registered pages.
For every page the following information is given:
titlecommandapi_onlyrefresh
load_config()
View Source
load_config() :: [any()]
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
mapwith the following fields:titlecommandcallbackoptions(optional)
For more information and types see: Wobserver.Page.register/1.
Example:
config :wobserver,
pages: [
{"Example", :example, fn -> %{x: 9} end}
]
register(page)
View Source
register(page :: Wobserver.Page.data()) :: boolean()
register(page :: Wobserver.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
mapwith the following fields:titlecommandcallbackoptions(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 to0for no refresh.
register(title, command, callback, options \\ []) View Source
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 to0for no refresh.