Lines
100 %
Functions
Branches
//! Loading the values of a form from a stored entity.
use forms::{Form, FormValues};
use uuid::Uuid;
use super::Failure;
use super::account_edit_load::load_account_edit;
use super::commodity_edit_load::load_commodity_edit;
use super::handler::{Handler, unknown};
use super::script_edit_load::load_script_edit;
use super::tag_edit_load::load_tag_edit;
use super::template_edit_load::load_template_edit;
use super::transaction_create_load::load_transaction_create;
use super::transaction_edit_load::load_transaction_edit;
/// The values of the compiled-in form `form` for the entity `id`.
pub async fn load(user_id: Uuid, form: &Form, id: &str) -> Result<FormValues, Failure> {
match Handler::of(form)? {
Handler::TransactionEdit => load_transaction_edit(user_id, id).await,
Handler::TransactionCreate => load_transaction_create(user_id, id).await,
Handler::AccountEdit => load_account_edit(user_id, id).await,
Handler::CommodityEdit => load_commodity_edit(user_id, id).await,
Handler::TagEdit => load_tag_edit(user_id, id).await,
Handler::TemplateEdit => load_template_edit(user_id, id).await,
Handler::ScriptEdit => load_script_edit(user_id, id)
.await
.map(|(values, _)| values),
Handler::TransactionQuery
| Handler::ReportBalance
| Handler::ReportActivity
| Handler::ReportCategory
| Handler::AccountMerge
| Handler::AccountCreate
| Handler::CommodityCreate
| Handler::TagCreate
| Handler::TemplateCreate
| Handler::ScriptCreate
| Handler::SshKeyAdd
| Handler::TemplateTest
| Handler::ConfigSet
| Handler::Convert => Err(unknown(form.name)),
}