mirror of
https://github.com/we-promise/sure.git
synced 2026-05-08 05:04:59 +00:00
* feat: remember chart period by last selection not user preferences * feat: schema update * fix: revert unnecessary parts of schema.rb update * fix: check period key is valid before setting it * revert: no database changes and keep the UI setting * refactor: don't store the default period in the session, just use the user * fix: migration The migration uses the User model directly, which loads all current enums including ui_layout which doesn't exist yet at that point in migration history. Fix it with raw SQL. * revert: not relevant to this PR
28 lines
688 B
Ruby
28 lines
688 B
Ruby
module Periodable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
before_action :set_period
|
|
end
|
|
|
|
private
|
|
def set_period
|
|
if params[:period].present?
|
|
period_key = params[:period]
|
|
Current.user&.update!(default_period: period_key) if Period.valid_key?(period_key)
|
|
else
|
|
period_key = Current.user&.default_period
|
|
end
|
|
|
|
@period = if period_key == "current_month"
|
|
Period.current_month_for(Current.family)
|
|
elsif period_key == "last_month"
|
|
Period.last_month_for(Current.family)
|
|
else
|
|
Period.from_key(period_key)
|
|
end
|
|
rescue Period::InvalidKeyError
|
|
@period = Period.last_30_days
|
|
end
|
|
end
|