quokka-admin 0.1.0

An admin panel for quokka
Documentation
///
/// Allows you to extend the sidebar with a navigation section.
///
/// If an [AdminNavigationGroup] with the same name is added they will be merged, keeping the order of the firstly added group.
///
/// TODO: Permissions are not yet respected. So no matter which permissions the user has it will see all the items, even those to which the
/// user has no permission to work on.
///
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct AdminNavigationGroup {
    pub title: String,
    pub items: Vec<NavigationItem>,
    pub order: i32,
}

///
/// Represents a navigation item.
///
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct NavigationItem {
    pub name: String,
    pub title: String,
    pub link: String,
    pub subnavigation: Vec<NavigationItem>,
}

impl AdminNavigationGroup {
    pub fn new(title: impl ToString) -> Self {
        Self {
            title: title.to_string(),
            ..Default::default()
        }
    }

    pub fn add(mut self, item: impl Into<NavigationItem>) -> Self {
        self.items.push(item.into());

        self
    }

    pub fn order(mut self, order: i32) -> Self {
        self.order = order;

        self
    }
}

impl NavigationItem {
    pub fn new(name: impl ToString, title: impl ToString) -> Self {
        Self {
            name: name.to_string(),
            title: title.to_string(),
            ..Default::default()
        }
    }

    pub fn link(mut self, link: impl ToString) -> Self {
        self.link = link.to_string();

        self
    }

    pub fn nest(mut self, subnavigation: impl Into<NavigationItem>) -> Self {
        self.subnavigation.push(subnavigation.into());

        self
    }
}