Skip to content

Commit

Permalink
Merge branch 'hotfix/v1.8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
odinsride committed Aug 1, 2021
2 parents 2d1dd36 + 559f7b0 commit dc4d9b2
Show file tree
Hide file tree
Showing 21 changed files with 334 additions and 81 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] changes

## [v1.8.2] - 2021-07-31

### Fixed
- Re-added Stimulus Reflex dependencies that were erroneously removed due to a bad merge

### Chores
- Update all dependencies

## [v1.8.1] - 2021-07-24

### New
Expand Down Expand Up @@ -269,7 +277,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Account overview with list of all accounts and balances for each


[Unreleased]: https://github.com/odinsride/olubalance/compare/v1.8.1...develop
[Unreleased]: https://github.com/odinsride/olubalance/compare/v1.8.2...develop
[v1.8.2]: https://github.com/odinsride/olubalance/compare/v1.8.1...v1.8.2
[v1.8.1]: https://github.com/odinsride/olubalance/compare/v1.8.0...v1.8.1
[v1.8.0]: https://github.com/odinsride/olubalance/compare/v1.7.3...v1.8.0
[v1.7.3]: https://github.com/odinsride/olubalance/compare/v1.7.2...v1.7.3
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -24,6 +24,7 @@ gem 'puma', '~> 5.1.1'
gem 'rails', '~> 6.1.0'
gem 'recaptcha', '~> 5.6.0'
gem 'redis', '>= 4.0', require: ['redis', 'redis/connection/hiredis']
gem 'stimulus_reflex', '~> 3.4.0'
gem 'webpacker', '~> 5.2.1'

