mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Preference to set default_period (#1941)
This commit is contained in:
parent
372b64ffea
commit
26762477a3
12 changed files with 35 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
class AccountsController < ApplicationController
|
||||
before_action :set_account, only: %i[sync chart sparkline]
|
||||
include Periodable
|
||||
|
||||
def index
|
||||
@manual_accounts = family.accounts.manual.alphabetically
|
||||
|
|
|
@ -2,7 +2,7 @@ module AccountableResource
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include ScrollFocusable
|
||||
include ScrollFocusable, Periodable
|
||||
|
||||
before_action :set_account, only: [ :show, :edit, :update, :destroy ]
|
||||
before_action :set_link_token, only: :new
|
||||
|
|
14
app/controllers/concerns/periodable.rb
Normal file
14
app/controllers/concerns/periodable.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module Periodable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :set_period
|
||||
end
|
||||
|
||||
private
|
||||
def set_period
|
||||
@period = Period.from_key(params[:period] || Current.user&.default_period)
|
||||
rescue Period::InvalidKeyError
|
||||
@period = Period.last_30_days
|
||||
end
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
class PagesController < ApplicationController
|
||||
skip_before_action :authenticate_user!, only: %i[early_access]
|
||||
include Periodable
|
||||
|
||||
def dashboard
|
||||
@period = params[:period] ? Period.from_key(params[:period]) : Period.last_30_days
|
||||
@balance_sheet = Current.family.balance_sheet
|
||||
@accounts = Current.family.accounts.active.with_attached_logo
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class UsersController < ApplicationController
|
|||
|
||||
def user_params
|
||||
params.require(:user).permit(
|
||||
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at, :show_sidebar,
|
||||
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at, :show_sidebar, :default_period,
|
||||
family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id, :data_enrichment_enabled ]
|
||||
)
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@ class User < ApplicationRecord
|
|||
|
||||
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||
validate :ensure_valid_profile_image
|
||||
validates :default_period, inclusion: { in: Period::PERIODS.keys }
|
||||
normalizes :email, with: ->(email) { email.strip.downcase }
|
||||
normalizes :unconfirmed_email, with: ->(email) { email&.strip&.downcase }
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<% period = params[:period] ? Period.from_key(params[:period]) : Period.last_30_days %>
|
||||
<% series = @account.balance_series(period: period) %>
|
||||
<% series = @account.balance_series(period: @period) %>
|
||||
<% trend = series.trend %>
|
||||
|
||||
<%= turbo_frame_tag dom_id(@account, :chart_details) do %>
|
||||
|
@ -13,7 +12,7 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= tag.span period.comparison_label, class: "text-secondary" %>
|
||||
<%= tag.span @period.comparison_label, class: "text-secondary" %>
|
||||
</div>
|
||||
|
||||
<div class="h-64 pb-4">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<%# locals: (account:, title: nil, tooltip: nil, **args) %>
|
||||
|
||||
<% period = params[:period] ? Period.from_key(params[:period]) : Period.last_30_days %>
|
||||
<% period = @period || Period.last_30_days %>
|
||||
<% default_value_title = account.asset? ? t(".balance") : t(".owed") %>
|
||||
|
||||
<div id="<%= dom_id(account, :chart) %>" class="bg-white shadow-xs rounded-xl border border-alpha-black-25 rounded-lg space-y-2">
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
{ label: t(".date_format") },
|
||||
{ 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" } } %>
|
||||
|
||||
<%= family_form.select :country,
|
||||
country_options,
|
||||
{ label: t(".country") },
|
||||
|
|
|
@ -20,6 +20,7 @@ en:
|
|||
date_format: Date format
|
||||
general_subtitle: Configure your preferences
|
||||
general_title: General
|
||||
default_period: Default Period
|
||||
language: Language
|
||||
page_title: Preferences
|
||||
theme_dark: Dark
|
||||
|
|
5
db/migrate/20250304140435_add_default_period_to_users.rb
Normal file
5
db/migrate/20250304140435_add_default_period_to_users.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddDefaultPeriodToUsers < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_column :users, :default_period, :string, default: "last_30_days", null: false
|
||||
end
|
||||
end
|
3
db/schema.rb
generated
3
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_03_03_141007) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_03_04_140435) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -675,6 +675,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_03_03_141007) do
|
|||
t.boolean "otp_required", default: false, null: false
|
||||
t.string "otp_backup_codes", default: [], array: true
|
||||
t.boolean "show_sidebar", default: true
|
||||
t.string "default_period", default: "last_30_days", null: false
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["family_id"], name: "index_users_on_family_id"
|
||||
t.index ["otp_secret"], name: "index_users_on_otp_secret", unique: true, where: "(otp_secret IS NOT NULL)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue