mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
87 lines
2.3 KiB
Ruby
87 lines
2.3 KiB
Ruby
class CategoriesController < ApplicationController
|
|
before_action :set_category, only: %i[edit update destroy]
|
|
before_action :set_categories, only: %i[update edit]
|
|
before_action :set_transaction, only: :create
|
|
|
|
def index
|
|
@categories = Current.family.categories.alphabetically
|
|
|
|
render layout: "settings"
|
|
end
|
|
|
|
def new
|
|
@category = Current.family.categories.new color: Category::COLORS.sample
|
|
set_categories
|
|
end
|
|
|
|
def create
|
|
@category = Current.family.categories.new(category_params)
|
|
|
|
if @category.save
|
|
@transaction.update(category_id: @category.id) if @transaction
|
|
|
|
flash[:notice] = t(".success")
|
|
|
|
redirect_target_url = request.referer || categories_path
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to categories_path, notice: t(".success") }
|
|
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
|
|
end
|
|
else
|
|
set_categories
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if @category.update(category_params)
|
|
flash[:notice] = t(".success")
|
|
|
|
redirect_target_url = request.referer || categories_path
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to categories_path, notice: t(".success") }
|
|
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
|
|
end
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@category.destroy
|
|
|
|
redirect_back_or_to categories_path, notice: t(".success")
|
|
end
|
|
|
|
def bootstrap
|
|
Current.family.categories.bootstrap_defaults
|
|
|
|
redirect_back_or_to categories_path, notice: t(".success")
|
|
end
|
|
|
|
private
|
|
def set_category
|
|
@category = Current.family.categories.find(params[:id])
|
|
end
|
|
|
|
def set_categories
|
|
@categories = unless @category.parent?
|
|
Current.family.categories.alphabetically.roots.where.not(id: @category.id)
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
|
|
def set_transaction
|
|
if params[:transaction_id].present?
|
|
@transaction = Current.family.transactions.find(params[:transaction_id])
|
|
end
|
|
end
|
|
|
|
def category_params
|
|
params.require(:category).permit(:name, :color, :parent_id, :classification, :lucide_icon)
|
|
end
|
|
end
|