pub struct AdminState<S> {
pub title: String,
pub navigation_groups: HashMap<String, AdminNavigationGroup>,
pub sidebar_widgets: Vec<AdminSidebarWidget>,
pub dashboard_widgets: Vec<AdminDashboardWidget>,
pub entities: Vec<Arc<dyn TypeErasedEntityHandler<S> + Send + Sync>>,
pub auth_providers: AuthProviders<S>,
pub login_url: String,
pub super_admin_group: Option<String>,
pub login_providers: LoginProviders,
}Fields§
§title: String§dashboard_widgets: Vec<AdminDashboardWidget>§entities: Vec<Arc<dyn TypeErasedEntityHandler<S> + Send + Sync>>§auth_providers: AuthProviders<S>§login_url: String§super_admin_group: Option<String>§login_providers: LoginProvidersImplementations§
Source§impl<S> AdminState<S>where
S: State + 'static,
impl<S> AdminState<S>where
S: State + 'static,
Adds a navigation section for your bundle
Examples found in repository?
examples/full-admin.rs (lines 74-78)
67 fn configure_state(&mut self, state: &mut S) -> quokka::Result<()> {
68 let admin: &mut AdminState<_> = state.provide_mut();
69
70 admin.super_admin_group = EXAMPLE_SUPER_USER_GROUP.to_string().into(); // This can be and usually should be set via the config
71 admin.add_auth_provider(TestAuthProvider);
72 admin.add_login_provider(TestLoginProvider);
73
74 admin.add_navigation(
75 AdminNavigationGroup::new("Example").add(
76 NavigationItem::new("example_page", "Example Page").link("/admin/example/page"),
77 ),
78 );
79
80 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/test_widget"));
81 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/time_widget")); // .hx_trigger("load, every 1s") // This widget should be refreshed, but as it spams the console I leave this comment here so you know that it is possible
82
83 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
84 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
85 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
86 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
87
88 admin.register_entity_handler(EntityHandler::<
89 S,
90 TestEntityCreateForm,
91 TestEntityUpdateForm,
92 TestEntityListing,
93 >::new("Example"));
94
95 Ok(())
96 }Gets an ordered version of the navigation
Adds a sidebar widget, check AdminSidebarWidget for details
Examples found in repository?
examples/full-admin.rs (line 80)
67 fn configure_state(&mut self, state: &mut S) -> quokka::Result<()> {
68 let admin: &mut AdminState<_> = state.provide_mut();
69
70 admin.super_admin_group = EXAMPLE_SUPER_USER_GROUP.to_string().into(); // This can be and usually should be set via the config
71 admin.add_auth_provider(TestAuthProvider);
72 admin.add_login_provider(TestLoginProvider);
73
74 admin.add_navigation(
75 AdminNavigationGroup::new("Example").add(
76 NavigationItem::new("example_page", "Example Page").link("/admin/example/page"),
77 ),
78 );
79
80 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/test_widget"));
81 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/time_widget")); // .hx_trigger("load, every 1s") // This widget should be refreshed, but as it spams the console I leave this comment here so you know that it is possible
82
83 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
84 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
85 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
86 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
87
88 admin.register_entity_handler(EntityHandler::<
89 S,
90 TestEntityCreateForm,
91 TestEntityUpdateForm,
92 TestEntityListing,
93 >::new("Example"));
94
95 Ok(())
96 }Sourcepub fn add_dashboard_widget(&mut self, widget: impl Into<AdminDashboardWidget>)
pub fn add_dashboard_widget(&mut self, widget: impl Into<AdminDashboardWidget>)
Adds a dashboard widget, check AdminDashboardWidget for details
Examples found in repository?
examples/full-admin.rs (line 83)
67 fn configure_state(&mut self, state: &mut S) -> quokka::Result<()> {
68 let admin: &mut AdminState<_> = state.provide_mut();
69
70 admin.super_admin_group = EXAMPLE_SUPER_USER_GROUP.to_string().into(); // This can be and usually should be set via the config
71 admin.add_auth_provider(TestAuthProvider);
72 admin.add_login_provider(TestLoginProvider);
73
74 admin.add_navigation(
75 AdminNavigationGroup::new("Example").add(
76 NavigationItem::new("example_page", "Example Page").link("/admin/example/page"),
77 ),
78 );
79
80 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/test_widget"));
81 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/time_widget")); // .hx_trigger("load, every 1s") // This widget should be refreshed, but as it spams the console I leave this comment here so you know that it is possible
82
83 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
84 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
85 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
86 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
87
88 admin.register_entity_handler(EntityHandler::<
89 S,
90 TestEntityCreateForm,
91 TestEntityUpdateForm,
92 TestEntityListing,
93 >::new("Example"));
94
95 Ok(())
96 }Sourcepub fn register_entity_handler<C, U, L>(
&mut self,
handler: EntityHandler<S, C, U, L>,
)where
S: ProvideState<Database> + ProvideState<Templating> + ProvideState<FormBuilder<S>> + ProvideState<AdminCreateFormPageLoader<S, C>> + ProvideState<AdminUpdateFormPageLoader<S, U>> + ProvideState<AdminPageLoader>,
C: AdminCreateForm<S> + DeserializeOwned + Serialize + Debug + Send + Sync + 'static,
U: AdminUpdateForm<S> + DeserializeOwned + Serialize + Debug + Send + Sync + 'static,
U::PrimaryKeys: DeserializeOwned + Send + Sync + 'static,
L: AdminListing<S> + Clone + Send + Sync + Serialize + 'static,
L::PrimaryKeys: DeserializeOwned + Send + Sync + 'static,
L::Entity: Serialize + DeserializeOwned + Clone + Debug + Send + 'static,
pub fn register_entity_handler<C, U, L>(
&mut self,
handler: EntityHandler<S, C, U, L>,
)where
S: ProvideState<Database> + ProvideState<Templating> + ProvideState<FormBuilder<S>> + ProvideState<AdminCreateFormPageLoader<S, C>> + ProvideState<AdminUpdateFormPageLoader<S, U>> + ProvideState<AdminPageLoader>,
C: AdminCreateForm<S> + DeserializeOwned + Serialize + Debug + Send + Sync + 'static,
U: AdminUpdateForm<S> + DeserializeOwned + Serialize + Debug + Send + Sync + 'static,
U::PrimaryKeys: DeserializeOwned + Send + Sync + 'static,
L: AdminListing<S> + Clone + Send + Sync + Serialize + 'static,
L::PrimaryKeys: DeserializeOwned + Send + Sync + 'static,
L::Entity: Serialize + DeserializeOwned + Clone + Debug + Send + 'static,
Registers your custom entity to be managable in the admin-ui. Check the EntityHandler for more details.
Examples found in repository?
examples/full-admin.rs (lines 88-93)
67 fn configure_state(&mut self, state: &mut S) -> quokka::Result<()> {
68 let admin: &mut AdminState<_> = state.provide_mut();
69
70 admin.super_admin_group = EXAMPLE_SUPER_USER_GROUP.to_string().into(); // This can be and usually should be set via the config
71 admin.add_auth_provider(TestAuthProvider);
72 admin.add_login_provider(TestLoginProvider);
73
74 admin.add_navigation(
75 AdminNavigationGroup::new("Example").add(
76 NavigationItem::new("example_page", "Example Page").link("/admin/example/page"),
77 ),
78 );
79
80 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/test_widget"));
81 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/time_widget")); // .hx_trigger("load, every 1s") // This widget should be refreshed, but as it spams the console I leave this comment here so you know that it is possible
82
83 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
84 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
85 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
86 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
87
88 admin.register_entity_handler(EntityHandler::<
89 S,
90 TestEntityCreateForm,
91 TestEntityUpdateForm,
92 TestEntityListing,
93 >::new("Example"));
94
95 Ok(())
96 }Sourcepub fn register_routes(&self, router: Router<S>) -> Router<S>
pub fn register_routes(&self, router: Router<S>) -> Router<S>
Registers the route for the [AdminBundle]
Sourcepub fn add_auth_provider<P: AdminAuthProvider<S> + InnerAuthProvider<S> + 'static>(
&mut self,
provider: P,
)
pub fn add_auth_provider<P: AdminAuthProvider<S> + InnerAuthProvider<S> + 'static>( &mut self, provider: P, )
Adds a custom auth provider. Check the AdminAuthProvider for more details.
Examples found in repository?
examples/full-admin.rs (line 71)
67 fn configure_state(&mut self, state: &mut S) -> quokka::Result<()> {
68 let admin: &mut AdminState<_> = state.provide_mut();
69
70 admin.super_admin_group = EXAMPLE_SUPER_USER_GROUP.to_string().into(); // This can be and usually should be set via the config
71 admin.add_auth_provider(TestAuthProvider);
72 admin.add_login_provider(TestLoginProvider);
73
74 admin.add_navigation(
75 AdminNavigationGroup::new("Example").add(
76 NavigationItem::new("example_page", "Example Page").link("/admin/example/page"),
77 ),
78 );
79
80 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/test_widget"));
81 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/time_widget")); // .hx_trigger("load, every 1s") // This widget should be refreshed, but as it spams the console I leave this comment here so you know that it is possible
82
83 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
84 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
85 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
86 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
87
88 admin.register_entity_handler(EntityHandler::<
89 S,
90 TestEntityCreateForm,
91 TestEntityUpdateForm,
92 TestEntityListing,
93 >::new("Example"));
94
95 Ok(())
96 }Sourcepub fn add_login_provider<P: AdminLoginProvider + InnerLoginProvider + Send + Sync + 'static>(
&mut self,
provider: P,
)
pub fn add_login_provider<P: AdminLoginProvider + InnerLoginProvider + Send + Sync + 'static>( &mut self, provider: P, )
Adds a custom login provider. Check the AdminLoginProvider for details.
Examples found in repository?
examples/full-admin.rs (line 72)
67 fn configure_state(&mut self, state: &mut S) -> quokka::Result<()> {
68 let admin: &mut AdminState<_> = state.provide_mut();
69
70 admin.super_admin_group = EXAMPLE_SUPER_USER_GROUP.to_string().into(); // This can be and usually should be set via the config
71 admin.add_auth_provider(TestAuthProvider);
72 admin.add_login_provider(TestLoginProvider);
73
74 admin.add_navigation(
75 AdminNavigationGroup::new("Example").add(
76 NavigationItem::new("example_page", "Example Page").link("/admin/example/page"),
77 ),
78 );
79
80 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/test_widget"));
81 admin.add_sidebar_widget(AdminSidebarWidget::htmx("/example/admin/time_widget")); // .hx_trigger("load, every 1s") // This widget should be refreshed, but as it spams the console I leave this comment here so you know that it is possible
82
83 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
84 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
85 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
86 admin.add_dashboard_widget(AdminDashboardWidget::htmx("/example/admin/test_widget"));
87
88 admin.register_entity_handler(EntityHandler::<
89 S,
90 TestEntityCreateForm,
91 TestEntityUpdateForm,
92 TestEntityListing,
93 >::new("Example"));
94
95 Ok(())
96 }Trait Implementations§
Source§impl<S: Clone> Clone for AdminState<S>
impl<S: Clone> Clone for AdminState<S>
Source§fn clone(&self) -> AdminState<S>
fn clone(&self) -> AdminState<S>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S> TryFromModule for AdminState<S>
impl<S> TryFromModule for AdminState<S>
Auto Trait Implementations§
impl<S> !RefUnwindSafe for AdminState<S>
impl<S> !UnwindSafe for AdminState<S>
impl<S> Freeze for AdminState<S>
impl<S> Send for AdminState<S>
impl<S> Sync for AdminState<S>
impl<S> Unpin for AdminState<S>
impl<S> UnsafeUnpin for AdminState<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more