Wobserver v0.1.8 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 :: Wobserver.Page.t | map | {String.t, atom, (... -> any)} | {String.t, atom, (... -> any), boolean}
Accepted page formats.
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 to0
for no refresh.
Link to this section Functions
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 the page for a given command
Returns :page_not_found
, if no page can be found.
List all registered pages.
For every page the following information is given:
title
command
api_only
refresh
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}
]
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 to0
for no refresh.
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 to0
for no refresh.