StatusIndicator

The StatusIndicator is a composed component, consisting of a Container that contains an HtmlElement and a Hidden value. It can be used as a visual indication of the state of the data and can be managed on the back-end. The status indicator as follows, the color depends on the active state:

Initialization

To add a StatusIndicator programmatically, use its static method create, that takes the following input arguments:

InputDescriptionDatatype
keyKey used to reference the status indicator. Use this key later to update the status.String
parentThe parent component. Can be any component that can contain other components, or the form.Component/Form

Additional options can be given as named arguments:

NameDescriptionDatatypeDefault
contentText to display on the status indicator.String'Status'
defaultValueDefault status value.String'muted'
statusesDefines the value and theme of every reachable status. Array of structs/dicts that have fields value and theme. An optional field content defines the text to display per status. If the statuses.content field and a defaultValue are provided, this defines the initial text of the status indicator and any content name-value pair is ignored.Dict/Struct[{'value': 'muted', 'theme': 'muted'}, {'value': 'primary', 'theme': 'primary'}, {'value': 'success', 'theme': 'success'}, {'value': 'info', 'theme': 'info'}, {'value': 'warning', 'theme': 'warning'}, {'value': 'danger', 'theme': 'danger'}, {'value': 'secondary', 'theme': 'secondary'}, {'value': 'dark', 'theme': 'dark'}, {'value': 'light', 'theme': 'light'}]
From Json

The StatusIndicator can be added from a Json form definition as a generic Composed component, by specifying its fully qualified className:

{
    "label": "Status",
    "className": "simian.gui.composed_component.StatusIndicator",
    "displayHeight": 40,
    "hideLabel": true,
    "key": "my_status",
    "type": "customcomposed",
}

The component can be initialized using the static method get_initializer that takes the same optional input arguments as create.

Form.componentInitializer(
    my_status=composed_component.StatusIndicator.get_initializer(
        content="Hello, world!", defaultValue="success"
    )
)

form = Form(from_file=__file__)
Form.componentInitializer(...
    my_status=composedComponent.StatusIndicator.getInitializer(...
    content="Hello, world!", defaultValue="success"));

form = Form(FromFile="/path/to/my/form.json");
Updating

Update the status in your gui_event code using:

payload = composed_component.StatusIndicator.update(
    payload,
    key,
    status,
    nestedFormKey,
    parent=parentKey,
)

where key is the key provided when creating the StatusIndicator, status is one of the items of statuses.value and nestedFormKey is an optional nested parent form. Use the parent name-value pair to further specify which status indicator must be selected.

Example
# Initialize using defaults:
testStatus = composed_component.StatusIndicator.create("testStatus", form)
        
# Initialize using options:
testStatus = composed_component.StatusIndicator.create(
    "testStatus", form,
    content="Tests",
    defaultValue="notRun",
    statuses=[{
        "value": "notRun",
        "theme": "secondary"
    }, {
        "value": "running",
        "theme": "warning"
    }, {
        "value": "success",
        "theme": "success"
    }, {
        "value": "failed",
        "theme": "danger"
    }]
)

# Update the status:
composed_component.StatusIndicator.update(payload, "testStatus", "failed")
% Initialize using defaults:
testStatus = composedComponent.StatusIndicator.create("testStatus", form);

% Initialize using options:
statuses = struct(...
    "value", {'notRun', 'running', 'success', 'failed'}, ...
    "theme", {'secondary', 'warning', 'success', 'danger'});

testStatus = composedComponent.StatusIndicator.create(...
    "testStatus", form, ...
    "Content", "Tests", ...
    "DefaultValue", "notRun", ...
    "Statuses", statuses);
    
% Update the status:
payload = composedComponent.StatusIndicator.update(payload, "testStatus", "failed");