diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d9fd83f..9345777 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,10 +21,13 @@ //= require_tree . ready = function() { - $(".select2-selector").select2({ - width: 'resolve', - placeholder: "Ontvanger" - }); + $.each($(".select2-selector"), function(index, val) { + $(val).select2({ + width: 'resolve', + placeholder: $(".select2-selector") + }); + } + ) } $(document).ready(ready) diff --git a/app/assets/javascripts/transactions.js b/app/assets/javascripts/transactions.js index 32cbd0b..e586b47 100644 --- a/app/assets/javascripts/transactions.js +++ b/app/assets/javascripts/transactions.js @@ -5,6 +5,70 @@ ready = function() { panel_ul = $(errors).find(".panel-body ul") flash_success = $("#transaction_success") + var table = $('#transactions').DataTable({ + processing: true, + serverSide: true, + searching: true, + lengthChange: false, + ordering: false, + ajax: $('#transactions').data('source'), + pagingType: 'full_numbers', + autoWidth: false, + responsive: true, + columns: [ + { data: 'time', name: 'Time', width: "15%", className: 'min-tablet-l'}, + { data: 'amount', name: 'Amount', width: "10%", className: 'min-mobile'}, + { data: 'peer', name: 'Peer', width: "15%", className: 'min-mobile'}, + { data: 'issuer', name: 'Issuer', width: "15%", className: 'min-desktop'}, + { data: 'message', name: 'Message', width: "45%", className: 'min-tablet-p'} + ], + columnDefs: [ + { + targets: 0, + render: function(data, type, full, meta) { + return $.format.date(data, 'E dd/MM/yyyy HH:mm'); + } + }, + { + targets: 1, + render: function(data, type, full, meta) { + return (data/100).toFixed(2); + } + } + ] + }); + + $('.dataTables_filter').hide(); + + $('.input-listen').each(function(index, element) { + var filter = $(element); + var type = filter.attr('data-input-type'); + var column = table.column(filter.attr('data-filter-name') + ':name'); + console.log(column); + filter.find('input').on('keyup change', function() { + var value = null + if(filter.hasClass('bound')) { + var lower = filter.find('.lower-bound'); + var upper = filter.find('.upper-bound'); + value = lower.val() + '~' + upper.val(); + } else { + value = $(this).val(); + } + value = filter.attr('data-input-type') + ':' + value; + if(column.search() !== value) { + column.search(value).draw(); + } + }); + }); + + // 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) { $(flash_success).addClass("hidden") $(submit_button).val("Processing") @@ -22,9 +86,11 @@ ready = function() { }).on("ajax:complete", function(xhr, status) { $(submit_button).val("Send it") $(submit_button).attr('disabled', false); + table.ajax.reload(); }) } + $.ajaxSetup({ dataType: 'text' }) diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss index 0e61ec8..ca2d83d 100644 --- a/app/assets/stylesheets/users.css.scss +++ b/app/assets/stylesheets/users.css.scss @@ -30,7 +30,10 @@ table.pure-table-striped { } } -.data-table-filters { +#transactions-filters { + .panel-heading { + cursor: pointer; + } .row { padding: 10px; padding-top: 20px; @@ -42,3 +45,7 @@ table.pure-table-striped { } } } + +#s2id_transaction_creditor { + min-width: 150px; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b126fc6..44864a9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,7 +15,8 @@ class ApplicationController < ActionController::Base end def current_client - @current_client ||= Client.find_by key: request.headers["X-API-KEY"] + Client.find_by key: request.headers.inspect.to_s + @current_client ||= Client.find_by key: (request.headers["X_API_KEY"] || request.headers["HTTP_X_API_KEY"]) end def current_ability @@ -23,4 +24,8 @@ class ApplicationController < ActionController::Base current_client.try { |c| ClientAbility.new(c) } || UserAbility.new(current_user) end + + def after_sign_in_path_for(resource) + current_user + end end diff --git a/app/controllers/concerns/data_table.rb b/app/controllers/concerns/data_table.rb index bc9468b..3ce4dde 100644 --- a/app/controllers/concerns/data_table.rb +++ b/app/controllers/concerns/data_table.rb @@ -16,13 +16,11 @@ class DataTable end private def data - run_query(paginated_query.project(Arel.star)).map do |record| - record.reject! {|k,v| k.is_a? Numeric} # Remove unneeded query results - end + run_query(paginated_query.project(Arel.star)) end def count - run_query(query.project(Arel.star.count)).first[0] + run_query(query.project(Arel.star.count)).first["COUNT(*)"] end def paginated_query @@ -64,7 +62,7 @@ class DataTable end def run_query query - ActiveRecord::Base.connection.execute(query.to_sql) + ActiveRecord::Base.connection.exec_query(query.to_sql) end def sanitize_params(params) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 897b33c..1dd2d96 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -14,6 +14,9 @@ - if current_user %li.pure-menu-item = link_to current_user.name.capitalize, current_user, class: "pure-menu-link" + - if current_user.penning + %li.pure-menu-item + =link_to "Zeus", User.zeus, class: "pure-menu-link" - else = link_to "Sign in", user_omniauth_authorize_path(:zeuswpi), class: "pure-menu-link" unless current_user .pure-u-1 diff --git a/app/views/transactions/_new.html.haml b/app/views/transactions/_new.html.haml index 37a7d02..1df3aee 100644 --- a/app/views/transactions/_new.html.haml +++ b/app/views/transactions/_new.html.haml @@ -7,7 +7,7 @@ = f.select :creditor, options_from_collection_for_select(User.all.order(:name), :name, :name), { include_blank: true }, - { class: 'select2-selector form-control', size: 50, required: true } + { class: 'select2-selector', size: 50, required: true, data: { placeholder: "Creditor" } } = f.text_field :message, placeholder: "Message", size: 75, class: "form-control", required: true .input-group %span.input-group-addon @@ -15,4 +15,4 @@ = f.number_field :euros, value: amount(@transaction.amount), placeholder: "Bedrag", step: 0.01, min: (0.01 unless current_user.penning), class: "form-control", size: 20, required: true - = f.submit "Send it!", class: "pure-button pure-button-primary" + = f.submit "Send it!", class: "pure-button pure-button-primary btn" diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 1e5da96..2c69085 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -2,46 +2,57 @@ = render 'transactions/new' -.panel.panel-default.data-table-filters +#transactions-filters.panel.panel-default .panel-heading %h3.panel-title Filters .panel-body .row .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 .col-md-6 .input-group %span.input-group-addon %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 .input-group %span.input-group-addon %span.glyphicon.glyphicon-calendar - %input.upper-bound.form-control.filter-align{type: 'date', placeholder: 'Before', class: 'pure-group-addon'} - .bound.input-listen.pure-u-1{ 'data-input-type': 'number-range', 'data-filter-name': 'Amount' } + %input.upper-bound.form-control.filter-align{type: 'date', + placeholder: 'Before', class: 'pure-group-addon'} + .bound.input-listen.pure-u-1{ 'data-input-type': 'number-range', + 'data-filter-name': 'Amount' } .row .col-md-6 .input-group %span.input-group-addon %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 .input-group %span.input-group-addon %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 .col-md-4 .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Issuer' } - %input{type: 'text', placeholder: 'Filter on Issuer', class: "form-control" } + = grouped_collection_select nil, nil, [User, Client], :all, :name, :name, :name, + { include_blank: true }, + { data: { placeholder: "Filter on Issuer" }, class: "select2-selector form-control" } .col-md-4 .input-listen{ 'data-input-type': 'text', 'data-filter-name': 'Peer' } - %input{type: 'text', placeholder: 'Filter on Peer', class: "form-control" } + = select_tag nil, + options_from_collection_for_select(User.all.order(:name), :name, :name), + include_blank: true, class: "select2-selector form-control", data: { placeholder: "Filter on Peer" } .col-md-4 .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) }} %thead @@ -52,62 +63,3 @@ %th Issuer %th Message %tbody - -:javascript - $(document).ready(function() { - var table = $('#transactions').DataTable({ - processing: true, - serverSide: true, - searching: true, - lengthChange: false, - ordering: false, - ajax: $('#transactions').data('source'), - pagingType: 'full_numbers', - autoWidth: false, - responsive: true, - columns: [ - { data: 'time', name: 'Time', width: "15%", className: 'min-tablet-l'}, - { data: 'amount', name: 'Amount', width: "10%", className: 'min-mobile'}, - { data: 'peer', name: 'Peer', width: "15%", className: 'min-mobile'}, - { data: 'issuer', name: 'Issuer', width: "15%", className: 'min-desktop'}, - { data: 'message', name: 'Message', width: "45%", className: 'min-tablet-p'} - ], - columnDefs: [ - { - targets: 0, - render: function(data, type, full, meta) { - return $.format.date(data, 'E dd/MM/yyyy HH:mm'); - } - }, - { - targets: 1, - render: function(data, type, full, meta) { - return (data/100).toFixed(2); - } - } - ] - }); - - $('.dataTables_filter').hide(); - - $('.input-listen').each(function(index, element) { - var filter = $(element); - var type = filter.attr('data-input-type'); - var column = table.column(filter.attr('data-filter-name') + ':name'); - console.log(column); - filter.find('input').on('keyup change', function() { - var value = null - if(filter.hasClass('bound')) { - var lower = filter.find('.lower-bound'); - var upper = filter.find('.upper-bound'); - value = lower.val() + '~' + upper.val(); - } else { - value = $(this).val(); - } - value = filter.attr('data-input-type') + ':' + value; - if(column.search() !== value) { - column.search(value).draw(); - } - }); - }); - }); diff --git a/config/deploy.rb b/config/deploy.rb index e9fb683..13c1bfa 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -29,7 +29,7 @@ set :deploy_to, '/home/tab/production' set :linked_files, %w{config/database.yml config/secrets.yml} # Default value for linked_dirs is [] -set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} +set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} # Default value for default_env is {} # set :default_env, { path: "/opt/ruby/bin:$PATH" } diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 52ad315..4224ad9 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -7,3 +7,4 @@ server 'zeus.ugent.be', user: 'tab', roles: %w{web app db}, ssh_options: { set :rails_env, 'production' set :rbenv_type, :system set :rbenv_ruby, File.read('.ruby-version').strip +set :default_env, 'RAILS_RELATIVE_URL_ROOT' => '/tab' diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index d54ff64..cd6e844 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,4 +1,4 @@ -server 'king.ugent.be', user: 'tap', roles: %w{web app db}, ssh_options: { +server 'king.ugent.be', user: 'tab', roles: %w{web app db}, ssh_options: { forward_agent: true, auth_methods: ['publickey'], port: 2222 diff --git a/lib/tasks/devseed.rake b/lib/tasks/devseed.rake index eccac63..041998f 100644 --- a/lib/tasks/devseed.rake +++ b/lib/tasks/devseed.rake @@ -1,11 +1,11 @@ -require 'factory_girl' -require 'faker' - -task :sow => :environment do - users = FactoryGirl.create_list(:user, 20) - 100.times do - sample_users = users.sample(2) - FactoryGirl.create :transaction, debtor: sample_users[0], creditor: sample_users[1], amount: 1 + rand(100) +unless Rails.env.production? + require 'factory_girl' + require 'faker' + task :sow => :environment do + users = FactoryGirl.create_list(:user, 20) + 100.times do + sample_users = users.sample(2) + FactoryGirl.create :transaction, debtor: sample_users[0], creditor: sample_users[1], amount: 1 + rand(100) + end end end -