mirror of
https://github.com/we-promise/sure
synced 2026-04-25 17:15:07 +02:00
Feature: remember value of chart period selector (#1528)
* 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
This commit is contained in:
@@ -7,7 +7,12 @@ module Periodable
|
|||||||
|
|
||||||
private
|
private
|
||||||
def set_period
|
def set_period
|
||||||
period_key = params[:period] || Current.user&.default_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 = if period_key == "current_month"
|
||||||
Period.current_month_for(Current.family)
|
Period.current_month_for(Current.family)
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ class Period
|
|||||||
}
|
}
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
def valid_key?(key)
|
||||||
|
PERIODS.key?(key)
|
||||||
|
end
|
||||||
|
|
||||||
def from_key(key)
|
def from_key(key)
|
||||||
unless PERIODS.key?(key)
|
unless PERIODS.key?(key)
|
||||||
raise InvalidKeyError, "Invalid period key: #{key}"
|
raise InvalidKeyError, "Invalid period key: #{key}"
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
Family::DATE_FORMATS,
|
Family::DATE_FORMATS,
|
||||||
{ label: t(".date_format") },
|
{ label: t(".date_format") },
|
||||||
{ data: { auto_submit_form_target: "auto" } } %>
|
{ data: { auto_submit_form_target: "auto" } } %>
|
||||||
<%= form.select :default_period,
|
|
||||||
Period.all.map { |period| [ period.label, period.key ] },
|
|
||||||
{ label: t(".default_period") },
|
|
||||||
{ data: { auto_submit_form_target: "auto" } } %>
|
|
||||||
<%= form.select :default_account_order,
|
<%= form.select :default_account_order,
|
||||||
AccountOrder.all.map { |order| [ order.label, order.key ] },
|
AccountOrder.all.map { |order| [ order.label, order.key ] },
|
||||||
{ label: t(".default_account_order") },
|
{ label: t(".default_account_order") },
|
||||||
|
|||||||
Reference in New Issue
Block a user