diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index 6042114..2b25fde 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -6,7 +6,13 @@ class TransactionsController < ApplicationController before_action :authenticate_user_or_client!, only: :create def index - @grid = TransactionsGrid.new(params[:transactions_grid]) do |scope| + gridparams = params[:transactions_grid] || Hash.new + gridparams = gridparams.merge( + order: :created_at, + descending: true, + current_user: current_user + ) + @grid = TransactionsGrid.new(gridparams) do |scope| scope.page(params[:page]) end end diff --git a/app/grids/transactions_grid.rb b/app/grids/transactions_grid.rb index 4a4d428..174e981 100644 --- a/app/grids/transactions_grid.rb +++ b/app/grids/transactions_grid.rb @@ -2,16 +2,31 @@ class TransactionsGrid include Datagrid + attr_accessor :current_user + scope do Transaction + #@current_user.transactions + # TODO current user should not be nil end - filter(:id, :integer) + self.default_column_options = { order: false } + + column(:created_at, order: true) { |model| model.created_at.to_date } filter(:created_at, :date, range: true) - column(:id) column(:amount) - column(:created_at) do |model| - model.created_at.to_date - end + filter(:amount, :integer, range: true) + + column(:peer) { |model| model.peer_of(@current_user).try(:name) } + #filter(:peer) { |value| where( + # TODO extensive? + + column(:issuer) { |model| model.issuer.name } + #filter(:issuer) { |value| where("issuer.name LIKE :value", value: "%#{value}%") } + # TODO issuer.name needs join + + column(:message) + filter(:message) { |value| where("message LIKE :value", value: "%#{value}%") } + end diff --git a/app/views/transactions/index.html.haml b/app/views/transactions/index.html.haml index c08d315..f8ad708 100644 --- a/app/views/transactions/index.html.haml +++ b/app/views/transactions/index.html.haml @@ -1,4 +1,4 @@ -= datagrid_form_for @grid, :method => :get, :url => transactions_path += datagrid_form_for @grid, method: :get, url: transactions_path = paginate(@grid.assets) = datagrid_table @grid = paginate(@grid.assets)