morph 0.1.0
Asynchronous bridge between GUI thread and business models
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
17namespace morph::ui::author {
18
19/// @brief A view descriptor: a `views::` kind and the registered query action it lists.
20template <typename V>
21concept ViewDescriptor = requires {
22 typename V::kind;
23 typename V::query;
24};
25
26/// @brief A `flows::Wizard`: a title and its steps.
27template <typename W>
28concept 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.
35template <WizardDescriptor W>
36using 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.
45template <ViewDescriptor View, typename Model>
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()},
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.
66template <WizardDescriptor Wizard, typename Model>
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()},
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
Server-side authoring of UI documents (spec 5 §11): typed builders that write a screen's JSON,...
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
Node wizard(ModelHandle< Model > const &model, FormPresentation const &presentation={})
A wizard node: the forms engine's wizard over an action.
Definition author.hpp:4324
void present(NodeWriter &node, FormPresentation const &presentation)
Writes presentation's keys on node.
Definition author.hpp:4221
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.
A model alias of a scope.
Definition author.hpp:1531
std::string const & alias() const noexcept
The alias.
Definition author.hpp:1539
A view node (spec 5 §9). The kind's own properties come from its builder's options; the properties ev...
Definition author.hpp:1778
Satisfied when Model runs Action: the model has an execute that takes it.
Definition author.hpp:94
A view descriptor: a views:: kind and the registered query action it lists.
A flows::Wizard: a title and its steps.
Multi-step wizards: an ordered sequence of registered actions that share a "flow draft" spanning the ...
std::string wizardSchemaJson()
Generates the w-* JSON document for wizard type W.
Definition flows.hpp:109
Traits specialisation that maps an action type to its id, JSON codec, and result type.
Definition registry.hpp:48
How a form, collection or wizard presents its forms: the keys every one of them takes.
Definition author.hpp:4202
View-schema generation: composes a registered query action's result rows with an optional row-opener ...
const std::string & viewSchemaJson()
Generates the view-schema JSON document for view descriptor V.
Definition views.hpp:560