morph
0.1.0
Asynchronous bridge between GUI thread and business models
Toggle main menu visibility
Loading...
Searching...
No Matches
author_forms.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
#pragma once
3
4
#include <string>
5
#include <tuple>
6
7
#include "
../forms/flows.hpp
"
8
#include "
../forms/views.hpp
"
9
#include "
author.hpp
"
10
11
/// @file
12
/// The `collection` and `wizard` builders that carry their forms documents (spec 5 §11): a view descriptor's `v-*`
13
/// document and a wizard's `w-*` document go into the node's catalog facts, so the bundle serves them with the
14
/// `ui-catalog` reply and a client builds the node without knowing the types. Separate from `author.hpp` so the
15
/// builders that need no forms documents do not pull in the forms headers.
16
17
namespace
morph::ui::author {
18
19
/// @brief A view descriptor: a `views::` kind and the registered query action it lists.
20
template
<
typename
V>
21
concept
ViewDescriptor
=
requires
{
22
typename
V::kind;
23
typename
V::query;
24
};
25
26
/// @brief A `flows::Wizard`: a title and its steps.
27
template
<
typename
W>
28
concept
WizardDescriptor
=
requires
{
29
typename
W::steps;
30
W::title();
31
};
32
33
/// @brief The action of a wizard's first step, which names the wizard in a document.
34
/// @tparam W The wizard.
35
template
<WizardDescriptor W>
36
using
FirstStepAction
= std::tuple_element_t<0, typename W::steps>::action;
37
38
/// @brief A `collection` node over a view descriptor: the node names the view's query action, and the view's
39
/// document travels with the node's catalog facts.
40
/// @tparam View The view descriptor.
41
/// @tparam Model The model type of the alias; it must run the view's query.
42
/// @param model The alias.
43
/// @param presentation The keys that reach every form the view draws; its title replaces the view's heading.
44
/// @return The node.
45
template
<ViewDescriptor View,
typename
Model>
46
requires
Runs<Model, typename View::query>
47
[[nodiscard]]
Node
collection
(
ModelHandle<Model>
const
& model,
FormPresentation
const
& presentation = {}) {
48
using
Query = View::query;
49
CatalogFacts facts;
50
facts.action<Model, Query>();
51
facts.views.emplace(std::string{
::morph::model::ActionTraits<Query>::typeId
()},
52
::morph::views::viewSchemaJson<View>
());
53
detail::NodeWriter node{
"collection"
};
54
node.text(
"model"
, model.
alias
()).text(
"action"
, std::string{
::morph::model::ActionTraits<Query>::typeId
()});
55
detail::present
(node, presentation);
56
return
node.facts(facts).done();
57
}
58
59
/// @brief A `wizard` node over a `flows::Wizard`: the node names the first step's action, and the wizard's document
60
/// travels with the node's catalog facts.
61
/// @tparam Wizard The wizard.
62
/// @tparam Model The model type of the alias; it must run the first step.
63
/// @param model The alias.
64
/// @param presentation The keys that reach every step's form; its title replaces the view's heading.
65
/// @return The node.
66
template
<WizardDescriptor Wizard,
typename
Model>
67
requires
Runs<Model, FirstStepAction<Wizard>
>
68
[[nodiscard]]
Node
wizard
(
ModelHandle<Model>
const
& model,
FormPresentation
const
& presentation = {}) {
69
using
First = FirstStepAction<Wizard>;
70
CatalogFacts facts;
71
facts.action<Model, First>();
72
facts.wizards.emplace(std::string{
::morph::model::ActionTraits<First>::typeId
()},
73
::morph::flows::wizardSchemaJson<Wizard>
());
74
detail::NodeWriter node{
"wizard"
};
75
node.text(
"model"
, model.
alias
()).text(
"action"
, std::string{
::morph::model::ActionTraits<First>::typeId
()});
76
detail::present
(node, presentation);
77
return
node.facts(facts).done();
78
}
79
80
}
// namespace morph::ui::author
author.hpp
Server-side authoring of UI documents (spec 5 §11): typed builders that write a screen's JSON,...
morph::ui::author::collection
Node collection(ModelHandle< Model > const &model, FormPresentation const &presentation={})
A collection node: the forms engine's list screen over an action.
Definition
author.hpp:4307
morph::ui::author::wizard
Node wizard(ModelHandle< Model > const &model, FormPresentation const &presentation={})
A wizard node: the forms engine's wizard over an action.
Definition
author.hpp:4324
morph::ui::author::detail::present
void present(NodeWriter &node, FormPresentation const &presentation)
Writes presentation's keys on node.
Definition
author.hpp:4221
morph::ui::author::FirstStepAction
std::tuple_element_t< 0, typename W::steps >::action FirstStepAction
The action of a wizard's first step, which names the wizard in a document.
Definition
author_forms.hpp:36
morph::ui::author::ModelHandle
A model alias of a scope.
Definition
author.hpp:1531
morph::ui::author::ModelHandle::alias
std::string const & alias() const noexcept
The alias.
Definition
author.hpp:1539
morph::ui::author::Node
A view node (spec 5 §9). The kind's own properties come from its builder's options; the properties ev...
Definition
author.hpp:1778
morph::ui::author::Runs
Satisfied when Model runs Action: the model has an execute that takes it.
Definition
author.hpp:94
morph::ui::author::ViewDescriptor
A view descriptor: a views:: kind and the registered query action it lists.
Definition
author_forms.hpp:21
morph::ui::author::WizardDescriptor
A flows::Wizard: a title and its steps.
Definition
author_forms.hpp:28
flows.hpp
Multi-step wizards: an ordered sequence of registered actions that share a "flow draft" spanning the ...
morph::flows::wizardSchemaJson
std::string wizardSchemaJson()
Generates the w-* JSON document for wizard type W.
Definition
flows.hpp:109
morph::model::ActionTraits
Traits specialisation that maps an action type to its id, JSON codec, and result type.
Definition
registry.hpp:48
morph::ui::author::FormPresentation
How a form, collection or wizard presents its forms: the keys every one of them takes.
Definition
author.hpp:4202
views.hpp
View-schema generation: composes a registered query action's result rows with an optional row-opener ...
morph::views::viewSchemaJson
const std::string & viewSchemaJson()
Generates the view-schema JSON document for view descriptor V.
Definition
views.hpp:560
morph
ui
author_forms.hpp
Generated by
1.17.0