Struct feattle::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> AdminPanel<F>where F: Feattles + Sync,

source

pub fn new(feattles: Arc<F>, label: String) -> AdminPanel<F>

Create a new UI provider for a given feattles and a user-visible label

source

pub async fn list_feattles( &self ) -> impl Future<Output = 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.

source

pub async fn list_feattles_api_v1( &self ) -> impl Future<Output = Result<ListFeattlesResponse, RenderError>>

The JSON-API equivalent of AdminPanel::list_feattles().

To ensure fresh data is displayed, Feattles::reload() is called.

source

pub async fn show_feattle( &self, key: &str ) -> impl Future<Output = 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.

source

pub async fn show_feattle_api_v1( &self, key: &str ) -> impl Future<Output = Result<ShowFeattleResponse, RenderError>>

The JSON-API equivalent of AdminPanel::show_feattle().

To ensure fresh data is displayed, Feattles::reload() is called.

source

pub async fn edit_feattle( &self, key: &str, value_json: &str, modified_by: String ) -> impl Future<Output = 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.

source

pub async fn edit_feattle_api_v1( &self, key: &str, request: EditFeattleRequest ) -> impl Future<Output = 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.

source

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.

Auto Trait Implementations§

§

impl<F> !RefUnwindSafe for AdminPanel<F>

§

impl<F> Send for AdminPanel<F>where F: Send + Sync,

§

impl<F> Sync for AdminPanel<F>where F: Send + Sync,

§

impl<F> Unpin for AdminPanel<F>

§

impl<F> !UnwindSafe for AdminPanel<F>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.