From 6fb0be1dd7066527350d08a34e4744389a3207a4 Mon Sep 17 00:00:00 2001 From: Christopher Vollick <0@psycoti.ca> Date: Wed, 16 Mar 2022 16:12:51 -0400 Subject: [PATCH] Transactions List Using the new Financials object a user can list their transaction list We only show the user the date, amount, and method. --- forms/transactions.rb | 9 +++++++++ lib/form_template.rb | 11 +++++++++++ sgx_jmp.rb | 12 ++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 forms/transactions.rb diff --git a/forms/transactions.rb b/forms/transactions.rb new file mode 100644 index 0000000..b48b1de --- /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 b04bd64..55fdcc6 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 bcfe101..c582b56 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", -- 2.45.2