Struct feattle_ui::AdminPanel
source · pub struct AdminPanel<F> { /* private fields */ }
Expand description
The administration panel, agnostic to the choice of web-framework.
This type is designed to be easily integrated with Rust web-frameworks, by providing one method per page and form submission, each returning bytes with their “Content-Type”.
§Example
use feattle_ui::AdminPanel;
use feattle_core::{feattles, Feattles};
use feattle_core::persist::NoPersistence;
use std::sync::Arc;
feattles! {
struct MyToggles { a: bool, b: i32 }
}
// `NoPersistence` here is just a mock for the sake of the example
let my_toggles = Arc::new(MyToggles::new(Arc::new(NoPersistence)));
let admin_panel = AdminPanel::new(my_toggles, "Project Panda - DEV".to_owned());
let home_content = admin_panel.list_feattles().await?;
assert_eq!(home_content.content_type, "text/html; charset=utf-8");
assert!(home_content.content.len() > 0);
Implementations§
source§impl<F: Feattles + Sync> AdminPanel<F>
impl<F: Feattles + Sync> AdminPanel<F>
sourcepub fn new(feattles: Arc<F>, label: String) -> Self
pub fn new(feattles: Arc<F>, label: String) -> Self
Create a new UI provider for a given feattles and a user-visible label
sourcepub async fn list_feattles(&self) -> Result<RenderedPage, RenderError>
pub async fn list_feattles(&self) -> Result<RenderedPage, RenderError>
Render the page that lists the current feattles values, together with navigation links to modify them. This page is somewhat the “home screen” of the UI.
To ensure fresh data is displayed, Feattles::reload()
is called.
sourcepub async fn list_feattles_api_v1(
&self,
) -> Result<ListFeattlesResponse, RenderError>
pub async fn list_feattles_api_v1( &self, ) -> Result<ListFeattlesResponse, RenderError>
The JSON-API equivalent of AdminPanel::list_feattles()
.
To ensure fresh data is displayed, Feattles::reload()
is called.
sourcepub async fn show_feattle(&self, key: &str) -> Result<RenderedPage, RenderError>
pub async fn show_feattle(&self, key: &str) -> Result<RenderedPage, RenderError>
Render the page that shows the current and historical values of a single feattle, together with the form to modify it. The generated form submits to “/feattle/{{ key }}/edit” with the POST method in url-encoded format with a single field called “value_json”.
To ensure fresh data is displayed, Feattles::reload()
is called.
sourcepub async fn show_feattle_api_v1(
&self,
key: &str,
) -> Result<ShowFeattleResponse, RenderError>
pub async fn show_feattle_api_v1( &self, key: &str, ) -> Result<ShowFeattleResponse, RenderError>
The JSON-API equivalent of AdminPanel::show_feattle()
.
To ensure fresh data is displayed, Feattles::reload()
is called.
sourcepub async fn edit_feattle(
&self,
key: &str,
value_json: &str,
modified_by: String,
) -> Result<(), RenderError>
pub async fn edit_feattle( &self, key: &str, value_json: &str, modified_by: String, ) -> Result<(), RenderError>
Process a modification of a single feattle, given its key and the JSON representation of its future value. In case of success, the return is empty, so caller should usually redirect the user somewhere after.
To ensure fresh data is displayed, Feattles::reload()
is called. Unlike the other pages,
if the reload fails, this operation will fail.
sourcepub async fn edit_feattle_api_v1(
&self,
key: &str,
request: EditFeattleRequest,
) -> Result<EditFeattleResponse, RenderError>
pub async fn edit_feattle_api_v1( &self, key: &str, request: EditFeattleRequest, ) -> Result<EditFeattleResponse, RenderError>
The JSON-API equivalent of AdminPanel::edit_feattle()
.
To ensure fresh data is displayed, Feattles::reload()
is called. Unlike the other pages,
if the reload fails, this operation will fail.
sourcepub fn render_public_file(
&self,
path: &str,
) -> Result<RenderedPage, RenderError>
pub fn render_public_file( &self, path: &str, ) -> Result<RenderedPage, RenderError>
Renders a public file with the given path. The pages include public files like “/public/some/path.js”, but this method should be called with only the “some/path.js” part.