group :development, :test do
Expand Down
27 changes: 18 additions & 9 deletions Gemfile.lock
Expand Up @@ -68,14 +68,14 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
aws-eventstream (1.1.1)
aws-partitions (1.479.0)
aws-sdk-core (3.117.0)
aws-partitions (1.482.0)
aws-sdk-core (3.119.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.44.0)
aws-sdk-core (~> 3, >= 3.112.0)
aws-sdk-kms (1.46.0)
aws-sdk-core (~> 3, >= 3.119.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.87.0)
aws-sdk-core (~> 3, >= 3.109.0)
Expand All @@ -92,6 +92,8 @@ GEM
debug_inspector (>= 0.0.1)
builder (3.2.4)
byebug (11.1.3)
cable_ready (4.4.6)
rails (>= 5.2)
capybara (3.35.3)
addressable
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -133,8 +135,8 @@ GEM
figaro (1.2.0)
thor (>= 0.14.0, < 2)
foreman (0.87.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
globalid (0.5.1)
activesupport (>= 5.0)
hiredis (0.6.3)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -227,7 +229,7 @@ GEM
ffi (~> 1.0)
recaptcha (5.6.0)
json
redis (4.3.1)
redis (4.4.0)
regexp_parser (2.1.1)
request_store (1.5.0)
rack (>= 1.4)
Expand All @@ -252,13 +254,13 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubocop (1.18.3)
rubocop (1.18.4)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.7.0, < 2.0)
rubocop-ast (>= 1.8.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.8.0)
Expand Down Expand Up @@ -297,6 +299,12 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stimulus_reflex (3.4.0)
cable_ready (>= 4.4)
nokogiri
rack
rails (>= 5.2)
redis
thor (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -358,6 +366,7 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-watcher-listen
stimulus_reflex (~> 3.4.0)
webdrivers
webpacker (~> 5.2.1)

Expand Down
15 changes: 15 additions & 0 deletions app/channels/application_cable/connection.rb
Expand Up @@ -2,5 +2,20 @@

module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user

def connect
self.current_user = find_verified_user
end

protected

def find_verified_user
if (current_user = env['warden'].user)
current_user
else
reject_unauthorized_connection
end
end
end
end
21 changes: 19 additions & 2 deletions app/controllers/transactions_controller.rb
Expand Up @@ -10,8 +10,17 @@ class TransactionsController < ApplicationController

# Index action to render all transactions
def index
@transactions = @account.transactions.search(params[:description]).with_balance.desc
@pagy, @transactions = pagy(@transactions, page: session[:trx_index_page], items: 15)
@query = session[:query]
@order_by = permitted_column_name(session[:order_by])
@direction = permitted_direction(session[:direction])
@page = (session[:page] || 1).to_i

transactions = @account.transactions.order(pending: :desc, @order_by => @direction, id: :desc)
transactions = transactions.search(@query) if @query.present?
pages = (transactions.count / Pagy::VARS[:items].to_f).ceil

@page = 1 if @page > pages
@pagy, @transactions = pagy(transactions, page: @page)
@transactions = @transactions.decorate

@stashes = @account.stashes.order(id: :asc).decorate
Expand Down Expand Up @@ -81,6 +90,14 @@ def destroy

private

def permitted_column_name(column_name)
%w[trx_date description amount].find { |permitted| column_name == permitted } || 'trx_date'
end

def permitted_direction(direction)
%w[asc desc].find { |permitted| direction == permitted } || 'desc'
end

def transaction_params
params.require(:transaction) \
.permit(:trx_date, :description, :amount, :trx_type, :memo, :attachment, :page, :pending, :locked, :transfer)
Expand Down
28 changes: 28 additions & 0 deletions app/helpers/transactions_helper.rb
Expand Up @@ -2,4 +2,32 @@

module TransactionsHelper
include Pagy::Frontend

def column_css(column_name)
return 'has-text-white sortable sort-selected' if column_name.to_s == @order_by

'has-text-white sortable'
end

def arrow(column_name)
return 'fa-sort' if column_name.to_s != @order_by

@direction == 'desc' ? 'fa-sort-down' : 'fa-sort-up'
end

def direction
@direction == 'asc' ? 'desc' : 'asc'
end

def pagy_get_params(params)
params.merge query: @query, order_by: @order_by, direction: @direction
end

def prev_page
@pagy.prev || 1
end

def next_page
@pagy.next || @pagy.last
end
end
6 changes: 6 additions & 0 deletions app/javascript/channels/consumer.js
@@ -0,0 +1,6 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.

import { createConsumer } from '@rails/actioncable'

export default createConsumer()
5 changes: 5 additions & 0 deletions app/javascript/channels/index.js
@@ -0,0 +1,5 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.

const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
32 changes: 32 additions & 0 deletions app/javascript/controllers/application_controller.js
@@ -1,4 +1,5 @@
import { Controller } from 'stimulus'
import StimulusReflex from 'stimulus_reflex'

/* This is your application's ApplicationController.
* All StimulusReflex controllers should inherit from this class.
Expand All @@ -13,5 +14,36 @@ import { Controller } from 'stimulus'
*/
export default class extends Controller {
connect () {
StimulusReflex.register(this)
}

/* Application wide lifecycle methods.
* Use these methods to handle lifecycle concerns for the entire application.
* Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
*
* Arguments:
*
* element - the element that triggered the reflex
* may be different than the Stimulus controller's this.element
*
* reflex - the name of the reflex e.g. "ExampleReflex#demo"
*
* error - error message from the server
*/

beforeReflex (element, reflex) {
// document.body.classList.add('wait')
}

reflexSuccess (element, reflex, error) {
// show success message etc...
}

reflexError (element, reflex, error) {
// show error message etc...
}

afterReflex (element, reflex) {
// document.body.classList.remove('wait')
}
}
4 changes: 4 additions & 0 deletions app/javascript/controllers/index.js
Expand Up @@ -3,7 +3,11 @@

import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"
import StimulusReflex from 'stimulus_reflex'
import consumer from '../channels/consumer'
import controller from './application_controller'

const application = Application.start()
const context = require.context("controllers", true, /_controller\.js$/)
application.load(definitionsFromContext(context))
StimulusReflex.initialize(application, { consumer, controller, debug: false })
2 changes: 2 additions & 0 deletions app/javascript/packs/application.js
@@ -1,7 +1,9 @@
// Core libraries
require("turbolinks").start()
require("@rails/ujs").start()
require("@rails/actioncable")
require("@rails/activestorage").start()
require("channels")
require.context("../application/images", true)

import "@fortawesome/fontawesome-free/js/all"
Expand Down
13 changes: 6 additions & 7 deletions app/models/transaction.rb
Expand Up @@ -33,13 +33,12 @@ class Transaction < ApplicationRecord
scope :current_day, -> { where('created_at > ?', 18.hours.ago) }
scope :pending, -> { where(pending: true) }

def self.search(description)
if description
where('description ILIKE ?', "%#{description}%")
else
all
end
end
scope :search, lambda { |query|
query = sanitize_sql_like(query)
where(arel_table[:description]
.lower
.matches("%#{query.downcase}%"))
}

# Determine the transaction_type for existing records based on amount
def transaction_type
Expand Down
15 changes: 15 additions & 0 deletions app/reflexes/application_reflex.rb
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class ApplicationReflex < StimulusReflex::Reflex
# Put application wide Reflex behavior in this file.
#
# Example:
#
# # If your ActionCable connection is: `identified_by :current_user`
# delegate :current_user, to: :connection
#
# Learn more at: https://docs.stimulusreflex.com

# Devise authentication for stimulus reflex
delegate :current_user, to: :connection
end
21 changes: 21 additions & 0 deletions app/reflexes/transaction_reflex.rb
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# Reflex for Transactions to allow various functionality in the transaction list
class TransactionReflex < ApplicationReflex
def search
session[:query] = element[:value].strip
end

def search_reset
session[:query] = ''
end

def order
session[:order_by] = element.dataset['column-name']
session[:direction] = element.dataset['direction']
end

def paginate
session[:page] = element.dataset[:page].to_i
end
end
7 changes: 4 additions & 3 deletions app/views/transactions/components/_pagination.html.erb
Expand Up @@ -3,16 +3,17 @@


<nav class="pagination is-centered" role="navigation" aria-label="pagination">
<a class="pagination-previous" href="#"></a>
<a class="pagination-next" href="#"></a>
<a class="pagination-previous" href="#" data-reflex="click->TransactionReflex#paginate" data-page="<%= prev_page %>"></a>
<a class="pagination-next" href="#" data-reflex="click->TransactionReflex#paginate" data-page="<%= next_page %>"></a>
<ul class="pagination-list">
<% @pagy.series.each do |item| %>
<% if item == :gap %>
<li><span class="pagination-ellipsis">&hellip;</span></li>
<% else %>
<li>
<a href="#"
class="pagination-link"
class="pagination-link <%= "is-current" if item.is_a?(String) %>"
data-reflex="click->TransactionReflex#paginate"
data-page="<%= item %>">
<%= item %>
</a>
Expand Down
11 changes: 6 additions & 5 deletions app/views/transactions/components/_search.html.erb
Expand Up @@ -7,11 +7,12 @@
<div class="level-item" id="transaction-search">
<div class="field">
<div class="control has-icons-right">
<input type="text" placeholder="Find transactions..." class="input" />
<a href='#'>
<span class="icon is-right" style="pointer-events: initial">
<i class="fas fa-times"></i>
</span>
<input type="text" placeholder="Find transactions..." class="input" value="<%= @query %>"
data-reflex="input->TransactionReflex#search" data-reflex-root="#search-results" />
<a href='#' data-reflex="click->TransactionReflex#search_reset" data-reflex-root="#search-results">
<span class="icon is-right" style="pointer-events: initial">
<i class="fas fa-times"></i>
</span>
</a>
</div>
</div>
Expand Down

0 comments on commit dc4d9b2

Please sign in to comment.