morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::forms::WizardSession Class Reference

The reactive state of one wizard: its steps' sessions, the position, and what each step resolved. More...

#include <wizard.hpp>

Public Member Functions

 WizardSession (reactive::Runtime &runtime, WizardModel model, SchemaLookup const &schemas, Submitter submit, ChoiceFetcher const &choices, FormSessionOptions const &options={})
 WizardSession (WizardSession const &)=delete
WizardSession & operator= (WizardSession const &)=delete
 WizardSession (WizardSession &&)=delete
WizardSession & operator= (WizardSession &&)=delete
WizardModel const & model () const noexcept
 The wizard model.
std::size_t current () const
 The current step. Tracked.
std::size_t stepCount () const noexcept
 How many steps there are.
FormSession & step (std::size_t index) const
 A step's form session.
bool stepDone (std::size_t index) const
 Whether a step is done: its current body is the one whose submission last succeeded. Tracked.
bool canBack () const
 Whether Back is possible. Tracked.
bool canNext () const
 Whether Next is possible. Tracked.
bool onLastStep () const
 Whether the current step is the last. Tracked.
void next ()
 Moves on: at once from a done step; from a ready step after submitting its body and that submission succeeding. Does nothing while canNext() is false.
void back ()
 Returns to the previous step, its values as they were; nothing is submitted.
std::optional< std::string > resolved (std::string_view path) const
 A value an earlier successful submission resolved: its body's member, or its reply's, the reply winning when both have one. Not tracked.
std::string title () const
 The wizard's title, resolved through the translations (<id>.title).
std::string stepTitle (std::size_t index) const
 A step's title, resolved through the translations (<id>.step.<index>.title).

Detailed Description

The reactive state of one wizard: its steps' sessions, the position, and what each step resolved.

A step is done while its current body is the one whose submission last succeeded: editing a done step makes it not done until that body succeeds. Next moves on from a done step without submitting; from a step that is ready but not done it submits and moves on once that submission succeeds. Back always returns, keeping every step's values. Entering a step applies its prefill from the resolved values as JSON values (programmatic, so it submits nothing by itself); a step left ready and not done by its prefill submits once in automatic mode.

Non-copyable and non-movable: the steps' submitters point into it. Destroy a view of it before the session.

Definition at line 140 of file wizard.hpp.

Constructor & Destructor Documentation

◆ WizardSession()

morph::forms::WizardSession::WizardSession ( reactive::Runtime & runtime,
WizardModel model,
SchemaLookup const & schemas,
Submitter submit,
ChoiceFetcher const & choices,
FormSessionOptions const & options = {} )
inline
Parameters
runtimeThe runtime. Borrowed: it must outlive the session.
modelThe wizard model.
schemasFinds each step's schema.
submitExecutes every step's action. Required.
choicesFetches the steps' Choice options; may be empty.
optionsEvery step's session options.
Exceptions
std::invalid_argumentwhen submit is empty, or a step's schema is unknown or does not read.

Definition at line 151 of file wizard.hpp.

Member Function Documentation

◆ model()

WizardModel const & morph::forms::WizardSession::model ( ) const
inlinenodiscardnoexcept

The wizard model.

Returns
The model.

Definition at line 186 of file wizard.hpp.

◆ current()

std::size_t morph::forms::WizardSession::current ( ) const
inlinenodiscard

The current step. Tracked.

Returns
Its index.

Definition at line 190 of file wizard.hpp.

◆ stepCount()

std::size_t morph::forms::WizardSession::stepCount ( ) const
inlinenodiscardnoexcept

How many steps there are.

Returns
The count; at least one.

Definition at line 194 of file wizard.hpp.

◆ step()

FormSession & morph::forms::WizardSession::step ( std::size_t index) const
inlinenodiscard

A step's form session.

Parameters
indexThe step.
Returns
Its session, alive as long as the wizard.
Exceptions
std::out_of_rangefor an index past the steps.

Definition at line 200 of file wizard.hpp.

◆ stepDone()

bool morph::forms::WizardSession::stepDone ( std::size_t index) const
inlinenodiscard

Whether a step is done: its current body is the one whose submission last succeeded. Tracked.

Parameters
indexThe step.
Returns
true when done.
Exceptions
std::out_of_rangefor an index past the steps.

Definition at line 206 of file wizard.hpp.

◆ canBack()

bool morph::forms::WizardSession::canBack ( ) const
inlinenodiscard

Whether Back is possible. Tracked.

Returns
true past the first step.

Definition at line 213 of file wizard.hpp.

◆ canNext()

bool morph::forms::WizardSession::canNext ( ) const
inlinenodiscard

Whether Next is possible. Tracked.

Returns
true when the current step is not the last, and is done, or ready with no submission in flight.

Definition at line 217 of file wizard.hpp.

◆ onLastStep()

bool morph::forms::WizardSession::onLastStep ( ) const
inlinenodiscard

Whether the current step is the last. Tracked.

Returns
true on the last step.

Definition at line 228 of file wizard.hpp.

◆ next()

void morph::forms::WizardSession::next ( )
inline

Moves on: at once from a done step; from a ready step after submitting its body and that submission succeeding. Does nothing while canNext() is false.

Definition at line 232 of file wizard.hpp.

◆ back()

void morph::forms::WizardSession::back ( )
inline

Returns to the previous step, its values as they were; nothing is submitted.

Definition at line 246 of file wizard.hpp.

◆ resolved()

std::optional< std::string > morph::forms::WizardSession::resolved ( std::string_view path) const
inlinenodiscard

A value an earlier successful submission resolved: its body's member, or its reply's, the reply winning when both have one. Not tracked.

Parameters
path<ActionType>.<member>.
Returns
The member's JSON, or std::nullopt.

Definition at line 257 of file wizard.hpp.

◆ title()

std::string morph::forms::WizardSession::title ( ) const
inlinenodiscard

The wizard's title, resolved through the translations (<id>.title).

Returns
The title.

Definition at line 264 of file wizard.hpp.

◆ stepTitle()

std::string morph::forms::WizardSession::stepTitle ( std::size_t index) const
inlinenodiscard

A step's title, resolved through the translations (<id>.step.<index>.title).

Parameters
indexThe step.
Returns
The title.
Exceptions
std::out_of_rangefor an index past the steps.

Definition at line 274 of file wizard.hpp.


The documentation for this class was generated from the following file: