diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 33b3980a..f003ab31 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -31,7 +31,7 @@ class AccountsController < ApplicationController family.sync_later end - redirect_to accounts_path + redirect_back_or_to accounts_path end private diff --git a/app/controllers/rules_controller.rb b/app/controllers/rules_controller.rb index ed1f1f46..a5661508 100644 --- a/app/controllers/rules_controller.rb +++ b/app/controllers/rules_controller.rb @@ -38,7 +38,7 @@ class RulesController < ApplicationController def apply @rule.update!(active: true) - @rule.apply_later + @rule.apply_later(ignore_attribute_locks: true) redirect_back_or_to rules_path, notice: "#{@rule.resource_type.humanize} rule activated" end diff --git a/app/controllers/transaction_categories_controller.rb b/app/controllers/transaction_categories_controller.rb index b02ca194..dac6b5be 100644 --- a/app/controllers/transaction_categories_controller.rb +++ b/app/controllers/transaction_categories_controller.rb @@ -15,14 +15,17 @@ class TransactionCategoriesController < ApplicationController } end + transaction.lock_saved_attributes! + @entry.lock_saved_attributes! + respond_to do |format| format.html { redirect_back_or_to transaction_path(@entry) } format.turbo_stream do render turbo_stream: [ turbo_stream.replace( - dom_id(@entry, :category_menu), + dom_id(transaction, :category_menu), partial: "categories/menu", - locals: { transaction: @entry.transaction } + locals: { transaction: transaction } ), *flash_notification_stream_items ] diff --git a/app/javascript/controllers/rule/conditions_controller.js b/app/javascript/controllers/rule/conditions_controller.js index a3ebdce9..63dcd17a 100644 --- a/app/javascript/controllers/rule/conditions_controller.js +++ b/app/javascript/controllers/rule/conditions_controller.js @@ -54,8 +54,8 @@ export default class extends Controller { for (const operator of conditionFilter.operators) { const optionEl = document.createElement("option"); - optionEl.value = operator; - optionEl.textContent = operator; + optionEl.value = operator[1]; + optionEl.textContent = operator[0]; this.operatorSelectTarget.appendChild(optionEl); } } diff --git a/app/jobs/rule_job.rb b/app/jobs/rule_job.rb index 8b17d140..d7bbcd2d 100644 --- a/app/jobs/rule_job.rb +++ b/app/jobs/rule_job.rb @@ -1,7 +1,7 @@ class RuleJob < ApplicationJob queue_as :default - def perform(rule) - rule.apply + def perform(rule, ignore_attribute_locks: false) + rule.apply(ignore_attribute_locks: ignore_attribute_locks) end end diff --git a/app/models/rule.rb b/app/models/rule.rb index a02fab23..812dbff0 100644 --- a/app/models/rule.rb +++ b/app/models/rule.rb @@ -40,14 +40,14 @@ class Rule < ApplicationRecord matching_resources_scope.count end - def apply + def apply(ignore_attribute_locks: false) actions.each do |action| - action.apply(matching_resources_scope) + action.apply(matching_resources_scope, ignore_attribute_locks: ignore_attribute_locks) end end - def apply_later - RuleJob.perform_later(self) + def apply_later(ignore_attribute_locks: false) + RuleJob.perform_later(self, ignore_attribute_locks: ignore_attribute_locks) end private diff --git a/app/models/rule/condition_filter.rb b/app/models/rule/condition_filter.rb index 48655982..492dbc8f 100644 --- a/app/models/rule/condition_filter.rb +++ b/app/models/rule/condition_filter.rb @@ -4,9 +4,9 @@ class Rule::ConditionFilter TYPES = [ "text", "number", "select" ] OPERATORS_MAP = { - "text" => [ "like", "=" ], - "number" => [ ">", ">=", "<", "<=", "=" ], - "select" => [ "=" ] + "text" => [ [ "Contains", "like" ], [ "Equal to", "=" ] ], + "number" => [ [ "Greater than", ">" ], [ "Greater or equal to", ">=" ], [ "Less than", "<" ], [ "Less than or equal to", "<=" ], [ "Is equal to", "=" ] ], + "select" => [ [ "Equal to", "=" ] ] } def initialize(rule) @@ -70,7 +70,7 @@ class Rule::ConditionFilter end def sanitize_operator(operator) - raise UnsupportedOperatorError, "Unsupported operator: #{operator} for type: #{type}" unless operators.include?(operator) + raise UnsupportedOperatorError, "Unsupported operator: #{operator} for type: #{type}" unless operators.map(&:last).include?(operator) if operator == "like" "ILIKE" diff --git a/app/views/rule/actions/_action.html.erb b/app/views/rule/actions/_action.html.erb index 0af732c3..22d3fbbe 100644 --- a/app/views/rule/actions/_action.html.erb +++ b/app/views/rule/actions/_action.html.erb @@ -8,9 +8,11 @@ <%= form.hidden_field :_destroy, value: false, data: { rule__actions_target: "destroyField" } %>
<%= rule.actions.first.executor.label %>
diff --git a/app/views/transactions/index.html.erb b/app/views/transactions/index.html.erb
index e563aaf9..14d5fa6b 100644
--- a/app/views/transactions/index.html.erb
+++ b/app/views/transactions/index.html.erb
@@ -4,6 +4,11 @@