boomack 0.4.1

Client library for Boomack
Documentation
//! Structures and functions to create
//! [`ClientRequest`](../api/struct.ClientRequest.html) instances
//! for managing panels

use serde::Serialize;
use super::json::{JsonMap, to_json_map};
use super::api::ClientRequest;

pub fn get_panel_ids_request() -> ClientRequest {
    ClientRequest::get(format!("panels"))
}

pub fn get_panel_layout_request(panel_id: Option<&str>) -> ClientRequest {
    ClientRequest::get(format!("panels/{}/layout",
        panel_id.unwrap_or("default")))
}

pub fn set_panel_layout_request(panel_id: &str, layout: JsonMap) -> ClientRequest {
    let mut req = ClientRequest::put(format!("panels/{}/layout", panel_id));
    req.set_json_body(layout);
    req
}

pub fn delete_panel_request(panel_id: &str) -> ClientRequest {
    ClientRequest::delete(format!("panels/{}", panel_id))
}

pub fn clear_panel_request(panel_id: Option<&str>) -> ClientRequest {
    ClientRequest::post(format!("panels/{}/clear",
        panel_id.unwrap_or("default")))
}

/// Parameters for exporting an individual panel
/// as HTML file to the filesystem of the Boomack Server.
#[derive(Serialize)]
pub struct PanelExportParameters<'l> {
    /// A relative path to the target folder of the export.
    /// The path is always relative to the root export folder,
    /// configured in the Boomack Server.
    pub path: Option<&'l str>,
    /// The target filename without extensions
    pub name: Option<&'l str>,
    /// The theme to use during export
    pub theme: Option<&'l str>,
    /// A static CSS zoom factor for the export (1.0 = 100%)
    pub zoom: Option<f32>,
    // Controls visibility of the logo from the panel header during export.
    pub logo: Option<bool>,
    // Control visibility of the panel header during export.
    pub header: Option<bool>,
    // Controls visibility of tools in slot toolbars during export.
    pub tools: Option<bool>,
    // Control visibility of slot toolbars during export.
    pub toolbars: Option<bool>,
}

pub fn export_panel_request(panel_id: Option<&str>, p: PanelExportParameters) -> ClientRequest {
    let mut req = ClientRequest::post(format!("panels/{}/export",
        panel_id.unwrap_or("default")));
    req.set_json_body(to_json_map(&p).unwrap());
    req
}

/// Parameters for exporting all panels
/// as HTML files to the filesystem of the Boomack Server.
#[derive(Serialize)]
pub struct AllPanelExportParameters<'l> {
    /// A relative path to the target folder of the export.
    /// The path is always relative to the root export folder,
    /// configured in the Boomack Server.
    pub path: Option<&'l str>,
    // The theme to use during export
    pub theme: Option<&'l str>,
    // A static CSS zoom factor for the export (1.0 = 100%)
    pub zoom: Option<f32>,
    // Controls visibility of the logo from the panel header during export.
    pub logo: Option<bool>,
    // Control visibility of the panel header during export.
    pub header: Option<bool>,
    // Controls visibility of tools in slot toolbars during export.
    pub tools: Option<bool>,
    // Control visibility of slot toolbars during export.
    pub toolbars: Option<bool>,
}

pub fn export_all_panels_request(p: AllPanelExportParameters)
    -> ClientRequest
{
    let mut req = ClientRequest::post(format!("panels/export"));
    req.set_json_body(to_json_map(&p).unwrap());
    req
}