Code Snippets

A collection of some helpfull code snippets to faster integrate workflows.

Set Status

Workflow

Simple Status Workflow with user inbox notification and higlight color.

pub fn show() {
    let record = webapp::get_record()?;
    if record.status.to_string() == "status_0" {
        return true;
    }
    else if record.status.to_string() == "status_1" {
        return true;
    }
    return false;
}

pub async fn main() {
    let record = webapp::get_record()?;
    webapp::rpc_call("model","set_status", ["status_2", "#2B7D2B"]).await?; //highlight color green
    // set in inbox
    let usr = record.get_value("assigned_user_1")?.get_reference()?.to_string();
    dbg(usr);
    dbg(record.uuid);
    webapp::rpc_call("model", "set_user_inbox", [usr, record.uuid]).await?;
    Ok(())
}

pub async fn test() {
    //let x = show();
    //println!("Show {}", x);
    main().await?;
}

Service

pub async fn main(ident, color) {
    dbg(ident);
    dbg(color);
    let status = Ident::new(ident);
    let record = server::get_record()?;
    server::db::update_record_value(record.uuid, Ident::new("status"), Value::Ident(status)).await?;
    server::db::update_record_value(record.uuid, Ident::new("highlight_color"), Value::Color(Color::new(color))).await?;
    Ok(true)
}

pub async fn test() {
    main("new","").await?;
}

Workflow

pub async fn main(user, rec_uuid) {
    dbg(user);
    dbg(rec_uuid);
    server::db::add_inbox(user, rec_uuid).await?;
    Ok(true)
}

pub async fn test() {
}

Service

pub async fn main(user, rec_uuid) {
    dbg(user);
    dbg(rec_uuid);
    server::db::add_inbox(user, rec_uuid).await?;
    Ok(true)
}

pub async fn test() {
}

Set User Password

Workflow and Service code to set user passwords.

Workflow

Icon: two-keys

pub fn show() {
    true
}

pub async fn main() {
    let vars = [Variable::new(Ident::new("password"), Value::String(""))?];
    let result = webapp::ui::popup("Reset Password", "", vars).await?;
    if result.0 == false {
        return;
    }
    let new_pw = result.1;
    let new_pw = new_pw[0].value.get_string()?;
    dbg(new_pw);
    webapp::rpc_call("model", "set_user_password_service", new_pw).await?;
}

pub async fn test() {
    main().await?;
}

Service

Icon: two-keys

pub async fn main(inp) {
    // todo - check for user rights - API still missing
    dbg(inp);
    let user=server::get_record()?.uuid;
    server::db::reset_password(user, inp).await?;
}

pub async fn test() {
}

Add Favorite

Workflow

Icon: favorite

Service

Icon: favorite

Remove Favorite

Workflow

Icon: unfavorite

Service

Icon: unfavorite