~singpolyma/sgx-jmp

6fb0be1dd7066527350d08a34e4744389a3207a4 — Christopher Vollick 2 years ago a5cf98a
Transactions List

Using the new Financials object a user can list their transaction list
We only show the user the date, amount, and method.
3 files changed, 32 insertions(+), 0 deletions(-)

A forms/transactions.rb
M lib/form_template.rb
M sgx_jmp.rb
A forms/transactions.rb => forms/transactions.rb +9 -0
@@ 0,0 1,9 @@
result!
title "Transactions"

table(
	@transactions,
	formatted_amount: "Amount",
	note: "Note",
	created_at: "Date"
)

M lib/form_template.rb => lib/form_template.rb +11 -0
@@ 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

M sgx_jmp.rb => sgx_jmp.rb +12 -0
@@ 473,6 473,18 @@ Command.new(
}.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",
	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)