diff --git a/forms/transactions.rb b/forms/transactions.rb new file mode 100644 index 0000000000000000000000000000000000000000..b48b1deabcdff8fee104be11a67168fdaebb5095 --- /dev/null +++ b/forms/transactions.rb @@ -0,0 +1,9 @@ +result! +title "Transactions" + +table( + @transactions, + formatted_amount: "Amount", + note: "Note", + created_at: "Date" +) diff --git a/lib/form_template.rb b/lib/form_template.rb index b04bd64806b040f4ccffe1f04b7e37960fabc514..55fdcc6147853a043bc0acd6eec2de67d84d04ac 100644 --- a/lib/form_template.rb +++ b/lib/form_template.rb @@ -80,6 +80,17 @@ class FormTemplate open || regex || range end + # Given a map of fields to labels, and a list of objects this will + # produce a table from calling each field's method on every object in the + # list. So, this list is value_semantics / OpenStruct style + def table(list, **fields) + keys = fields.keys + FormTable.new( + list.map { |x| keys.map { |k| x.public_send(k) } }, + **fields + ).add_to_form(@__form) + end + def field(datatype: nil, open: false, regex: nil, range: nil, **kwargs) f = Blather::Stanza::X::Field.new(kwargs) if datatype || open || regex || range diff --git a/sgx_jmp.rb b/sgx_jmp.rb index bcfe1019977077f9eb30ccb582ad2a18bb127952..c582b56e3e716b3779e58c2cbde892144310fc2c 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -472,6 +472,18 @@ Command.new( end }.register(self).then(&CommandList.method(:register)) +Command.new( + "transactions", + "Show Transactions", + list_for: ->(customer:, **) { !!customer&.currency } +) { + Command.customer.then(&:transactions).then do |txs| + Command.finish do |reply| + reply.command << FormTemplate.render("transactions", transactions: txs) + end + end +}.register(self).then(&CommandList.method(:register)) + Command.new( "configure calls", "Configure Calls",