87 lines
2.6 KiB
Rust
87 lines
2.6 KiB
Rust
use heromodels::db::Db;
|
|
use macros::{
|
|
register_authorized_create_by_id_fn, register_authorized_delete_by_id_fn,
|
|
register_authorized_get_by_id_fn,
|
|
};
|
|
use rhai::plugin::*;
|
|
use rhai::{Dynamic, Engine, EvalAltResult, Module, INT};
|
|
use std::mem;
|
|
use std::sync::Arc;
|
|
|
|
use heromodels::db::hero::OurDB;
|
|
use heromodels::db::Collection;
|
|
use heromodels::models::flow::flow_step::FlowStep;
|
|
|
|
type RhaiFlowStep = FlowStep;
|
|
|
|
#[export_module]
|
|
mod rhai_flow_step_module {
|
|
use super::{RhaiFlowStep, INT};
|
|
|
|
#[rhai_fn(name = "new_flow_step", return_raw)]
|
|
pub fn new_flow_step() -> Result<RhaiFlowStep, Box<EvalAltResult>> {
|
|
Ok(FlowStep::default())
|
|
}
|
|
|
|
// --- Setters ---
|
|
#[rhai_fn(name = "description", return_raw)]
|
|
pub fn set_description(
|
|
step: &mut RhaiFlowStep,
|
|
description: String,
|
|
) -> Result<RhaiFlowStep, Box<EvalAltResult>> {
|
|
let owned = std::mem::take(step);
|
|
*step = owned.description(description);
|
|
Ok(step.clone())
|
|
}
|
|
|
|
#[rhai_fn(name = "status", return_raw)]
|
|
pub fn set_status(
|
|
step: &mut RhaiFlowStep,
|
|
status: String,
|
|
) -> Result<RhaiFlowStep, Box<EvalAltResult>> {
|
|
let owned = std::mem::take(step);
|
|
*step = owned.status(status);
|
|
Ok(step.clone())
|
|
}
|
|
|
|
// --- Getters ---
|
|
#[rhai_fn(get = "id", pure)]
|
|
pub fn get_id(s: &mut RhaiFlowStep) -> INT {
|
|
s.base_data.id as INT
|
|
}
|
|
#[rhai_fn(get = "description", pure)]
|
|
pub fn get_description(s: &mut RhaiFlowStep) -> Option<String> {
|
|
s.description.clone()
|
|
}
|
|
#[rhai_fn(get = "status", pure)]
|
|
pub fn get_status(s: &mut RhaiFlowStep) -> String {
|
|
s.status.clone()
|
|
}
|
|
}
|
|
|
|
pub fn register_flow_step_rhai_module(engine: &mut Engine) {
|
|
engine.build_type::<RhaiFlowStep>();
|
|
let mut module = exported_module!(rhai_flow_step_module);
|
|
|
|
register_authorized_create_by_id_fn!(
|
|
module: &mut module,
|
|
rhai_fn_name: "save_flow_step",
|
|
resource_type_str: "FlowStep",
|
|
rhai_return_rust_type: heromodels::models::flow::flow_step::FlowStep
|
|
);
|
|
register_authorized_get_by_id_fn!(
|
|
module: &mut module,
|
|
rhai_fn_name: "get_flow_step",
|
|
resource_type_str: "FlowStep",
|
|
rhai_return_rust_type: heromodels::models::flow::flow_step::FlowStep
|
|
);
|
|
register_authorized_delete_by_id_fn!(
|
|
module: &mut module,
|
|
rhai_fn_name: "delete_flow_step",
|
|
resource_type_str: "FlowStep",
|
|
rhai_return_rust_type: heromodels::models::flow::flow_step::FlowStep
|
|
);
|
|
|
|
engine.register_global_module(module.into());
|
|
}
|