tab/app/grids/transactions_grid.rb

37 lines
1.1 KiB
Ruby
Raw Normal View History

class TransactionsGrid
include Datagrid
2015-09-10 01:31:47 +02:00
attr_accessor :current_user
scope do
Transaction
2015-09-10 01:31:47 +02:00
#@current_user.transactions
2015-09-10 13:25:25 +02:00
# TODO how to get current user here?
end
2015-09-10 01:31:47 +02:00
self.default_column_options = { order: false }
column(:created_at, order: true) { |model| model.created_at.to_date }
filter(:created_at, :date, range: true)
column(:amount)
2015-09-10 01:31:47 +02:00
filter(:amount, :integer, range: true)
2015-09-10 13:25:25 +02:00
column(:peer) { |model, scope, grid| model.peer_of(grid.current_user).try(:name) }
filter(:peer, :string, header: 'Peer') do |value, scope, grid|
scope.joins(debtor: 'id', creditor: 'id')
.where("(debtor_id = :user AND creditor.name LIKE :name) OR (creditor_id = :user AND debtor.name LIKE :name)", user: grid.current_user.id, name: "%#{value}%")
end
# TODO this should probably by a SQL statement
2015-09-10 01:31:47 +02:00
column(:issuer) { |model| model.issuer.name }
2015-09-10 13:25:25 +02:00
filter(:issuer, :string, header: 'Issuer') do |value|
self.joins(:issuer).where("issuer.name LIKE :value", value: "%#{value}%")
end
2015-09-10 01:31:47 +02:00
column(:message)
filter(:message) { |value| where("message LIKE :value", value: "%#{value}%") }
end