1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! [`Page`] — a panel page that is not a resource: a dashboard, a report, a
//! settings screen, a media library.
use Future;
use ;
use crate::;
/// A panel page that is not a resource, mounted at `{prefix}/{slug}` with a
/// sidebar entry; the panel owns the route and entry while the page owns its
/// markup.
///
/// ```rust
/// # use tablo_core::{Page, Panel};
/// # use topcoat::{Result, context::Cx, view::{View, view}};
/// struct ReportsPage;
///
/// impl Page for ReportsPage {
/// async fn render(cx: &Cx) -> Result<impl View> {
/// Ok(view! { cx => tablo_ui::page(tablo_ui::page_title("Reports")) })
/// }
/// }
///
/// Panel::new("admin").page::<ReportsPage>(); // GET /admin/reports
/// ```
///
/// A page serves one `GET` with a sidebar entry; a form it renders posts to an
/// app-declared route the auth gate covers. [`can_access`](Page::can_access) limits both to
/// the users it admits.
/// The header buttons of the page `P` the request may run, for its
/// [`page_actions`](tablo_ui::page_actions):
///
/// ```rust
/// # use tablo_core::{HeaderAction, HeaderActions, Page};
/// # use topcoat::{Result, context::Cx, view::{View, view}};
/// # struct ClearCache;
/// # impl HeaderAction for ClearCache {
/// # type Input = ();
/// # const NAME: &'static str = "clear-cache";
/// # async fn run(_: &Cx, _: (), _: &mut dyn toasty::Executor) -> Result<()> { Ok(()) }
/// # }
/// struct MaintenancePage;
///
/// impl Page for MaintenancePage {
/// fn header_actions() -> HeaderActions {
/// HeaderActions::new().add::<ClearCache>()
/// }
///
/// async fn render(cx: &Cx) -> Result<impl View> {
/// Ok(view! {
/// cx =>
/// tablo_ui::page(
/// tablo_ui::page_header(
/// tablo_ui::page_title("Maintenance")
/// tablo_ui::page_actions((tablo_core::header_action_buttons::<Self>(cx)))
/// )
/// )
/// })
/// }
/// }
/// ```
///
/// It renders nothing outside a request to `P`'s panel or for a request
/// [`can_access`](Page::can_access) refuses, and no button for an action whose
/// [`can_run`](crate::HeaderAction::can_run) refuses the request.