This commit is contained in:
benji 2015-09-11 21:06:22 +02:00
commit eb26d14e40
4 changed files with 33 additions and 15 deletions

View file

@ -4,6 +4,7 @@ ready = function() {
errors = $("#transaction_errors") errors = $("#transaction_errors")
panel_ul = $(errors).find(".panel-body ul") panel_ul = $(errors).find(".panel-body ul")
flash_success = $("#transaction_success") flash_success = $("#transaction_success")
var table = $('#transactions').DataTable({ var table = $('#transactions').DataTable({
processing: true, processing: true,
serverSide: true, serverSide: true,
@ -60,6 +61,14 @@ ready = function() {
}); });
}); });
// filters
filters = $("#transactions-filters");
filters_body = filters.find(".panel-body");
filters.find(".panel-heading").click( function() {
filters_body.slideToggle();
});
filters_body.hide();
$(form).on("ajax:before", function(xhr, settings) { $(form).on("ajax:before", function(xhr, settings) {
$(flash_success).addClass("hidden") $(flash_success).addClass("hidden")
$(submit_button).val("Processing") $(submit_button).val("Processing")

View file

@ -30,7 +30,10 @@ table.pure-table-striped {
} }
} }
.data-table-filters { #transactions-filters {
.panel-heading {
cursor: pointer;
}
.row { .row {
padding: 10px; padding: 10px;
padding-top: 20px; padding-top: 20px;

View file

@ -16,13 +16,11 @@ class DataTable
end end
private private
def data def data
run_query(paginated_query.project(Arel.star)).map do |record| run_query(paginated_query.project(Arel.star))
record.reject! {|k,v| k.is_a? Numeric} # Remove unneeded query results
end
end end
def count def count
run_query(query.project(Arel.star.count)).first[0] run_query(query.project(Arel.star.count)).first["COUNT(*)"]
end end
def paginated_query def paginated_query
@ -64,7 +62,7 @@ class DataTable
end end
def run_query query def run_query query
ActiveRecord::Base.connection.execute(query.to_sql) ActiveRecord::Base.connection.exec_query(query.to_sql)
end end
def sanitize_params(params) def sanitize_params(params)

View file

@ -2,36 +2,42 @@
= render 'transactions/new' = render 'transactions/new'
.panel.panel-default.data-table-filters #transactions-filters.panel.panel-default
.panel-heading .panel-heading
%h3.panel-title Filters %h3.panel-title Filters
.panel-body .panel-body
.row .row
.col-md-8.col-md-offset-2 .col-md-8.col-md-offset-2
.bound.input-listen{ 'data-input-type': 'date-range', 'data-filter-name': 'Time' } .bound.input-listen{ 'data-input-type': 'date-range',
'data-filter-name': 'Time' }
.row .row
.col-md-6 .col-md-6
.input-group .input-group
%span.input-group-addon %span.input-group-addon
%span.glyphicon.glyphicon-calendar %span.glyphicon.glyphicon-calendar
%input.lower-bound.form-control.filter-align{type: 'date', placeholder: 'After', class: 'pure-group-addon'} %input.lower-bound.form-control.filter-align{type: 'date',
placeholder: 'After', class: 'pure-group-addon'}
.col-md-6 .col-md-6
.input-group .input-group
%span.input-group-addon %span.input-group-addon
%span.glyphicon.glyphicon-calendar %span.glyphicon.glyphicon-calendar
%input.upper-bound.form-control.filter-align{type: 'date', placeholder: 'Before', class: 'pure-group-addon'} %input.upper-bound.form-control.filter-align{type: 'date',
.bound.input-listen.pure-u-1{ 'data-input-type': 'number-range', 'data-filter-name': 'Amount' } placeholder: 'Before', class: 'pure-group-addon'}
.bound.input-listen.pure-u-1{ 'data-input-type': 'number-range',
'data-filter-name': 'Amount' }
.row .row
.col-md-6 .col-md-6
.input-group .input-group
%span.input-group-addon %span.input-group-addon
%span.glyphicon.glyphicon-euro %span.glyphicon.glyphicon-euro
%input.lower-bound.form-control.filter-align{type: 'number', placeholder: 'Minimum'} %input.lower-bound.form-control.filter-align{type: 'number',
placeholder: 'Minimum'}
.col-md-6 .col-md-6
.input-group .input-group
%span.input-group-addon %span.input-group-addon
%span.glyphicon.glyphicon-euro %span.glyphicon.glyphicon-euro
%input.upper-bound.form-control.filter-align{type: 'number', placeholder: 'Maximum'} %input.upper-bound.form-control.filter-align{type: 'number',
placeholder: 'Maximum'}
.row .row
.col-md-4 .col-md-4
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Issuer' } .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Issuer' }
@ -40,10 +46,12 @@
{ data: { placeholder: "Filter on Issuer" }, class: "select2-selector form-control" } { data: { placeholder: "Filter on Issuer" }, class: "select2-selector form-control" }
.col-md-4 .col-md-4
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Peer' } .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Peer' }
%input{type: 'text', placeholder: 'Filter on Peer', class: "form-control" } %input{type: 'text', placeholder: 'Filter on Peer',
class: "form-control" }
.col-md-4 .col-md-4
.input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Message' } .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Message' }
%input{type: 'text', placeholder: 'Filter on Message', class: "form-control" } %input{type: 'text', placeholder: 'Filter on Message',
class: "form-control" }
%table#transactions.pure-table.pure-table-striped{data: { source: user_path(@user) }} %table#transactions.pure-table.pure-table-striped{data: { source: user_path(@user) }}
%thead %thead