yew-full-calendar 0.1.1

Yew component for fullcalendar
Documentation
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EventBuilder {
    pub id: Option<String>,
    group_id: Option<String>,
    all_day: Option<bool>,
    start: Option<crate::EventDate>,
    end: Option<crate::EventDate>,
    days_of_week: Option<Vec<u32>>,
    start_time: Option<crate::EventDuration>,
    end_time: Option<crate::EventDuration>,
    start_recurr: Option<crate::EventDate>,
    end_recurr: Option<crate::EventDate>,
    title: Option<String>,
    url: Option<String>,
    interactive: Option<bool>,
    class_name: Option<yew::html::Classes>,
    editable: Option<bool>,
    start_editable: Option<bool>,
    end_editable: Option<bool>,
    duration_editable: Option<bool>,
    overlap: Option<bool>,
    display: Option<super::EventDisplay>,
    color: Option<String>,
    background_color: Option<String>,
    text_color: Option<String>,
    border_color: Option<String>,
    extended_props: Option<web_sys::js_sys::Object>,
}

impl EventBuilder {
    #[must_use]
    pub fn id(mut self, id: &str) -> Self {
        self.id = Some(id.to_string());
        self
    }
    #[must_use]
    pub fn group_id(mut self, group_id: &str) -> Self {
        self.group_id = Some(group_id.to_string());
        self
    }
    #[must_use]
    pub const fn all_day(mut self, all_day: bool) -> Self {
        self.all_day = Some(all_day);
        self
    }
    #[must_use]
    pub fn start(mut self, start: crate::EventDate) -> Self {
        self.start = Some(start);
        self
    }
    #[must_use]
    pub fn end(mut self, end: crate::EventDate) -> Self {
        self.end = Some(end);
        self
    }
    #[must_use]
    pub fn days_of_week(mut self, days_of_week: Vec<u32>) -> Self {
        self.days_of_week = Some(days_of_week);
        self
    }
    #[must_use]
    pub fn start_time(mut self, start_time: crate::EventDuration) -> Self {
        self.start_time = Some(start_time);
        self
    }
    #[must_use]
    pub fn end_time(mut self, end_time: crate::EventDuration) -> Self {
        self.end_time = Some(end_time);
        self
    }
    #[must_use]
    pub fn start_recurr(mut self, start_recurr: crate::EventDate) -> Self {
        self.start_recurr = Some(start_recurr);
        self
    }
    #[must_use]
    pub fn end_recurr(mut self, end_recurr: crate::EventDate) -> Self {
        self.end_recurr = Some(end_recurr);
        self
    }
    #[must_use]
    pub fn title(mut self, title: &str) -> Self {
        self.title = Some(title.to_string());
        self
    }
    #[must_use]
    pub fn url(mut self, url: &str) -> Self {
        self.url = Some(url.to_string());
        self
    }
    #[must_use]
    pub const fn interactive(mut self, interactive: bool) -> Self {
        self.interactive = Some(interactive);
        self
    }
    #[must_use]
    pub fn class_name(mut self, class_name: yew::html::Classes) -> Self {
        self.class_name = Some(class_name);
        self
    }
    #[must_use]
    pub const fn editable(mut self, editable: bool) -> Self {
        self.editable = Some(editable);
        self
    }
    #[must_use]
    pub const fn start_editable(mut self, start_editable: bool) -> Self {
        self.start_editable = Some(start_editable);
        self
    }
    #[must_use]
    pub const fn end_editable(mut self, end_editable: bool) -> Self {
        self.end_editable = Some(end_editable);
        self
    }
    #[must_use]
    pub const fn duration_editable(mut self, duration_editable: bool) -> Self {
        self.duration_editable = Some(duration_editable);
        self
    }
    #[must_use]
    pub const fn overlap(mut self, overlap: bool) -> Self {
        self.overlap = Some(overlap);
        self
    }
    #[must_use]
    pub const fn display(mut self, display: super::EventDisplay) -> Self {
        self.display = Some(display);
        self
    }
    #[must_use]
    pub fn color(mut self, color: &str) -> Self {
        self.color = Some(color.to_string());
        self
    }
    #[must_use]
    pub fn background_color(mut self, background_color: &str) -> Self {
        self.background_color = Some(background_color.to_string());
        self
    }
    #[must_use]
    pub fn text_color(mut self, text_color: &str) -> Self {
        self.text_color = Some(text_color.to_string());
        self
    }
    #[must_use]
    pub fn border_color(mut self, border_color: &str) -> Self {
        self.border_color = Some(border_color.to_string());
        self
    }
    /// Adds extended props to the event
    ///
    /// # Errors
    ///
    /// Returns an error if the event is invalid
    pub fn extended_props<T: serde::Serialize>(
        mut self,
        extended_props: T,
    ) -> Result<Self, web_sys::wasm_bindgen::JsValue> {
        let value = serde_wasm_bindgen::to_value(&extended_props)?;
        self.extended_props = Some(value.into());
        Ok(self)
    }
    /// Builds the event
    ///
    /// # Errors
    ///
    /// Returns an error if the event is invalid
    #[allow(clippy::too_many_lines)]
    pub fn build(self) -> Result<web_sys::wasm_bindgen::JsValue, web_sys::wasm_bindgen::JsValue> {
        let obj = web_sys::js_sys::Object::new();
        if let Some(id) = self.id {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("id"),
                &id.into(),
            )?;
        }
        if let Some(group_id) = self.group_id {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("groupId"),
                &group_id.into(),
            )?;
        }
        if let Some(all_day) = self.all_day {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("allDay"),
                &all_day.into(),
            )?;
        }
        if let Some(start) = self.start {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("start"),
                &serde_wasm_bindgen::to_value(&start)?,
            )?;
        }
        if let Some(end) = self.end {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("end"),
                &serde_wasm_bindgen::to_value(&end)?,
            )?;
        }
        if let Some(days_of_week) = self.days_of_week {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("daysOfWeek"),
                &days_of_week.into(),
            )?;
        }
        if let Some(start_time) = self.start_time {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("start"),
                &serde_wasm_bindgen::to_value(&start_time)?,
            )?;
        }
        if let Some(end_time) = self.end_time {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("endTime"),
                &serde_wasm_bindgen::to_value(&end_time)?,
            )?;
        }
        if let Some(start_recurr) = self.start_recurr {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("startRecurr"),
                &serde_wasm_bindgen::to_value(&start_recurr)?,
            )?;
        }
        if let Some(end_recurr) = self.end_recurr {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("endRecurr"),
                &serde_wasm_bindgen::to_value(&end_recurr)?,
            )?;
        }
        if let Some(title) = self.title {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("title"),
                &title.into(),
            )?;
        }
        if let Some(url) = self.url {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("url"),
                &url.into(),
            )?;
        }
        if let Some(interactive) = self.interactive {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("interactive"),
                &interactive.into(),
            )?;
        }
        // TODO: Add className
        // if let Some(class_name) = self.class_name {
        //     web_sys::js_sys::Reflect::set(&obj, &web_sys::wasm_bindgen::JsValue::from_str("className"), &class_name.try_into()?)?;
        // }
        if let Some(editable) = self.editable {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("editable"),
                &editable.into(),
            )?;
        }
        if let Some(start_editable) = self.start_editable {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("startEditable"),
                &start_editable.into(),
            )?;
        }
        if let Some(end_editable) = self.end_editable {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("endEditable"),
                &end_editable.into(),
            )?;
        }
        if let Some(duration_editable) = self.duration_editable {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("durationEditable"),
                &duration_editable.into(),
            )?;
        }
        if let Some(overlap) = self.overlap {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("overlap"),
                &overlap.into(),
            )?;
        }
        if let Some(display) = self.display {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("display"),
                &web_sys::wasm_bindgen::JsValue::from_str(display.as_ref()),
            )?;
        }
        if let Some(color) = self.color {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("color"),
                &color.into(),
            )?;
        }
        if let Some(background_color) = self.background_color {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("backgroundColor"),
                &background_color.into(),
            )?;
        }
        if let Some(text_color) = self.text_color {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("textColor"),
                &text_color.into(),
            )?;
        }
        if let Some(border_color) = self.border_color {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("borderColor"),
                &border_color.into(),
            )?;
        }
        if let Some(extended_props) = self.extended_props {
            web_sys::js_sys::Reflect::set(
                &obj,
                &web_sys::wasm_bindgen::JsValue::from_str("extendedProps"),
                &extended_props,
            )?;
        }
        Ok(obj.into())
    }
}