Skip to main content

forms/
commodity.rs

1//! The commodity form descriptors.
2
3use crate::descriptor::{Action, COMMODITY, Form, Kind, TEXT, field};
4use crate::tags::COMMODITY_TAGS;
5
6/// Create a commodity from a symbol and a name.
7pub const COMMODITY_CREATE: Form = Form {
8    name: "commodity-create",
9    title: "Create commodity",
10    fields: &[
11        field("symbol", "Symbol", TEXT, true),
12        field("name", "Name", TEXT, true),
13    ],
14    action: Action::Mutation,
15};
16
17/// Replace the symbol, the name and the tags of a commodity; `tags` excludes
18/// both and is edited, not carried.
19pub const COMMODITY_EDIT: Form = Form {
20    name: "commodity-edit",
21    title: "Edit commodity",
22    fields: &[
23        field("id", "Id", Kind::Hidden, true),
24        field("revision", "Revision", Kind::Hidden, true),
25        field("symbol", "Symbol", TEXT, true),
26        field("name", "Name", TEXT, true),
27        COMMODITY_TAGS,
28    ],
29    action: Action::LoadMutation,
30};
31
32/// Convert an amount between two commodities with the latest price.
33pub const CONVERT: Form = Form {
34    name: "convert",
35    title: "Convert amount",
36    fields: &[
37        field("amount", "Amount", Kind::Amount, true),
38        field("from", "From", COMMODITY, true),
39        field("to", "To", COMMODITY, true),
40    ],
41    action: Action::Query,
42};