mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
* Add ability to name a rule * Add sorting by name and date, * Improve rule page and form design * Small header tweak * Improve sorting click areas by including icon * Fix brakeman * Use icon helper instead of lucide_icon helper * Fix double headers with new DialogComponent * Use updated_at for sorting instead of created_at * Use copy-plus icon for compound rules * Remove icons and change IF/THEN/FOR font in edit form * Use text-secondary on disabled rules * First pass at redesigning the sorting menu * New rule list * Borders instead of shadows * Apply proper text color to TO in edit form * Improve dark mode with proper background color classes * Use border-secondary * Add touch: true to conditions and actions of a rule, so updated_at works as expected * Fix db schema * Change sort direction to be a LinkComponent outside of the form for better sort behavior * Clean up dropdown design to match figma * Match tags/categories design * Fix name text color, add bg-divider background for dividers * Fix family subscription tests (thanks zach!)
84 lines
2.1 KiB
Ruby
84 lines
2.1 KiB
Ruby
class RulesController < ApplicationController
|
|
include StreamExtensions
|
|
|
|
before_action :set_rule, only: [ :edit, :update, :destroy, :apply, :confirm ]
|
|
|
|
def index
|
|
@sort_by = params[:sort_by] || "name"
|
|
@direction = params[:direction] || "asc"
|
|
|
|
allowed_columns = [ "name", "updated_at" ]
|
|
@sort_by = "name" unless allowed_columns.include?(@sort_by)
|
|
@direction = "asc" unless [ "asc", "desc" ].include?(@direction)
|
|
|
|
@rules = Current.family.rules.order(@sort_by => @direction)
|
|
render layout: "settings"
|
|
end
|
|
|
|
def new
|
|
@rule = Current.family.rules.build(
|
|
resource_type: params[:resource_type] || "transaction",
|
|
)
|
|
end
|
|
|
|
def create
|
|
@rule = Current.family.rules.build(rule_params)
|
|
|
|
if @rule.save
|
|
redirect_to confirm_rule_path(@rule)
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def apply
|
|
@rule.update!(active: true)
|
|
@rule.apply_later(ignore_attribute_locks: true)
|
|
redirect_back_or_to rules_path, notice: "#{@rule.resource_type.humanize} rule activated"
|
|
end
|
|
|
|
def confirm
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if @rule.update(rule_params)
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to rules_path, notice: "Rule updated" }
|
|
format.turbo_stream { stream_redirect_back_or_to rules_path, notice: "Rule updated" }
|
|
end
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@rule.destroy
|
|
redirect_to rules_path, notice: "Rule deleted"
|
|
end
|
|
|
|
def destroy_all
|
|
Current.family.rules.destroy_all
|
|
redirect_to rules_path, notice: "All rules deleted"
|
|
end
|
|
|
|
private
|
|
def set_rule
|
|
@rule = Current.family.rules.find(params[:id])
|
|
end
|
|
|
|
def rule_params
|
|
params.require(:rule).permit(
|
|
:resource_type, :effective_date, :active, :name,
|
|
conditions_attributes: [
|
|
:id, :condition_type, :operator, :value, :_destroy,
|
|
sub_conditions_attributes: [ :id, :condition_type, :operator, :value, :_destroy ]
|
|
],
|
|
actions_attributes: [
|
|
:id, :action_type, :value, :_destroy
|
|
]
|
|
)
|
|
end
|
|
end
|