Merge branch 'master' of https://github.com/ZeusWPI/Tab
This commit is contained in:
commit
f1af878c9e
7 changed files with 41 additions and 40 deletions
|
@ -1,10 +1,7 @@
|
|||
class TransactionsController < ApplicationController
|
||||
|
||||
def index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render json: TransactionDatatable.new(view_context) }
|
||||
end
|
||||
@transactions = Transaction.all
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -3,6 +3,12 @@ class UsersController < ApplicationController
|
|||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render json: TransactionDatatable.new(
|
||||
view_context, {user: @user})
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
class TransactionDatatable < AjaxDatatablesRails::Base
|
||||
include TransactionsHelper
|
||||
|
||||
def sortable_columns
|
||||
@sortable_columns ||= ['Transaction.id']
|
||||
@sortable_columns ||= ['Transaction.amount']
|
||||
end
|
||||
|
||||
def searchable_columns
|
||||
|
@ -9,14 +10,18 @@ class TransactionDatatable < AjaxDatatablesRails::Base
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
def data
|
||||
records.map do |record|
|
||||
[ record.id, record.debtor.name, record.creditor.name, record.amount ]
|
||||
[ amount_in_perspective(record, options[:user]),
|
||||
record.origin,
|
||||
record.message,
|
||||
get_transaction_peer(record, options[:user]).name,
|
||||
record.created_at.strftime('%d/%m/%y %H:%M')
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def get_raw_records
|
||||
Transaction.all.eager_load(:debtor, :creditor)
|
||||
options[:user].transactions.eager_load(:debtor, :creditor)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,11 @@
|
|||
module TransactionsHelper
|
||||
def get_transaction_peer(transaction, user)
|
||||
return transaction.creditor if user == transaction.debtor
|
||||
return transaction.debtor if user == transaction.creditor
|
||||
end
|
||||
|
||||
def amount_in_perspective(transaction, user)
|
||||
return -transaction.amount if user == transaction.debtor
|
||||
return transaction.amount if user == transaction.creditor
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,6 @@ class User < ActiveRecord::Base
|
|||
class_name: 'Transaction', foreign_key: 'debtor_id'
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
validates :balance, presence: true
|
||||
|
||||
def transactions
|
||||
Transaction.where("creditor_id = ? OR debtor_id = ?", id, id)
|
||||
|
@ -35,4 +34,8 @@ class User < ActiveRecord::Base
|
|||
user.name = auth.uid
|
||||
end
|
||||
end
|
||||
|
||||
def self.zeus
|
||||
@@zeus ||= find_or_create_by name: 'Zeus'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
%table#transactions.display{data: { source: transactions_path }}
|
||||
%thead
|
||||
%tr
|
||||
%th id
|
||||
%th debtor
|
||||
%th creditor
|
||||
%th amount
|
||||
%tbody
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
$('#transactions').DataTable({
|
||||
'processing': true,
|
||||
'serverSide': true,
|
||||
'ajax': $('#transactions').data('source'),
|
||||
'pagingType': 'full_numbers'
|
||||
});
|
||||
});
|
|
@ -1,21 +1,20 @@
|
|||
%h2= @user.name
|
||||
%table
|
||||
%table#transactions.display{data: { source: user_path(@user) }}
|
||||
%thead
|
||||
%tr
|
||||
%th ID
|
||||
%th Debtor
|
||||
%th Creditor
|
||||
%th Amount
|
||||
%th Origin
|
||||
%th Message
|
||||
%th Peer
|
||||
%th Time
|
||||
%tbody
|
||||
- @user.transactions.each do |t|
|
||||
%tr
|
||||
%td= t.id
|
||||
%td= t.debtor.name
|
||||
%td= t.creditor.name
|
||||
%td= t.amount
|
||||
%td= t.origin
|
||||
%td= t.message
|
||||
%td= t.created_at
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
$('#transactions').DataTable({
|
||||
'processing': true,
|
||||
'serverSide': true,
|
||||
'ajax': $('#transactions').data('source'),
|
||||
'pagingType': 'full_numbers'
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue